Skip to content

Commit 659f73d

Browse files
authored
Merge pull request #4389 from jdufresne/make-bytes
Remove unnecessary make_bytes() function
2 parents 5965437 + c84c736 commit 659f73d

2 files changed

Lines changed: 10 additions & 16 deletions

File tree

src/PIL/PdfImagePlugin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@ def _save(im, fp, filename, save_all=False):
214214
#
215215
# page contents
216216

217-
page_contents = PdfParser.make_bytes(
218-
"q %d 0 0 %d 0 0 cm /image Do Q\n"
219-
% (int(width * 72.0 / resolution), int(height * 72.0 / resolution))
217+
page_contents = b"q %d 0 0 %d 0 0 cm /image Do Q\n" % (
218+
int(width * 72.0 / resolution),
219+
int(height * 72.0 / resolution),
220220
)
221221

222222
existing_pdf.write_obj(contents_refs[pageNumber], stream=page_contents)

src/PIL/PdfParser.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
import zlib
99

1010

11-
def make_bytes(s):
12-
return s.encode("us-ascii")
13-
14-
1511
# see 7.9.2.2 Text String Type on page 86 and D.3 PDFDocEncoding Character Set
1612
# on page 656
1713
def encode_text(s):
@@ -179,10 +175,10 @@ def write(self, f):
179175
else:
180176
contiguous_keys = keys
181177
keys = None
182-
f.write(make_bytes("%d %d\n" % (contiguous_keys[0], len(contiguous_keys))))
178+
f.write(b"%d %d\n" % (contiguous_keys[0], len(contiguous_keys)))
183179
for object_id in contiguous_keys:
184180
if object_id in self.new_entries:
185-
f.write(make_bytes("%010d %05d n \n" % self.new_entries[object_id]))
181+
f.write(b"%010d %05d n \n" % self.new_entries[object_id])
186182
else:
187183
this_deleted_object_id = deleted_keys.pop(0)
188184
check_format_condition(
@@ -195,10 +191,8 @@ def write(self, f):
195191
except IndexError:
196192
next_in_linked_list = 0
197193
f.write(
198-
make_bytes(
199-
"%010d %05d f \n"
200-
% (next_in_linked_list, self.deleted_entries[object_id])
201-
)
194+
b"%010d %05d f \n"
195+
% (next_in_linked_list, self.deleted_entries[object_id])
202196
)
203197
return startxref
204198

@@ -238,7 +232,7 @@ def __bytes__(self):
238232
if b in self.allowed_chars:
239233
result.append(b)
240234
else:
241-
result.extend(make_bytes("#%02X" % b))
235+
result.extend(b"#%02X" % b)
242236
return bytes(result)
243237

244238
__str__ = __bytes__
@@ -304,7 +298,7 @@ def __init__(self, data):
304298
self.data = data
305299

306300
def __bytes__(self):
307-
return make_bytes("<%s>" % "".join("%02X" % b for b in self.data))
301+
return b"<%s>" % b"".join(b"%02X" % b for b in self.data)
308302

309303

310304
class PdfStream:
@@ -495,7 +489,7 @@ def write_xref_and_trailer(self, new_root_ref=None):
495489
self.f.write(
496490
b"trailer\n"
497491
+ bytes(PdfDict(trailer_dict))
498-
+ make_bytes("\nstartxref\n%d\n%%%%EOF" % start_xref)
492+
+ b"\nstartxref\n%d\n%%%%EOF" % start_xref
499493
)
500494

501495
def write_page(self, ref, *objs, **dict_obj):

0 commit comments

Comments
 (0)