17
17
...
18
18
19
19
"""
20
- from __future__ import absolute_import , division , print_function
21
-
22
- import six
23
- from six .moves import xrange
24
-
25
20
from collections import namedtuple
26
- from functools import partial , wraps
21
+ from functools import lru_cache , partial , wraps
27
22
import logging
28
23
import numpy as np
29
24
import os
35
30
from matplotlib import cbook , rcParams
36
31
from matplotlib .compat import subprocess
37
32
38
- try :
39
- from functools import lru_cache
40
- except ImportError : # Py2
41
- from backports .functools_lru_cache import lru_cache
42
-
43
- if six .PY3 :
44
- def ord (x ):
45
- return x
46
-
47
33
_log = logging .getLogger (__name__ )
48
34
49
35
# Dvi is a bytecode format documented in
@@ -172,7 +158,7 @@ def wrapper(self, byte):
172
158
if max is None :
173
159
table [min ] = wrapper
174
160
else :
175
- for i in xrange (min , max + 1 ):
161
+ for i in range (min , max + 1 ):
176
162
assert table [i ] is None
177
163
table [i ] = wrapper
178
164
return wrapper
@@ -194,7 +180,7 @@ class Dvi(object):
194
180
>>> print(''.join(unichr(t.glyph) for t in page.text))
195
181
"""
196
182
# dispatch table
197
- _dtable = [None for _ in xrange ( 256 )]
183
+ _dtable = [None ] * 256
198
184
_dispatch = partial (_dispatch , _dtable )
199
185
200
186
def __init__ (self , filename , dpi ):
@@ -311,7 +297,7 @@ def _read(self):
311
297
False if there were no more pages.
312
298
"""
313
299
while True :
314
- byte = ord ( self .file .read (1 )[0 ])
300
+ byte = self .file .read (1 )[0 ]
315
301
self ._dtable [byte ](self , byte )
316
302
if byte == 140 : # end of page
317
303
return True
@@ -325,11 +311,11 @@ def _arg(self, nbytes, signed=False):
325
311
Signedness is determined by the *signed* keyword.
326
312
"""
327
313
str = self .file .read (nbytes )
328
- value = ord ( str [0 ])
314
+ value = str [0 ]
329
315
if signed and value >= 0x80 :
330
316
value = value - 0x100
331
317
for i in range (1 , nbytes ):
332
- value = 0x100 * value + ord ( str [i ])
318
+ value = 0x100 * value + str [i ]
333
319
return value
334
320
335
321
@_dispatch (min = 0 , max = 127 , state = _dvistate .inpage )
@@ -445,14 +431,9 @@ def _fnt_num(self, new_f):
445
431
@_dispatch (min = 239 , max = 242 , args = ('ulen1' ,))
446
432
def _xxx (self , datalen ):
447
433
special = self .file .read (datalen )
448
- if six .PY3 :
449
- chr_ = chr
450
- else :
451
- def chr_ (x ):
452
- return x
453
434
_log .debug (
454
435
'Dvi._xxx: encountered special: %s' ,
455
- '' .join ([chr_ (ch ) if 32 <= ord ( ch ) < 127 else '<%02x>' % ord ( ch )
436
+ '' .join ([chr (ch ) if 32 <= ch < 127 else '<%02x>' % ch
456
437
for ch in special ]))
457
438
458
439
@_dispatch (min = 243 , max = 246 , args = ('olen1' , 'u4' , 'u4' , 'u4' , 'u1' , 'u1' ))
@@ -464,11 +445,7 @@ def _fnt_def_real(self, k, c, s, d, a, l):
464
445
fontname = n [- l :].decode ('ascii' )
465
446
tfm = _tfmfile (fontname )
466
447
if tfm is None :
467
- if six .PY2 :
468
- error_class = OSError
469
- else :
470
- error_class = FileNotFoundError
471
- raise error_class ("missing font metrics file: %s" % fontname )
448
+ raise FileNotFoundError ("missing font metrics file: %s" % fontname )
472
449
if c != 0 and tfm .checksum != 0 and c != tfm .checksum :
473
450
raise ValueError ('tfm checksum mismatch: %s' % n )
474
451
@@ -561,7 +538,7 @@ def __init__(self, scale, tfm, texname, vf):
561
538
except ValueError :
562
539
nchars = 0
563
540
self .widths = [(1000 * tfm .width .get (char , 0 )) >> 20
564
- for char in xrange (nchars )]
541
+ for char in range (nchars )]
565
542
566
543
def __eq__ (self , other ):
567
544
return self .__class__ == other .__class__ and \
@@ -643,7 +620,7 @@ def _read(self):
643
620
packet_char , packet_ends = None , None
644
621
packet_len , packet_width = None , None
645
622
while True :
646
- byte = ord ( self .file .read (1 )[0 ])
623
+ byte = self .file .read (1 )[0 ]
647
624
# If we are in a packet, execute the dvi instructions
648
625
if self .state == _dvistate .inpage :
649
626
byte_at = self .file .tell ()- 1
@@ -774,9 +751,9 @@ def __init__(self, filename):
774
751
widths , heights , depths = \
775
752
[struct .unpack ('!%dI' % (len (x )/ 4 ), x )
776
753
for x in (widths , heights , depths )]
777
- for idx , char in enumerate (xrange (bc , ec + 1 )):
778
- byte0 = ord ( char_info [4 * idx ])
779
- byte1 = ord ( char_info [4 * idx + 1 ])
754
+ for idx , char in enumerate (range (bc , ec + 1 )):
755
+ byte0 = char_info [4 * idx ]
756
+ byte1 = char_info [4 * idx + 1 ]
780
757
self .width [char ] = _fix2comp (widths [byte0 ])
781
758
self .height [char ] = _fix2comp (heights [byte1 >> 4 ])
782
759
self .depth [char ] = _fix2comp (depths [byte1 & 0xf ])
@@ -836,7 +813,7 @@ class PsfontsMap(object):
836
813
def __init__ (self , filename ):
837
814
self ._font = {}
838
815
self ._filename = filename
839
- if six . PY3 and isinstance (filename , bytes ):
816
+ if isinstance (filename , bytes ):
840
817
encoding = sys .getfilesystemencoding () or 'utf-8'
841
818
self ._filename = filename .decode (encoding , errors = 'replace' )
842
819
with open (filename , 'rb' ) as file :
@@ -1024,25 +1001,19 @@ def find_tex_file(filename, format=None):
1024
1001
The library that :program:`kpsewhich` is part of.
1025
1002
"""
1026
1003
1027
- if six .PY3 :
1028
- # we expect these to always be ascii encoded, but use utf-8
1029
- # out of caution
1030
- if isinstance (filename , bytes ):
1031
- filename = filename .decode ('utf-8' , errors = 'replace' )
1032
- if isinstance (format , bytes ):
1033
- format = format .decode ('utf-8' , errors = 'replace' )
1004
+ # we expect these to always be ascii encoded, but use utf-8
1005
+ # out of caution
1006
+ if isinstance (filename , bytes ):
1007
+ filename = filename .decode ('utf-8' , errors = 'replace' )
1008
+ if isinstance (format , bytes ):
1009
+ format = format .decode ('utf-8' , errors = 'replace' )
1034
1010
1035
1011
cmd = ['kpsewhich' ]
1036
1012
if format is not None :
1037
1013
cmd += ['--format=' + format ]
1038
1014
cmd += [filename ]
1039
1015
_log .debug ('find_tex_file(%s): %s' , filename , cmd )
1040
- # stderr is unused, but reading it avoids a subprocess optimization
1041
- # that breaks EINTR handling in some Python versions:
1042
- # http://bugs.python.org/issue12493
1043
- # https://github.com/matplotlib/matplotlib/issues/633
1044
- pipe = subprocess .Popen (cmd , stdout = subprocess .PIPE ,
1045
- stderr = subprocess .PIPE )
1016
+ pipe = subprocess .Popen (cmd , stdout = subprocess .PIPE )
1046
1017
result = pipe .communicate ()[0 ].rstrip ()
1047
1018
_log .debug ('find_tex_file result: %s' , result )
1048
1019
return result .decode ('ascii' )
0 commit comments