How to use the motor.MotorGridFSBucket function in motor

To help you get started, we’ve selected a few motor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mongodb / motor / test / tornado_tests / test_motor_gridfsbucket.py View on Github external
def setUp(self):
        super(MotorGridFSBucketTest, self).setUp()
        self.io_loop.run_sync(self._reset)
        self.bucket = motor.MotorGridFSBucket(self.db)
github mongodb / motor / test / tornado_tests / test_motor_grid_file.py View on Github external
def test_iteration(self):
        fs = motor.MotorGridFSBucket(self.db)
        _id = yield fs.upload_from_stream('filename', b'foo')
        g = motor.MotorGridOut(self.db.fs, _id)

        # Iteration is prohibited.
        self.assertRaises(TypeError, iter, g)
github mongodb / motor / test / tornado_tests / test_motor_core.py View on Github external
def test_gridout_cursor_attrs(self):
        self.assertEqual(
            attrs(self.sync_fs.find()) - pymongo_cursor_only,
            attrs(MotorGridFSBucket(self.cx.test).find()) - motor_cursor_only)
github mongodb / motor / test / tornado_tests / test_motor_core.py View on Github external
def test_gridout_attrs(self):
        motor_gridout_only = set([
            'open',
            'stream_to_handler'
        ]).union(motor_only)

        fs = MotorGridFSBucket(self.cx.test)
        motor_gridout = yield fs.open_download_stream(1)
        self.assertEqual(
            attrs(self.sync_fs.open_download_stream(1)),
            attrs(motor_gridout) - motor_gridout_only)
github mongodb / motor / test / tornado_tests / test_motor_grid_file.py View on Github external
def test_stream_to_handler(self):
        fs = motor.MotorGridFSBucket(self.db)

        for content_length in (0, 1, 100, 100 * 1000):
            _id = yield fs.upload_from_stream('filename', b'a' * content_length)
            gridout = yield fs.open_download_stream(_id)
            handler = MockRequestHandler()
            yield gridout.stream_to_handler(handler)
            self.assertEqual(content_length, handler.n_written)
            yield fs.delete(_id)
github mongodb / motor / synchro / __init__.py View on Github external
def __init__(self, database, *args, **kwargs):
        if not isinstance(database, Database):
            raise TypeError(
                "Expected Database, got %s" % repr(database))

        self.delegate = motor.MotorGridFSBucket(
            database.delegate, *args, **kwargs)
github mongodb / motor / synchro / __init__.py View on Github external
return GridOut(self.collection, delegate=motor_grid_out)

    __next__ = next


class CursorManager(object):
    # Motor doesn't support cursor managers, just avoid ImportError.
    pass


class BulkOperationBuilder(object):
    pass


class GridFSBucket(Synchro):
    __delegate_class__ = motor.MotorGridFSBucket

    find = WrapOutgoing()

    def __init__(self, database, *args, **kwargs):
        if not isinstance(database, Database):
            raise TypeError(
                "Expected Database, got %s" % repr(database))

        self.delegate = motor.MotorGridFSBucket(
            database.delegate, *args, **kwargs)


class GridIn(Synchro):
    __delegate_class__ = motor.MotorGridIn

    def __init__(self, collection, **kwargs):
github mongodb / motor / motor / web.py View on Github external
def get(self, path, include_body=True):
        fs = motor.MotorGridFSBucket(self.database, self.root_collection)

        try:
            gridout = yield self.get_gridfs_file(fs, path, self.request)
        except gridfs.NoFile:
            raise tornado.web.HTTPError(404)

        # If-Modified-Since header is only good to the second.
        modified = gridout.upload_date.replace(microsecond=0)
        self.set_header("Last-Modified", modified)

        # MD5 is calculated on the MongoDB server when GridFS file is created
        self.set_header("Etag", '"%s"' % gridout.md5)

        mime_type = gridout.content_type

        # If content type is not defined, try to check it with mimetypes