本文整理汇总了Python中pymogile.Client.read_file方法的典型用法代码示例。如果您正苦于以下问题:Python Client.read_file方法的具体用法?Python Client.read_file怎么用?Python Client.read_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymogile.Client
的用法示例。
在下文中一共展示了Client.read_file方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_read_file
# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import read_file [as 别名]
def test_read_file():
client = Client(TEST_NS, HOSTS)
key = 'test_file_%s_%s' % (random.random(), time.time())
client.store_content(key, key)
fp = client.read_file(key)
assert fp is not None
assert key == fp.read()
示例2: test_read_file
# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import read_file [as 别名]
def test_read_file(self):
client = Client(TEST_NS, HOSTS)
key = 'test_file_%s_%s' % (random.random(), time.time())
client.store_content(key, key)
fp = client.read_file(key)
self.assertNotEqual(fp, None)
self.assertEqual(key, fp.read())
示例3: test_read_file
# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import read_file [as 别名]
def test_read_file():
cl = Client(TEST_NS, HOSTS)
cl = Client(TEST_NS, HOSTS)
key = 'test_file_%s_%s' % (random.random(), time.time())
cl.store_content(key, key)
with cl.read_file(key) as fp:
assert fp.read() == key
示例4: test_readonly_file
# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import read_file [as 别名]
def test_readonly_file():
client = Client(TEST_NS, HOSTS)
key = 'test_file_%s_%s' % (random.random(), time.time())
client.store_content(key, "SPAM")
fp = client.read_file(key)
try:
fp.write("egg")
except:
pass
else:
assert False, "operation not permitted to read-only file"
示例5: test_seek_read
# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import read_file [as 别名]
def test_seek_read():
client = Client(TEST_NS, HOSTS)
key = 'test_file_%s_%s' % (random.random(), time.time())
client.store_content(key, "0123456789")
fp = client.read_file(key)
fp.seek(1)
assert fp.tell() == 1
content = fp.read(3)
assert content == "123"
assert fp.tell() == 4
示例6: test_seek_read
# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import read_file [as 别名]
def test_seek_read(self):
client = Client(TEST_NS, HOSTS)
key = 'test_file_%s_%s' % (random.random(), time.time())
client.store_content(key, "0123456789")
fp = client.read_file(key)
fp.seek(1)
self.assertEqual(fp.tell(), 1)
content = fp.read(3)
assert content == "123"
self.assertEqual(fp.tell(), 4)
示例7: prepare_photo_files
# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import read_file [as 别名]
def prepare_photo_files(owner, nb):
storage = Client(domain = settings.MOGILEFS_DOMAIN,
trackers = settings.MOGILEFS_TRACKERS)
#im = Image.open(path.join(settings.UNPROCESSED_PHOTOS_DIR, '%s.jpg' % id))
f = storage.read_file(path.join(settings.UNPROCESSED_PHOTOS_DIR, '%s,%s.jpg' % (owner, nb)))
im = Image.open(f)
im.thumbnail((160, 160), Image.ANTIALIAS)
tn = storage.new_file(path.join(settings.PROCESSED_PHOTOS_DIR, '%s,%s-160x160.jpg' % (owner, nb)))
im.save(tn, 'JPEG')
#sleep(20)
photo = Photo.get(owner, nb)
photo.ready()
示例8: photo_thumbnail
# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import read_file [as 别名]
def photo_thumbnail(request, owner, nb):
storage = Client(domain = settings.MOGILEFS_DOMAIN,
trackers = settings.MOGILEFS_TRACKERS)
f = storage.read_file(path.join(settings.PROCESSED_PHOTOS_DIR, '%s,%s-160x160.jpg' % (owner, nb)))
return HttpResponse(make_reader(f), content_type='image/jpeg')