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

Skip to content

Commit 34723f2

Browse files
committed
Fix all Python 2.6 deprecation warnings.
svn path=/trunk/matplotlib/; revision=6142
1 parent 5d59438 commit 34723f2

15 files changed

Lines changed: 103 additions & 66 deletions

lib/matplotlib/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
__revision__ = '$Revision$'
9494
__date__ = '$Date$'
9595

96-
import md5, os, re, shutil, sys, warnings
96+
import os, re, shutil, sys, warnings
9797
import distutils.sysconfig
9898

9999

@@ -234,7 +234,7 @@ def wrap(self, fmt, func, level='helpful', always=True):
234234
if always is True, the report will occur on every function
235235
call; otherwise only on the first time the function is called
236236
"""
237-
assert(callable, func)
237+
assert callable(func)
238238
def wrapper(*args, **kwargs):
239239
ret = func(*args, **kwargs)
240240

lib/matplotlib/backends/backend_cairo.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525

2626
def _fn_name(): return sys._getframe(1).f_code.co_name
2727

28-
import cairo
28+
try:
29+
import cairo
30+
except ImportError:
31+
raise ImportError("Cairo backend requires that pycairo is installed.")
32+
2933
_version_required = (1,2,0)
3034
if cairo.version_info < _version_required:
3135
raise ImportError ("Pycairo %d.%d.%d is installed\n"

lib/matplotlib/backends/backend_gtk.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
import os, sys
44
def fn_name(): return sys._getframe(1).f_code.co_name
55

6-
import gobject
7-
import gtk; gdk = gtk.gdk
8-
import pango
6+
try:
7+
import gobject
8+
import gtk; gdk = gtk.gdk
9+
import pango
10+
except ImportError:
11+
raise ImportError("Gtk* backend requires pygtk to be installed.")
12+
913
pygtk_version_required = (2,2,0)
1014
if gtk.pygtk_version < pygtk_version_required:
1115
raise ImportError ("PyGTK %d.%d.%d is installed\n"

lib/matplotlib/backends/backend_pdf.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
from cStringIO import StringIO
1818
from datetime import datetime
1919
from math import ceil, cos, floor, pi, sin
20-
from sets import Set
20+
try:
21+
set
22+
except NameError:
23+
from sets import Set as set
2124

2225
import matplotlib
2326
from matplotlib import __version__, rcParams, get_data_path
@@ -692,7 +695,7 @@ def get_char_width(charcode):
692695
cmap = font.get_charmap()
693696
glyph_ids = []
694697
differences = []
695-
multi_byte_chars = Set()
698+
multi_byte_chars = set()
696699
for c in characters:
697700
ccode = c
698701
gind = cmap.get(ccode) or 0
@@ -1215,14 +1218,14 @@ def track_characters(self, font, s):
12151218
fname = font.fname
12161219
realpath, stat_key = get_realpath_and_stat(fname)
12171220
used_characters = self.used_characters.setdefault(
1218-
stat_key, (realpath, Set()))
1221+
stat_key, (realpath, set()))
12191222
used_characters[1].update([ord(x) for x in s])
12201223

12211224
def merge_used_characters(self, other):
1222-
for stat_key, (realpath, set) in other.items():
1225+
for stat_key, (realpath, charset) in other.items():
12231226
used_characters = self.used_characters.setdefault(
1224-
stat_key, (realpath, Set()))
1225-
used_characters[1].update(set)
1227+
stat_key, (realpath, set()))
1228+
used_characters[1].update(charset)
12261229

12271230
def draw_image(self, x, y, im, bbox, clippath=None, clippath_trans=None):
12281231
#print >>sys.stderr, "draw_image called"

lib/matplotlib/backends/backend_ps.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ def _fn_name(): return sys._getframe(1).f_code.co_name
3636
import numpy as npy
3737
import binascii
3838
import re
39-
from sets import Set
39+
try:
40+
set
41+
except NameError:
42+
from sets import Set as set
4043

4144
if sys.platform.startswith('win'): cmd_split = '&'
4245
else: cmd_split = ';'
@@ -173,14 +176,14 @@ def track_characters(self, font, s):
173176
each font."""
174177
realpath, stat_key = get_realpath_and_stat(font.fname)
175178
used_characters = self.used_characters.setdefault(
176-
stat_key, (realpath, Set()))
179+
stat_key, (realpath, set()))
177180
used_characters[1].update([ord(x) for x in s])
178181

179182
def merge_used_characters(self, other):
180-
for stat_key, (realpath, set) in other.items():
183+
for stat_key, (realpath, charset) in other.items():
181184
used_characters = self.used_characters.setdefault(
182-
stat_key, (realpath, Set()))
183-
used_characters[1].update(set)
185+
stat_key, (realpath, set()))
186+
used_characters[1].update(charset)
184187

185188
def set_color(self, r, g, b, store=1):
186189
if (r,g,b) != self.color:

lib/matplotlib/backends/backend_qt.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
from matplotlib.mathtext import MathTextParser
1414
from matplotlib.widgets import SubplotTool
1515

16-
import qt
16+
try:
17+
import qt
18+
except ImportError:
19+
raise ImportError("Qt backend requires pyqt to be installed.")
1720

1821
backend_version = "0.9.1"
1922
def fn_name(): return sys._getframe(1).f_code.co_name

lib/matplotlib/backends/backend_qt4.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
from matplotlib.mathtext import MathTextParser
1414
from matplotlib.widgets import SubplotTool
1515

16-
from PyQt4 import QtCore, QtGui, Qt
16+
try:
17+
from PyQt4 import QtCore, QtGui, Qt
18+
except ImportError:
19+
raise ImportError("Qt4 backend requires that PyQt4 is installed.")
1720

1821
backend_version = "0.9.1"
1922
def fn_name(): return sys._getframe(1).f_code.co_name

lib/matplotlib/backends/backend_wx.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@
112112
import wx
113113
backend_version = wx.VERSION_STRING
114114
except:
115-
print >>sys.stderr, "Matplotlib backend_wx requires wxPython be installed"
116-
sys.exit()
115+
raise ImportError("Matplotlib backend_wx requires wxPython be installed")
117116

118117
#!!! this is the call that is causing the exception swallowing !!!
119118
#wx.InitAllImageHandlers()

lib/matplotlib/delaunay/triangulate.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import warnings
2-
# 2.3 compatibility
32
try:
43
set
54
except NameError:
6-
import sets
7-
set = sets.Set
5+
from sets import Set as set
86

97
import numpy as np
108

@@ -98,7 +96,7 @@ def _collapse_duplicate_points(self):
9896
# Find the indices of the unique entries
9997
j_sorted = np.lexsort(keys=(self.x, self.y))
10098
mask_unique = np.hstack([
101-
True,
99+
True,
102100
(np.diff(self.x[j_sorted]) != 0) | (np.diff(self.y[j_sorted]) != 0),
103101
])
104102
return j_sorted[mask_unique]

lib/matplotlib/font_manager.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@
3434
"""
3535

3636
import os, sys, glob
37-
from sets import Set
37+
try:
38+
set
39+
except NameError:
40+
from sets import Set as set
3841
import matplotlib
3942
from matplotlib import afm
4043
from matplotlib import ft2font
@@ -1036,7 +1039,7 @@ def lookup_name(name):
10361039
verbose.report('findfont returning %s'%fname, 'debug')
10371040
return fname
10381041

1039-
font_family_aliases = Set(['serif', 'sans-serif', 'cursive',
1042+
font_family_aliases = set(['serif', 'sans-serif', 'cursive',
10401043
'fantasy', 'monospace', 'sans'])
10411044

10421045
for name in prop.get_family():

0 commit comments

Comments
 (0)