python-mega
python-mega copied to clipboard
Python 3 support
I noticed that python-mega
doesn't works on Python 3.x.
I'm checking the code and I think we can add support for Python 3.x, with few bugfixes.
How far are you with that @JuanjoSalvador ?
I need to rewrite a lot of code. WIP, but I'm a bit bussy those days
Maybe I should start fixing those issues. I will fork the project as soon as possible and start to work with that. It seems like @juanriaza has abandoned his own project :(
Update.
#6 seems fixed on #8 (maybe #9 too!). But my priority here is to add Python 3 support.
The issue 6 seems to be solved although not integrated in the files. Issue 9 is linked to following errors coming back from the mega API: API_EAGAIN (-3) (always at the request level): A temporary congestion or server malfunction prevented your request from being processed. No data was altered. Retry. Retries must be spaced with exponential backoff.
To fix the TypeError bug, I tested as follow in Python 2:
if isinstance(req.json(), (int, long)):
return req.json()
else:
return req.json()[0]
I need to check travis's logs, but seems good.
@JuanjoSalvador busy as well. PRs are always welcome
@JuanjoSalvador :+1: I'd like python3 support as well. Let me know if I can help somewhere.
@juanriaza I have a PR open :)
@jeroenmeulenaar we need to rewrite a lot of code, I guess. To be honest, I never migrated a project from Python 2.x to 3.x, so it will be nice if we can coordinate for this task.
I never did as well, but by now it should be well known how to do it :), e.g. transforming strings to bytes now have to specify an encoding, etc.
How do you want to coordinate? You could push your (unfinished) changes to your repo and I can pick up some issues. Or you can tell me which function I should investigate.
My time is also fragmented so in either case don't wait for me :)
utils.py -> 12 functions, 84 lines crypto.py using utils.py functions -> 10 functions, 71 lines mega.py -> 12 functions, 269 lines
I will try to work in that order on my side. I keep you posted.
@madchucky @jeroenmeulenaar i'm using Python's 2to3 lib to make the translations, but we need to improve the tests, and a looot of testing, I guess.
Check the lib here
https://docs.python.org/3.6/library/2to3.html
Tomorrow I will upload my code ready-to-test, but it will be fine if everyone of us take a file (or files) to translate and fix.
My fork is updated with my work for Python3 support [WIP]. There is a lot of issues yet, so we need to re-write the tests and work with them.
https://github.com/JuanjoSalvador/python-mega
I now setup my code-base to work with your changes + my earlier pull request https://github.com/juanriaza/python-mega/pull/8.
The first error I hit is
File "~/github/python-mega/mega/utils.py", line 25, in str_to_a32
return struct.unpack('>%dI' % (len(b) / 4), b)
TypeError: 'str' does not support the buffer interface
Did anybody already figure out how to update this? It something like python3 doesn't convert from String to Bytes without specifying an encoding (python2 then uses UTF-8 by default?), but I don't understand all details yet.
I'm working on it.
Nice. I have a version now which does seem to upload correctly, but I have to implement downloads to test it better. It will be interesting to compare our solutions :).
Would it help you if I pushed my local hacking branch?
@jeroenmeulenaar of course! Publish whatever you have, we can test both libs and find solutions together.
Here is my branch: https://github.com/jeroenmeulenaar/python-mega/tree/python3
I have a testcase now also for downloading, and it looks like everything works.
@juanriaza: do you still want to maintain this project? If so, I'll make a pull request to add python3 support (and fix other bugs).
@JuanjoSalvador : I've published my new project at https://github.com/jeroenmeulenaar/python3-mega. It's python 3 only for now.