[Python-Dev] RFC: PEP 460: Add bytes % args and bytes.format(args) to Python 3.5

Juraj Sukop juraj.sukop at gmail.com
Sat Jan 11 00:43:39 CET 2014


On Fri, Jan 10, 2014 at 11:12 PM, Victor Stinner
<victor.stinner at gmail.com>wrote:

>
> What not building "10 0 obj ... stream" and "endstream endobj" in
> Unicode and then encode to ASCII? Example:
>
> data = b''.join((
>   ("%d %d obj ... stream" % (10, 0)).encode('ascii'),
>   binary_image_data,
>   ("endstream endobj").encode('ascii'),
> ))
>

The key is "encode to ASCII" which means that the result is bytes. Then,
there is this "11 0 obj" which should also be bytes. But it has no
"binary_image_data" - only lots of numbers waiting to be somehow converted
to bytes. I already mentioned the problems with ".encode('ascii')" but it
does not stop here. Numbers may appear not only inside "streams" but almost
anywhere: in the header there is PDF version, an image has to have "width"
and "height", at the end of PDF there is a structure containing offsets to
all of the objects in file. Basically, to ".encode('ascii')" every possible
number is not exactly simple or pretty.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20140111/c60009ca/attachment.html>


More information about the Python-Dev mailing list