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


Python Client.get_file_data方法代码示例

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


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

示例1: test_append_file

# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import get_file_data [as 别名]
  def test_append_file(self):
    cl = Client(TEST_NS, HOSTS)
    key = 'test_file_%s_%s' % (random.random(), time.time())

    cl.store_content(key, "SPAM")
    self.assertTrue(cl.get_paths(key))
    self.assertEqual("SPAM", cl.get_file_data(key))

    fp = cl.edit_file(key)
    self.assertTrue(fp)
    fp.seek(4)
    fp.write("HamEggs")
    fp.close()

    self.assertEqual("SPAMHamEggs", cl.get_file_data(key))
开发者ID:cypreess,项目名称:pymogile,代码行数:17,代码来源:test_client.py

示例2: test_store_content

# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import get_file_data [as 别名]
def test_store_content():
    client = Client(TEST_NS, HOSTS)
    key = 'test_file_%s_%s' % (random.random(), time.time())

    data = ''.join(random.choice("0123456789") for x in xrange(8192 * 2))
    length = client.store_content(key, data)
    assert length == len(data)

    content = client.get_file_data(key)
    assert content == data
开发者ID:pombredanne,项目名称:pymogile,代码行数:12,代码来源:test_client.py

示例3: test_store_content

# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import get_file_data [as 别名]
  def test_store_content(self): 
    client = Client(TEST_NS, HOSTS)
    key = 'test_file_%s_%s' % (random.random(), time.time())

    data = ''.join(random.choice("0123456789") for _ in xrange(8192 * 2))
    length = client.store_content(key, data)
    self.assertEqual(length, len(data))

    content = client.get_file_data(key)
    self.assertEqual(content, data)
开发者ID:cypreess,项目名称:pymogile,代码行数:12,代码来源:test_client.py

示例4: test_new_file

# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import get_file_data [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

示例5: test_edit_file

# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import get_file_data [as 别名]
def test_edit_file():
    # TODO
    # PASS
    return

    cl = Client(TEST_NS, HOSTS)
    key = 'test_file_%s_%s' % (random.random(), time.time())

    cl.store_content(key, "SPAM")
    assert cl.get_paths(key)
    assert cl.get_file_data(key) == "SPAM"

    fp = cl.edit_file(key)
    assert fp
    fp.write("s")
    fp.seek(2)
    fp.write("a")
    fp.close()

    assert cl.get_file_data(key) == "sPaM"
开发者ID:pombredanne,项目名称:pymogile,代码行数:22,代码来源:test_client.py

示例6: test_store_file

# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import get_file_data [as 别名]
    def test_store_file(self):
        client = Client(TEST_NS, HOSTS)
        key = "test_file_%s_%s" % (random.random(), time.time())

        data = "".join(random.choice("0123456789") for _ in xrange(8192 * 2))
        fp = StringIO(data)
        length = client.store_file(key, fp)
        self.assertEqual(length, len(data))

        content = client.get_file_data(key)
        self.assertEqual(content, data)
开发者ID:lananhbk168,项目名称:pymogile,代码行数:13,代码来源:test_client.py

示例7: func

# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import get_file_data [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.seek(-10)
        assert fp.tell() == 0
        fp.write("s")
        fp.close()

        assert client.get_file_data(key) == "sPAM"
开发者ID:pombredanne,项目名称:pymogile,代码行数:14,代码来源:test_client.py

示例8: test_seek_negative

# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import get_file_data [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

示例9: test_seek

# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import get_file_data [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

示例10: test_rename

# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import get_file_data [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

示例11: test_rename

# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import get_file_data [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

示例12: test_new_large_file

# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import get_file_data [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

示例13: test_new_file

# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import get_file_data [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

示例14: Client

# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import get_file_data [as 别名]
cpub = Client(domain="publicmedia", trackers=['127.0.0.1:7001'])

# list keys
c.list_keys()

# create a file in mogilefs
f = c.new_file('foobar.txt')
f.write('hi, my name bar, foo bar.')
f.close()

# show paths
c.get_paths('foobar.txt')
c.get_paths('404.txt')

# get file data
c.get_file_data('404.txt')
c.get_file_data('foobar.txt')

# remove
c.delete('foobar.txt')



# django storage backend

from ogv_documents.storage.mogilefs import MogilefsStorage
from django.core.files.base import ContentFile

s = MogilefsStorage(domain='privatemedia', container='documents', base_url='/documents/', trackers=['127.0.0.1:7001'])
s.exists('six/2011/justone.pdf')
s.save(u'epic.txt', ContentFile('my epic content. now with a content file'))
开发者ID:MontesDaLua,项目名称:AgDevRepo,代码行数:33,代码来源:mogilefs_tests.py

示例15: Storage

# 需要导入模块: from pymogile import Client [as 别名]
# 或者: from pymogile.Client import get_file_data [as 别名]
class Storage(BaseStorage):
    def __init__(self, context):
        BaseStorage.__init__(self, context)

        domain = self.context.config.MOGILEFS_STORAGE_DOMAIN
        trackers = self.context.config.MOGILEFS_STORAGE_TRACKERS
        self.storage = Client(domain=domain, trackers=trackers)

    def __key_for(self, url):
        return 'thumbor-crypto-%s' % url

    def __detector_key_for(self, url):
        return 'thumbor-detector-%s' % url

    def put(self, path, bytes):
        fp = self.storage.new_file(path)
        fp.write(bytes)
        fp.close()
        return path

    def put_crypto(self, path, data):
        if not self.context.config.STORES_CRYPTO_KEY_FOR_EACH_IMAGE:
            return

        if not self.context.server.security_key:
            raise RuntimeError("""STORES_CRYPTO_KEY_FOR_EACH_IMAGE can't be True
                               if no SECURITY_KEY specified""")

        key = self.__key_for(path)
        fp = self.storage.new_file(key)
        fp.write(self.context.server.security_key)
        fp.close()
        return key

    def put_detector_data(self, path, data):
        key = self.__detector_key_for(path)
        fp = self.storage.new_file(key)
        fp.write(dumps(data))
        fp.close()
        return key

    def get_crypto(self, path):
        if not self.context.config.STORES_CRYPTO_KEY_FOR_EACH_IMAGE:
            return None

        crypto = self.storage.get_file_data(self.__key_for(path))

        if not crypto:
            return None
        return crypto

    def get_detector_data(self, path):
        data = self.storage.get_file_data(self.__detector_key_for(path))

        if not data:
            return None
        return loads(data)

    def get(self, path):
        return self.storage.get_file_data(path) is not None

    def exists(self, path):
        return self.storage.keys(path) is not None

    def remove(self, path):
        if not self.exists(path):
            return
        return self.storage.delete(path)
开发者ID:darkseed,项目名称:thumbor-mogilefs,代码行数:70,代码来源:mogilefs_storage.py


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