本文整理汇总了Python中libgsync.drive.Drive.open方法的典型用法代码示例。如果您正苦于以下问题:Python Drive.open方法的具体用法?Python Drive.open怎么用?Python Drive.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类libgsync.drive.Drive
的用法示例。
在下文中一共展示了Drive.open方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_open_for_read_and_read_data
# 需要导入模块: from libgsync.drive import Drive [as 别名]
# 或者: from libgsync.drive.Drive import open [as 别名]
def test_open_for_read_and_read_data(self):
drive = Drive()
f = drive.open("drive://unittest/open_for_read.txt", "r")
contents = f.read()
self.assertIsNotNone(contents)
self.assertNotEqual(contents, "")
示例2: test_revisions
# 需要导入模块: from libgsync.drive import Drive [as 别名]
# 或者: from libgsync.drive.Drive import open [as 别名]
def test_revisions(self):
drive = Drive()
num_revisions = 6
info = drive.create("drive://gsync_unittest/revision_test", {
"description": "revision-0"
})
self.assertEqual(info['description'], "revision-0")
for revision in range(1, num_revisions):
description = "revision-%d" % revision
info = drive.update("drive://gsync_unittest/revision_test", {
"description": description
},
media_body=MediaFileUpload("tests/data/open_for_read.txt",
mimetype=MimeTypes.BINARY_FILE, resumable=True
)
)
self.assertEqual(info['description'], description)
f = drive.open("drive://gsync_unittest/revision_test", "r")
revisions = f.revisions()
self.assertEqual(len(revisions), num_revisions)
self.assertEqual(int(revisions[0]['fileSize']), 0)
self.assertNotEqual(int(revisions[-1]['fileSize']), 0)
示例3: test_write
# 需要导入模块: from libgsync.drive import Drive [as 别名]
# 或者: from libgsync.drive.Drive import open [as 别名]
def test_write(self):
drive = Drive()
try:
drive.open("drive://gsync_unittest/open_for_read.txt", "w")
self.assertEqual("Expected IOError for unsupported mode", None)
except IOError:
pass
f = drive.open("drive://gsync_unittest/open_for_read.txt", "r")
try:
f.write("Some data")
self.assertEqual(
"Expected IOError for writing to readable file", None
)
except IOError:
pass
示例4: test_open_for_read_and_seek
# 需要导入模块: from libgsync.drive import Drive [as 别名]
# 或者: from libgsync.drive.Drive import open [as 别名]
def test_open_for_read_and_seek(self):
drive = Drive()
f = drive.open("drive://gsync_unittest/open_for_read.txt", "r")
self.assertNotEqual(int(f._info.fileSize), 0)
f.seek(0, os.SEEK_END)
self.assertNotEqual(f.tell(), 0)
示例5: test_mimetypes
# 需要导入模块: from libgsync.drive import Drive [as 别名]
# 或者: from libgsync.drive.Drive import open [as 别名]
def test_mimetypes(self):
drive = Drive()
drive.mkdir("drive://gsync_unittest/mimetype_test_dir")
f = drive.open("drive://gsync_unittest/mimetype_test_dir", "r")
self.assertEqual(f.mimetype(), MimeTypes.FOLDER)
f.mimetype(MimeTypes.BINARY_FILE)
self.assertEqual(f.mimetype(), MimeTypes.BINARY_FILE)
示例6: get_uploader
# 需要导入模块: from libgsync.drive import Drive [as 别名]
# 或者: from libgsync.drive.Drive import open [as 别名]
def get_uploader(self, path = None):
info = self.get_info(path)
if info is None:
raise Exception("Could not obtain file information: %s" % path)
path = self.get_path(path)
drive = Drive()
debug("Opening remote file for reading: %s" % repr(path))
fd = drive.open(path, "r")
if fd is None:
raise Exception("Open failed: %s" % path)
return MediaIoBaseUpload(fd, info.mimeType, resumable=True)
示例7: test_close
# 需要导入模块: from libgsync.drive import Drive [as 别名]
# 或者: from libgsync.drive.Drive import open [as 别名]
def test_close(self):
drive = Drive()
f = drive.open("drive://gsync_unittest/open_for_read.txt", "r")
contents = f.read()
self.assertNotEqual(contents, None)
f.close()
self.assertTrue(f.closed)
try:
f.seek(0)
self.assertEqual("Expected IOError for seek on closed file", None)
except IOError:
pass
示例8: test_open_for_read_and_seek
# 需要导入模块: from libgsync.drive import Drive [as 别名]
# 或者: from libgsync.drive.Drive import open [as 别名]
def test_open_for_read_and_seek(self):
drive = Drive()
f = drive.open("drive://unittest/open_for_read.txt", "r")
f.seek(0, os.SEEK_END)
self.assertNotEqual(f.tell(), 0)
示例9: test_open_for_read
# 需要导入模块: from libgsync.drive import Drive [as 别名]
# 或者: from libgsync.drive.Drive import open [as 别名]
def test_open_for_read(self):
drive = Drive()
f = drive.open("drive://unittest/open_for_read.txt", "r")
self.assertIsNotNone(f)