Skip to content

Merge binascii module into 2and3 #1144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 7, 2017
Merged

Conversation

euresti
Copy link
Contributor

@euresti euresti commented Apr 6, 2017

Kept the python 3 version but modified it so that python 2 also accepts unicode strings.

Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

def a2b_uu(string: Union[Text, bytes]) -> bytes: ...
def b2a_uu(data: _Bytes) -> bytes: ...
def a2b_base64(string: Union[Text, bytes]) -> bytes: ...
def b2a_base64(data: _Bytes) -> bytes: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has another positional-only parameter as of Python 3: newline: bool(accept={int}) = True.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add.

def rledecode_hqx(data: _Bytes) -> bytes: ...
def rlecode_hqx(data: _Bytes) -> bytes: ...
def b2a_hqx(data: _Bytes) -> bytes: ...
def crc_hqx(data: _Bytes, crc: int) -> int: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The argument is called oldcrc in the Python 2 docstring, but it's positional-only so it doesn't really matter. If we want to be really precise we can make the arguments positional-only in Python 2 (and probably also pre-3.5 Python 3, but I haven't checked), but I think it's fine to ignore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's positional only in both. Technically this entire module is positonal only everywhere.

Copy link
Member

@JelleZijlstra JelleZijlstra Apr 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in 3.6. Presumably it was changed to use Argument Clinic at some point.

In [5]: binascii.b2a_base64(data=b'')
Out[5]: b'\n'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting. Well crc is still positional only at least in 3.6.1

>>> binascii.crc32(b'foo', crc=1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: crc32() takes no keyword arguments

@JelleZijlstra
Copy link
Member

Also, there's some trailing whitespace (see Travis) and I just noticed that the documentation says Changed in version 3.3: ASCII-only unicode strings are now accepted by the a2b_* functions.. We technically still support 3.2.

# Python 2 accepts unicode ascii pretty much everywhere.
_Bytes = Union[bytes, Text]
_Ascii = Union[bytes, Text]
elif sys.version_info <= (3, 2):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be < (3, 3). But we're probably going to drop 3.2 support anyway (#1145).

@JelleZijlstra JelleZijlstra merged commit 8bed2fc into python:master Apr 7, 2017
@euresti euresti deleted the binascii branch April 7, 2017 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants