2929from six .moves import filter
3030from six import unichr
3131
32+ import binascii
3233import io
3334import itertools
3435import numpy as np
@@ -92,8 +93,7 @@ def _read(self, file):
9293 if type == 1 : # ASCII text: include verbatim
9394 data += segment
9495 elif type == 2 : # binary data: encode in hexadecimal
95- data += b'' .join ([('%02x' % ord (char )).encode ('ascii' )
96- for char in segment ])
96+ data += binascii .hexlify (segment )
9797 elif type == 3 : # end of file
9898 break
9999 else :
@@ -123,9 +123,8 @@ def _split(self, data):
123123 # zeros backward
124124 idx = data .rindex (b'cleartomark' ) - 1
125125 zeros = 512
126- while zeros and ord (data [idx ]) in (
127- ord (b'0' [0 ]), ord (b'\n ' [0 ]), ord (b'\r ' [0 ])):
128- if ord (data [idx ]) == ord (b'0' [0 ]):
126+ while zeros and data [idx ] in b'0\n \r ' :
127+ if data [idx ] in b'0' :
129128 zeros -= 1
130129 idx -= 1
131130 if zeros :
@@ -136,10 +135,9 @@ def _split(self, data):
136135 # but if we read a pfa file, this part is already in hex, and
137136 # I am not quite sure if even the pfb format guarantees that
138137 # it will be in binary).
139- binary = b'' .join ([unichr (int (data [i :i + 2 ], 16 )).encode ('latin-1' )
140- for i in range (len1 , idx , 2 )])
138+ binary = binascii .unhexlify (data [len1 :idx + 1 ])
141139
142- return data [:len1 ], binary , data [idx :]
140+ return data [:len1 ], binary , data [idx + 1 :]
143141
144142 _whitespace_re = re .compile (br'[\0\t\r\014\n ]+' )
145143 _token_re = re .compile (br'/{0,2}[^]\0\t\r\v\n ()<>{}/%[]+' )
0 commit comments