Remove unnecessary make_bytes() function

The function was introduced in 65112bad7e
to handle the differences between Python 2 & 3 byte handling. Now that
Python 3 supports byte formatting, can drop the unnecessary
compatibility shim in favor of native features.
This commit is contained in:
Jon Dufresne 2020-01-26 14:46:27 -08:00
parent 22a6738a81
commit c84c736e5b
2 changed files with 10 additions and 16 deletions

View File

@ -214,9 +214,9 @@ def _save(im, fp, filename, save_all=False):
# #
# page contents # page contents
page_contents = PdfParser.make_bytes( page_contents = b"q %d 0 0 %d 0 0 cm /image Do Q\n" % (
"q %d 0 0 %d 0 0 cm /image Do Q\n" int(width * 72.0 / resolution),
% (int(width * 72.0 / resolution), int(height * 72.0 / resolution)) int(height * 72.0 / resolution),
) )
existing_pdf.write_obj(contents_refs[pageNumber], stream=page_contents) existing_pdf.write_obj(contents_refs[pageNumber], stream=page_contents)

View File

@ -8,10 +8,6 @@ import time
import zlib import zlib
def make_bytes(s):
return s.encode("us-ascii")
# see 7.9.2.2 Text String Type on page 86 and D.3 PDFDocEncoding Character Set # see 7.9.2.2 Text String Type on page 86 and D.3 PDFDocEncoding Character Set
# on page 656 # on page 656
def encode_text(s): def encode_text(s):
@ -179,10 +175,10 @@ class XrefTable:
else: else:
contiguous_keys = keys contiguous_keys = keys
keys = None keys = None
f.write(make_bytes("%d %d\n" % (contiguous_keys[0], len(contiguous_keys)))) f.write(b"%d %d\n" % (contiguous_keys[0], len(contiguous_keys)))
for object_id in contiguous_keys: for object_id in contiguous_keys:
if object_id in self.new_entries: if object_id in self.new_entries:
f.write(make_bytes("%010d %05d n \n" % self.new_entries[object_id])) f.write(b"%010d %05d n \n" % self.new_entries[object_id])
else: else:
this_deleted_object_id = deleted_keys.pop(0) this_deleted_object_id = deleted_keys.pop(0)
check_format_condition( check_format_condition(
@ -195,10 +191,8 @@ class XrefTable:
except IndexError: except IndexError:
next_in_linked_list = 0 next_in_linked_list = 0
f.write( f.write(
make_bytes( b"%010d %05d f \n"
"%010d %05d f \n" % (next_in_linked_list, self.deleted_entries[object_id])
% (next_in_linked_list, self.deleted_entries[object_id])
)
) )
return startxref return startxref
@ -238,7 +232,7 @@ class PdfName:
if b in self.allowed_chars: if b in self.allowed_chars:
result.append(b) result.append(b)
else: else:
result.extend(make_bytes("#%02X" % b)) result.extend(b"#%02X" % b)
return bytes(result) return bytes(result)
__str__ = __bytes__ __str__ = __bytes__
@ -304,7 +298,7 @@ class PdfBinary:
self.data = data self.data = data
def __bytes__(self): def __bytes__(self):
return make_bytes("<%s>" % "".join("%02X" % b for b in self.data)) return b"<%s>" % b"".join(b"%02X" % b for b in self.data)
class PdfStream: class PdfStream:
@ -495,7 +489,7 @@ class PdfParser:
self.f.write( self.f.write(
b"trailer\n" b"trailer\n"
+ bytes(PdfDict(trailer_dict)) + bytes(PdfDict(trailer_dict))
+ make_bytes("\nstartxref\n%d\n%%%%EOF" % start_xref) + b"\nstartxref\n%d\n%%%%EOF" % start_xref
) )
def write_page(self, ref, *objs, **dict_obj): def write_page(self, ref, *objs, **dict_obj):