|
30 | 30 | from gcloud.credentials import generate_signed_url |
31 | 31 | from gcloud.storage._helpers import _PropertyMixin |
32 | 32 | from gcloud.storage._helpers import _scalar_property |
| 33 | +from gcloud.storage import _implicit_environ |
33 | 34 | from gcloud.storage.acl import ObjectACL |
34 | 35 |
|
35 | 36 |
|
36 | 37 | _API_ACCESS_ENDPOINT = 'https://storage.googleapis.com' |
37 | 38 |
|
38 | 39 |
|
39 | 40 | class Blob(_PropertyMixin): |
40 | | - """A wrapper around Cloud Storage's concept of an ``Object``.""" |
| 41 | + """A wrapper around Cloud Storage's concept of an ``Object``. |
| 42 | +
|
| 43 | + :type name: string |
| 44 | + :param name: The name of the blob. This corresponds to the |
| 45 | + unique path of the object in the bucket. |
| 46 | +
|
| 47 | + :type bucket: :class:`gcloud.storage.bucket.Bucket` |
| 48 | + :param bucket: The bucket to which this blob belongs. Required, unless the |
| 49 | + implicit default bucket has been set. |
| 50 | +
|
| 51 | + :type properties: dict |
| 52 | + :param properties: All the other data provided by Cloud Storage. |
| 53 | + """ |
41 | 54 |
|
42 | 55 | CUSTOM_PROPERTY_ACCESSORS = { |
43 | 56 | 'acl': 'acl', |
@@ -70,23 +83,18 @@ class Blob(_PropertyMixin): |
70 | 83 | # ACL rules are lazily retrieved. |
71 | 84 | _acl = None |
72 | 85 |
|
73 | | - def __init__(self, bucket=None, name=None, properties=None): |
74 | | - """Blob constructor. |
75 | | -
|
76 | | - :type bucket: :class:`gcloud.storage.bucket.Bucket` |
77 | | - :param bucket: The bucket to which this blob belongs. |
78 | | -
|
79 | | - :type name: string |
80 | | - :param name: The name of the blob. This corresponds to the |
81 | | - unique path of the object in the bucket. |
82 | | -
|
83 | | - :type properties: dict |
84 | | - :param properties: All the other data provided by Cloud Storage. |
85 | | - """ |
| 86 | + def __init__(self, name, bucket=None, properties=None): |
86 | 87 | if name is None and properties is not None: |
87 | 88 | name = properties.get('name') |
| 89 | + |
88 | 90 | super(Blob, self).__init__(name=name, properties=properties) |
| 91 | + |
| 92 | + if bucket is None: |
| 93 | + bucket = _implicit_environ.BUCKET |
| 94 | + |
89 | 95 | self.bucket = bucket |
| 96 | + if bucket is None: |
| 97 | + raise ValueError('A Blob must have a bucket set.') |
90 | 98 |
|
91 | 99 | @property |
92 | 100 | def acl(self): |
@@ -120,9 +128,7 @@ def path(self): |
120 | 128 | :rtype: string |
121 | 129 | :returns: The URL path to this Blob. |
122 | 130 | """ |
123 | | - if not self.bucket: |
124 | | - raise ValueError('Cannot determine path without a bucket defined.') |
125 | | - elif not self.name: |
| 131 | + if not self.name: |
126 | 132 | raise ValueError('Cannot determine path without a blob name.') |
127 | 133 |
|
128 | 134 | return self.bucket.path + '/o/' + quote(self.name, safe='') |
|
0 commit comments