google.appengine.ext.cloudstorage.common module

Summary

Helpers shared by cloudstorage_stub and cloudstorage_api.

Contents

google.appengine.ext.cloudstorage.common.CSFileStat

alias of GCSFileStat

google.appengine.ext.cloudstorage.common.dt_str_to_posix(dt_str)source

format str to posix.

datetime str is of format %Y-%m-%dT%H:%M:%S.%fZ, e.g. 2013-04-12T00:22:27.978Z. According to ISO 8601, T is a separator between date and time when they are on the same line. Z indicates UTC (zero meridian).

A pointer: http://www.cl.cam.ac.uk/~mgk25/iso-time.html

This is used to parse LastModified node from GCS's GET bucket XML response.

Parameters

dt_str -- A datetime str.

Returns

A float of secs from unix epoch. By posix definition, epoch is midnight 1970/1/1 UTC.

google.appengine.ext.cloudstorage.common.local_api_url()source

Return URL for GCS emulation on dev appserver.

google.appengine.ext.cloudstorage.common.local_run()source

Whether we should hit GCS dev appserver stub.

google.appengine.ext.cloudstorage.common.get_access_token()source

Returns the shared access token.

google.appengine.ext.cloudstorage.common.get_stored_content_length(headers)source

Return the content length (in bytes) of the object as stored in GCS.

x-goog-stored-content-length should always be present except when called via the local dev_appserver. Therefore if it is not present we default to the standard content-length header.

Parameters

headers -- a dict of headers from the http response.

Returns

the stored content length.

google.appengine.ext.cloudstorage.common.get_metadata(headers)source

Get user defined options from HTTP response headers.

class google.appengine.ext.cloudstorage.common.GCSFileStat(filename, st_size, etag, st_ctime, content_type=None, metadata=None, is_dir=False)source

Bases: object

Container for GCS file stat.

google.appengine.ext.cloudstorage.common.http_time_to_posix(http_time)source

Convert HTTP time format to posix time.

See http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1 for http time format.

Parameters

http_time -- time in RFC 2616 format. e.g. "Mon, 20 Nov 1995 19:12:08 GMT".

Returns

A float of secs from unix epoch.

google.appengine.ext.cloudstorage.common.memory_usage(method)source

Log memory usage before and after a method.

google.appengine.ext.cloudstorage.common.posix_time_to_http(posix_time)source

Convert posix time to HTML header time format.

Parameters

posix_time -- unix time.

Returns

A datatime str in RFC 2616 format.

google.appengine.ext.cloudstorage.common.posix_to_dt_str(posix)source

Reverse of str_to_datetime.

This is used by GCS stub to generate GET bucket XML response.

Parameters

posix -- A float of secs from unix epoch.

Returns

A datetime str.

google.appengine.ext.cloudstorage.common.set_access_token(access_token)source

Set the shared access token to authenticate with Google Cloud Storage.

When set, the library will always attempt to communicate with the real Google Cloud Storage with this token even when running on dev appserver. Note the token could expire so it's up to you to renew it.

When absent, the library will automatically request and refresh a token on appserver, or when on dev appserver, talk to a Google Cloud Storage stub.

Parameters

access_token -- you can get one by run 'gsutil -d ls' and copy the str after 'Bearer'.

google.appengine.ext.cloudstorage.common.validate_options(options)source

Validate Google Cloud Storage options.

Parameters

options -- a str->basestring dict of options to pass to Google Cloud Storage.

Raises
  • ValueError -- if option is not supported.

  • TypeError -- if option is not of type str or value of an option is not of type basestring.

google.appengine.ext.cloudstorage.common.validate_bucket_name(name)source

Validate a Google Storage bucket name.

Parameters

name -- a Google Storage bucket name with no prefix or suffix.

Raises

ValueError -- if name is invalid.

google.appengine.ext.cloudstorage.common.validate_bucket_path(path)source

Validate a Google Cloud Storage bucket path.

Parameters

path -- a Google Storage bucket path. It should have form '/bucket'.

Raises

ValueError -- if path is invalid.

google.appengine.ext.cloudstorage.common.validate_file_path(path)source

Validate a Google Cloud Storage file path.

Parameters

path -- a Google Storage file path. It should have form '/bucket/filename'.

Raises

ValueError -- if path is invalid.

Send feedback about...

App Engine standard environment for Python