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

Public Member Functions

def __init__ (self, root_collection, session=None, disable_md5=False, **kwargs)
 
def abort (self)
 
def closed (self)
 
def __getattr__ (self, name)
 
def __setattr__ (self, name, value)
 
def close (self)
 
def read (self, size=-1)
 
def readable (self)
 
def seekable (self)
 
def write (self, data)
 
def writelines (self, sequence)
 
def writeable (self)
 
def __enter__ (self)
 
def __exit__ (self, exc_type, exc_val, exc_tb)
 

Static Public Attributes

 read_only
 
 filename
 
 name
 
 content_type
 
 length
 
 closed_only
 
 chunk_size
 
 upload_date
 
 md5
 

Detailed Description

Class to write data to GridFS.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  root_collection,
  session = None,
  disable_md5 = False,
**  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: 255 kb)

  - ``"encoding"``: encoding used for this file. In Python 2,
    any :class:`unicode` that is written to the file will be
    converted to a :class:`str`. In Python 3, any :class:`str`
    that is written to the file will be converted to
    :class:`bytes`.

:Parameters:
  - `root_collection`: root collection to write to
  - `session` (optional): a
    :class:`~pymongo.client_session.ClientSession` to use for all
    commands
  - `disable_md5` (optional): When True, an MD5 checksum will not be
    computed for the uploaded file. Useful in environments where
    MD5 cannot be used for regulatory or other reasons. Defaults to
    False.
  - `**kwargs` (optional): file level options (see above)

.. versionchanged:: 3.6
   Added ``session`` parameter.

.. versionchanged:: 3.0
   `root_collection` must use an acknowledged
   :attr:`~pymongo.collection.Collection.write_concern`

Member Function Documentation

◆ __enter__()

def __enter__ (   self)
Support for the context manager protocol.

◆ __exit__()

def __exit__ (   self,
  exc_type,
  exc_val,
  exc_tb 
)
Support for the context manager protocol.

Close the file and allow exceptions to propagate.

◆ __getattr__()

def __getattr__ (   self,
  name 
)

◆ __setattr__()

def __setattr__ (   self,
  name,
  value 
)

◆ abort()

def abort (   self)
Remove all chunks/files that may have been uploaded and close.

◆ close()

def close (   self)
Flush the file and close it.

A closed file cannot be written any more. Calling
:meth:`close` more than once is allowed.

◆ closed()

def closed (   self)
Is this file closed?

◆ read()

def read (   self,
  size = -1 
)

◆ readable()

def readable (   self)

◆ seekable()

def seekable (   self)

◆ write()

def 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` (:class:`str` in python 3) 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` (:class:`bytes` in python 3), a file-like object,
or an instance of :class:`unicode` (:class:`str` in python 3).
Unicode data is 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

◆ writeable()

def writeable (   self)

◆ writelines()

def writelines (   self,
  sequence 
)
Write a sequence of strings to the file.

Does not add seperators.

Field Documentation

◆ chunk_size

chunk_size
static

◆ closed_only

closed_only
static

◆ content_type

content_type
static

◆ filename

filename
static

◆ length

length
static

◆ md5

md5
static

◆ name

name
static

◆ read_only

read_only
static

◆ upload_date

upload_date
static

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