当前位置: 首页>>代码示例>>Python>>正文


Python GridFile.close方法代码示例

本文整理汇总了Python中gridfs.grid_file.GridFile.close方法的典型用法代码示例。如果您正苦于以下问题:Python GridFile.close方法的具体用法?Python GridFile.close怎么用?Python GridFile.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gridfs.grid_file.GridFile的用法示例。


在下文中一共展示了GridFile.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_create_grid_file

# 需要导入模块: from gridfs.grid_file import GridFile [as 别名]
# 或者: from gridfs.grid_file.GridFile import close [as 别名]
    def test_create_grid_file(self):
        self.db.fs.files.remove({})
        self.db.fs.chunks.remove({})

        # just write a blank file so that reads on {} don't fail
        file = GridFile({"filename": "test"}, self.db, "w")
        file.close()

        self.assertRaises(TypeError, GridFile, "hello", self.db)
        self.assertRaises(TypeError, GridFile, None, self.db)
        self.assertRaises(TypeError, GridFile, 5, self.db)

        self.assertRaises(TypeError, GridFile, {}, "hello")
        self.assertRaises(TypeError, GridFile, {}, None)
        self.assertRaises(TypeError, GridFile, {}, 5)
        GridFile({}, self.db).close()

        self.assertRaises(TypeError, GridFile, {}, self.db, None)
        self.assertRaises(TypeError, GridFile, {}, self.db, 5)
        self.assertRaises(TypeError, GridFile, {}, self.db, [])
        self.assertRaises(ValueError, GridFile, {}, self.db, "m")
        self.assertRaises(ValueError, GridFile, {}, self.db, u"m")
        GridFile({}, self.db, "r").close()
        GridFile({}, self.db, u"r").close()
        GridFile({}, self.db, "w").close()
        GridFile({}, self.db, u"w").close()

        self.assertRaises(TypeError, GridFile, {}, self.db, "r", None)
        self.assertRaises(TypeError, GridFile, {}, self.db, "r", 5)
        self.assertRaises(TypeError, GridFile, {}, self.db, "r", [])

        self.assertRaises(IOError, GridFile, {"filename": "mike"}, self.db)
        GridFile({"filename": "test"}, self.db).close()
开发者ID:JMassapina,项目名称:mongo-python-driver,代码行数:35,代码来源:test_grid_file.py

示例2: test_seek

# 需要导入模块: from gridfs.grid_file import GridFile [as 别名]
# 或者: from gridfs.grid_file.GridFile import close [as 别名]
    def test_seek(self):
        self.db.fs.files.remove({})
        self.db.fs.chunks.remove({})

        file = GridFile({"filename": "test", "chunkSize": 3}, self.db, "w")
        file.write("hello world")
        self.assertRaises(ValueError, file.seek, 0)
        file.close()

        file = GridFile({"filename": "test"}, self.db, "r")
        self.assertEqual(file.read(), "hello world")
        file.seek(0)
        self.assertEqual(file.read(), "hello world")
        file.seek(1)
        self.assertEqual(file.read(), "ello world")
        self.assertRaises(IOError, file.seek, -1)

        file.seek(-3, _SEEK_END)
        self.assertEqual(file.read(), "rld")
        file.seek(0, _SEEK_END)
        self.assertEqual(file.read(), "")
        self.assertRaises(IOError, file.seek, -100, _SEEK_END)

        file.seek(3)
        file.seek(3, _SEEK_CUR)
        self.assertEqual(file.read(), "world")
        self.assertRaises(IOError, file.seek, -100, _SEEK_CUR)

        file.close()
开发者ID:JMassapina,项目名称:mongo-python-driver,代码行数:31,代码来源:test_grid_file.py

示例3: test_alternate_collection

# 需要导入模块: from gridfs.grid_file import GridFile [as 别名]
# 或者: from gridfs.grid_file.GridFile import close [as 别名]
    def test_alternate_collection(self):
        self.db.pymongo_test.files.remove({})
        self.db.pymongo_test.chunks.remove({})

        self.assertEqual(self.db.pymongo_test.files.find().count(), 0)
        self.assertEqual(self.db.pymongo_test.chunks.find().count(), 0)
        file = GridFile({"filename": "test"}, self.db, "w", collection="pymongo_test")
        file.write("hello world")
        file.close()

        self.assertEqual(self.db.pymongo_test.files.find().count(), 1)
        self.assertEqual(self.db.pymongo_test.chunks.find().count(), 1)

        file = GridFile({"filename": "test"}, self.db, collection="pymongo_test")
        self.assertEqual(file.read(), "hello world")
        file.close()

        # test that md5 still works...
        self.assertEqual(file.md5, "5eb63bbbe01eeed093cb22bb8f5acdc3")

        # make sure it's still there...
        file = GridFile({"filename": "test"}, self.db, collection="pymongo_test")
        self.assertEqual(file.read(), "hello world")
        file.close()

        file = GridFile({"filename": "test"}, self.db, "w", collection="pymongo_test")
        file.close()

        self.assertEqual(self.db.pymongo_test.files.find().count(), 1)
        self.assertEqual(self.db.pymongo_test.chunks.find().count(), 0)

        file = GridFile({"filename": "test"}, self.db, collection="pymongo_test")
        self.assertEqual(file.read(), "")
        file.close()
开发者ID:svetlyak40wt,项目名称:mongo-python-driver,代码行数:36,代码来源:test_grid_file.py

示例4: test_basic

# 需要导入模块: from gridfs.grid_file import GridFile [as 别名]
# 或者: from gridfs.grid_file.GridFile import close [as 别名]
    def test_basic(self):
        self.db.fs.files.remove({})
        self.db.fs.chunks.remove({})

        self.assertEqual(self.db.fs.files.find().count(), 0)
        self.assertEqual(self.db.fs.chunks.find().count(), 0)
        file = GridFile({"filename": "test"}, self.db, "w")
        file.write("hello world")
        file.close()

        self.assertEqual(self.db.fs.files.find().count(), 1)
        self.assertEqual(self.db.fs.chunks.find().count(), 1)

        file = GridFile({"filename": "test"}, self.db)
        self.assertEqual(file.read(), "hello world")
        file.close()

        # make sure it's still there...
        file = GridFile({"filename": "test"}, self.db)
        self.assertEqual(file.read(), "hello world")
        file.close()

        file = GridFile({"filename": "test"}, self.db, "w")
        file.close()

        self.assertEqual(self.db.fs.files.find().count(), 1)
        self.assertEqual(self.db.fs.chunks.find().count(), 0)

        file = GridFile({"filename": "test"}, self.db)
        self.assertEqual(file.read(), "")
        file.close()
开发者ID:JMassapina,项目名称:mongo-python-driver,代码行数:33,代码来源:test_grid_file.py

示例5: test_properties

# 需要导入模块: from gridfs.grid_file import GridFile [as 别名]
# 或者: from gridfs.grid_file.GridFile import close [as 别名]
    def test_properties(self):
        self.db.fs.files.remove({})
        self.db.fs.chunks.remove({})

        file = GridFile({"filename": "test"}, self.db, "w")
        self.assertEqual(file.mode, "w")
        self.failIf(file.closed)
        file.close()
        self.assert_(file.closed)

        self.assertRaises(IOError, GridFile, {"filename": "mike"}, self.db)
        a = GridFile({"filename": "test"}, self.db)

        self.assertEqual(a.mode, "r")
        self.failIf(a.closed)

        self.assertEqual(a.length, 0)
        self.assertEqual(a.content_type, None)
        self.assertEqual(a.name, "test")
        self.assertEqual(a.chunk_size, 256000)
        self.assert_(isinstance(a.upload_date, datetime.datetime))
        self.assertEqual(a.aliases, None)
        self.assertEqual(a.metadata, None)
        self.assertEqual(a.md5, "d41d8cd98f00b204e9800998ecf8427e")

        a.content_type = "something"
        self.assertEqual(a.content_type, "something")

        def set_length():
            a.length = 10

        self.assertRaises(AttributeError, set_length)

        def set_chunk_size():
            a.chunk_size = 100

        self.assertRaises(AttributeError, set_chunk_size)

        def set_upload_date():
            a.upload_date = datetime.datetime.utcnow()

        self.assertRaises(AttributeError, set_upload_date)

        a.aliases = ["hello", "world"]
        self.assertEqual(a.aliases, ["hello", "world"])

        a.metadata = {"something": "else"}
        self.assertEqual(a.metadata, {"something": "else"})

        def set_name():
            a.name = "hello"

        self.assertRaises(AttributeError, set_name)

        def set_md5():
            a.md5 = "what"

        self.assertRaises(AttributeError, set_md5)

        a.close()
开发者ID:svetlyak40wt,项目名称:mongo-python-driver,代码行数:62,代码来源:test_grid_file.py

示例6: test_md5

# 需要导入模块: from gridfs.grid_file import GridFile [as 别名]
# 或者: from gridfs.grid_file.GridFile import close [as 别名]
    def test_md5(self):
        file = GridFile({"filename": "test"}, self.db, "w")
        file.write("hello world\n")
        file.close()

        file = GridFile({"filename": "test"}, self.db)
        self.assertEqual(file.md5, "6f5902ac237024bdd0c176cb93063dc4")
        file.close()
开发者ID:JMassapina,项目名称:mongo-python-driver,代码行数:10,代码来源:test_grid_file.py

示例7: test_flush_close

# 需要导入模块: from gridfs.grid_file import GridFile [as 别名]
# 或者: from gridfs.grid_file.GridFile import close [as 别名]
    def test_flush_close(self):
        self.db.fs.files.remove({})
        self.db.fs.chunks.remove({})

        file = GridFile({"filename": "test"}, self.db, "w")
        file.flush()
        file.close()
        file.close()
        self.assertRaises(ValueError, file.write, "test")

        file = GridFile({}, self.db)
        self.assertEqual(file.read(), "")
        file.close()

        file = GridFile({"filename": "test"}, self.db, "w")
        file.write("mike")
        file.flush()
        file.write("test")
        file.flush()
        file.write("huh")
        file.flush()
        file.flush()
        file.close()
        file.close()
        self.assertRaises(ValueError, file.write, "test")
        file = GridFile({}, self.db)
        self.assertEqual(file.read(), "miketesthuh")
        file.close()
开发者ID:JMassapina,项目名称:mongo-python-driver,代码行数:30,代码来源:test_grid_file.py

示例8: test_multi_chunk_file

# 需要导入模块: from gridfs.grid_file import GridFile [as 别名]
# 或者: from gridfs.grid_file.GridFile import close [as 别名]
    def test_multi_chunk_file(self):
        self.db.fs.files.remove({})
        self.db.fs.chunks.remove({})

        random_string = qcheck.gen_string(qcheck.lift(300000))()

        file = GridFile({"filename": "test"}, self.db, "w")
        file.write(random_string)
        file.close()

        self.assertEqual(self.db.fs.files.find().count(), 1)
        self.assertEqual(self.db.fs.chunks.find().count(), 2)

        f = GridFile({}, self.db)
        self.assertEqual(f.read(), random_string)
        f.close()
开发者ID:JMassapina,项目名称:mongo-python-driver,代码行数:18,代码来源:test_grid_file.py

示例9: test_rename

# 需要导入模块: from gridfs.grid_file import GridFile [as 别名]
# 或者: from gridfs.grid_file.GridFile import close [as 别名]
    def test_rename(self):
        self.db.fs.files.remove({})
        self.db.fs.chunks.remove({})

        file = GridFile({"filename": "test"}, self.db, "w")
        file.close()

        self.assertRaises(IOError, GridFile, {"filename": "mike"}, self.db)
        a = GridFile({"filename": "test"}, self.db)

        a.rename("mike")
        self.assertEqual("mike", a.name)
        a.close()

        self.assertRaises(IOError, GridFile, {"filename": "test"}, self.db)
        GridFile({"filename": "mike"}, self.db).close()
开发者ID:JMassapina,项目名称:mongo-python-driver,代码行数:18,代码来源:test_grid_file.py

示例10: test_multiple_reads

# 需要导入模块: from gridfs.grid_file import GridFile [as 别名]
# 或者: from gridfs.grid_file.GridFile import close [as 别名]
    def test_multiple_reads(self):
        self.db.fs.files.remove({})
        self.db.fs.chunks.remove({})

        file = GridFile({"filename": "test"}, self.db, "w")
        file.write("hello world")
        file.close()

        file = GridFile({"filename": "test"}, self.db, "r")
        self.assertEqual(file.read(2), "he")
        self.assertEqual(file.read(2), "ll")
        self.assertEqual(file.read(2), "o ")
        self.assertEqual(file.read(2), "wo")
        self.assertEqual(file.read(2), "rl")
        self.assertEqual(file.read(2), "d")
        self.assertEqual(file.read(2), "")
        file.close()
开发者ID:JMassapina,项目名称:mongo-python-driver,代码行数:19,代码来源:test_grid_file.py

示例11: test_modes

# 需要导入模块: from gridfs.grid_file import GridFile [as 别名]
# 或者: from gridfs.grid_file.GridFile import close [as 别名]
    def test_modes(self):
        self.db.fs.files.remove({})
        self.db.fs.chunks.remove({})

        file = GridFile({"filename": "test"}, self.db, "w")
        self.assertRaises(ValueError, file.read)
        file.write("hello")
        file.close()
        self.assertRaises(ValueError, file.read)
        self.assertRaises(ValueError, file.write, "hello")

        file = GridFile({"filename": "test"}, self.db, "r")
        self.assertRaises(ValueError, file.write, "hello")
        file.read()
        file.close()
        self.assertRaises(ValueError, file.read)
        self.assertRaises(ValueError, file.write, "hello")
开发者ID:JMassapina,项目名称:mongo-python-driver,代码行数:19,代码来源:test_grid_file.py

示例12: test_read_chunks_unaligned_buffer_size

# 需要导入模块: from gridfs.grid_file import GridFile [as 别名]
# 或者: from gridfs.grid_file.GridFile import close [as 别名]
    def test_read_chunks_unaligned_buffer_size(self):
        self.db.fs.files.remove({})
        self.db.fs.chunks.remove({})

        in_data = "This is a text that doesn't quite fit in a single 16-byte chunk."
        f = GridFile({"filename":"test", "chunkSize":16}, self.db, "w")
        f.write(in_data)
        f.close()

        f = GridFile({"filename":"test"}, self.db)
        out_data = ''
        while 1:
            s = f.read(13)
            if not s:
                break
            out_data += s
        f.close()

        self.assertEqual(in_data, out_data)
开发者ID:mcfunley,项目名称:mongo-python-driver,代码行数:21,代码来源:test_grid_file.py

示例13: test_tell

# 需要导入模块: from gridfs.grid_file import GridFile [as 别名]
# 或者: from gridfs.grid_file.GridFile import close [as 别名]
    def test_tell(self):
        self.db.fs.files.remove({})
        self.db.fs.chunks.remove({})

        file = GridFile({"filename": "test", "chunkSize": 3}, self.db, "w")
        file.write("hello world")
        self.assertRaises(ValueError, file.tell)
        file.close()

        file = GridFile({"filename": "test"}, self.db, "r")
        self.assertEqual(file.tell(), 0)
        file.read(0)
        self.assertEqual(file.tell(), 0)
        file.read(1)
        self.assertEqual(file.tell(), 1)
        file.read(2)
        self.assertEqual(file.tell(), 3)
        file.read()
        self.assertEqual(file.tell(), file.length)

        file.close()
开发者ID:JMassapina,项目名称:mongo-python-driver,代码行数:23,代码来源:test_grid_file.py

示例14: remove

# 需要导入模块: from gridfs.grid_file import GridFile [as 别名]
# 或者: from gridfs.grid_file.GridFile import close [as 别名]
    def remove(self, filename_or_spec, collection="fs"):
        """Remove one or more :class:`~gridfs.grid_file.GridFile`
        instances.

        Can remove by filename, or by an entire file spec (see
        :meth:`~gridfs.grid_file.GridFile` for documentation on valid
        fields. Delete all :class:`~gridfs.grid_file.GridFile`
        instances that match `filename_or_spec`. Raises
        :class:`TypeError` if `filename_or_spec` is not an instance of
        (:class:`basestring`, :class:`dict`,
        :class:`~pymongo.son.SON`) or collection is not an instance of
        :class:`basestring`.

        :Parameters:
          - `filename_or_spec`: identifier of file(s) to remove
          - `collection` (optional): root collection where this file is located
        """
        spec = filename_or_spec
        if isinstance(filename_or_spec, basestring):
            spec = {"filename": filename_or_spec}
        if not isinstance(spec, dict):
            raise TypeError("filename_or_spec must be an "
                            "instance of (basestring, dict, SON)")
        if not isinstance(collection, basestring):
            raise TypeError("collection must be an instance of basestring")

        # convert to _id's so we can uniquely create GridFile instances
        ids = []
        for grid_file in self.__database[collection].files.find(spec):
            ids.append(grid_file["_id"])

        # open for writing to remove the chunks for these files
        for file_id in ids:
            f = GridFile({"_id": file_id}, self.__database, "w", collection)
            f.close()

        self.__database[collection].files.remove(spec)
开发者ID:RedBeard0531,项目名称:mongo-python-driver,代码行数:39,代码来源:__init__.py

示例15: test_overwrite

# 需要导入模块: from gridfs.grid_file import GridFile [as 别名]
# 或者: from gridfs.grid_file.GridFile import close [as 别名]
    def test_overwrite(self):
        self.db.fs.files.remove({})
        self.db.fs.chunks.remove({})

        file = GridFile({"filename": "test"}, self.db, "w")
        file.write("test")
        file.close()

        file = GridFile({"filename": "test"}, self.db, "w")
        file.write("mike")
        file.close()

        f = GridFile({}, self.db)
        self.assertEqual(f.read(), "mike")
        f.close()
开发者ID:JMassapina,项目名称:mongo-python-driver,代码行数:17,代码来源:test_grid_file.py


注:本文中的gridfs.grid_file.GridFile.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。