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