Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 503367f

Browse files
committed
Backporting lots of Python 2.x-safe changes based on the output of 2to3.
1 parent 31a428c commit 503367f

63 files changed

Lines changed: 776 additions & 752 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

lib/matplotlib/__init__.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
to MATLAB®, a registered trademark of The MathWorks, Inc.
9898
9999
"""
100-
from __future__ import generators
100+
from __future__ import print_function
101101

102102
__version__ = '1.1.0'
103103

@@ -233,7 +233,7 @@ def report(self, s, level='helpful'):
233233
234234
"""
235235
if self.ge(level):
236-
print >>self.fileo, s
236+
print(s, file=self.fileo)
237237
return True
238238
return False
239239

@@ -550,7 +550,7 @@ def get_py2exe_datafiles():
550550
root = root.replace(tail, 'mpl-data')
551551
root = root[root.index('mpl-data'):]
552552
d[root] = files
553-
return d.items()
553+
return list(d.items())
554554

555555

556556
def matplotlib_fname():
@@ -569,20 +569,20 @@ def matplotlib_fname():
569569

570570
oldname = os.path.join( os.getcwd(), '.matplotlibrc')
571571
if os.path.exists(oldname):
572-
print >> sys.stderr, """\
572+
print("""\
573573
WARNING: Old rc filename ".matplotlibrc" found in working dir
574574
and and renamed to new default rc file name "matplotlibrc"
575-
(no leading"dot"). """
575+
(no leading"dot"). """, file=sys.stderr)
576576
shutil.move('.matplotlibrc', 'matplotlibrc')
577577

578578
home = get_home()
579579
oldname = os.path.join( home, '.matplotlibrc')
580580
if os.path.exists(oldname):
581581
configdir = get_configdir()
582582
newname = os.path.join(configdir, 'matplotlibrc')
583-
print >> sys.stderr, """\
583+
print("""\
584584
WARNING: Old rc filename "%s" found and renamed to
585-
new default rc file name "%s"."""%(oldname, newname)
585+
new default rc file name "%s"."""%(oldname, newname), file=sys.stderr)
586586

587587
shutil.move(oldname, newname)
588588

@@ -679,7 +679,7 @@ def values(self):
679679
"""
680680
Return values in order of sorted keys.
681681
"""
682-
return [self[k] for k in self.keys()]
682+
return [self[k] for k in self.iterkeys()]
683683

684684
def rc_params(fail_on_error=False):
685685
'Return the default params updated from the values in the rc file'
@@ -721,7 +721,7 @@ def rc_params(fail_on_error=False):
721721
ret[key] = val # try to convert to proper type or raise
722722
else:
723723
try: ret[key] = val # try to convert to proper type or skip
724-
except Exception, msg:
724+
except Exception as msg:
725725
warnings.warn('Bad val "%s" on line #%d\n\t"%s"\n\tin file \
726726
"%s"\n\t%s' % (val, cnt, line, fname, msg))
727727

@@ -734,19 +734,19 @@ def rc_params(fail_on_error=False):
734734
ret[key] = val # try to convert to proper type or raise
735735
else:
736736
try: ret[key] = val # try to convert to proper type or skip
737-
except Exception, msg:
737+
except Exception as msg:
738738
warnings.warn('Bad val "%s" on line #%d\n\t"%s"\n\tin file \
739739
"%s"\n\t%s' % (val, cnt, line, fname, msg))
740740
elif key in _deprecated_ignore_map:
741741
warnings.warn('%s is deprecated. Update your matplotlibrc to use %s instead.'% (key, _deprecated_ignore_map[key]))
742742

743743
else:
744-
print >> sys.stderr, """
744+
print("""
745745
Bad key "%s" on line %d in
746746
%s.
747747
You probably need to get an updated matplotlibrc file from
748748
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
749-
distribution""" % (key, cnt, fname)
749+
distribution""" % (key, cnt, fname), file=sys.stderr)
750750

751751
if ret['datapath'] is None:
752752
ret['datapath'] = get_data_path()
@@ -855,7 +855,7 @@ def rc(group, **kwargs):
855855
if is_string_like(group):
856856
group = (group,)
857857
for g in group:
858-
for k,v in kwargs.items():
858+
for k,v in kwargs.iteritems():
859859
name = aliases.get(k) or k
860860
key = '%s.%s' % (g, name)
861861
try:
@@ -980,7 +980,7 @@ def test(verbosity=0):
980980
"""run the matplotlib test suite"""
981981
import nose
982982
import nose.plugins.builtin
983-
from testing.noseclasses import KnownFailure
983+
from .testing.noseclasses import KnownFailure
984984
from nose.plugins.manager import PluginManager
985985

986986
# store the old values before overriding
@@ -1004,4 +1004,4 @@ def test(verbosity=0):
10041004
verbose.report('interactive is %s'%rcParams['interactive'])
10051005
verbose.report('units is %s'%rcParams['units'])
10061006
verbose.report('platform is %s'%sys.platform)
1007-
verbose.report('loaded modules: %s'%sys.modules.keys(), 'debug')
1007+
verbose.report('loaded modules: %s'%sys.modules.iterkeys(), 'debug')

lib/matplotlib/_mathtext_data.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -363,39 +363,39 @@
363363
r'\lceil' : ('psyr', 233),
364364
r'\lbrace' : ('psyr', 123),
365365
r'\Psi' : ('psyr', 89),
366-
r'\bot' : ('psyr', 0136),
367-
r'\Omega' : ('psyr', 0127),
368-
r'\leftbracket' : ('psyr', 0133),
369-
r'\rightbracket' : ('psyr', 0135),
366+
r'\bot' : ('psyr', 0o136),
367+
r'\Omega' : ('psyr', 0o127),
368+
r'\leftbracket' : ('psyr', 0o133),
369+
r'\rightbracket' : ('psyr', 0o135),
370370
r'\leftbrace' : ('psyr', 123),
371-
r'\leftparen' : ('psyr', 050),
372-
r'\prime' : ('psyr', 0242),
373-
r'\sharp' : ('psyr', 043),
374-
r'\slash' : ('psyr', 057),
375-
r'\Lamda' : ('psyr', 0114),
376-
r'\neg' : ('psyr', 0330),
377-
r'\Upsilon' : ('psyr', 0241),
378-
r'\rightbrace' : ('psyr', 0175),
379-
r'\rfloor' : ('psyr', 0373),
380-
r'\lambda' : ('psyr', 0154),
381-
r'\to' : ('psyr', 0256),
382-
r'\Xi' : ('psyr', 0130),
383-
r'\emptyset' : ('psyr', 0306),
384-
r'\lfloor' : ('psyr', 0353),
385-
r'\rightparen' : ('psyr', 051),
386-
r'\rceil' : ('psyr', 0371),
387-
r'\ni' : ('psyr', 047),
388-
r'\epsilon' : ('psyr', 0145),
389-
r'\Theta' : ('psyr', 0121),
390-
r'\langle' : ('psyr', 0341),
391-
r'\leftangle' : ('psyr', 0341),
392-
r'\rangle' : ('psyr', 0361),
393-
r'\rightangle' : ('psyr', 0361),
394-
r'\rbrace' : ('psyr', 0175),
395-
r'\circ' : ('psyr', 0260),
396-
r'\diamond' : ('psyr', 0340),
397-
r'\mu' : ('psyr', 0155),
398-
r'\mid' : ('psyr', 0352),
371+
r'\leftparen' : ('psyr', 0o50),
372+
r'\prime' : ('psyr', 0o242),
373+
r'\sharp' : ('psyr', 0o43),
374+
r'\slash' : ('psyr', 0o57),
375+
r'\Lamda' : ('psyr', 0o114),
376+
r'\neg' : ('psyr', 0o330),
377+
r'\Upsilon' : ('psyr', 0o241),
378+
r'\rightbrace' : ('psyr', 0o175),
379+
r'\rfloor' : ('psyr', 0o373),
380+
r'\lambda' : ('psyr', 0o154),
381+
r'\to' : ('psyr', 0o256),
382+
r'\Xi' : ('psyr', 0o130),
383+
r'\emptyset' : ('psyr', 0o306),
384+
r'\lfloor' : ('psyr', 0o353),
385+
r'\rightparen' : ('psyr', 0o51),
386+
r'\rceil' : ('psyr', 0o371),
387+
r'\ni' : ('psyr', 0o47),
388+
r'\epsilon' : ('psyr', 0o145),
389+
r'\Theta' : ('psyr', 0o121),
390+
r'\langle' : ('psyr', 0o341),
391+
r'\leftangle' : ('psyr', 0o341),
392+
r'\rangle' : ('psyr', 0o361),
393+
r'\rightangle' : ('psyr', 0o361),
394+
r'\rbrace' : ('psyr', 0o175),
395+
r'\circ' : ('psyr', 0o260),
396+
r'\diamond' : ('psyr', 0o340),
397+
r'\mu' : ('psyr', 0o155),
398+
r'\mid' : ('psyr', 0o352),
399399
r'\imath' : ('pncri8a', 105),
400400
r'\%' : ('pncr8a', 37),
401401
r'\$' : ('pncr8a', 36),
@@ -1760,7 +1760,7 @@
17601760
'uni044B' : 1099
17611761
}
17621762

1763-
uni2type1 = dict([(v,k) for k,v in type12uni.items()])
1763+
uni2type1 = dict(((v,k) for k,v in type12uni.iteritems()))
17641764

17651765
tex2uni = {
17661766
'widehat' : 0x0302,

lib/matplotlib/_pylab_helpers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Manage figures for pyplot interface.
33
"""
4+
from __future__ import print_function
45

56
import sys, gc
67

@@ -9,7 +10,7 @@
910

1011

1112
def error_msg(msg):
12-
print >>sys.stderr, msg
13+
print(msg, file=sys.stderr)
1314

1415
class Gcf(object):
1516
"""
@@ -71,7 +72,7 @@ def destroy(num):
7172
@staticmethod
7273
def destroy_fig(fig):
7374
"*fig* is a Figure instance"
74-
for manager in Gcf.figs.values():
75+
for manager in Gcf.figs.itervalues():
7576
if manager.canvas.figure == fig:
7677
Gcf.destroy(manager.num)
7778

lib/matplotlib/afm.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
John D. Hunter <[email protected]>
3535
"""
3636

37+
from __future__ import print_function
38+
3739
import sys, os, re
3840
from _mathtext_data import uni2type1
3941

@@ -143,10 +145,10 @@ def _parse_header(fh):
143145
#key, val = line.split(' ', 1)
144146
try: d[key] = headerConverters[key](val)
145147
except ValueError:
146-
print >>sys.stderr, 'Value error parsing header in AFM:', key, val
148+
print('Value error parsing header in AFM:', key, val, file=sys.stderr)
147149
continue
148150
except KeyError:
149-
print >>sys.stderr, 'Found an unknown keyword in AFM header (was %s)' % key
151+
print('Found an unknown keyword in AFM header (was %s)' % key, file=sys.stderr)
150152
continue
151153
if key=='StartCharMetrics': return d
152154
raise RuntimeError('Bad parse')

lib/matplotlib/animation.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
# * RC parameter for config?
2020
# * Can blit be enabled for movies?
2121
# * Need to consider event sources to allow clicking through multiple figures
22+
from __future__ import print_function
23+
2224
import itertools
2325
from matplotlib.cbook import iterable
2426

@@ -166,7 +168,7 @@ def _step(self, *args):
166168
# call _step, until the frame sequence reaches the end of iteration,
167169
# at which point False will be returned.
168170
try:
169-
framedata = self.frame_seq.next()
171+
framedata = next(self.frame_seq)
170172
self._draw_next_frame(framedata, self._blit)
171173
return True
172174
except StopIteration:
@@ -430,7 +432,7 @@ def __init__(self, fig, func, frames=None ,init_func=None, fargs=None,
430432
self._init_func = init_func
431433

432434
# Needs to be initialized so the draw functions work without checking
433-
self._save_seq = []
435+
self._save_seq = []
434436

435437
TimedAnimation.__init__(self, fig, **kwargs)
436438

@@ -457,7 +459,7 @@ def _init_draw(self):
457459
# For blitting, the init_func should return a sequence of modified
458460
# artists.
459461
if self._init_func is None:
460-
self._draw_frame(self.new_frame_seq().next())
462+
self._draw_frame(next(self.new_frame_seq()))
461463
else:
462464
self._drawn_artists = self._init_func()
463465

lib/matplotlib/artist.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from __future__ import division
1+
from __future__ import division, print_function
22
import re, warnings
33
import matplotlib
44
import matplotlib.cbook as cbook
@@ -205,7 +205,7 @@ def pchanged(self):
205205
Fire an event when property changed, calling all of the
206206
registered callbacks.
207207
"""
208-
for oid, func in self._propobservers.items():
208+
for oid, func in self._propobservers.iteritems():
209209
func(self)
210210

211211
def is_transform_set(self):
@@ -247,7 +247,7 @@ def hitlist(self, event):
247247
except:
248248
import traceback
249249
traceback.print_exc()
250-
print "while checking",self.__class__
250+
print("while checking",self.__class__)
251251

252252

253253
for a in self.get_children():
@@ -512,7 +512,7 @@ def set_clip_path(self, path, transform=None):
512512
success = True
513513

514514
if not success:
515-
print type(path), type(transform)
515+
print(type(path), type(transform))
516516
raise TypeError("Invalid arguments to set_clip_path")
517517

518518
self.pchanged()
@@ -653,7 +653,7 @@ def update(self, props):
653653
store = self.eventson
654654
self.eventson = False
655655
changed = False
656-
for k,v in props.items():
656+
for k,v in props.iteritems():
657657
func = getattr(self, 'set_'+k, None)
658658
if func is None or not callable(func):
659659
raise AttributeError('Unknown property %s'%k)
@@ -721,7 +721,7 @@ def set(self, **kwargs):
721721
A tkstyle set command, pass *kwargs* to set properties
722722
"""
723723
ret = []
724-
for k,v in kwargs.items():
724+
for k,v in kwargs.iteritems():
725725
k = k.lower()
726726
funcName = "set_%s"%k
727727
func = getattr(self,funcName)
@@ -898,7 +898,7 @@ def aliased_name(self, s):
898898
"""
899899

900900
if s in self.aliasd:
901-
return s + ''.join([' or %s' % x for x in self.aliasd[s].keys()])
901+
return s + ''.join([' or %s' % x for x in self.aliasd[s].iterkeys()])
902902
else:
903903
return s
904904

@@ -914,7 +914,7 @@ def aliased_name_rest(self, s, target):
914914
"""
915915

916916
if s in self.aliasd:
917-
aliases = ''.join([' or %s' % x for x in self.aliasd[s].keys()])
917+
aliases = ''.join([' or %s' % x for x in self.aliasd[s].iterkeys()])
918918
else:
919919
aliases = ''
920920
return ':meth:`%s <%s>`%s' % (s, target, aliases)
@@ -1119,7 +1119,7 @@ def getp(obj, property=None):
11191119
if property is None:
11201120
insp = ArtistInspector(obj)
11211121
ret = insp.pprint_getters()
1122-
print '\n'.join(ret)
1122+
print('\n'.join(ret))
11231123
return
11241124

11251125
func = getattr(obj, 'get_' + property)
@@ -1174,11 +1174,11 @@ def setp(obj, *args, **kwargs):
11741174
insp = ArtistInspector(obj)
11751175

11761176
if len(kwargs)==0 and len(args)==0:
1177-
print '\n'.join(insp.pprint_setters())
1177+
print('\n'.join(insp.pprint_setters()))
11781178
return
11791179

11801180
if len(kwargs)==0 and len(args)==1:
1181-
print insp.pprint_setters(prop=args[0])
1181+
print(insp.pprint_setters(prop=args[0]))
11821182
return
11831183

11841184
if not cbook.iterable(obj):
@@ -1193,7 +1193,7 @@ def setp(obj, *args, **kwargs):
11931193
funcvals = []
11941194
for i in range(0, len(args)-1, 2):
11951195
funcvals.append((args[i], args[i+1]))
1196-
funcvals.extend(kwargs.items())
1196+
funcvals.extend(kwargs.iteritems())
11971197

11981198
ret = []
11991199
for o in objs:

0 commit comments

Comments
 (0)