homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: binascii.a2b_* functions could accept unicode strings
Type: behavior Stage: resolved
Components: Documentation, Library (Lib) Versions: Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Arfrever, berker.peksag, docs@python, luke-jr, martin.panter, pitrou, python-dev, r.david.murray, vajrasky, vstinner
Priority: normal Keywords: patch

Created on 2011年12月19日 16:30 by pitrou, last changed 2022年04月11日 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
binasciistr.patch pitrou, 2011年12月20日 08:57 review
fix_doc_binascii_unhexlify.patch vajrasky, 2013年11月02日 04:42 review
better_error_message_binascii.patch vajrasky, 2013年11月02日 13:43 review
fix_doc_binascii_unhexlify.v2.patch martin.panter, 2015年02月08日 04:43 review
fix_doc_binascii_unhexlify.v3.patch martin.panter, 2015年02月14日 00:12 review
Messages (20)
msg149876 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011年12月19日 16:30
a2b_hex and friends accept only byte strings:
>>> binascii.a2b_hex(b'00')
b'\x00'
>>> binascii.a2b_hex('00')
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
TypeError: 'str' does not support the buffer interface
But they could just as well accept ASCII-only unicode strings. Also, with PEP 393, accessing the 8-bit ASCII data doesn't even need a conversion.
msg149905 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011年12月20日 08:57
Here is a patch.
msg149911 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011年12月20日 13:00
New changeset eb8d62706d5f by Antoine Pitrou in branch 'default':
Issue #13637: "a2b" functions in the binascii module now accept ASCII-only unicode strings.
http://hg.python.org/cpython/rev/eb8d62706d5f 
msg149913 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011年12月20日 13:08
Committed now.
msg153829 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012年02月21日 01:11
I disagree with this feature. Reopening pending discussion on python-dev.
msg154265 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012年02月25日 15:40
Discussion resolved in favor of patch.
msg154964 - (view) Author: Luke-Jr (luke-jr) Date: 2012年03月05日 17:19
Has this been fixed in 3.2 yet? Somehow it seems to have been "reclassified" as an enhancement when it's really a regression. str worked fine in these functions in 3.1.
msg155001 - (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * (Python triager) Date: 2012年03月06日 05:47
I confirm that it works in Python 3.1 and doesn't work in Python 3.2.
msg201963 - (view) Author: Vajrasky Kok (vajrasky) * Date: 2013年11月02日 04:42
Antoine, I think you forgot to update the doc.
http://docs.python.org/3.4/library/binascii.html#binascii.unhexlify
Changed in version 3.2: Accept only bytestring or bytearray objects as input.
Attached the patch to update the doc to reflect the changes in this ticket.
msg201972 - (view) Author: Vajrasky Kok (vajrasky) * Date: 2013年11月02日 13:43
Here is another patch to better the error message. Right now, the error message when wrong input sent to unhexlify is a little bit funny.
>>> import binascii
>>> binascii.unhexlify(3)
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
TypeError: argument should be bytes, buffer or ASCII string, not <class 'int'>
After patch:
>>> import binascii
>>> binascii.unhexlify(3)
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
TypeError: argument should be bytes, buffer or ASCII string, not int
msg202181 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2013年11月05日 00:08
The a2b_qp() function also documents a byte string restriction for 3.2, and now 3.3 also seems to support ASCII-compatible text strings. Maybe the documentation should reflect this also?
msg235545 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015年02月08日 04:43
The error fix patch looks good.
I updated the doc patch as fix_doc_binascii_unhexlify.v2.patch, which also clarifies a2b_qp(), and restores the description of Python 3.2 not allowing text strings.
msg235931 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2015年02月13日 23:55
The binascii documentation already says
 ``a2b_*`` functions accept Unicode strings containing only ASCII characters.
 [...]
 .. versionchanged:: 3.3
 ASCII-only unicode strings are now accepted by the ``a2b_*`` functions.
I think we can just remove versionchanged directives in fix_doc_binascii_unhexlify.v2.patch.
msg235934 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015年02月14日 00:12
That’s another option. Someone might wonder why a2b_hex() and a2b_qp() actually accept text strings in Python 3.1 when the documentation says you need 3.3, but I guess that’s not such a big deal. Posting patch v3 which removes the 3.2 notices.
msg235996 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015年02月14日 22:05
New changeset 8d32453dd0f7 by Berker Peksag in branch '3.4':
Issue #13637: Remove outdated versionchanged directives.
https://hg.python.org/cpython/rev/8d32453dd0f7
New changeset d3ca674cf716 by Berker Peksag in branch 'default':
Issue #13637: Remove outdated versionchanged directives.
https://hg.python.org/cpython/rev/d3ca674cf716 
msg236000 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015年02月14日 22:31
New changeset ad4a8176a71a by Berker Peksag in branch '3.4':
Issue #13637: Improve exception message of a2b_* functions.
https://hg.python.org/cpython/rev/ad4a8176a71a
New changeset 55f5e960cc40 by Berker Peksag in branch 'default':
Issue #13637: Improve exception message of a2b_* functions.
https://hg.python.org/cpython/rev/55f5e960cc40 
msg236001 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2015年02月14日 22:33
Thank you to both Vajrasky and Martin.
msg236373 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015年02月21日 16:30
I think this doc change was incorrect. The current document is supposed to provide the correct historical information. So "changed in 3.3: accept ASCII input" (and just ignore the fact that 3.1 also accepted ascii, since we pretty much prefer to ignore the existence of 3.0 and 3.1 :) would be the better choice, IMO.
msg236390 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015年02月21日 21:38
If I understand what you are saying, you don’t mind not mentioning 3.1 behaviour, but want to mention 3.2 behaviour. Perhaps the existing "Note" box at the top of the page is good enough for you, as pointed out in <http://bugs.python.org/issue13637#msg235931>.
msg236395 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015年02月22日 00:17
Ah, yes, I see. Sorry for the confusion, I misread that part of the discussion and did not look at that part of the docs.
(I find that note confusing...it seems to imply that a2b only accepts ascii. But that's a different issue and I don't feel strongly enough about it to open one :)
History
Date User Action Args
2022年04月11日 14:57:24adminsetgithub: 57846
2015年02月22日 00:17:47r.david.murraysetmessages: + msg236395
2015年02月21日 21:38:31martin.pantersetmessages: + msg236390
2015年02月21日 16:30:26r.david.murraysetmessages: + msg236373
2015年02月14日 22:33:10berker.peksagsetstatus: open -> closed
resolution: fixed
messages: + msg236001

stage: resolved
2015年02月14日 22:31:08python-devsetmessages: + msg236000
2015年02月14日 22:05:39python-devsetmessages: + msg235996
2015年02月14日 00:12:59martin.pantersetfiles: + fix_doc_binascii_unhexlify.v3.patch

messages: + msg235934
2015年02月13日 23:55:31berker.peksagsetnosy: + berker.peksag
messages: + msg235931
2015年02月08日 04:43:30martin.pantersetfiles: + fix_doc_binascii_unhexlify.v2.patch

nosy: + docs@python
messages: + msg235545

assignee: docs@python
components: + Documentation
2013年11月05日 00:08:44martin.pantersetnosy: + martin.panter
messages: + msg202181
2013年11月02日 13:43:42vajraskysetfiles: + better_error_message_binascii.patch

messages: + msg201972
2013年11月02日 04:42:35vajraskysetfiles: + fix_doc_binascii_unhexlify.patch
nosy: + vajrasky
messages: + msg201963

2012年03月06日 05:47:37Arfreversetstatus: closed -> open

type: enhancement -> behavior

nosy: + Arfrever
messages: + msg155001
resolution: fixed -> (no value)
stage: resolved -> (no value)
2012年03月05日 17:19:25luke-jrsetnosy: + luke-jr
messages: + msg154964
2012年02月25日 15:40:46r.david.murraysetstatus: open -> closed

messages: + msg154265
2012年02月21日 01:11:27r.david.murraysetstatus: closed -> open
nosy: + r.david.murray
messages: + msg153829

2011年12月20日 13:09:24pitrousetstatus: open -> closed
2011年12月20日 13:08:10pitrousetresolution: fixed
messages: + msg149913
stage: patch review -> resolved
2011年12月20日 13:00:54python-devsetnosy: + python-dev
messages: + msg149911
2011年12月20日 08:57:35pitrousetfiles: + binasciistr.patch
keywords: + patch
messages: + msg149905

stage: needs patch -> patch review
2011年12月19日 16:30:44pitroucreate

AltStyle によって変換されたページ (->オリジナル) /