示例#1
0
def create(mime_type='application/octet-stream',
           _blobinfo_uploaded_filename=None):
    """Create a writable blobstore file.

  Args:
    mime_type: Resulting blob content MIME type as string.
    _blobinfo_uploaded_filename: Resulting blob's BlobInfo file name as string.

  Returns:
    A file name for blobstore file. This file can be opened for write
    by File API open function. To read the file or obtain its blob key, finalize
    it and call get_blob_key function.
  """
    if not mime_type:
        raise files.InvalidArgumentError('Empty mime_type')
    if not isinstance(mime_type, six.string_types):
        raise files.InvalidArgumentError('Expected string for mime_type')

    params = {_MIME_TYPE_PARAMETER: mime_type}
    if _blobinfo_uploaded_filename:
        if not isinstance(_blobinfo_uploaded_filename, six.string_types):
            raise files.InvalidArgumentError(
                'Expected string for _blobinfo_uploaded_filename')
        params[
            _BLOBINFO_UPLOADED_FILENAME_PARAMETER] = _blobinfo_uploaded_filename
    return files._create(_BLOBSTORE_FILESYSTEM, params=params)
示例#2
0
def create(mime_type='application/octet-stream',
           _blobinfo_uploaded_filename=None):
  """Create a writable blobstore file.

  Args:
    mime_type: Resulting blob content MIME type as string.
    _blobinfo_uploaded_filename: Resulting blob's BlobInfo file name as string.

  Returns:
    A file name for blobstore file. This file can be opened for write
    by File API open function. To read the file or obtain its blob key, finalize
    it and call get_blob_key function.
  """
  if not mime_type:
    raise files.InvalidArgumentError('Empty mime_type')
  if not isinstance(mime_type, str):
    raise files.InvalidArgumentError('Expected string for mime_type')

  params = {_MIME_TYPE_PARAMETER: mime_type}
  if _blobinfo_uploaded_filename:
    if not isinstance(_blobinfo_uploaded_filename, str):
      raise files.InvalidArgumentError(
          'Expected string for _blobinfo_uploaded_filename')
    params[_BLOBINFO_UPLOADED_FILENAME_PARAMETER] = _blobinfo_uploaded_filename
  return files._create(_BLOBSTORE_FILESYSTEM, params=params)
def create(mime_type="application/octet-stream", _blobinfo_uploaded_filename=None):
    """Create a writable blobstore file.

  Args:
    mime_type: Resulting blob content MIME type as string.
    _blobinfo_uploaded_filename: Resulting blob's BlobInfo file name as string.

  Returns:
    A file name for blobstore file. This file can be opened for write
    by File API open function. To read the file or obtain its blob key, finalize
    it and call get_blob_key function.
  """
    params = {_MIME_TYPE_PARAMETER: mime_type}
    if _blobinfo_uploaded_filename:
        params[_BLOBINFO_UPLOADED_FILENAME_PARAMETER] = _blobinfo_uploaded_filename
    return files._create(_BLOBSTORE_FILESYSTEM, params=params)
def create(mime_type='application/octet-stream',
           _blobinfo_uploaded_filename=None):
  """Create a writable blobstore file.

  Args:
    mime_type: Resulting blob content MIME type as string.
    _blobinfo_uploaded_filename: Resulting blob's BlobInfo file name as string.

  Returns:
    A file name for blobstore file. This file can be opened for write
    by File API open function. To read the file or obtain its blob key, finalize
    it and call get_blob_key function.
  """
  params = {_MIME_TYPE_PARAMETER: mime_type}
  if _blobinfo_uploaded_filename:
    params[_BLOBINFO_UPLOADED_FILENAME_PARAMETER] = _blobinfo_uploaded_filename
  return files._create(_BLOBSTORE_FILESYSTEM, params=params)
示例#5
0
def create(filename,
           mime_type='application/octet-stream',
           acl=None,
           cache_control=None,
           content_encoding=None,
           content_disposition=None,
           user_metadata=None):
    """Create a writable googlestore file.

  Args:
    filename: Google Storage object name (/gs/bucket/object)
    mime_type: Blob content MIME type as string.
    acl: Canned acl to apply to the object as per:
      http://code.google.com/apis/storage/docs/reference-headers.html#xgoogacl
      If not specified (or set to None), default object acl is used.
    cache_control: Cache control header to set when serving through Google
      storage. If not specified, default of 3600 seconds is used.
    content_encoding: If object is compressed, specify the compression method
      here to set the header correctly when served through Google Storage.
    content_disposition: Header to use when serving through Google Storage.
    user_metadata: Dictionary specifying key value pairs to apply to the
      object. Each key is prefixed with x-goog-meta- when served through
      Google Storage.

  Returns:
    A writable file name for a Google Storage file. This file can be opened for
    write by File API open function. To read the file call file::open with the
    plain Google Storage filename (/gs/bucket/object).
  """
    if not filename:
        raise files.InvalidArgumentError('Empty filename')
    elif not isinstance(filename, basestring):
        raise files.InvalidArgumentError('Expected string for filename',
                                         filename)
    elif not filename.startswith(_GS_PREFIX) or filename == _GS_PREFIX:
        raise files.InvalidArgumentError(
            'Google storage files must be of the form /gs/bucket/object',
            filename)
    elif not mime_type:
        raise files.InvalidArgumentError('Empty mime_type')
    elif not isinstance(mime_type, basestring):
        raise files.InvalidArgumentError('Expected string for mime_type',
                                         mime_type)

    params = {_MIME_TYPE_PARAMETER: mime_type}

    if acl:
        if not isinstance(acl, basestring):
            raise files.InvalidArgumentError('Expected string for acl', acl)
        params[_CANNED_ACL_PARAMETER] = acl

    if content_encoding:
        if not isinstance(content_encoding, basestring):
            raise files.InvalidArgumentError(
                'Expected string for content_encoding')
        else:
            params[_CONTENT_ENCODING_PARAMETER] = content_encoding
    if content_disposition:
        if not isinstance(content_disposition, basestring):
            raise files.InvalidArgumentError(
                'Expected string for content_disposition')
        else:
            params[_CONTENT_DISPOSITION_PARAMETER] = content_disposition
    if cache_control:
        if not isinstance(cache_control, basestring):
            raise files.InvalidArgumentError(
                'Expected string for cache_control')
        else:
            params[_CACHE_CONTROL_PARAMETER] = cache_control
    if user_metadata:
        if not isinstance(user_metadata, dict):
            raise files.InvalidArgumentError('Expected dict for user_metadata')
        for key, value in user_metadata.items():
            if not isinstance(key, basestring):
                raise files.InvalidArgumentError(
                    'Expected string for key in user_metadata')
            if not isinstance(value, basestring):
                raise files.InvalidArgumentError(
                    'Expected string for value in user_metadata for key: ',
                    key)
            params[_USER_METADATA_PREFIX + key] = value
    return files._create(_GS_FILESYSTEM, filename=filename, params=params)
示例#6
0
文件: gs.py 项目: cheesun/chees-test
def create(filename,
           mime_type='application/octet-stream',
           acl=None,
           cache_control=None,
           content_encoding=None,
           content_disposition=None,
           user_metadata=None):
  """Create a writable googlestore file.

  Args:
    filename: Google Storage object name (/gs/bucket/object)
    mime_type: Blob content MIME type as string.
    acl: Canned acl to apply to the object as per:
      http://code.google.com/apis/storage/docs/reference-headers.html#xgoogacl
      If not specified (or set to None), default object acl is used.
    cache_control: Cache control header to set when serving through Google
      storage. If not specified, default of 3600 seconds is used.
    content_encoding: If object is compressed, specify the compression method
      here to set the header correctly when served through Google Storage.
    content_disposition: Header to use when serving through Google Storage.
    user_metadata: Dictionary specifying key value pairs to apply to the
      object. Each key is prefixed with x-goog-meta- when served through
      Google Storage.

  Returns:
    A writable file name for a Google Storage file. This file can be opened for
    write by File API open function. To read the file call file::open with the
    plain Google Storage filename (/gs/bucket/object).
  """
  if not filename:
    raise files.InvalidArgumentError('Empty filename')
  elif not isinstance(filename, basestring):
    raise files.InvalidArgumentError('Expected string for filename', filename)
  elif not filename.startswith(_GS_PREFIX) or filename == _GS_PREFIX:
    raise files.InvalidArgumentError(
        'Google storage files must be of the form /gs/bucket/object', filename)
  elif not mime_type:
    raise files.InvalidArgumentError('Empty mime_type')
  elif not isinstance(mime_type, basestring):
    raise files.InvalidArgumentError('Expected string for mime_type', mime_type)

  params = {_MIME_TYPE_PARAMETER: mime_type}

  if acl:
    if not isinstance(acl, basestring):
      raise files.InvalidArgumentError('Expected string for acl', acl)
    params[_CANNED_ACL_PARAMETER] = acl

  if content_encoding:
    if not isinstance(content_encoding, basestring):
      raise files.InvalidArgumentError('Expected string for content_encoding')
    else:
      params[_CONTENT_ENCODING_PARAMETER] = content_encoding
  if content_disposition:
    if not isinstance(content_disposition, basestring):
      raise files.InvalidArgumentError(
          'Expected string for content_disposition')
    else:
      params[_CONTENT_DISPOSITION_PARAMETER] = content_disposition
  if cache_control:
    if not isinstance(cache_control, basestring):
      raise files.InvalidArgumentError('Expected string for cache_control')
    else:
      params[_CACHE_CONTROL_PARAMETER] = cache_control
  if user_metadata:
    if not isinstance(user_metadata, dict):
      raise files.InvalidArgumentError('Expected dict for user_metadata')
    for key, value in user_metadata.items():
      if not isinstance(key, basestring):
        raise files.InvalidArgumentError(
            'Expected string for key in user_metadata')
      if not isinstance(value, basestring):
        raise files.InvalidArgumentError(
            'Expected string for value in user_metadata for key: ', key)
      params[_USER_METADATA_PREFIX + key] = value
  return files._create(_GS_FILESYSTEM, filename=filename, params=params)