OpenQuizz
Une application de gestion des contenus pédagogiques
|
Public Member Functions | |
def | __init__ (self, root_collection, file_id=None, file_document=None, session=None) |
def | __getattr__ (self, name) |
def | readable (self) |
def | readchunk (self) |
def | read (self, size=-1) |
def | readline (self, size=-1) |
def | tell (self) |
def | seek (self, pos, whence=_SEEK_SET) |
def | seekable (self) |
def | __iter__ (self) |
def | close (self) |
def | write (self, value) |
def | __enter__ (self) |
def | __exit__ (self, exc_type, exc_val, exc_tb) |
Static Public Attributes | |
filename | |
name | |
content_type | |
length | |
chunk_size | |
upload_date | |
aliases | |
metadata | |
md5 | |
Class to read data out of GridFS.
def __init__ | ( | self, | |
root_collection, | |||
file_id = None , |
|||
file_document = None , |
|||
session = None |
|||
) |
Read a file from GridFS Application developers should generally not need to instantiate this class directly - instead see the methods provided by :class:`~gridfs.GridFS`. Either `file_id` or `file_document` must be specified, `file_document` will be given priority if present. Raises :class:`TypeError` if `root_collection` is not an instance of :class:`~pymongo.collection.Collection`. :Parameters: - `root_collection`: root collection to read from - `file_id` (optional): value of ``"_id"`` for the file to read - `file_document` (optional): file document from `root_collection.files` - `session` (optional): a :class:`~pymongo.client_session.ClientSession` to use for all commands .. versionchanged:: 3.8 For better performance and to better follow the GridFS spec, :class:`GridOut` now uses a single cursor to read all the chunks in the file. .. versionchanged:: 3.6 Added ``session`` parameter. .. versionchanged:: 3.0 Creating a GridOut does not immediately retrieve the file metadata from the server. Metadata is fetched when first needed.
def __enter__ | ( | self | ) |
Makes it possible to use :class:`GridOut` files with the context manager protocol.
def __exit__ | ( | self, | |
exc_type, | |||
exc_val, | |||
exc_tb | |||
) |
Makes it possible to use :class:`GridOut` files with the context manager protocol.
def __getattr__ | ( | self, | |
name | |||
) |
def __iter__ | ( | self | ) |
Return an iterator over all of this file's data. The iterator will return chunk-sized instances of :class:`str` (:class:`bytes` in python 3). This can be useful when serving files using a webserver that handles such an iterator efficiently. .. note:: This is different from :py:class:`io.IOBase` which iterates over *lines* in the file. Use :meth:`GridOut.readline` to read line by line instead of chunk by chunk. .. versionchanged:: 3.8 The iterator now raises :class:`CorruptGridFile` when encountering any truncated, missing, or extra chunk in a file. The previous behavior was to only raise :class:`CorruptGridFile` on a missing chunk.
def close | ( | self | ) |
Make GridOut more generically file-like.
def read | ( | self, | |
size = -1 |
|||
) |
Read at most `size` bytes from the file (less if there isn't enough data). The bytes are returned as an instance of :class:`str` (:class:`bytes` in python 3). If `size` is negative or omitted all data is read. :Parameters: - `size` (optional): the number of bytes to read .. versionchanged:: 3.8 This method now only checks for extra chunks after reading the entire file. Previously, this method would check for extra chunks on every call.
def readable | ( | self | ) |
def readchunk | ( | self | ) |
Reads a chunk at a time. If the current position is within a chunk the remainder of the chunk is returned.
def readline | ( | self, | |
size = -1 |
|||
) |
Read one line or up to `size` bytes from the file. :Parameters: - `size` (optional): the maximum number of bytes to read
def seek | ( | self, | |
pos, | |||
whence = _SEEK_SET |
|||
) |
Set the current position of this file. :Parameters: - `pos`: the position (or offset if using relative positioning) to seek to - `whence` (optional): where to seek from. :attr:`os.SEEK_SET` (``0``) for absolute file positioning, :attr:`os.SEEK_CUR` (``1``) to seek relative to the current position, :attr:`os.SEEK_END` (``2``) to seek relative to the file's end.
def seekable | ( | self | ) |
def tell | ( | self | ) |
Return the current position of this file.
def write | ( | self, | |
value | |||
) |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |