Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
super(MotorGridFSBucketTest, self).setUp()
self.io_loop.run_sync(self._reset)
self.bucket = motor.MotorGridFSBucket(self.db)
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)
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)
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)
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)
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)
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):
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