OpenQuizz
Une application de gestion des contenus pédagogiques
GridOut Class Reference
Inheritance diagram for GridOut:
Collaboration diagram for GridOut:

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
 

Detailed Description

Class to read data out of GridFS.

Constructor & Destructor Documentation

◆ __init__()

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.

Member Function Documentation

◆ __enter__()

def __enter__ (   self)
Makes it possible to use :class:`GridOut` files
with the context manager protocol.

◆ __exit__()

def __exit__ (   self,
  exc_type,
  exc_val,
  exc_tb 
)
Makes it possible to use :class:`GridOut` files
with the context manager protocol.

◆ __getattr__()

def __getattr__ (   self,
  name 
)

◆ __iter__()

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.

◆ close()

def close (   self)
Make GridOut more generically file-like.

◆ read()

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.

◆ readable()

def readable (   self)

◆ readchunk()

def readchunk (   self)
Reads a chunk at a time. If the current position is within a
chunk the remainder of the chunk is returned.

◆ readline()

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

◆ seek()

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.

◆ seekable()

def seekable (   self)

◆ tell()

def tell (   self)
Return the current position of this file.

◆ write()

def write (   self,
  value 
)

Field Documentation

◆ aliases

aliases
static

◆ chunk_size

chunk_size
static

◆ content_type

content_type
static

◆ filename

filename
static

◆ length

length
static

◆ md5

md5
static

◆ metadata

metadata
static

◆ name

name
static

◆ upload_date

upload_date
static

The documentation for this class was generated from the following file: