From 400701f50d638f6b3145bbb7bf500cb89d4ae163 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Thu, 1 Oct 2020 11:27:31 -0700 Subject: [PATCH] Dedent by raising early. --- src/mega/mega.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/mega/mega.py b/src/mega/mega.py index a950287..f32d8bd 100644 --- a/src/mega/mega.py +++ b/src/mega/mega.py @@ -427,23 +427,23 @@ class Mega: files = [self._node_data(file) for file in files] - if all('h' in file and 'k' in file for file in files): - request = [{'a': 'l', 'n': file['h']} for file in files] - public_handles = self._api_request(request) - if public_handles == -11: - raise errors.RequestError( - "Can't get a public link from that file " - "(is this a shared file?)" - ) - urls = [] - for (file, public_handle) in zip(files, public_handles): - decrypted_key = crypto.a32_to_base64(file['key']) - url = f'{self.schema}://{self.domain}/#!{public_handle}!{decrypted_key}' - urls.append(url) - return urls - else: + if not all('h' in file and 'k' in file for file in files): raise errors.ValidationError('File id and key must be present') + request = [{'a': 'l', 'n': file['h']} for file in files] + public_handles = self._api_request(request) + if public_handles == -11: + raise errors.RequestError( + "Can't get a public link from that file " + "(is this a shared file?)" + ) + urls = [] + for (file, public_handle) in zip(files, public_handles): + decrypted_key = crypto.a32_to_base64(file['key']) + url = f'{self.schema}://{self.domain}/#!{public_handle}!{decrypted_key}' + urls.append(url) + return urls + def _node_data(self, node): if isinstance(node, dict): return node