Public Member Functions | |
def | __enter__ |
def | __exit__ |
def | __getattr__ |
def | __init__ |
def | __setattr__ |
def | close |
def | closed |
def | write |
def | writelines |
Static Public Attributes | |
tuple | chunk_size |
tuple | content_type = _create_property("contentType", "Mime-type for this file.") |
tuple | filename = _create_property("filename", "Name of this file.") |
tuple | length |
tuple | md5 |
tuple | upload_date |
Private Member Functions | |
def | __flush |
def | __flush_buffer |
def | __flush_data |
Private Attributes | |
_buffer | |
_closed | |
Static Private Attributes | |
tuple | _id |
Class to write data to GridFS.
Definition at line 78 of file grid_file.py.
def gridfs::grid_file::GridIn::__enter__ | ( | self | ) |
Support for the context manager protocol.
Definition at line 293 of file grid_file.py.
def gridfs::grid_file::GridIn::__exit__ | ( | self, | ||
exc_type, | ||||
exc_val, | ||||
exc_tb | ||||
) |
Support for the context manager protocol. Close the file and allow exceptions to propogate.
Definition at line 298 of file grid_file.py.
def gridfs::grid_file::GridIn::__flush | ( | self | ) | [private] |
Flush the file to the database.
Definition at line 196 of file grid_file.py.
def gridfs::grid_file::GridIn::__flush_buffer | ( | self | ) | [private] |
Flush the buffer contents out to a chunk.
Definition at line 189 of file grid_file.py.
def gridfs::grid_file::GridIn::__flush_data | ( | self, | ||
data | ||||
) | [private] |
Flush `data` to a chunk.
Definition at line 174 of file grid_file.py.
def gridfs::grid_file::GridIn::__getattr__ | ( | self, | ||
name | ||||
) |
Definition at line 163 of file grid_file.py.
def gridfs::grid_file::GridIn::__init__ | ( | self, | ||
root_collection, | ||||
kwargs | ||||
) |
Write a file to GridFS Application developers should generally not need to instantiate this class directly - instead see the methods provided by :class:`~gridfs.GridFS`. Raises :class:`TypeError` if `root_collection` is not an instance of :class:`~pymongo.collection.Collection`. Any of the file level options specified in the `GridFS Spec <http://dochub.mongodb.org/core/gridfsspec>`_ may be passed as keyword arguments. Any additional keyword arguments will be set as additional fields on the file document. Valid keyword arguments include: - ``"_id"``: unique ID for this file (default: :class:`~bson.objectid.ObjectId`) - this ``"_id"`` must not have already been used for another file - ``"filename"``: human name for the file - ``"contentType"`` or ``"content_type"``: valid mime-type for the file - ``"chunkSize"`` or ``"chunk_size"``: size of each of the chunks, in bytes (default: 256 kb) - ``"encoding"``: encoding used for this file - any :class:`unicode` that is written to the file will be converted to a :class:`str` with this encoding :Parameters: - `root_collection`: root collection to write to - `**kwargs` (optional): file level options (see above)
Definition at line 81 of file grid_file.py.
def gridfs::grid_file::GridIn::__setattr__ | ( | self, | ||
name, | ||||
value | ||||
) |
Definition at line 168 of file grid_file.py.
def gridfs::grid_file::GridIn::close | ( | self | ) |
Flush the file and close it. A closed file cannot be written any more. Calling :meth:`close` more than once is allowed.
Definition at line 213 of file grid_file.py.
def gridfs::grid_file::GridIn::closed | ( | self | ) |
Is this file closed?
Definition at line 143 of file grid_file.py.
def gridfs::grid_file::GridIn::write | ( | self, | ||
data | ||||
) |
Write data to the file. There is no return value. `data` can be either a string of bytes or a file-like object (implementing :meth:`read`). If the file has an :attr:`encoding` attribute, `data` can also be a :class:`unicode` instance, which will be encoded as :attr:`encoding` before being written. Due to buffering, the data may not actually be written to the database until the :meth:`close` method is called. Raises :class:`ValueError` if this file is already closed. Raises :class:`TypeError` if `data` is not an instance of :class:`str`, a file-like object, or an instance of :class:`unicode` (only allowed if the file has an :attr:`encoding` attribute). :Parameters: - `data`: string of bytes or file-like object to be written to the file .. versionadded:: 1.9 The ability to write :class:`unicode`, if the file has an :attr:`encoding` attribute.
Definition at line 223 of file grid_file.py.
def gridfs::grid_file::GridIn::writelines | ( | self, | ||
sequence | ||||
) |
Write a sequence of strings to the file. Does not add seperators.
Definition at line 285 of file grid_file.py.
gridfs::grid_file::GridIn::_buffer [private] |
Definition at line 194 of file grid_file.py.
gridfs::grid_file::GridIn::_closed [private] |
Definition at line 221 of file grid_file.py.
tuple gridfs::grid_file::GridIn::_id [static, private] |
_create_property("_id", "The ``'_id'`` value for this file.", read_only=True)
Definition at line 148 of file grid_file.py.
tuple gridfs::grid_file::GridIn::chunk_size [static] |
_create_property("chunkSize", "Chunk size for this file.", read_only=True)
Definition at line 154 of file grid_file.py.
tuple gridfs::grid_file::GridIn::content_type = _create_property("contentType", "Mime-type for this file.") [static] |
Definition at line 151 of file grid_file.py.
tuple gridfs::grid_file::GridIn::filename = _create_property("filename", "Name of this file.") [static] |
Definition at line 150 of file grid_file.py.
tuple gridfs::grid_file::GridIn::length [static] |
_create_property("length", "Length (in bytes) of this file.", closed_only=True)
Definition at line 152 of file grid_file.py.
tuple gridfs::grid_file::GridIn::md5 [static] |
_create_property("md5", "MD5 of the contents of this file " "(generated on the server).", closed_only=True)
Definition at line 159 of file grid_file.py.
tuple gridfs::grid_file::GridIn::upload_date [static] |
_create_property("uploadDate", "Date that this file was uploaded.", closed_only=True)
Definition at line 156 of file grid_file.py.