1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
Description: Migrate old string exceptions to real Exceptions
Author: Paul Tagliamonte <paultag@ubuntu.com>
Last-Update: 2012-02-1
With python 2.7, we can see the following behavior:
>>> raise "foo"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: exceptions must be old-style classes or derived from BaseException, not str
>>> raise Exception("foo")
raceback (most recent call last):
File "<stdin>", line 1, in <module>
Exception: foo
>>> raise Exception, "Foo"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Exception: Foo
>>>
As a result, patching the source to remove cases of throwing a str
(which was valid in old versions of Python) is needed.
--- a/components/gauge.py 2012-02-01 11:23:08.930201770 -0500
+++ b/components/gauge.py 2012-02-01 11:23:54.874199316 -0500
@@ -51,13 +51,13 @@ class Gauge(widget.Widget, wx.Gauge):
elif aString == 'vertical' :
return wx.GA_VERTICAL
else :
- raise 'invalid Gauge.layout value: ', aString
+ raise Exception('invalid Gauge.layout value: %s' % aString)
def _getLayout( self ) :
return self._layout
def _setLayout( self, aString ) :
- raise AttributeError, "layout attribute is read-only"
+ raise AttributeError( "layout attribute is read-only" )
layout = property(_getLayout, _setLayout)
max = property(wx.Gauge.GetRange, wx.Gauge.SetRange)
--- a/components/multicolumnlist.py 2012-02-01 11:23:08.930201770 -0500
+++ b/components/multicolumnlist.py 2012-02-01 11:26:00.386192615 -0500
@@ -292,7 +292,7 @@ class MultiColumnList(widget.Widget, wx.
if isinstance(aList, ListType) or isinstance(aList, TupleType) or isinstance(aList, StringTypes):
pass
else:
- raise 'invalid MultiColumnList.SetHeading value: ', aList
+ raise Exception( 'invalid MultiColumnList.SetHeading value: %s' % aList )
self.ClearAll()
self.itemDataMap = {}
@@ -343,9 +343,11 @@ class MultiColumnList(widget.Widget, wx.
self.InsertColumn(i, aList[i][0], width=wx.LIST_AUTOSIZE)
self._autoresize = 1
else:
- raise 'invalid MultiColumnList.SetHeading value: ', aList
+ raise Exception( 'invalid MultiColumnList.SetHeading value: %s' %
+ aList )
else:
- raise 'invalid MultiColumnList.SetHeading value: ', aList
+ raise Exception( 'invalid MultiColumnList.SetHeading value: %s' %
+ aList )
if numcols == 1:
self.SetColumnWidth(0, self.GetBestVirtualSize()[0])
--- a/components/radiogroup.py 2012-02-01 11:23:08.930201770 -0500
+++ b/components/radiogroup.py 2012-02-01 11:26:24.234191342 -0500
@@ -68,7 +68,7 @@ class RadioGroup(widget.Widget, wx.Radio
elif aString == 'horizontal':
return wx.RA_SPECIFY_ROWS
else:
- raise 'invalid RadioGroup.layout value: ', aString
+ raise Exception( 'invalid RadioGroup.layout value: %s' % aString )
def _getItems(self):
return self._labels
--- a/components/slider.py 2012-02-01 11:23:08.930201770 -0500
+++ b/components/slider.py 2012-02-01 11:26:57.802189549 -0500
@@ -67,7 +67,7 @@ class Slider(widget.Widget, wx.Slider):
elif aString == 'vertical' :
return wx.SL_VERTICAL
else :
- raise 'invalid Slider.layout value: ', aString
+ raise Exception('invalid Slider.layout value: %s' % aString )
def __getLabels(self, aBoolean):
if aBoolean:
--- a/components/staticline.py 2012-02-01 11:23:08.930201770 -0500
+++ b/components/staticline.py 2012-02-01 11:27:46.726186937 -0500
@@ -49,13 +49,13 @@ class StaticLine(widget.Widget, wx.Stati
elif aString == 'vertical' :
return wx.LI_VERTICAL
else :
- raise 'invalid StaticLine.layout value: ', aString
+ raise Exception( 'invalid StaticLine.layout value: %s' % aString )
#def _setHelpText( self, aString ) :
# pass
def _setLayout( self, aString ) :
- raise AttributeError, "layout attribute is read-only"
+ raise AttributeError( "layout attribute is read-only" )
def _getLayout( self ) :
return self._layout
--- a/components/statictext.py 2012-02-01 11:23:08.930201770 -0500
+++ b/components/statictext.py 2012-02-01 11:28:08.830185757 -0500
@@ -50,7 +50,7 @@ class StaticText(widget.Widget, wx.Stati
elif aString == 'right' :
return wx.ALIGN_RIGHT | wx.ST_NO_AUTORESIZE
else :
- raise 'invalid StaticText.alignment value: ', aString
+ raise Exception( 'invalid StaticText.alignment value: %s' % aString )
def _setText( self, aString):
self.SetLabel(aString)
--- a/components/textfield.py 2012-02-01 11:23:08.930201770 -0500
+++ b/components/textfield.py 2012-02-01 11:29:00.470183000 -0500
@@ -51,7 +51,7 @@ def getAlignment(aString):
elif aString == 'right':
return wx.TE_RIGHT
else :
- raise 'invalid TextField.alignment value:', aString
+ raise Exception( 'invalid TextField.alignment value: %s' % aString )
class TextField(widget.Widget, wx.TextCtrl):
"""
--- a/graphic.py 2012-02-01 11:23:08.926201770 -0500
+++ b/graphic.py 2012-02-01 11:30:10.090179283 -0500
@@ -73,7 +73,7 @@ def bitmapType(filename):
# KEA 2001-10-10
# rather than throw an exception, we could try and have wxPython figure out the image
# type by returning wxBITMAP_TYPE_ANY
- raise 'invalid graphics format' # should throw an exception here
+ raise Exception( 'invalid graphics format' )
def saveWindowScreenshot(w, path):
@@ -177,7 +177,7 @@ class Bitmap :
# KEA 2001-10-10
# rather than throw an exception, we could try and have wxPython figure out the image
# type by returning wxBITMAP_TYPE_ANY
- raise 'invalid graphics format' # should throw an exception here
+ raise Exception('invalid graphics format')
# xbm format doesn't seem to work on Windows
def loadFile(self, filename=None, size=(-1, -1)):
|