[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#585323: [patch] fix exceptions in pythoncard 0.8.2



Severity: normal
tag 585323 +patch
kthxbye

Patch attached. Needs testing.

The issue looks like it's enough reachable code to become an issue for
pythoncard.

-- 
All programmers are playwrights, and all computers are lousy actors.

#define sizeof(x) rand()
:wq
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)):

Reply to: