예제 #1
0
파일: blobstore.py 프로젝트: girum11/hang
def fetch_data_async(blob, start_index, end_index, rpc=None):
    """Fetch data for blob -- async version.

  Fetches a fragment of a blob up to MAX_BLOB_FETCH_SIZE in length.  Attempting
  to fetch a fragment that extends beyond the boundaries of the blob will return
  the amount of data from start_index until the end of the blob, which will be
  a smaller size than requested.  Requesting a fragment which is entirely
  outside the boundaries of the blob will return empty string.  Attempting
  to fetch a negative index will raise an exception.

  Args:
    blob: BlobInfo, BlobKey, str or unicode representation of BlobKey of
      blob to fetch data from.
    start_index: Start index of blob data to fetch.  May not be negative.
    end_index: End index (inclusive) of blob data to fetch.  Must be
      >= start_index.
    rpc: Optional UserRPC object.

  Returns:
    A UserRPC whose result will be a str as returned by fetch_data().

  Raises:
    TypeError if start_index or end_index are not indexes.  Also when blob
      is not a string, BlobKey or BlobInfo.
    The following exceptions may be raised when rpc.get_result() is
    called:
    DataIndexOutOfRangeError when start_index < 0 or end_index < start_index.
    BlobFetchSizeTooLargeError when request blob fragment is larger than
      MAX_BLOB_FETCH_SIZE.
    BlobNotFoundError when blob does not exist.
  """
    if isinstance(blob, BlobInfo):
        blob = blob.key()
    return blobstore.fetch_data_async(blob, start_index, end_index, rpc=rpc)
예제 #2
0
def fetch_data_async(blob, start_index, end_index, rpc=None):
  """Fetch data for blob -- async version.

  Fetches a fragment of a blob up to MAX_BLOB_FETCH_SIZE in length.  Attempting
  to fetch a fragment that extends beyond the boundaries of the blob will return
  the amount of data from start_index until the end of the blob, which will be
  a smaller size than requested.  Requesting a fragment which is entirely
  outside the boundaries of the blob will return empty string.  Attempting
  to fetch a negative index will raise an exception.

  Args:
    blob: BlobInfo, BlobKey, str or unicode representation of BlobKey of
      blob to fetch data from.
    start_index: Start index of blob data to fetch.  May not be negative.
    end_index: End index (inclusive) of blob data to fetch.  Must be
      >= start_index.
    rpc: Optional UserRPC object.

  Returns:
    A UserRPC whose result will be a str as returned by fetch_data().

  Raises:
    TypeError if start_index or end_index are not indexes.  Also when blob
      is not a string, BlobKey or BlobInfo.
    The following exceptions may be raised when rpc.get_result() is
    called:
    DataIndexOutOfRangeError when start_index < 0 or end_index < start_index.
    BlobFetchSizeTooLargeError when request blob fragment is larger than
      MAX_BLOB_FETCH_SIZE.
    BlobNotFoundError when blob does not exist.
  """
  if isinstance(blob, BlobInfo):
    blob = blob.key()
  return blobstore.fetch_data_async(blob, start_index, end_index, rpc=rpc)
예제 #3
0
def fetch_data_async(blob, start_index, end_index, **options):
    """Async version of fetch_data()."""
    if isinstance(blob, BlobInfo):
        blob = blob.key()
    rpc = blobstore.create_rpc(**options)
    rpc = blobstore.fetch_data_async(blob, start_index, end_index, rpc=rpc)
    result = yield rpc
    raise tasklets.Return(result)
예제 #4
0
def fetch_data_async(blob, start_index, end_index, **options):
  """Async version of fetch_data()."""
  if isinstance(blob, BlobInfo):
    blob = blob.key()
  rpc = blobstore.create_rpc(**options)
  rpc = blobstore.fetch_data_async(blob, start_index, end_index, rpc=rpc)
  result = yield rpc
  raise tasklets.Return(result)
예제 #5
0
def fetch_data_async(blob, start_index, end_index, rpc=None):
  """Asynchronously fetches data for a blob.

  Fetches a fragment of a blob up to `MAX_BLOB_FETCH_SIZE` in length. Attempting
  to fetch a fragment that extends beyond the boundaries of the blob will return
  the amount of data from `start_index` until the end of the blob, which will be
  a smaller size than requested. Requesting a fragment that is entirely outside
  the boundaries of the blob will return an empty string. Attempting to fetch a
  negative index will raise an exception.

  Args:
    blob: A `BlobInfo`, `BlobKey`, string, or Unicode representation of
        the `BlobKey` of the blob from which you want to fetch data.
    start_index: The start index of blob data to fetch. This value must not be
        negative.
    end_index: The end index (inclusive) of the blob data to fetch. This value
        must be greater than or equal to `start_index`.
    rpc: Optional UserRPC object.

  Returns:
    A UserRPC whose result will be a string as returned by `fetch_data()`.

  Raises:
    TypeError: If `start_index` or `end_index` are not indexes, or if `blob` is
        not a string, `BlobKey` or `BlobInfo`.
    DataIndexOutOfRangeError: If `start_index` is set to a value that is less
        than 0 or `end_index` is less than `start_index` when calling
        `rpc.get_result()`.
    BlobFetchSizeTooLargeError: If the requested blob fragment is larger than
        `MAX_BLOB_FETCH_SIZE` when calling `rpc.get_result()`.
    BlobNotFoundError: If the blob does not exist when calling
        `rpc.get_result()`.
  """
  if isinstance(blob, BlobInfo):
    blob = blob.key()
  return blobstore.fetch_data_async(blob, start_index, end_index, rpc=rpc)
예제 #6
0
def fetch_data_async(blob, start_index, end_index, rpc=None):
  """Asynchronously fetches data for a blob.

  Fetches a fragment of a blob up to `MAX_BLOB_FETCH_SIZE` in length. Attempting
  to fetch a fragment that extends beyond the boundaries of the blob will return
  the amount of data from `start_index` until the end of the blob, which will be
  a smaller size than requested. Requesting a fragment that is entirely outside
  the boundaries of the blob will return an empty string. Attempting to fetch a
  negative index will raise an exception.

  Args:
    blob: A `BlobInfo`, `BlobKey`, string, or Unicode representation of
        the `BlobKey` of the blob from which you want to fetch data.
    start_index: The start index of blob data to fetch. This value must not be
        negative.
    end_index: The end index (inclusive) of the blob data to fetch. This value
        must be greater than or equal to `start_index`.
    rpc: Optional UserRPC object.

  Returns:
    A UserRPC whose result will be a string as returned by `fetch_data()`.

  Raises:
    TypeError: If `start_index` or `end_index` are not indexes, or if `blob` is
        not a string, `BlobKey` or `BlobInfo`.
    DataIndexOutOfRangeError: If `start_index` is set to a value that is less
        than 0 or `end_index` is less than `start_index` when calling
        `rpc.get_result()`.
    BlobFetchSizeTooLargeError: If the requested blob fragment is larger than
        `MAX_BLOB_FETCH_SIZE` when calling `rpc.get_result()`.
    BlobNotFoundError: If the blob does not exist when calling
        `rpc.get_result()`.
  """
  if isinstance(blob, BlobInfo):
    blob = blob.key()
  return blobstore.fetch_data_async(blob, start_index, end_index, rpc=rpc)