python-mega icon indicating copy to clipboard operation
python-mega copied to clipboard

Python 3 support

Open JuanjoSalvador opened this issue 6 years ago • 20 comments

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.

JuanjoSalvador avatar Nov 04 '17 11:11 JuanjoSalvador

How far are you with that @JuanjoSalvador ?

madchucky avatar Nov 17 '17 18:11 madchucky

I need to rewrite a lot of code. WIP, but I'm a bit bussy those days

JuanjoSalvador avatar Nov 19 '17 15:11 JuanjoSalvador

@JuanjoSalvador Will you solve issue 6 and the error handling of issue 9 too?

madchucky avatar Nov 22 '17 15:11 madchucky

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.

JuanjoSalvador avatar Nov 22 '17 16:11 JuanjoSalvador

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]

madchucky avatar Nov 22 '17 16:11 madchucky

I need to check travis's logs, but seems good.

JuanjoSalvador avatar Nov 22 '17 17:11 JuanjoSalvador

@JuanjoSalvador busy as well. PRs are always welcome

juanriaza avatar Nov 26 '17 15:11 juanriaza

@JuanjoSalvador :+1: I'd like python3 support as well. Let me know if I can help somewhere.

@juanriaza I have a PR open :)

jeroenmeulenaar avatar Dec 02 '17 18:12 jeroenmeulenaar

@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.

JuanjoSalvador avatar Dec 02 '17 21:12 JuanjoSalvador

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 :)

jeroenmeulenaar avatar Dec 03 '17 10:12 jeroenmeulenaar

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 avatar Dec 03 '17 18:12 madchucky

@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.

JuanjoSalvador avatar Dec 03 '17 20:12 JuanjoSalvador

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

JuanjoSalvador avatar Dec 10 '17 19:12 JuanjoSalvador

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.

jeroenmeulenaar avatar Dec 26 '17 08:12 jeroenmeulenaar

I'm working on it.

JuanjoSalvador avatar Dec 26 '17 15:12 JuanjoSalvador

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 avatar Dec 27 '17 07:12 jeroenmeulenaar

@jeroenmeulenaar of course! Publish whatever you have, we can test both libs and find solutions together.

JuanjoSalvador avatar Dec 27 '17 09:12 JuanjoSalvador

Here is my branch: https://github.com/jeroenmeulenaar/python-mega/tree/python3

jeroenmeulenaar avatar Dec 27 '17 12:12 jeroenmeulenaar

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).

jeroenmeulenaar avatar Dec 30 '17 12:12 jeroenmeulenaar

@JuanjoSalvador : I've published my new project at https://github.com/jeroenmeulenaar/python3-mega. It's python 3 only for now.

jeroenmeulenaar avatar Mar 19 '18 10:03 jeroenmeulenaar