diff --git a/gcloud/datastore/__init__.py b/gcloud/datastore/__init__.py index 0de26dddcb2eb..bff7408255cf3 100644 --- a/gcloud/datastore/__init__.py +++ b/gcloud/datastore/__init__.py @@ -71,7 +71,8 @@ def get_connection(client_email, private_key_path): def get_dataset(dataset_id, client_email, private_key_path): - """Shortcut method to establish a connection to a particular dataset in the Cloud Datastore. + """Shortcut method to establish a connection to a particular + dataset in the Cloud Datastore. You'll generally use this as the first call to working with the API: diff --git a/gcloud/datastore/connection.py b/gcloud/datastore/connection.py index cd04302496bdc..60744ee41a3ae 100644 --- a/gcloud/datastore/connection.py +++ b/gcloud/datastore/connection.py @@ -72,8 +72,7 @@ def _request(self, dataset_id, method, data): """ headers = { 'Content-Type': 'application/x-protobuf', - 'Content-Length': str(len(data)), - } + 'Content-Length': str(len(data)), } headers, content = self.http.request( uri=self.build_api_url(dataset_id=dataset_id, method=method), method='POST', headers=headers, body=data) @@ -99,7 +98,7 @@ def build_api_url(cls, dataset_id, method, base_url=None, api_version=None): :type dataset_id: string :param dataset_id: The ID of the dataset to connect to. - This is usually your project name in the cloud console. + This is usually your project name in the cloud console. :type method: string :param method: The API method to call (ie, runQuery, lookup, ...). @@ -134,7 +133,7 @@ def dataset(self, *args, **kwargs): """Factory method for Dataset objects. :param args: All args and kwargs will be passed along to the - :class:`gcloud.datastore.dataset.Dataset` initializer. + :class:`gcloud.datastore.dataset.Dataset` initializer. :rtype: :class:`gcloud.datastore.dataset.Dataset` :returns: A dataset object that will use this connection as its transport. @@ -156,7 +155,8 @@ def begin_transaction(self, dataset_id, serializable=False): request = datastore_pb.BeginTransactionRequest() if serializable: - request.isolation_level = datastore_pb.BeginTransactionRequest.SERIALIZABLE + request.isolation_level = ( + datastore_pb.BeginTransactionRequest.SERIALIZABLE) else: request.isolation_level = datastore_pb.BeginTransactionRequest.SNAPSHOT @@ -226,7 +226,8 @@ def run_query(self, dataset_id, query_pb, namespace=None): request.partition_id.namespace = namespace request.query.CopyFrom(query_pb) - response = self._rpc(dataset_id, 'runQuery', request, datastore_pb.RunQueryResponse) + response = self._rpc(dataset_id, 'runQuery', request, + datastore_pb.RunQueryResponse) return [e.entity for e in response.batch.entity_result] def lookup(self, dataset_id, key_pbs): diff --git a/gcloud/datastore/demo/__init__.py b/gcloud/datastore/demo/__init__.py index a4cc561e63153..9de811485b0cb 100644 --- a/gcloud/datastore/demo/__init__.py +++ b/gcloud/datastore/demo/__init__.py @@ -5,7 +5,8 @@ __all__ = ['get_dataset', 'CLIENT_EMAIL', 'DATASET_ID', 'PRIVATE_KEY_PATH'] -CLIENT_EMAIL = '754762820716-gimou6egs2hq1rli7el2t621a1b04t9i@developer.gserviceaccount.com' +CLIENT_EMAIL = ('754762820716-gimou6egs2hq1rli7el2t621a1b04t9i' + '@developer.gserviceaccount.com') DATASET_ID = 'gcloud-datastore-demo' PRIVATE_KEY_PATH = os.path.join(os.path.dirname(__file__), 'demo.key') diff --git a/gcloud/datastore/entity.py b/gcloud/datastore/entity.py index 9d7de7a4f5846..6ec029c3967bf 100644 --- a/gcloud/datastore/entity.py +++ b/gcloud/datastore/entity.py @@ -43,19 +43,22 @@ class Entity(dict): >>> dataset.entity('MyEntityKind') - - :func:`gcloud.datastore.dataset.Dataset.get_entity` to retrive an existing entity. + - :func:`gcloud.datastore.dataset.Dataset.get_entity` + to retrive an existing entity. >>> dataset.get_entity(key) - You can the set values on the entity just like you would on any other dictionary. + You can the set values on the entity + just like you would on any other dictionary. >>> entity['age'] = 20 >>> entity['name'] = 'JJ' >>> entity - And you can cast an entity to a regular Python dictionary with the `dict` builtin: + And you can cast an entity to a regular Python dictionary + with the `dict` builtin: >>> dict(entity) {'age': 20, 'name': 'JJ'} @@ -68,7 +71,8 @@ def __init__(self, dataset=None, kind=None): self._key = None def dataset(self): - """Get the :class:`gcloud.datastore.dataset.Dataset` in which this entity belonds. + """Get the :class:`gcloud.datastore.dataset.Dataset` + in which this entity belonds. .. note:: This is based on the :class:`gcloud.datastore.key.Key` set on the entity. @@ -116,12 +120,14 @@ def kind(self): @classmethod def from_key(cls, key): - """Factory method for creating an entity based on the :class:`gcloud.datastore.key.Key`. + """Factory method for creating an entity based on the + :class:`gcloud.datastore.key.Key`. :type key: :class:`gcloud.datastore.key.Key` :param key: The key for the entity. - :returns: The :class:`Entity` derived from the :class:`gcloud.datastore.key.Key`. + :returns: The :class:`Entity` derived from the + :class:`gcloud.datastore.key.Key`. """ return cls().key(key) @@ -135,7 +141,8 @@ def from_protobuf(cls, pb, dataset=None): :type key: :class:`gcloud.datastore.datastore_v1_pb2.Entity` :param key: The Protobuf representing the entity. - :returns: The :class:`Entity` derived from the :class:`gcloud.datastore.datastore_v1_pb2.Entity`. + :returns: The :class:`Entity` derived from the + :class:`gcloud.datastore.datastore_v1_pb2.Entity`. """ # This is here to avoid circular imports. diff --git a/gcloud/datastore/query.py b/gcloud/datastore/query.py index 821ee4ba95330..48a894d15260f 100644 --- a/gcloud/datastore/query.py +++ b/gcloud/datastore/query.py @@ -46,8 +46,7 @@ class Query(object): '<=': datastore_pb.PropertyFilter.LESS_THAN_OR_EQUAL, '>': datastore_pb.PropertyFilter.GREATER_THAN, '>=': datastore_pb.PropertyFilter.GREATER_THAN_OR_EQUAL, - '=': datastore_pb.PropertyFilter.EQUAL, - } + '=': datastore_pb.PropertyFilter.EQUAL, } """Mapping of operator strings and their protobuf equivalents.""" def __init__(self, kind=None, dataset=None): @@ -63,7 +62,8 @@ def _clone(self): return clone def to_protobuf(self): - """Convert the :class:`Query` instance to a :class:`gcloud.datastore.datastore_v1_pb2.Query`. + """Convert the :class:`Query` instance to a + :class:`gcloud.datastore.datastore_v1_pb2.Query`. :rtype: :class:`gclouddatstore.datastore_v1_pb2.Query` :returns: A Query protobuf that can be sent to the protobuf API. diff --git a/gcloud/storage/acl.py b/gcloud/storage/acl.py index 3c873bcaecc08..0daa49ec024c7 100644 --- a/gcloud/storage/acl.py +++ b/gcloud/storage/acl.py @@ -379,7 +379,8 @@ def save(self): class DefaultObjectACL(BucketACL): - """A subclass of BucketACL representing the default object ACL for a bucket.""" + """A subclass of BucketACL representing the + default object ACL for a bucket.""" def save(self): """Save this ACL as the default object ACL for the current bucket.""" diff --git a/gcloud/storage/bucket.py b/gcloud/storage/bucket.py index 605800c947656..5c4f14f5f01d2 100644 --- a/gcloud/storage/bucket.py +++ b/gcloud/storage/bucket.py @@ -102,7 +102,8 @@ def get_all_keys(self): return list(self) def new_key(self, key): - """Given a path name (or a Key), return a :class:`gcloud.storage.key.Key` object. + """Given a path name (or a Key), return a :class:`gcloud.storage.key.Key` + object. This is really useful when you're not sure if you have a Key object or a string path name. diff --git a/gcloud/storage/connection.py b/gcloud/storage/connection.py index cc6fcc435679a..9212a9615b509 100644 --- a/gcloud/storage/connection.py +++ b/gcloud/storage/connection.py @@ -464,8 +464,8 @@ def generate_signed_url(self, resource, expiration, expiration = int(time.mktime(expiration.timetuple())) if not isinstance(expiration, (int, long)): - raise ValueError('Expected an integer timestamp, datetime, or timedelta. ' - 'Got %s' % type(expiration)) + raise ValueError('Expected an integer timestamp, datetime, or ' + 'timedelta. Got %s' % type(expiration)) # Generate the string to sign. signature_string = '\n'.join([ @@ -476,7 +476,8 @@ def generate_signed_url(self, resource, expiration, resource]) # Take our PKCS12 (.p12) key and make it into a RSA key we can use... - pkcs12 = crypto.load_pkcs12(base64.b64decode(self.credentials.private_key), 'notasecret') + pkcs12 = crypto.load_pkcs12(base64.b64decode(self.credentials.private_key), + 'notasecret') pem = crypto.dump_privatekey(crypto.FILETYPE_PEM, pkcs12.get_privatekey()) pem_key = RSA.importKey(pem) diff --git a/gcloud/storage/demo/__init__.py b/gcloud/storage/demo/__init__.py index 862095a851b81..156a543144b81 100644 --- a/gcloud/storage/demo/__init__.py +++ b/gcloud/storage/demo/__init__.py @@ -5,7 +5,8 @@ __all__ = ['get_connection', 'CLIENT_EMAIL', 'PRIVATE_KEY_PATH', 'PROJECT'] -CLIENT_EMAIL = '606734090113-6ink7iugcv89da9sru7lii8bs3i0obqg@developer.gserviceaccount.com' +CLIENT_EMAIL = ('606734090113-6ink7iugcv89da9sru7lii8bs3i0obqg@' + 'developer.gserviceaccount.com') PRIVATE_KEY_PATH = os.path.join(os.path.dirname(__file__), 'demo.key') PROJECT = 'gcloud-storage-demo' diff --git a/gcloud/storage/iterator.py b/gcloud/storage/iterator.py index e7f75428f1f05..e76013eba1c82 100644 --- a/gcloud/storage/iterator.py +++ b/gcloud/storage/iterator.py @@ -146,7 +146,8 @@ def __init__(self, connection): super(BucketIterator, self).__init__(connection=connection, path='/b') def get_items_from_response(self, response): - """Factory method which yields :class:`gcloud.storage.bucket.Bucket` items from a response. + """Factory method which yields :class:`gcloud.storage.bucket.Bucket` + items from a response. :type response: dict :param response: The JSON API response for a page of buckets. @@ -174,7 +175,8 @@ def __init__(self, bucket): connection=bucket.connection, path=bucket.path + '/o') def get_items_from_response(self, response): - """Factory method which yields :class:`gcloud.storage.key.Key` items from a response. + """Factory method which yields :class:`gcloud.storage.key.Key` + items from a response. :type response: dict :param response: The JSON API response for a page of keys. diff --git a/gcloud/storage/key.py b/gcloud/storage/key.py index 174fe4fcd322b..d144283c9f06d 100644 --- a/gcloud/storage/key.py +++ b/gcloud/storage/key.py @@ -95,7 +95,8 @@ def public_url(self): return '{storage_base_url}/{self.bucket.name}/{self.name}'.format( storage_base_url='http://commondatastorage.googleapis.com', self=self) - def generate_signed_url(self, expiration, method='GET'): # pragma NO COVER UGH + def generate_signed_url(self, expiration, + method='GET'): # pragma NO COVER UGH """Generates a signed URL for this key. If you have a key that you want to allow access to @@ -207,8 +208,7 @@ def set_contents_from_file(self, fh, rewind=False, size=None, # Set up a resumable upload session. headers = { 'X-Upload-Content-Type': content_type or 'application/unknown', - 'X-Upload-Content-Length': total_bytes - } + 'X-Upload-Content-Length': total_bytes} upload_url = self.connection.build_api_url( path=self.bucket.path + '/o', @@ -231,8 +231,7 @@ def set_contents_from_file(self, fh, rewind=False, size=None, end = bytes_uploaded + chunk_size - 1 headers = { - 'Content-Range': 'bytes %d-%d/%d' % (start, end, total_bytes), - } + 'Content-Range': 'bytes %d-%d/%d' % (start, end, total_bytes), } response, content = self.connection.make_request( content_type='text/plain', diff --git a/gcloud/storage/test_bucket.py b/gcloud/storage/test_bucket.py index b655eaa06df1e..9fbed40e9ad77 100644 --- a/gcloud/storage/test_bucket.py +++ b/gcloud/storage/test_bucket.py @@ -350,7 +350,7 @@ def test_get_metadata_none_set_acl_hit(self): self.assertEqual(kw[0]['path'], '/b/%s' % NAME) self.assertEqual(kw[0]['query_params'], {'projection': 'full'}) - def test_get_metadata_none_set_defaultObjectAcl_miss_explicit_default(self): + def test_get_metadata_none_set_defaultObjectAcl_miss_clear_default(self): NAME = 'name' after = {'bar': 'Bar'} connection = _Connection(after) diff --git a/gcloud/storage/test_connection.py b/gcloud/storage/test_connection.py index d0a997c571a7c..32f03919b4791 100644 --- a/gcloud/storage/test_connection.py +++ b/gcloud/storage/test_connection.py @@ -155,7 +155,7 @@ def test_make_request_no_data_no_content_type_no_headers(self): self.assertEqual(http._called_with['body'], None) self.assertEqual(http._called_with['headers'], {'Accept-Encoding': 'gzip', - 'Content-Length': 0, }) + 'Content-Length': 0, }) def test_make_request_w_data_no_extra_headers(self): PROJECT = 'project' @@ -170,7 +170,7 @@ def test_make_request_w_data_no_extra_headers(self): self.assertEqual(http._called_with['body'], {}) self.assertEqual(http._called_with['headers'], {'Accept-Encoding': 'gzip', - 'Content-Length': 0, + 'Content-Length': 0, 'Content-Type': 'application/json', }) def test_make_request_w_extra_headers(self): @@ -186,7 +186,7 @@ def test_make_request_w_extra_headers(self): self.assertEqual(http._called_with['body'], None) self.assertEqual(http._called_with['headers'], {'Accept-Encoding': 'gzip', - 'Content-Length': 0, + 'Content-Length': 0, 'X-Foo': 'foo', }) def test_api_request_defaults(self): @@ -206,7 +206,7 @@ def test_api_request_defaults(self): self.assertEqual(http._called_with['body'], None) self.assertEqual(http._called_with['headers'], {'Accept-Encoding': 'gzip', - 'Content-Length': 0, }) + 'Content-Length': 0, }) def test_api_request_w_path(self): PROJECT = 'project' @@ -223,7 +223,7 @@ def test_api_request_w_path(self): self.assertEqual(http._called_with['body'], None) self.assertEqual(http._called_with['headers'], {'Accept-Encoding': 'gzip', - 'Content-Length': 0, }) + 'Content-Length': 0, }) def test_api_request_w_non_json_response(self): PROJECT = 'project' @@ -273,7 +273,7 @@ def test_api_request_w_query_params(self): self.assertEqual(http._called_with['body'], None) self.assertEqual(http._called_with['headers'], {'Accept-Encoding': 'gzip', - 'Content-Length': 0, }) + 'Content-Length': 0, }) def test_api_request_w_data(self): import json @@ -293,7 +293,7 @@ def test_api_request_w_data(self): self.assertEqual(http._called_with['body'], DATAJ) self.assertEqual(http._called_with['headers'], {'Accept-Encoding': 'gzip', - 'Content-Length': len(DATAJ), + 'Content-Length': len(DATAJ), 'Content-Type': 'application/json', }) def test_api_request_w_404(self):