本文整理汇总了Python中pymogile.Client.new_file方法的典型用法代码示例。如果您正苦于以下问题:Python Client.new_file方法的具体用法?Python Client.new_file怎么用?Python Client.new_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymogile.Client
的用法示例。
在下文中一共展示了Client.new_file方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_mkcol
# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import new_file [as 别名]
def test_mkcol():
client = Client(TEST_NS, HOSTS)
for x in xrange(0, 1000):
key = 'test_file_%s_%s_%d' % (random.random(), time.time(), x)
client.new_file(key).write("SPAM%s" % x)
paths = client.get_paths(key)
assert paths
示例2: test_mkcol
# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import new_file [as 别名]
def test_mkcol(self):
client = Client(TEST_NS, HOSTS)
for x in xrange(0, 10):
key = "test_file_%s_%s_%d" % (random.random(), time.time(), x)
client.new_file(key).write("SPAM%s" % x)
paths = client.get_paths(key)
self.assertTrue(paths)
示例3: test_delete
# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import new_file [as 别名]
def test_delete():
client = Client(TEST_NS, HOSTS)
key = 'test_file_%s_%s' % (random.random(), time.time())
client.new_file(key).write("SPAM")
paths = client.get_paths(key)
assert paths
client.delete(key)
paths = client.get_paths(key)
assert not paths
示例4: test_delete
# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import new_file [as 别名]
def test_delete(self):
client = Client(TEST_NS, HOSTS)
key = 'test_file_%s_%s' % (random.random(), time.time())
client.new_file(key).write("SPAM")
paths = client.get_paths(key)
self.assertTrue(paths)
client.delete(key)
paths = client.get_paths(key)
self.assertFalse(paths)
示例5: test_rename
# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import new_file [as 别名]
def test_rename(self):
client = Client(TEST_NS, HOSTS)
key = "test_file_%s_%s" % (random.random(), time.time())
client.new_file(key).write(key)
paths = client.get_paths(key)
self.assertTrue(paths)
newkey = "test_file2_%s_%s" % (random.random(), time.time())
client.rename(key, newkey)
paths = client.get_paths(newkey)
self.assertTrue(paths)
content = client.get_file_data(newkey)
assert content == key
示例6: test_rename
# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import new_file [as 别名]
def test_rename():
client = Client(TEST_NS, HOSTS)
key = 'test_file_%s_%s' % (random.random(), time.time())
client.new_file(key).write(key)
paths = client.get_paths(key)
assert paths
newkey = 'test_file2_%s_%s' % (random.random(), time.time())
client.rename(key, newkey)
paths = client.get_paths(newkey)
assert paths
content = client.get_file_data(newkey)
assert content == key
示例7: func
# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import new_file [as 别名]
def func(largefile):
client = Client(TEST_NS, HOSTS)
key = 'test_file_%s_%s' % (random.random(), time.time())
fp = client.new_file(key, largefile=largefile)
fp.write("spam")
fp.close()
try:
fp.write("egg")
except:
pass
else:
assert False, "operation not permitted to closed file"
try:
fp.read()
except:
pass
else:
assert False, "operation not permitted to closed file"
try:
fp.seek(0)
except:
pass
else:
assert False, "operation not permitted to closed file"
try:
fp.tell()
except:
pass
else:
assert False, "operation not permitted to closed file"
示例8: test_file_like_object
# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import new_file [as 别名]
def test_file_like_object(self):
client = Client(TEST_NS, HOSTS)
key = 'test_file_%s_%s' % (random.random(), time.time())
fp = client.new_file(key)
fp.write("spam\negg\nham\n")
fp.seek(0)
line = fp.readline()
self.assertEqual(line, "spam\n")
line = fp.readline()
self.assertEqual(line, "egg\n")
line = fp.readline()
self.assertEqual(line, "ham\n")
line = fp.readline()
self.assertEqual(line, '')
fp.seek(0)
lines = fp.readlines()
self.assertEqual(lines, ["spam\n", "egg\n", "ham\n"])
fp.close()
示例9: test_new_file
# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import new_file [as 别名]
def test_new_file():
cl = Client(TEST_NS, HOSTS)
key = 'test_file_%s_%s' % (random.random(), time.time())
with cl.new_file(key) as fp:
assert fp.__exit__
fp.write(key)
assert cl.get_paths(key)
assert cl.get_file_data(key) == key
示例10: test_closed_file
# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import new_file [as 别名]
def test_closed_file(self):
client = Client(TEST_NS, HOSTS)
key = 'test_file_%s_%s' % (random.random(), time.time())
fp = client.new_file(key)
fp.write("spam")
fp.close()
self.assertRaises(ValueError, fp.write, "egg")
self.assertRaises(ValueError, fp.read)
self.assertRaises(ValueError, fp.seek, 0)
self.assertRaises(ValueError, fp.tell)
示例11: test_seek_negative
# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import new_file [as 别名]
def test_seek_negative(self):
client = Client(TEST_NS, HOSTS)
key = 'test_file_%s_%s' % (random.random(), time.time())
fp = client.new_file(key)
fp.write("SPAM")
fp.seek(-10)
self.assertEqual(fp.tell(), 0)
fp.write("s")
fp.close()
self.assertEqual(client.get_file_data(key), "sPAM")
示例12: test_seek
# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import new_file [as 别名]
def test_seek(self):
client = Client(TEST_NS, HOSTS)
key = "test_file_%s_%s" % (random.random(), time.time())
fp = client.new_file(key)
fp.write("SPAM")
fp.seek(1)
self.assertEqual(fp.tell(), 1)
fp.write("p")
fp.close()
self.assertEqual(client.get_file_data(key), "SpAM")
示例13: prepare_photo_files
# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import new_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()
示例14: test_new_large_file
# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import new_file [as 别名]
def test_new_large_file():
client = Client(TEST_NS, HOSTS)
key = 'test_file_%s_%s' % (random.random(), time.time())
fp = client.new_file(key, largefile=True)
assert fp is not None
for x in xrange(50):
fp.write("0123456789")
fp.close()
paths = client.get_paths(key)
#assert len(paths) > 1, "should exist in one ore more places"
assert paths
content = client.get_file_data(key)
assert content == "0123456789" * 50
示例15: test_new_file
# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import new_file [as 别名]
def test_new_file():
client = Client(TEST_NS, HOSTS)
key = 'test_file_%s_%s' % (random.random(), time.time())
fp = client.new_file(key)
assert fp is not None
data = "0123456789" * 50
fp.write(data)
fp.close()
paths = client.get_paths(key)
#assert len(paths) > 1, "should exist in one ore more places"
assert paths
content = client.get_file_data(key)
assert content == data