1717 ...
1818
1919"""
20- from __future__ import absolute_import , division , print_function
21-
22- import six
23- from six .moves import xrange
24-
2520from collections import namedtuple
26- from functools import partial , wraps
21+ from functools import lru_cache , partial , wraps
2722import logging
2823import numpy as np
2924import os
3530from matplotlib import cbook , rcParams
3631from matplotlib .compat import subprocess
3732
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-
4733_log = logging .getLogger (__name__ )
4834
4935# Dvi is a bytecode format documented in
@@ -172,7 +158,7 @@ def wrapper(self, byte):
172158 if max is None :
173159 table [min ] = wrapper
174160 else :
175- for i in xrange (min , max + 1 ):
161+ for i in range (min , max + 1 ):
176162 assert table [i ] is None
177163 table [i ] = wrapper
178164 return wrapper
@@ -194,7 +180,7 @@ class Dvi(object):
194180 >>> print(''.join(unichr(t.glyph) for t in page.text))
195181 """
196182 # dispatch table
197- _dtable = [None for _ in xrange (256 )]
183+ _dtable = [None for _ in range (256 )]
198184 _dispatch = partial (_dispatch , _dtable )
199185
200186 def __init__ (self , filename , dpi ):
@@ -311,7 +297,7 @@ def _read(self):
311297 False if there were no more pages.
312298 """
313299 while True :
314- byte = ord ( self .file .read (1 )[0 ])
300+ byte = self .file .read (1 )[0 ]
315301 self ._dtable [byte ](self , byte )
316302 if byte == 140 : # end of page
317303 return True
@@ -325,11 +311,11 @@ def _arg(self, nbytes, signed=False):
325311 Signedness is determined by the *signed* keyword.
326312 """
327313 str = self .file .read (nbytes )
328- value = ord ( str [0 ])
314+ value = str [0 ]
329315 if signed and value >= 0x80 :
330316 value = value - 0x100
331317 for i in range (1 , nbytes ):
332- value = 0x100 * value + ord ( str [i ])
318+ value = 0x100 * value + str [i ]
333319 return value
334320
335321 @_dispatch (min = 0 , max = 127 , state = _dvistate .inpage )
@@ -445,14 +431,9 @@ def _fnt_num(self, new_f):
445431 @_dispatch (min = 239 , max = 242 , args = ('ulen1' ,))
446432 def _xxx (self , datalen ):
447433 special = self .file .read (datalen )
448- if six .PY3 :
449- chr_ = chr
450- else :
451- def chr_ (x ):
452- return x
453434 _log .debug (
454435 '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
456437 for ch in special ]))
457438
458439 @_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):
464445 fontname = n [- l :].decode ('ascii' )
465446 tfm = _tfmfile (fontname )
466447 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 )
472449 if c != 0 and tfm .checksum != 0 and c != tfm .checksum :
473450 raise ValueError ('tfm checksum mismatch: %s' % n )
474451
@@ -561,7 +538,7 @@ def __init__(self, scale, tfm, texname, vf):
561538 except ValueError :
562539 nchars = 0
563540 self .widths = [(1000 * tfm .width .get (char , 0 )) >> 20
564- for char in xrange (nchars )]
541+ for char in range (nchars )]
565542
566543 def __eq__ (self , other ):
567544 return self .__class__ == other .__class__ and \
@@ -642,7 +619,7 @@ def _read(self):
642619 """
643620 packet_len , packet_char , packet_width = None , None , None
644621 while True :
645- byte = ord ( self .file .read (1 )[0 ])
622+ byte = self .file .read (1 )[0 ]
646623 # If we are in a packet, execute the dvi instructions
647624 if self .state == _dvistate .inpage :
648625 byte_at = self .file .tell ()- 1
@@ -773,9 +750,9 @@ def __init__(self, filename):
773750 widths , heights , depths = \
774751 [struct .unpack ('!%dI' % (len (x )/ 4 ), x )
775752 for x in (widths , heights , depths )]
776- for idx , char in enumerate (xrange (bc , ec + 1 )):
777- byte0 = ord ( char_info [4 * idx ])
778- byte1 = ord ( char_info [4 * idx + 1 ])
753+ for idx , char in enumerate (range (bc , ec + 1 )):
754+ byte0 = char_info [4 * idx ]
755+ byte1 = char_info [4 * idx + 1 ]
779756 self .width [char ] = _fix2comp (widths [byte0 ])
780757 self .height [char ] = _fix2comp (heights [byte1 >> 4 ])
781758 self .depth [char ] = _fix2comp (depths [byte1 & 0xf ])
@@ -835,7 +812,7 @@ class PsfontsMap(object):
835812 def __init__ (self , filename ):
836813 self ._font = {}
837814 self ._filename = filename
838- if six . PY3 and isinstance (filename , bytes ):
815+ if isinstance (filename , bytes ):
839816 encoding = sys .getfilesystemencoding () or 'utf-8'
840817 self ._filename = filename .decode (encoding , errors = 'replace' )
841818 with open (filename , 'rb' ) as file :
@@ -1023,25 +1000,19 @@ def find_tex_file(filename, format=None):
10231000 The library that :program:`kpsewhich` is part of.
10241001 """
10251002
1026- if six .PY3 :
1027- # we expect these to always be ascii encoded, but use utf-8
1028- # out of caution
1029- if isinstance (filename , bytes ):
1030- filename = filename .decode ('utf-8' , errors = 'replace' )
1031- if isinstance (format , bytes ):
1032- format = format .decode ('utf-8' , errors = 'replace' )
1003+ # we expect these to always be ascii encoded, but use utf-8
1004+ # out of caution
1005+ if isinstance (filename , bytes ):
1006+ filename = filename .decode ('utf-8' , errors = 'replace' )
1007+ if isinstance (format , bytes ):
1008+ format = format .decode ('utf-8' , errors = 'replace' )
10331009
10341010 cmd = ['kpsewhich' ]
10351011 if format is not None :
10361012 cmd += ['--format=' + format ]
10371013 cmd += [filename ]
10381014 _log .debug ('find_tex_file(%s): %s' , filename , cmd )
1039- # stderr is unused, but reading it avoids a subprocess optimization
1040- # that breaks EINTR handling in some Python versions:
1041- # http://bugs.python.org/issue12493
1042- # https://github.com/matplotlib/matplotlib/issues/633
1043- pipe = subprocess .Popen (cmd , stdout = subprocess .PIPE ,
1044- stderr = subprocess .PIPE )
1015+ pipe = subprocess .Popen (cmd , stdout = subprocess .PIPE )
10451016 result = pipe .communicate ()[0 ].rstrip ()
10461017 _log .debug ('find_tex_file result: %s' , result )
10471018 return result .decode ('ascii' )
0 commit comments