in jupyter-gcs-contents-manager/gcs_contents_manager.py [0:0]
def _blob_model(self, normalized_path, blob, content=True):
blob_obj = {}
blob_obj['path'] = normalized_path
blob_obj['name'] = posixpath.basename(normalized_path)
blob_obj['last_modified'] = blob.updated
blob_obj['created'] = blob.time_created
blob_obj['writable'] = True
blob_obj['type'] = 'notebook' if blob_obj['name'].endswith(
'.ipynb') else 'file'
if not content:
blob_obj['mimetype'] = None
blob_obj['format'] = None
blob_obj['content'] = None
return blob_obj
content_str = blob.download_as_string() if content else None
if blob_obj['type'] == 'notebook':
blob_obj['mimetype'] = None
blob_obj['format'] = 'json'
blob_obj['content'] = nbformat.reads(content_str, as_version=4)
elif blob.content_type.startswith('text/'):
blob_obj['mimetype'] = 'text/plain'
blob_obj['format'] = 'text'
blob_obj['content'] = content_str.decode(utf8_encoding)
else:
blob_obj['mimetype'] = 'application/octet-stream'
blob_obj['format'] = 'base64'
blob_obj['content'] = base64.b64encode(content_str)
return blob_obj