De-nest multi-line dicts from function calls.

This commit is contained in:
Ethan Dalool 2020-03-23 19:41:35 -07:00
parent 7384ed9caa
commit e7a8aeda01

View file

@ -122,20 +122,11 @@ class Mega:
password_key = [random.randint(0, 0xFFFFFFFF)] * 4 password_key = [random.randint(0, 0xFFFFFFFF)] * 4
session_self_challenge = [random.randint(0, 0xFFFFFFFF)] * 4 session_self_challenge = [random.randint(0, 0xFFFFFFFF)] * 4
user = self._api_request( k = a32_to_base64(encrypt_key(master_key, password_key))
{ ts = a32_to_str(session_self_challenge)
'a': ts += a32_to_str(encrypt_key(session_self_challenge, master_key))
'up', ts = base64_url_encode(ts)
'k': user = self._api_request({'a': 'up', 'k': k, 'ts': ts})
a32_to_base64(encrypt_key(master_key, password_key)),
'ts':
base64_url_encode(
a32_to_str(session_self_challenge) + a32_to_str(
encrypt_key(session_self_challenge, master_key)
)
)
}
)
resp = self._api_request({'a': 'us', 'user': user}) resp = self._api_request({'a': 'us', 'user': user})
if isinstance(resp, int): if isinstance(resp, int):
@ -503,14 +494,13 @@ class Mega:
""" """
Get current remaining disk quota in MegaBytes Get current remaining disk quota in MegaBytes
""" """
json_resp = self._api_request( request = {
{
'a': 'uq', 'a': 'uq',
'xfer': 1, 'xfer': 1,
'strg': 1, 'strg': 1,
'v': 1 'v': 1
} }
) json_resp = self._api_request(request)
# convert bytes to megabyes # convert bytes to megabyes
return json_resp['mstrg'] / 1048576 return json_resp['mstrg'] / 1048576
@ -564,13 +554,12 @@ class Mega:
""" """
Destroy a file by its private id Destroy a file by its private id
""" """
return self._api_request( request = {
{
'a': 'd', 'a': 'd',
'n': file_id, 'n': file_id,
'i': self.request_id 'i': self.request_id
} }
) return self._api_request(request)
def destroy_url(self, url): def destroy_url(self, url):
""" """
@ -694,21 +683,18 @@ class Mega:
if file is None: if file is None:
if is_public: if is_public:
file_key = base64_to_a32(file_key) file_key = base64_to_a32(file_key)
file_data = self._api_request( request = {
{
'a': 'g', 'a': 'g',
'g': 1, 'g': 1,
'p': file_handle 'p': file_handle
} }
)
else: else:
file_data = self._api_request( request = {
{
'a': 'g', 'a': 'g',
'g': 1, 'g': 1,
'n': file_handle 'n': file_handle
} }
) file_data = self._api_request(request)
k = ( k = (
file_key[0] ^ file_key[4], file_key[1] ^ file_key[5], file_key[0] ^ file_key[4], file_key[1] ^ file_key[5],
@ -879,8 +865,7 @@ class Mega:
encrypted_key = a32_to_base64(encrypt_key(key, self.master_key)) encrypted_key = a32_to_base64(encrypt_key(key, self.master_key))
logger.info('Sending request to update attributes') logger.info('Sending request to update attributes')
# update attributes # update attributes
data = self._api_request( request = {
{
'a': 'p', 'a': 'p',
't': dest, 't': dest,
'i': self.request_id, 'i': self.request_id,
@ -893,7 +878,7 @@ class Mega:
} }
] ]
} }
) data = self._api_request(request)
logger.info('Upload complete') logger.info('Upload complete')
return data return data
@ -907,8 +892,7 @@ class Mega:
encrypted_key = a32_to_base64(encrypt_key(ul_key[:4], self.master_key)) encrypted_key = a32_to_base64(encrypt_key(ul_key[:4], self.master_key))
# update attributes # update attributes
data = self._api_request( request = {
{
'a': 'p', 'a': 'p',
't': parent_node_id, 't': parent_node_id,
'n': [ 'n': [
@ -921,7 +905,7 @@ class Mega:
], ],
'i': self.request_id 'i': self.request_id
} }
) data = self._api_request(request)
return data return data
def _root_node_id(self): def _root_node_id(self):
@ -961,17 +945,14 @@ class Mega:
encrypt_key(file['key'], self.master_key) encrypt_key(file['key'], self.master_key)
) )
# update attributes # update attributes
return self._api_request( request = {
[
{
'a': 'a', 'a': 'a',
'attr': encrypt_attribs, 'attr': encrypt_attribs,
'key': encrypted_key, 'key': encrypted_key,
'n': file['h'], 'n': file['h'],
'i': self.request_id 'i': self.request_id
} }
] return self._api_request(request)
)
def move(self, file_id, target): def move(self, file_id, target):
""" """
@ -990,14 +971,13 @@ class Mega:
else: else:
file = target[1] file = target[1]
target_node_id = file['h'] target_node_id = file['h']
return self._api_request( request = {
{
'a': 'm', 'a': 'm',
'n': file_id, 'n': file_id,
't': target_node_id, 't': target_node_id,
'i': self.request_id 'i': self.request_id
} }
) return self._api_request(request)
def add_contact(self, email): def add_contact(self, email):
""" """
@ -1025,14 +1005,13 @@ class Mega:
if not re.match(r"[^@]+@[^@]+\.[^@]+", email): if not re.match(r"[^@]+@[^@]+\.[^@]+", email):
ValidationError('add_contact requires a valid email address') ValidationError('add_contact requires a valid email address')
else: else:
return self._api_request( request = {
{
'a': 'ur', 'a': 'ur',
'u': email, 'u': email,
'l': l, 'l': l,
'i': self.request_id 'i': self.request_id
} }
) return self._api_request(request)
def get_public_url_info(self, url): def get_public_url_info(self, url):
""" """
@ -1095,8 +1074,7 @@ class Mega:
encrypted_key = a32_to_base64(encrypt_key(key, self.master_key)) encrypted_key = a32_to_base64(encrypt_key(key, self.master_key))
encrypted_name = base64_url_encode(encrypt_attr({'n': dest_name}, k)) encrypted_name = base64_url_encode(encrypt_attr({'n': dest_name}, k))
return self._api_request( request = {
{
'a': 'p', 'a': 'p',
't': dest_node['h'], 't': dest_node['h'],
'n': [ 'n': [
@ -1108,4 +1086,4 @@ class Mega:
} }
] ]
} }
) return self._api_request(request)