[Python-Dev] Problems with hex-conversion functions

Nick Coghlan ncoghlan at gmail.com
Sat Oct 2 08:36:21 CEST 2010


On Sat, Oct 2, 2010 at 5:17 AM, Arnon Yaari <wiggin15 at gmail.com> wrote:
> Hello again. I submitted two patches to resolve the issues from my first
> post.
>
> Patch 9951 - implement bytes.hex (http://bugs.python.org/issue9951)
> Patch 9996 - fix input and output of binascii functions
> (http://bugs.python.org/issue9996)
>
> Fix #1 - patch 9951 implements bytes.hex
> Fix #2 - this is not fixed for now, no deprecation
> Fix #3 - this is not fixed for now. I will probably submit another patch if
> patch 9996 is accepted (create shared conversion functions to be used by
> both binascii and bytes, maybe)
> Fix #4 - patch 9996 makes binascii behave correctly in this conversion
> Fix #5 - same as #4 (strict input and output)
>
> As you can see, patch 9996 was rejected and I was referred to this mailing
> list to continue the discussion.

I actually agree with that rejection. You appear to be thinking of hex
coding solely as a data display format, when it is also used fairly
often as a data interchange format (usually embedded inside a larger
formatting scheme rather than standalone). For data interchange, you
want the hex values as ASCII-encoded bytes, for display to the user,
you want it as a string.

The conversion of the binascii API to Py3k took a data interchange
view of the world, bytes.fromhex is more user I/O oriented.

> I would like to hear your thoughts about the backward compatibility issue in
> patch 9996, and getting patch 9951 commited. Thanks.

The 9951 patch looks pretty good on a quick read through. I put some
specific feedback on the tracker.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-Dev mailing list