-
Notifications
You must be signed in to change notification settings - Fork 363
Fix#37 : Migrate from 2.7 to 3.6 #38
Conversation
…nd 3.6 about `str` and `byte` concatenation. Also update `next()` method from `generator` to `__next__()`
.coverage
Outdated
@@ -0,0 +1 @@ | |||
!coverage.py: This is a private format, don't read it directly!{"lines":{"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/__init__.py":[1],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/adb_commands.py":[23,25,26,27,29,30,31,34,35,36,38,41,43,44,46,49,53,54,55,57,59,78,82,85,86,104,109,112,135,159,184,192,203,211,215,219,223,229,243,97,99,101,102,79,80,225,226,227,209,213,217,221,239,240,241,170,171,174,175,176,177,178,181,182,145,153,154,155,156,157],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/adb_protocol.py":[18,20,21,23,27,29,32,33,34,37,38,40,47,48,51,52,55,56,59,68,69,71,75,80,81,83,89,93,107,110,125,140,150,164,166,167,60,62,61,64,65,169,171,173,180,184,191,196,205,210,211,249,250,318,319,354,355,377,378,187,189,279,280,281,174,175,176,177,178,282,207,193,194,182,208,283,213,214,215,216,217,198,199,200,203,218,219,222,223,230,231,232,233,234,237,239,241,242,247,284,316,375,398,399,336,337,338,339,340,341,342,246,343,346,349,352,84,85,86,87,400,127,128,112,113,114,116,121,122,108,90,91,123,129,132,138,401,130,131,188,95,97,98,105,235,141,142,143],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/usb_exceptions.py":[14,17,18,21,28,30,35,36,39,40,43,48,50,54,59,60,63,64,67,68,71,72,31,32],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/common.py":[17,18,19,20,21,23,24,26,28,30,33,38,48,58,60,61,63,79,89,131,135,139,151,154,163,176,189,197,202,204,212,213,227,228,249,251,275,278,280,296,300,303,306,309,40,41,45],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/filesync_protocol.py":[18,20,21,22,23,25,27,28,31,33,36,37,40,41,44,45,48,49,52,53,55,66,78,88,90,125,126,129,130,132,134,146,166,191,199,203,211,81,135,138,139,142,143,144,82,157,158,160,200,201,163,164,83,193,194,168,169,204,205,209,172,213,214,215,217,218,219,173,175,177,183,187,188,189,195,84,86,196,85,103,105,106,108,109,110,112,111,114,118,119,120,121],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/sign_m2crypto.py":[15],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/fastboot.py":[14,16,17,18,19,20,21,22,24,25,28,30,31,32,35,36,37,38,39,41,46,47,50,51,54,55,58,59,60,63,64,65,67,77,81,93,106,107,139,176,188,202,203,205,214,218,221,223,230,235,239,240,262,263,294,308,316,328,342,346,360,211,212,74,75,280,284,286,287,288,290,88,89,90,190,193,194,195,196,198,291,292,127,128,155,156,157,158,160,162,163,166,168,130,131,132,136,137,167,169,170,171,133,134,135,305,306,236,237,103,161,253,255,256,257,258,281,282,191,192,178,179,180,199,181,182,259,260,314,326,344,357,358,362,339,340,173,174,164,165],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/common_cli.py":[],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/adb_debug.py":[],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/sign_pythonrsa.py":[],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/fastboot_debug.py":[]}} No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add this to .gitignore (without the /)
|
||
python: | ||
- 2.7 | ||
- 3.6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We must still support 2.7
adb.egg-info/PKG-INFO
Outdated
@@ -0,0 +1,31 @@ | |||
Metadata-Version: 1.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't check adb.egg_info in either (add to .gitignore)
adb/fastboot.py
Outdated
if progress_callback: | ||
progress = self._HandleProgress(length, progress_callback) | ||
progress.next() | ||
progress.__next__() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the next()
builtin to support 2.7 and 3.x
'License :: OSI Approved :: Apache Software License', | ||
'Programming Language :: Python', | ||
#'Programming Language :: Python :: 3', ## import cStringIO fails with python3 | ||
'Programming Language :: Python :: 3', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add 2.7 as well
Thank you for the contribution though! |
….6. Add retrocompatibility for python 2.7 with sys_version checking
.coverage
Outdated
@@ -1 +1 @@ | |||
!coverage.py: This is a private format, don't read it directly!{"lines":{"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/__init__.py":[1],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/adb_commands.py":[23,25,26,27,29,30,31,34,35,36,38,41,43,44,46,49,53,54,55,57,59,78,82,85,86,104,109,112,135,159,184,192,203,211,215,219,223,229,243,97,99,101,102,79,80,225,226,227,209,213,217,221,239,240,241,170,171,174,175,176,177,178,181,182,145,153,154,155,156,157],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/adb_protocol.py":[18,20,21,23,27,29,32,33,34,37,38,40,47,48,51,52,55,56,59,68,69,71,75,80,81,83,89,93,107,110,125,140,150,164,166,167,60,62,61,64,65,169,171,173,180,184,191,196,205,210,211,249,250,318,319,354,355,377,378,187,189,279,280,281,174,175,176,177,178,282,207,193,194,182,208,283,213,214,215,216,217,198,199,200,203,218,219,222,223,230,231,232,233,234,237,239,241,242,247,284,316,375,398,399,336,337,338,339,340,341,342,246,343,346,349,352,84,85,86,87,400,127,128,112,113,114,116,121,122,108,90,91,123,129,132,138,401,130,131,188,95,97,98,105,235,141,142,143],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/usb_exceptions.py":[14,17,18,21,28,30,35,36,39,40,43,48,50,54,59,60,63,64,67,68,71,72,31,32],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/common.py":[17,18,19,20,21,23,24,26,28,30,33,38,48,58,60,61,63,79,89,131,135,139,151,154,163,176,189,197,202,204,212,213,227,228,249,251,275,278,280,296,300,303,306,309,40,41,45],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/filesync_protocol.py":[18,20,21,22,23,25,27,28,31,33,36,37,40,41,44,45,48,49,52,53,55,66,78,88,90,125,126,129,130,132,134,146,166,191,199,203,211,81,135,138,139,142,143,144,82,157,158,160,200,201,163,164,83,193,194,168,169,204,205,209,172,213,214,215,217,218,219,173,175,177,183,187,188,189,195,84,86,196,85,103,105,106,108,109,110,112,111,114,118,119,120,121],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/sign_m2crypto.py":[15],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/fastboot.py":[14,16,17,18,19,20,21,22,24,25,28,30,31,32,35,36,37,38,39,41,46,47,50,51,54,55,58,59,60,63,64,65,67,77,81,93,106,107,139,176,188,202,203,205,214,218,221,223,230,235,239,240,262,263,294,308,316,328,342,346,360,211,212,74,75,280,284,286,287,288,290,88,89,90,190,193,194,195,196,198,291,292,127,128,155,156,157,158,160,162,163,166,168,130,131,132,136,137,167,169,170,171,133,134,135,305,306,236,237,103,161,253,255,256,257,258,281,282,191,192,178,179,180,199,181,182,259,260,314,326,344,357,358,362,339,340,173,174,164,165],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/common_cli.py":[],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/adb_debug.py":[],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/sign_pythonrsa.py":[],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/fastboot_debug.py":[]}} No newline at end of file | |||
!coverage.py: This is a private format, don't read it directly!{"lines":{"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/sign_m2crypto.py":[15],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/adb_commands.py":[171,135,175,145,174,154,23,25,26,27,156,29,30,31,240,34,35,36,38,227,41,170,43,44,46,221,176,49,178,155,53,54,55,184,57,59,181,192,182,225,177,203,78,79,80,209,82,211,85,86,215,217,219,101,159,223,97,226,99,229,102,104,109,239,112,241,243,157,153,213],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/fastboot.py":[14,16,17,18,19,21,22,25,26,27,29,30,33,35,36,37,40,41,42,43,44,46,51,52,55,56,59,60,63,64,65,68,69,70,72,79,80,82,86,93,94,95,96,101,111,114,115,135,136,138,139,140,141,142,143,144,145,147,163,164,165,166,168,169,170,171,172,173,174,175,176,177,178,179,181,182,184,186,187,188,189,190,196,198,199,200,201,204,205,206,207,209,210,213,214,216,222,223,225,229,232,234,241,246,247,248,250,251,264,266,267,268,269,270,271,273,274,291,292,293,295,297,298,299,302,304,305,306,308,319,320,322,328,330,340,342,353,354,356,358,360,371,372,374,376],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/filesync_protocol.py":[18,20,21,22,23,25,27,28,31,33,36,37,40,41,44,45,48,49,52,53,55,66,78,81,82,83,84,85,86,88,90,103,105,106,108,109,110,111,112,114,118,119,120,121,125,126,129,130,132,134,135,138,139,142,143,144,146,157,158,160,163,164,166,168,169,172,173,175,177,183,187,188,189,191,193,194,195,196,199,200,201,203,204,205,209,211,213,214,215,217,218,219],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/sign_pythonrsa.py":[],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/adb_protocol.py":[18,20,21,23,27,29,32,33,34,37,38,40,47,48,51,52,55,56,59,61,62,64,65,68,69,71,75,80,81,83,84,85,86,87,89,90,91,93,95,97,98,105,107,108,110,112,113,114,116,121,122,123,125,127,128,129,130,131,132,138,140,141,142,143,150,164,166,167,169,171,173,174,175,176,177,178,180,182,184,187,188,189,191,193,194,196,198,199,200,203,205,207,208,210,211,213,214,215,216,217,218,219,222,223,230,231,232,233,234,235,239,241,242,246,247,249,250,279,280,281,282,283,284,316,318,319,336,337,338,339,340,341,342,343,346,349,352,354,355,375,377,378,398,399,400,401],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/common.py":[131,135,139,45,17,18,19,20,21,278,23,24,26,28,154,30,33,163,38,296,41,176,300,151,303,48,306,309,58,60,61,63,197,202,204,79,212,213,89,280,227,228,189,40,275,249,250,251],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/__init__.py":[1],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/common_cli.py":[],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/usb_exceptions.py":[14,17,18,21,28,30,31,32,35,36,39,40,43,48,50,54,59,60,63,64,67,68,71,72],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/fastboot_debug.py":[],"/home/mathieu/Desktop/OpenSource/Python-ADB/python-adb/adb/adb_debug.py":[]}} No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still here?
adb/fastboot.py
Outdated
import io | ||
import sys | ||
|
||
if sys.version_info < (3, 0): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2.6 and 2.7 have the io module, which is enough for us
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All right, but there is a difference between io
from 2.7 and io
from 3.6
On 2.7 :
>>> import io
>>> io.StringIO('aoeuidhtnsqjkxbmwpyfgcrl')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: initial_value must be unicode or None, not str
On 3.6 :
>>> import io
>>> io.StringIO('aoeuidhtnsqjkxbmwpyfgcrl')
<_io.StringIO object at 0x7f18b3704798>
This is why, I preferred to check which Python version is running. (Or I did not understand what did you say 😞 )
adb/fastboot.py
Outdated
PYTHON_27 = False | ||
if sys.version_info < (3,0): | ||
PYTHON_27 = True | ||
import cStringIO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can do import cStringIO as io
and use the fact that they both call their class StringIO
to remove the version checks throughout these files. Alternatively, just do this:
PYTHON_27 = sys.version_info < (3,0)
if PYTHON_27:
from cStringIO import StringIO
else:
from io import StringIO
adb/fastboot.py
Outdated
if progress_callback: | ||
progress = self._HandleProgress(length, progress_callback) | ||
progress.next() | ||
if PYTHON_27: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 'next' builtin is in Python 2.7 and 3.0+: next(progress)
adb/filesync_protocol.py
Outdated
|
||
header = struct.pack('<2I', self.id_to_wire[command_id], size) | ||
self.send_buffer += header + data | ||
self.send_buffer += header.decode('ascii') + data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work for all sizes? If size = 128, then a byte in header will be 0x80, which is not in 7-bit ASCII's range.
In [3]: struct.pack('<I', 128).decode('ascii')
---------------------------------------------------------------------------
UnicodeDecodeError Traceback (most recent call last)
<ipython-input-3-b48ec2057ace> in <module>()
----> 1 struct.pack('<I', 128).decode('ascii')
UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 0: ordinal not in range(128)
It looks like you're converting the header to unicode since data might be unicode, but I think you need to convert data to be bytes using encode('utf8')
so that we only send bytes over the wire.
adb/filesync_protocol.py
Outdated
# Read one filesync packet off the recv buffer. | ||
header_data = self._ReadBuffered(self.recv_header_len) | ||
header = struct.unpack(self.recv_header_format, header_data) | ||
header = struct.unpack(self.recv_header_format, header_data.encode('ascii')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This again won't work for the same reason. header_data
needs to be bytes when we get it since it's raw data.
test/common_stub.py
Outdated
raise ValueError('Expected %s, got %s (%s)' % ( | ||
_Dotify(expected_data), binascii.hexlify(data), _Dotify(data))) | ||
raise ValueError('Expected %s got %s (%s)' % ( | ||
_Dotify(expected_data), binascii.hexlify(data.encode('ascii')), _Dotify(data))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you're going to use ascii as the encoding, you need to provide an errors that's either replace or ignore. The default is strict and will just raise an extra, confusing, error instead
AdbCommands doesn't seem to work with python3 when connecting over a socket, should Send() encode the data before sending it to the wire on line 208? |
…y: Use `utf8` as encoding for sending only bytes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there!
test/fastboot_test.py
Outdated
|
||
import cStringIO | ||
import sys | ||
PYTHON_27 = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missed the from X import StringIO
change here
test/common_stub.py
Outdated
if expected_data != data: | ||
raise ValueError('Expected %s, got %s (%s)' % ( | ||
_Dotify(expected_data), binascii.hexlify(data), _Dotify(data))) | ||
raise ValueError('Expected %s got %s (%s)' % ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2-space indent is the norm in this file
test/common_stub.py: Fix cString import
This reverts commit a9ea7b4.
This reverts commit a9ea7b4.
Update .gitignore and a couple of file. Manage conflict between 2.7 and 3.6 about
str
andbyte
concatenation. Also updatenext()
method fromgenerator
to__next__()
#37