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


Python Client.new_file方法代码示例

本文整理汇总了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
开发者ID:pombredanne,项目名称:pymogile,代码行数:9,代码来源:test_client.py

示例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)
开发者ID:lananhbk168,项目名称:pymogile,代码行数:9,代码来源:test_client.py

示例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
开发者ID:pombredanne,项目名称:pymogile,代码行数:13,代码来源:test_client.py

示例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)
开发者ID:cypreess,项目名称:pymogile,代码行数:13,代码来源:test_client.py

示例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
开发者ID:lananhbk168,项目名称:pymogile,代码行数:16,代码来源:test_client.py

示例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
开发者ID:pombredanne,项目名称:pymogile,代码行数:16,代码来源:test_client.py

示例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"
开发者ID:pombredanne,项目名称:pymogile,代码行数:36,代码来源:test_client.py

示例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()
开发者ID:cypreess,项目名称:pymogile,代码行数:27,代码来源:test_client.py

示例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
开发者ID:pombredanne,项目名称:pymogile,代码行数:12,代码来源:test_with_statement.py

示例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)
开发者ID:cypreess,项目名称:pymogile,代码行数:13,代码来源:test_client.py

示例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")
开发者ID:cypreess,项目名称:pymogile,代码行数:14,代码来源:test_client.py

示例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")
开发者ID:lananhbk168,项目名称:pymogile,代码行数:14,代码来源:test_client.py

示例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()
开发者ID:savix,项目名称:jnp3,代码行数:16,代码来源:tasks.py

示例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
开发者ID:pombredanne,项目名称:pymogile,代码行数:19,代码来源:test_client.py

示例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
开发者ID:pombredanne,项目名称:pymogile,代码行数:19,代码来源:test_client.py


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