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


Python blobstore.BlobKey方法代码示例

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


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

示例1: __init__

# 需要导入模块: from google.appengine.ext import blobstore [as 别名]
# 或者: from google.appengine.ext.blobstore import BlobKey [as 别名]
def __init__(self, blob_key, start_position, end_position):
    """Initializes this instance with the given blob key and character range.

    This BlobstoreInputReader will read from the first record starting after
    strictly after start_position until the first record ending at or after
    end_position (exclusive). As an exception, if start_position is 0, then
    this InputReader starts reading at the first record.

    Args:
      blob_key: the BlobKey that this input reader is processing.
      start_position: the position to start reading at.
      end_position: a position in the last record to read.
    """
    self._blob_key = blob_key
    self._blob_reader = blobstore.BlobReader(blob_key,
                                             self._BLOB_BUFFER_SIZE,
                                             start_position)
    self._end_position = end_position
    self._has_iterated = False
    self._read_before_start = bool(start_position) 
开发者ID:elsigh,项目名称:browserscope,代码行数:22,代码来源:input_readers.py

示例2: validate

# 需要导入模块: from google.appengine.ext import blobstore [as 别名]
# 或者: from google.appengine.ext.blobstore import BlobKey [as 别名]
def validate(cls, mapper_spec):
    """Validates mapper spec and all mapper parameters.

    Args:
      mapper_spec: The MapperSpec for this InputReader.

    Raises:
      BadReaderParamsError: required parameters are missing or invalid.
    """
    if mapper_spec.input_reader_class() != cls:
      raise BadReaderParamsError("Mapper input reader class mismatch")
    params = _get_params(mapper_spec)
    if cls.BLOB_KEY_PARAM not in params:
      raise BadReaderParamsError("Must specify 'blob_key' for mapper input")
    blob_key = params[cls.BLOB_KEY_PARAM]
    blob_info = blobstore.BlobInfo.get(blobstore.BlobKey(blob_key))
    if not blob_info:
      raise BadReaderParamsError("Could not find blobinfo for key %s" %
                                 blob_key) 
开发者ID:elsigh,项目名称:browserscope,代码行数:21,代码来源:input_readers.py

示例3: __init__

# 需要导入模块: from google.appengine.ext import blobstore [as 别名]
# 或者: from google.appengine.ext.blobstore import BlobKey [as 别名]
def __init__(self, blob_key, start_index, end_index,
               _reader=blobstore.BlobReader):
    """Initializes this instance with the given blob key and file range.

    This BlobstoreZipInputReader will read from the file with index start_index
    up to but not including the file with index end_index.

    Args:
      blob_key: the BlobKey that this input reader is processing.
      start_index: the index of the first file to read.
      end_index: the index of the first file that will not be read.
      _reader: a callable that returns a file-like object for reading blobs.
          Used for dependency injection.
    """
    self._blob_key = blob_key
    self._start_index = start_index
    self._end_index = end_index
    self._reader = _reader
    self._zip = None
    self._entries = None 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:22,代码来源:input_readers.py

示例4: __str__

# 需要导入模块: from google.appengine.ext import blobstore [as 别名]
# 或者: from google.appengine.ext.blobstore import BlobKey [as 别名]
def __str__(self):
    """Returns the string representation of this BlobstoreLineInputReader."""
    return "blobstore.BlobKey(%r):[%d, %d]" % (
        self._blob_key, self._blob_reader.tell(), self._end_position) 
开发者ID:elsigh,项目名称:browserscope,代码行数:6,代码来源:input_readers.py

示例5: split_input

# 需要导入模块: from google.appengine.ext import blobstore [as 别名]
# 或者: from google.appengine.ext.blobstore import BlobKey [as 别名]
def split_input(cls, mapper_spec):
    """Returns a list of shard_count input_spec_shards for input_spec.

    Args:
      mapper_spec: The mapper specification to split from. Must contain
          'blob_keys' parameter with one or more blob keys.

    Returns:
      A list of BlobstoreInputReaders corresponding to the specified shards.
    """
    params = _get_params(mapper_spec)
    blob_keys = params[cls.BLOB_KEYS_PARAM]
    if isinstance(blob_keys, basestring):
      # This is a mechanism to allow multiple blob keys (which do not contain
      # commas) in a single string. It may go away.
      blob_keys = blob_keys.split(",")

    blob_sizes = {}
    for blob_key in blob_keys:
      blob_info = blobstore.BlobInfo.get(blobstore.BlobKey(blob_key))
      blob_sizes[blob_key] = blob_info.size

    shard_count = min(cls._MAX_SHARD_COUNT, mapper_spec.shard_count)
    shards_per_blob = shard_count // len(blob_keys)
    if shards_per_blob == 0:
      shards_per_blob = 1

    chunks = []
    for blob_key, blob_size in blob_sizes.items():
      blob_chunk_size = blob_size // shards_per_blob
      for i in xrange(shards_per_blob - 1):
        chunks.append(BlobstoreLineInputReader.from_json(
            {cls.BLOB_KEY_PARAM: blob_key,
             cls.INITIAL_POSITION_PARAM: blob_chunk_size * i,
             cls.END_POSITION_PARAM: blob_chunk_size * (i + 1)}))
      chunks.append(BlobstoreLineInputReader.from_json(
          {cls.BLOB_KEY_PARAM: blob_key,
           cls.INITIAL_POSITION_PARAM: blob_chunk_size * (shards_per_blob - 1),
           cls.END_POSITION_PARAM: blob_size}))
    return chunks 
开发者ID:elsigh,项目名称:browserscope,代码行数:42,代码来源:input_readers.py

示例6: execute_blob_test

# 需要导入模块: from google.appengine.ext import blobstore [as 别名]
# 或者: from google.appengine.ext.blobstore import BlobKey [as 别名]
def execute_blob_test(self, blob_content, expected_result,
                        base64_encoding=False):
    """Execute a basic blob insertion."""
    expected_key = blobstore.BlobKey('expectedkey')
    expected_creation = datetime.datetime(2008, 11, 12)

    self.generate_blob_key().AndReturn(expected_key)

    self.mox.ReplayAll()
    self.handler.store_blob(content_type='image/png; a="b"; m="n"',
                            filename='stuff.png',
                            md5_hash=hashlib.md5(),
                            blob_file=StringIO.StringIO(blob_content),
                            creation=expected_creation,
                            base64_encoding=base64_encoding)

    self.assertEquals(expected_result,
                      self.storage.OpenBlob(expected_key).read())

    blob_info = blobstore.get(expected_key)
    self.assertFalse(blob_info is None)
    self.assertEquals(('image/png', {'a': 'b', 'm': 'n'}),
                      cgi.parse_header(blob_info.content_type))
    self.assertEquals(expected_creation, blob_info.creation)
    self.assertEquals('stuff.png', blob_info.filename)
    self.assertEquals(len(expected_result), blob_info.size)

    self.mox.VerifyAll() 
开发者ID:elsigh,项目名称:browserscope,代码行数:30,代码来源:blob_upload_test.py

示例7: test_store_and_build_forward_message_with_gs_bucket

# 需要导入模块: from google.appengine.ext import blobstore [as 别名]
# 或者: from google.appengine.ext.blobstore import BlobKey [as 别名]
def test_store_and_build_forward_message_with_gs_bucket(self):
    """Test the high-level method to store a blob and build a MIME message."""
    self.generate_blob_key().AndReturn(blobstore.BlobKey('item1'))

    self.now().AndReturn(datetime.datetime(2008, 11, 12, 10, 40))

    self.mox.ReplayAll()

    form = FakeForm({
        'field1': FakeForm(name='field1',
                           file=StringIO.StringIO('file1'),
                           type='image/png',
                           type_options={'a': 'b', 'x': 'y'},
                           filename='stuff.png',
                           headers={'h1': 'v1',
                                    'h2': 'v2',
                                   }),
        })

    content_type, content_text = self.handler.store_and_build_forward_message(
        form, '================1234==', bucket_name='my-test-bucket')

    self.mox.VerifyAll()

    self.assertEqual(EXPECTED_GENERATED_CONTENT_TYPE_WITH_BUCKET, content_type)
    self.assertMessageEqual(EXPECTED_GENERATED_MIME_MESSAGE_WITH_BUCKET,
                            content_text)

    blob1 = blobstore.get('item1')
    self.assertEquals('stuff.png', blob1.filename) 
开发者ID:elsigh,项目名称:browserscope,代码行数:32,代码来源:blob_upload_test.py

示例8: test_store_and_build_forward_message_utf8_values

# 需要导入模块: from google.appengine.ext import blobstore [as 别名]
# 或者: from google.appengine.ext.blobstore import BlobKey [as 别名]
def test_store_and_build_forward_message_utf8_values(self):
    """Test store and build message method with UTF-8 values."""
    self.generate_blob_key().AndReturn(blobstore.BlobKey('item1'))

    self.now().AndReturn(datetime.datetime(2008, 11, 12, 10, 40))

    self.mox.ReplayAll()

    form = FakeForm({
        'field1': FakeForm(name='field1',
                           file=StringIO.StringIO('file1'),
                           type='text/plain',
                           type_options={'a': 'b', 'x': 'y'},
                           filename='chinese_char_name_\xe6\xb1\x89.txt',
                           headers={'h1': 'v1',
                                    'h2': 'v2',
                                   }),
        })

    content_type, content_text = self.handler.store_and_build_forward_message(
        form, '================1234==')

    self.mox.VerifyAll()

    self.assertEqual(EXPECTED_GENERATED_UTF8_CONTENT_TYPE, content_type)
    self.assertMessageEqual(EXPECTED_GENERATED_UTF8_MIME_MESSAGE,
                            content_text)

    blob1 = blobstore.get('item1')
    self.assertEquals(u'chinese_char_name_\u6c49.txt', blob1.filename) 
开发者ID:elsigh,项目名称:browserscope,代码行数:32,代码来源:blob_upload_test.py

示例9: test_store_and_build_forward_message_latin1_values

# 需要导入模块: from google.appengine.ext import blobstore [as 别名]
# 或者: from google.appengine.ext.blobstore import BlobKey [as 别名]
def test_store_and_build_forward_message_latin1_values(self):
    """Test store and build message method with Latin-1 values."""
    # There is a special exception class for this case. This is designed to
    # emulate production, which currently fails silently. See b/6722082.
    self.generate_blob_key().AndReturn(blobstore.BlobKey('item1'))

    self.now().AndReturn(datetime.datetime(2008, 11, 12, 10, 40))

    self.mox.ReplayAll()

    form = FakeForm({
        'field1': FakeForm(name='field1',
                           file=StringIO.StringIO('file1'),
                           type='text/plain',
                           type_options={'a': 'b', 'x': 'y'},
                           filename='german_char_name_f\xfc\xdfe.txt',
                           headers={'h1': 'v1',
                                    'h2': 'v2',
                                   }),
        })

    self.assertRaises(blob_upload._InvalidMetadataError,
                      self.handler.store_and_build_forward_message, form,
                      '================1234==')

    self.mox.VerifyAll()

    blob1 = blobstore.get('item1')
    self.assertIsNone(blob1) 
开发者ID:elsigh,项目名称:browserscope,代码行数:31,代码来源:blob_upload_test.py

示例10: test_store_and_build_forward_message_no_headers

# 需要导入模块: from google.appengine.ext import blobstore [as 别名]
# 或者: from google.appengine.ext.blobstore import BlobKey [as 别名]
def test_store_and_build_forward_message_no_headers(self):
    """Test default header generation when no headers are provided."""
    self.generate_blob_key().AndReturn(blobstore.BlobKey('item1'))

    self.now().AndReturn(datetime.datetime(2008, 11, 12, 10, 40, 0, 100))

    self.mox.ReplayAll()

    form = FakeForm({'field1': FakeForm(name='field1',
                                        file=StringIO.StringIO('file1'),
                                        type=None,
                                        type_options={},
                                        filename='file1',
                                        headers={}),
                     'field2': FakeForm(name='field2',
                                        value='variable1',
                                        type=None,
                                        type_options={},
                                        filename=None,
                                        headers={}),
                    })

    content_type, content_text = self.handler.store_and_build_forward_message(
        form, '================1234==')

    self.mox.VerifyAll()

    self.assertEqual(EXPECTED_GENERATED_CONTENT_TYPE_NO_HEADERS, content_type)
    self.assertMessageEqual(EXPECTED_GENERATED_MIME_MESSAGE_NO_HEADERS,
                            content_text) 
开发者ID:elsigh,项目名称:browserscope,代码行数:32,代码来源:blob_upload_test.py

示例11: test_store_and_build_forward_message_zero_length_blob

# 需要导入模块: from google.appengine.ext import blobstore [as 别名]
# 或者: from google.appengine.ext.blobstore import BlobKey [as 别名]
def test_store_and_build_forward_message_zero_length_blob(self):
    """Test upload with a zero length blob."""
    self.generate_blob_key().AndReturn(blobstore.BlobKey('item1'))
    self.generate_blob_key().AndReturn(blobstore.BlobKey('item2'))

    self.now().AndReturn(datetime.datetime(2008, 11, 12, 10, 40))

    self.mox.ReplayAll()

    form = FakeForm({
        'field1': FakeForm(name='field1',
                           file=StringIO.StringIO('file1'),
                           type='image/png',
                           type_options={'a': 'b', 'x': 'y'},
                           filename='stuff.png',
                           headers={'h1': 'v1',
                                    'h2': 'v2',
                                   }),
        'field2': FakeForm(name='field2',
                           file=StringIO.StringIO(''),
                           type='application/pdf',
                           type_options={},
                           filename='stuff.pdf',
                           headers={}),
        })

    content_type, content_text = self.handler.store_and_build_forward_message(
        form, '================1234==')

    self.mox.VerifyAll()

    self.assertEqual(EXPECTED_GENERATED_CONTENT_TYPE_ZERO_LENGTH_BLOB,
                     content_type)
    self.assertMessageEqual(EXPECTED_GENERATED_MIME_MESSAGE_ZERO_LENGTH_BLOB,
                            content_text)

    blob1 = blobstore.get('item1')
    self.assertEquals('stuff.png', blob1.filename)

    blob2 = blobstore.get('item2')
    self.assertEquals('stuff.pdf', blob2.filename) 
开发者ID:elsigh,项目名称:browserscope,代码行数:43,代码来源:blob_upload_test.py

示例12: test_store_and_build_forward_message_max_blob_size_exceeded

# 需要导入模块: from google.appengine.ext import blobstore [as 别名]
# 或者: from google.appengine.ext.blobstore import BlobKey [as 别名]
def test_store_and_build_forward_message_max_blob_size_exceeded(self):
    """Test upload with a blob larger than the maximum blob size."""
    self.generate_blob_key().AndReturn(blobstore.BlobKey('item1'))

    self.now().AndReturn(datetime.datetime(2008, 11, 12, 10, 40))

    self.mox.ReplayAll()

    form = FakeForm({
        'field1': FakeForm(name='field1',
                           file=StringIO.StringIO('a'),
                           type='image/png',
                           type_options={'a': 'b', 'x': 'y'},
                           filename='stuff.png',
                           headers={'h1': 'v1',
                                    'h2': 'v2',
                                   }),
        'field2': FakeForm(name='field2',
                           file=StringIO.StringIO('longerfile'),
                           type='application/pdf',
                           type_options={},
                           filename='stuff.pdf',
                           headers={}),
        })

    self.assertRaises(webob.exc.HTTPRequestEntityTooLarge,
                      self.handler.store_and_build_forward_message,
                      form, '================1234==', max_bytes_per_blob=2)

    self.mox.VerifyAll()

    blob1 = blobstore.get('item1')
    self.assertIsNone(blob1) 
开发者ID:elsigh,项目名称:browserscope,代码行数:35,代码来源:blob_upload_test.py

示例13: test_store_and_build_forward_message_total_size_exceeded

# 需要导入模块: from google.appengine.ext import blobstore [as 别名]
# 或者: from google.appengine.ext.blobstore import BlobKey [as 别名]
def test_store_and_build_forward_message_total_size_exceeded(self):
    """Test upload with all blobs larger than the total allowed size."""
    self.generate_blob_key().AndReturn(blobstore.BlobKey('item1'))

    self.now().AndReturn(datetime.datetime(2008, 11, 12, 10, 40))

    self.mox.ReplayAll()

    form = FakeForm({
        'field1': FakeForm(name='field1',
                           file=StringIO.StringIO('a'),
                           type='image/png',
                           type_options={'a': 'b', 'x': 'y'},
                           filename='stuff.png',
                           headers={'h1': 'v1',
                                    'h2': 'v2',
                                   }),
        'field2': FakeForm(name='field2',
                           file=StringIO.StringIO('longerfile'),
                           type='application/pdf',
                           type_options={},
                           filename='stuff.pdf',
                           headers={}),
        })

    self.assertRaises(webob.exc.HTTPRequestEntityTooLarge,
                      self.handler.store_and_build_forward_message,
                      form, '================1234==', max_bytes_total=3)

    self.mox.VerifyAll()

    blob1 = blobstore.get('item1')
    self.assertIsNone(blob1) 
开发者ID:elsigh,项目名称:browserscope,代码行数:35,代码来源:blob_upload_test.py

示例14: get_blob_key

# 需要导入模块: from google.appengine.ext import blobstore [as 别名]
# 或者: from google.appengine.ext.blobstore import BlobKey [as 别名]
def get_blob_key(key):
    return blobstore.BlobKey(key) 
开发者ID:singhj,项目名称:locality-sensitive-hashing,代码行数:4,代码来源:blobstore.py


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