Skip to content

Commit b807a00

Browse files
authored
Clean up a documentation for the storage blob module. (#3376)
Many of the links were formatted incorrectly, etc.
1 parent 469d675 commit b807a00

File tree

1 file changed

+61
-43
lines changed
  • storage/google/cloud/storage

1 file changed

+61
-43
lines changed

storage/google/cloud/storage/blob.py

Lines changed: 61 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@
1414

1515
# pylint: disable=too-many-lines
1616

17-
"""Create / interact with Google Cloud Storage blobs."""
17+
"""Create / interact with Google Cloud Storage blobs.
18+
19+
.. _API reference docs: https://cloud.google.com/storage/docs/\
20+
json_api/v1/objects
21+
.. _customer-supplied: https://cloud.google.com/storage/docs/\
22+
encryption#customer-supplied
23+
.. _google-resumable-media: https://googlecloudplatform.github.io/\
24+
google-resumable-media-python/latest/\
25+
google.resumable_media.requests.html
26+
"""
1827

1928
import base64
2029
import copy
@@ -427,18 +436,20 @@ def download_to_file(self, file_obj, client=None):
427436
If the server-set property, :attr:`media_link`, is not yet
428437
initialized, makes an additional API request to load it.
429438
430-
Downloading a file that has been encrypted with a `customer-supplied`_
431-
encryption key:
439+
Downloading a file that has been encrypted with a `customer-supplied`_
440+
encryption key:
432441
433442
.. literalinclude:: storage_snippets.py
434443
:start-after: [START download_to_file]
435444
:end-before: [END download_to_file]
445+
:dedent: 4
436446
437447
The ``encryption_key`` should be a str or bytes with a length of at
438448
least 32.
439449
440-
.. _customer-supplied: https://cloud.google.com/storage/docs/\
441-
encryption#customer-supplied
450+
For more fine-grained over the download process, check out
451+
`google-resumable-media`_. For example, this library allows
452+
downloading **parts** of a blob rather than the whole thing.
442453
443454
:type file_obj: file
444455
:param file_obj: A file handle to which to write the blob's data.
@@ -531,8 +542,8 @@ def _get_writable_metadata(self):
531542
532543
This is intended to be used when creating a new object / blob.
533544
534-
See the `API reference`_ for more information, the fields marked as
535-
writable are:
545+
See the `API reference docs`_ for more information, the fields
546+
marked as writable are:
536547
537548
* ``acl``
538549
* ``cacheControl``
@@ -548,9 +559,6 @@ def _get_writable_metadata(self):
548559
549560
For now, we don't support ``acl``, access control lists should be
550561
managed directly through :class:`ObjectACL` methods.
551-
552-
.. _API reference: https://cloud.google.com/storage/\
553-
docs/json_api/v1/objects
554562
"""
555563
# NOTE: This assumes `self.name` is unicode.
556564
object_metadata = {'name': self.name}
@@ -828,22 +836,21 @@ def upload_from_file(self, file_obj, rewind=False, size=None,
828836
bucket. In the absence of those policies, upload will
829837
overwrite any existing contents.
830838
831-
See the `object versioning
832-
<https://cloud.google.com/storage/docs/object-versioning>`_ and
833-
`lifecycle <https://cloud.google.com/storage/docs/lifecycle>`_
834-
API documents for details.
839+
See the `object versioning`_ and `lifecycle`_ API documents
840+
for details.
835841
836842
Uploading a file with a `customer-supplied`_ encryption key:
837843
838844
.. literalinclude:: storage_snippets.py
839845
:start-after: [START upload_from_file]
840846
:end-before: [END upload_from_file]
847+
:dedent: 4
841848
842849
The ``encryption_key`` should be a str or bytes with a length of at
843850
least 32.
844851
845-
.. _customer-supplied: https://cloud.google.com/storage/docs/\
846-
encryption#customer-supplied
852+
For more fine-grained over the upload process, check out
853+
`google-resumable-media`_.
847854
848855
:type file_obj: file
849856
:param file_obj: A file handle open for reading.
@@ -870,6 +877,10 @@ def upload_from_file(self, file_obj, rewind=False, size=None,
870877
871878
:raises: :class:`~google.cloud.exceptions.GoogleCloudError`
872879
if the upload response returns an error status.
880+
881+
.. _object versioning: https://cloud.google.com/storage/\
882+
docs/object-versioning
883+
.. _lifecycle: https://cloud.google.com/storage/docs/lifecycle
873884
"""
874885
if num_retries is not None:
875886
warnings.warn(_NUM_RETRIES_MESSAGE, DeprecationWarning)
@@ -972,8 +983,9 @@ def create_resumable_upload_session(
972983
access-controlled bucket. For more details, see the
973984
`documentation on signed URLs`_.
974985
975-
.. _documentation on signed URLs: https://cloud.google.com/storage\
976-
/docs/access-control/signed-urls#signing-resumable
986+
.. _documentation on signed URLs:
987+
https://cloud.google.com/storage/\
988+
docs/access-control/signed-urls#signing-resumable
977989
978990
The content type of the upload will be determined in order
979991
of precedence:
@@ -993,10 +1005,8 @@ def create_resumable_upload_session(
9931005
`lifecycle <https://cloud.google.com/storage/docs/lifecycle>`_
9941006
API documents for details.
9951007
996-
If :attr:`encryption_key` is set, the blob will be `encrypted`_.
997-
998-
.. _encrypted: https://cloud.google.com/storage/docs/\
999-
encryption#customer-supplied
1008+
If :attr:`encryption_key` is set, the blob will be encrypted with
1009+
a `customer-supplied`_ encryption key.
10001010
10011011
:type size: int
10021012
:param size: (Optional). The maximum number of bytes that can be
@@ -1236,67 +1246,73 @@ def update_storage_class(self, new_class, client=None):
12361246
cache_control = _scalar_property('cacheControl')
12371247
"""HTTP 'Cache-Control' header for this object.
12381248
1239-
See: https://tools.ietf.org/html/rfc7234#section-5.2 and
1240-
https://cloud.google.com/storage/docs/json_api/v1/objects
1249+
See: `RFC 7234`_ and `API reference docs`_.
12411250
1242-
If the property is not set locally, returns ``None``.
1251+
If the property is not set locally, returns :data:`None`.
12431252
12441253
:rtype: str or ``NoneType``
1254+
1255+
.. _RFC 7234: https://tools.ietf.org/html/rfc7234#section-5.2
12451256
"""
12461257

12471258
content_disposition = _scalar_property('contentDisposition')
12481259
"""HTTP 'Content-Disposition' header for this object.
12491260
1250-
See: https://tools.ietf.org/html/rfc6266 and
1251-
https://cloud.google.com/storage/docs/json_api/v1/objects
1261+
See: `RFC 6266`_ and `API reference docs`_.
12521262
1253-
If the property is not set locally, returns ``None``.
1263+
If the property is not set locally, returns :data:`None`.
12541264
12551265
:rtype: str or ``NoneType``
1266+
1267+
.. _RFC 6266: https://tools.ietf.org/html/rfc7234#section-5.2
12561268
"""
12571269

12581270
content_encoding = _scalar_property('contentEncoding')
12591271
"""HTTP 'Content-Encoding' header for this object.
12601272
1261-
See: https://tools.ietf.org/html/rfc7231#section-3.1.2.2 and
1262-
https://cloud.google.com/storage/docs/json_api/v1/objects
1273+
See: `RFC 7231`_ and `API reference docs`_.
12631274
12641275
If the property is not set locally, returns ``None``.
12651276
12661277
:rtype: str or ``NoneType``
1278+
1279+
.. _RFC 7231: https://tools.ietf.org/html/rfc7231#section-3.1.2.2
12671280
"""
12681281

12691282
content_language = _scalar_property('contentLanguage')
12701283
"""HTTP 'Content-Language' header for this object.
12711284
1272-
See: https://tools.ietf.org/html/bcp47 and
1273-
https://cloud.google.com/storage/docs/json_api/v1/objects
1285+
See: `BCP47`_ and `API reference docs`_.
12741286
1275-
If the property is not set locally, returns ``None``.
1287+
If the property is not set locally, returns :data:`None`.
12761288
12771289
:rtype: str or ``NoneType``
1290+
1291+
.. _BCP47: https://tools.ietf.org/html/bcp47
12781292
"""
12791293

12801294
content_type = _scalar_property(_CONTENT_TYPE_FIELD)
12811295
"""HTTP 'Content-Type' header for this object.
12821296
1283-
See: https://tools.ietf.org/html/rfc2616#section-14.17 and
1284-
https://cloud.google.com/storage/docs/json_api/v1/objects
1297+
See: `RFC 2616`_ and `API reference docs`_.
12851298
1286-
If the property is not set locally, returns ``None``.
1299+
If the property is not set locally, returns :data:`None`.
12871300
12881301
:rtype: str or ``NoneType``
1302+
1303+
.. _RFC 2616: https://tools.ietf.org/html/rfc2616#section-14.17
12891304
"""
12901305

12911306
crc32c = _scalar_property('crc32c')
12921307
"""CRC32C checksum for this object.
12931308
1294-
See: https://tools.ietf.org/html/rfc4960#appendix-B and
1295-
https://cloud.google.com/storage/docs/json_api/v1/objects
1309+
See: `RFC 4960`_ and `API reference docs`_.
12961310
1297-
If the property is not set locally, returns ``None``.
1311+
If the property is not set locally, returns :data:`None`.
12981312
12991313
:rtype: str or ``NoneType``
1314+
1315+
.. _RFC 4960: https://tools.ietf.org/html/rfc4960#appendix-B
13001316
"""
13011317

13021318
@property
@@ -1318,11 +1334,12 @@ def component_count(self):
13181334
def etag(self):
13191335
"""Retrieve the ETag for the object.
13201336
1321-
See: https://tools.ietf.org/html/rfc2616#section-3.11 and
1322-
https://cloud.google.com/storage/docs/json_api/v1/objects
1337+
See: `RFC 2616 (etags)`_ and `API reference docs`_.
13231338
13241339
:rtype: str or ``NoneType``
13251340
:returns: The blob etag or ``None`` if the property is not set locally.
1341+
1342+
.. _RFC 2616 (etags): https://tools.ietf.org/html/rfc2616#section-3.11
13261343
"""
13271344
return self._properties.get('etag')
13281345

@@ -1355,12 +1372,13 @@ def id(self):
13551372
md5_hash = _scalar_property('md5Hash')
13561373
"""MD5 hash for this object.
13571374
1358-
See: https://tools.ietf.org/html/rfc4960#appendix-B and
1359-
https://cloud.google.com/storage/docs/json_api/v1/objects
1375+
See: `RFC 1321`_ and `API reference docs`_.
13601376
13611377
If the property is not set locally, returns ``None``.
13621378
13631379
:rtype: str or ``NoneType``
1380+
1381+
.. _RFC 1321: https://tools.ietf.org/html/rfc1321
13641382
"""
13651383

13661384
@property

0 commit comments

Comments
 (0)