8000 bytes % args is back since py3.5 by anntzer · Pull Request #11074 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

bytes % args is back since py3.5 #11074

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 1 commit into from
Apr 18, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 15 additions & 20 deletions lib/matplotlib/backends/backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def pdfRepr(obj):
elif isinstance(obj, (float, np.floating)):
if not np.isfinite(obj):
raise ValueError("Can only output finite numbers in PDF")
r = ("%.10f" % obj).encode('ascii')
r = b"%.10f" % obj
return r.rstrip(b'0').rstrip(b'.')

# Booleans. Needs to be tested before integers since
Expand All @@ -155,7 +155,7 @@ def pdfRepr(obj):

# Integers are written as such.
elif isinstance(obj, (int, np.integer)):
return ("%d" % obj).encode('ascii')
return b"%d" % obj

# Unicode strings are encoded in UTF-16BE with byte-order mark.
elif isinstance(obj, str):
Expand Down Expand Up @@ -236,11 +236,11 @@ def __repr__(self):
return "<Reference %d>" % self.id

def pdfRepr(self):
return ("%d 0 R" % self.id).encode('ascii')
return b"%d 0 R" % self.id

def write(self, contents, file):
write = file.write
write(("%d 0 obj\n" % self.id).encode('ascii'))
write(b"%d 0 obj\n" % self.id)
write(pdfRepr(contents))
write(b"\nendobj\n")

Expand Down Expand Up @@ -378,7 +378,7 @@ def __init__(self, id, len, file, extra=None, png=None):

def _writeHeader(self):
write = self.file.write
write(("%d 0 obj\n" % self.id).encode('ascii'))
write(b"%d 0 obj\n" % self.id)
dict = self.extra
dict['Length'] = self.len
if rcParams['pdf.compression']:
Expand Down Expand Up @@ -858,7 +858,7 @@ def _get_xobject_symbol_name(self, filename, symbol_name):
os.path.splitext(os.path.basename(filename))[0],
symbol_name)

_identityToUnicodeCMap = """/CIDInit /ProcSet findresource begin
_identityToUnicodeCMap = b"""/CIDInit /ProcSet findresource begin
12 dict begin
begincmap
/CIDSystemInfo
Expand Down Expand Up @@ -1096,18 +1096,17 @@ def embedTTFType42(font, characters, descriptor):
unicode_bfrange = []
for start, end in unicode_groups:
unicode_bfrange.append(
"<%04x> <%04x> [%s]" %
b"<%04x> <%04x> [%s]" %
(start, end,
" ".join(["<%04x>" % x for x in range(start, end+1)])))
b" ".join(b"<%04x>" % x for x in range(start, end+1))))
unicode_cmap = (self._identityToUnicodeCMap %
(len(unicode_groups),
"\n".join(unicode_bfrange))).encode('ascii')
(len(unicode_groups), b"\n".join(unicode_bfrange)))

# CIDToGIDMap stream
cid_to_gid_map = "".join(cid_to_gid_map).encode("utf-16be")
self.beginStream(cidToGidMapObject.id,
None,
{'Length': len(cid_to_gid_map)})
{'Length': len(cid_to_gid_map)})
self.currentstream.write(cid_to_gid_map)
self.endStream()

Expand Down Expand Up @@ -1529,7 +1528,7 @@ def writeXref(self):
"""Write out the xref table."""

self.startxref = self.fh.tell() - self.tell_base
self.write(("xref\n0 %d\n" % self.nextObject).encode('ascii'))
self.write(b"xref\n0 %d\n" % self.nextObject)
i = 0
borken = False
for offset, generation, name in self.xrefTable:
Expand All @@ -1538,12 +1537,9 @@ def writeXref(self):
file=sys.stderr)
borken = True
else:
if name == 'the zero object':
key = "f"
else:
key = "n"
text = "%010d %05d %s \n" % (offset, generation, key)
self.write(text.encode('ascii'))
key = b"f" if name == 'the zero object' else b"n"
text = b"%010d %05d %b \n" % (offset, generation, key)
self.write(text)
i += 1
if borken:
raise AssertionError('Indirect object does not exist')
Expand Down Expand Up @@ -1588,8 +1584,7 @@ def writeTrailer(self):
'Root': self.rootObject,
'Info': self.infoObject}))
# Could add 'ID'
self.write(("\nstartxref\n%d\n%%%%EOF\n" %
self.startxref).encode('ascii'))
self.write(b"\nstartxref\n%d\n%%%%EOF\n" % self.startxref)


class RendererPdf(RendererBase):
Expand Down
0