rm deprecation notice, its alive again

This commit is contained in:
Richard O'Dwyer 2019-10-22 22:40:11 +01:00
parent 93f3e6d376
commit deaa5468ec
11 changed files with 43 additions and 72 deletions

View file

@ -3,6 +3,7 @@ language: python
python: python:
- 2.7 - 2.7
- 3.7 - 3.7
- 3.8
env: env:
- TOXENV=py-normal - TOXENV=py-normal

View file

@ -3,12 +3,6 @@ a mirror of the primary remote located at
`https://code.richard.do/explore/projects`_. Please direct issues and `https://code.richard.do/explore/projects`_. Please direct issues and
pull requests there. pull requests there.
Deprecated
==========
Mega.py is now deprecated, please use the official SDK
`https://github.com/meganz/sdk`_.
I aim to write a wrapper for the SDK when i have the time to do so. I aim to write a wrapper for the SDK when i have the time to do so.
-------------- --------------

View file

@ -1,2 +1,4 @@
requests>=0.10 requests>=0.10
pycrypto pycrypto
pathlib==1.0.1
python2-secrets==1.0.5

View file

@ -11,7 +11,7 @@ norecursedirs = .git
[flake8] [flake8]
exclude = .git,__pycache__,legacy,build,dist,.tox exclude = .git,__pycache__,legacy,build,dist,.tox
max-complexity = 15 max-complexity = 15
ignore = E741 ignore = E741,W504
[yapf] [yapf]
based_on_style = pep8 based_on_style = pep8

View file

@ -14,11 +14,11 @@ os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))
with open('requirements.txt') as f: with open('requirements.txt') as f:
install_requires = f.read().splitlines() install_requires = f.read().splitlines()
# with open('README.rst', 'r', encoding='utf-8') as rm_file: with open('README.rst', 'r', encoding='utf-8') as rm_file:
# readme = rm_file.read() readme = rm_file.read()
# with open('HISTORY.rst', 'r', encoding='utf-8') as hist_file: with open('HISTORY.rst', 'r', encoding='utf-8') as hist_file:
# history = hist_file.read() history = hist_file.read()
setup( setup(
name='mega.py', name='mega.py',
@ -28,6 +28,7 @@ setup(
include_package_data=True, include_package_data=True,
zip_safe=False, zip_safe=False,
description='Python lib for the Mega.co.nz API', description='Python lib for the Mega.co.nz API',
long_description=readme + '\n\n' + history,
author='Richard O\'Dwyer', author='Richard O\'Dwyer',
author_email='richard@richard.do', author_email='richard@richard.do',
license='Creative Commons Attribution-Noncommercial-Share Alike license', license='Creative Commons Attribution-Noncommercial-Share Alike license',

View file

@ -1,19 +0,0 @@
[{
"a": "log",
"e": 99635
}, {
"a": "s2",
"n": "oUchHSzJ",
"s": [{
"u": "EXP",
"r": 0
}],
"i": "q6CpLxTDNV",
"ok": "uGuwXS80VfifU1hcLlKcrQ",
"ha": "n6dI3_qVste9XPma5fMIKQ",
"cr": [
["oUchHSzJ"],
["oUchHSzJ"],
[0, 0, "ff5m7sr6LZlYyRtiEE9EZA"]
]
}]

View file

@ -1,6 +1,8 @@
import re import re
import time
import json import json
import secrets import secrets
from pathlib import Path
import hashlib import hashlib
from Crypto.Cipher import AES from Crypto.Cipher import AES
from Crypto.PublicKey import RSA from Crypto.PublicKey import RSA
@ -114,7 +116,8 @@ class Mega(object):
for i in range(4): for i in range(4):
if PYTHON2: if PYTHON2:
l = ( l = (
(ord(private_key[0]) * 256 + ord(private_key[1]) + 7) / 8 (ord(private_key[0]) * 256 +
ord(private_key[1]) + 7) / 8
) + 2 ) + 2
else: else:
l = int( l = int(
@ -155,6 +158,9 @@ class Mega(object):
) )
json_resp = json.loads(req.text) json_resp = json.loads(req.text)
if isinstance(json_resp, int): if isinstance(json_resp, int):
if json_resp == -3:
time.sleep(0.2)
return self._api_request(data=data)
raise RequestError(json_resp) raise RequestError(json_resp)
return json_resp[0] return json_resp[0]
@ -289,7 +295,6 @@ class Mega(object):
""" """
Return file object from given filename Return file object from given filename
""" """
from pathlib import Path
path = Path(filename) path = Path(filename)
filename = path.name filename = path.name
files = self.get_files() files = self.get_files()
@ -300,12 +305,10 @@ class Mega(object):
parent_node_id = self.find_path_descriptor(parent_dir_name) parent_node_id = self.find_path_descriptor(parent_dir_name)
if ( if (
filename and parent_node_id and filename and parent_node_id and
file[1]['a'] and file[1]['a']['n'] == filename file[1]['a'] and file[1]['a']['n'] == filename and
and parent_node_id == file[1]['p'] parent_node_id == file[1]['p']
): ):
return file return file
# if not isinstance(file[1]['a'], dict):
# continue
if ( if (
filename and filename and
file[1]['a'] and file[1]['a']['n'] == filename file[1]['a'] and file[1]['a']['n'] == filename
@ -577,10 +580,6 @@ class Mega(object):
except (RequestError, KeyError): except (RequestError, KeyError):
pass pass
user_id = folder[1]['u']
user_pub_key = self._api_request({'a': 'uk', 'u': user_id})['pubk']
node_key = folder[1]['k']
master_key_cipher = AES.new(a32_to_str(self.master_key), AES.MODE_ECB) master_key_cipher = AES.new(a32_to_str(self.master_key), AES.MODE_ECB)
ha = base64_url_encode( ha = base64_url_encode(
master_key_cipher.encrypt(folder[1]['h'] + folder[1]['h']) master_key_cipher.encrypt(folder[1]['h'] + folder[1]['h'])
@ -590,6 +589,7 @@ class Mega(object):
ok = base64_url_encode(master_key_cipher.encrypt(share_key)) ok = base64_url_encode(master_key_cipher.encrypt(share_key))
share_key_cipher = AES.new(share_key, AES.MODE_ECB) share_key_cipher = AES.new(share_key, AES.MODE_ECB)
node_key = folder[1]['k']
encrypted_node_key = base64_url_encode( encrypted_node_key = base64_url_encode(
share_key_cipher.encrypt(a32_to_str(node_key)) share_key_cipher.encrypt(a32_to_str(node_key))
) )
@ -606,12 +606,9 @@ class Mega(object):
'i': self.request_id, 'i': self.request_id,
'ok': ok, 'ok': ok,
'ha': ha, 'ha': ha,
'cr': [ 'cr': [[node_id], [node_id], [0, 0, encrypted_node_key]]
[node_id], }
[node_id],
[0, 0, encrypted_node_key]
] ]
}]
self._api_request(request_body) self._api_request(request_body)
nodes = self.get_files() nodes = self.get_files()
link = self.get_folder_link(nodes[node_id]) link = self.get_folder_link(nodes[node_id])
@ -792,13 +789,6 @@ class Mega(object):
# encrypt file and upload # encrypt file and upload
chunk = aes.encrypt(chunk) chunk = aes.encrypt(chunk)
try:
output_file = requests.post(
ul_url + "/" + str(chunk_start),
data=chunk,
timeout=self.timeout
)
except:
output_file = requests.post( output_file = requests.post(
ul_url + "/" + str(chunk_start), ul_url + "/" + str(chunk_start),
data=chunk, data=chunk,
@ -876,7 +866,7 @@ class Mega(object):
# update attributes # update attributes
data = self._api_request( data = self._api_request(
{ {
'a':'p', 'a': 'p',
't': dest, 't': dest,
'n': [ 'n': [
{ {

0
src/tests/__init__.py Normal file
View file

0
src/tests/test_errors.py Normal file
View file

View file

@ -75,10 +75,10 @@ class TestExport:
# Upload a single file into a folder # Upload a single file into a folder
folder = mega.find(TEST_FOLDER) folder = mega.find(TEST_FOLDER)
dest_node_id = folder[1]['h'] dest_node_id = folder[1]['h']
result = mega.upload( mega.upload(
__file__, dest=dest_node_id, dest_filename='test.py' __file__, dest=dest_node_id, dest_filename='test.py'
) )
path = f'{TEST_FOLDER}/test.py' path = '{}/test.py'.format(TEST_FOLDER)
assert mega.find(path) assert mega.find(path)
for _ in range(2): for _ in range(2):

View file

@ -1,5 +1,5 @@
[tox] [tox]
envlist = py{27,37}-normal,lint envlist = py{27,37,38}-normal,lint
[testenv] [testenv]
commands = commands =
@ -7,7 +7,9 @@ commands =
coverage erase coverage erase
python setup.py install python setup.py install
pytest {toxinidir}/src/tests/tests.py pytest {toxinidir}/src/tests/tests.py
passenv =
EMAIL
PASS
deps = deps =
-rrequirements-dev.txt -rrequirements-dev.txt