Skip to content

Commit a7c70ef

Browse files
committed
Fix the issue where get_alt_export_link
raises key error and update gdrive utils to use `dict.get()` instead of `dict[]`.
1 parent 197582d commit a7c70ef

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

waterbutler/providers/googledrive/provider.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,11 @@ async def download(self, # type: ignore
235235
metadata = await self.metadata(path, revision=revision)
236236

237237
if kwargs.get('mfr', None) and kwargs['mfr'].lower() == 'true':
238-
download_url = drive_utils.get_alt_export_link(metadata.raw) # type: ignore
238+
download_url = metadata.raw.get('downloadUrl') or drive_utils.get_alt_export_link(metadata.raw)
239239
export_name = metadata.alt_export_name
240240
else:
241-
242-
# TODO figure out metadata.raw.get('downloadUrl')
243-
download_url = metadata.raw.get('downloadUrl') or drive_utils.get_export_link(metadata.raw) # type: ignore
244-
export_name = metadata.export_name # type: ignore
241+
download_url = metadata.raw.get('downloadUrl') or drive_utils.get_export_link(metadata.raw)
242+
export_name = metadata.export_name
245243

246244
download_resp = await self.make_request(
247245
'GET',

waterbutler/providers/googledrive/utils.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
'type': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
2727
},
2828
]
29+
2930
DOCS_DEFAULT_FORMAT = {
3031
'ext': '',
3132
'download_ext': '.pdf',
@@ -40,41 +41,41 @@ def is_docs_file(metadata):
4041

4142
def get_mimetype_from_ext(ext):
4243
for format_type in DOCS_FORMATS:
43-
if format_type['ext'] == ext:
44-
return format_type['mime_type']
44+
if format_type.get('ext') == ext:
45+
return format_type.get('mime_type')
4546

4647

4748
def get_format(metadata):
4849
for format_type in DOCS_FORMATS:
49-
if format_type['mime_type'] == metadata['mimeType']:
50+
if format_type.get('mime_type') == metadata.get('mimeType'):
5051
return format_type
5152
return DOCS_DEFAULT_FORMAT
5253

5354

5455
def get_extension(metadata):
5556
format_type = get_format(metadata)
56-
return format_type['ext']
57+
return format_type.get('ext')
5758

5859

5960
def get_download_extension(metadata):
6061
format_type = get_format(metadata)
61-
return format_type['download_ext']
62+
return format_type.get('download_ext')
6263

6364

6465
def get_alt_download_extension(metadata):
6566
format_type = get_format(metadata)
66-
return format_type.get('alt_download_ext', None) or format_type['download_ext']
67+
return format_type.get('alt_download_ext', None) or format_type.get('download_ext')
6768

6869

6970
def get_alt_export_link(metadata):
7071
format_type = get_format(metadata)
71-
export_links = metadata['exportLinks']
72+
export_links = metadata.get('exportLinks')
7273
if format_type.get('alt_type'):
73-
return export_links.get(format_type['alt_type'])
74+
return export_links.get(format_type.get('alt_type'))
7475
else:
75-
return export_links[format_type['type']]
76+
return export_links.get(format_type.get('type'))
7677

7778

7879
def get_export_link(metadata):
7980
format_type = get_format(metadata)
80-
return metadata['exportLinks'][format_type['type']]
81+
return metadata.get('exportLinks').get(format_type.get('type'))

0 commit comments

Comments
 (0)