Edgewall Software

Ticket #7876: trac-py26.patch

File trac-py26.patch, 3.4 KB (added by jonas, 3 years ago)

A patch that fixes a couple of Python 2.6 compatibility problems

  • trac/core.py

     
    3333        error message. 
    3434        """ 
    3535        Exception.__init__(self, message) 
    36         self.message = message 
     36        self.msg = message 
    3737        if title: 
    3838            self.title = title 
    3939        self.show_traceback = show_traceback 
    4040 
    4141    def __unicode__(self): 
    42         return unicode(self.message) 
     42        return unicode(self.msg) 
    4343 
    4444class Interface(object): 
    4545    """Marker base class for extension point interfaces.""" 
  • trac/web/api.py

     
    467467        if ctype not in ('application/x-www-form-urlencoded', 
    468468                         'multipart/form-data'): 
    469469            fp = StringIO('') 
    470  
     470        # Python 2.6 introduced a backwards incompatible change for 
     471        # FieldStorage where QUERY_STRING is no longer ignored for POST 
     472        # requests. We'll keep the pre 2.6 behaviour for now... 
     473        if self.method == 'POST': 
     474            qs_on_post = self.environ.pop('QUERY_STRING') 
    471475        fs = cgi.FieldStorage(fp, environ=self.environ, keep_blank_values=True) 
     476        if self.method == 'POST': 
     477            self.environ['QUERY_STRING'] = qs_on_post 
    472478        if fs.list: 
    473479            for name in fs.keys(): 
    474480                values = fs[name] 
  • trac/web/tests/api.py

     
    113113        req = Request(environ, None) 
    114114        self.assertEqual('test', req.read(size=4)) 
    115115 
     116    def test_qs_on_post(self): 
     117        """Make sure req.args parsing is consistent even after the backwards 
     118        incompatible change introduced in Python 2.6. 
     119        """ 
     120        environ = self._make_environ(method='GET', 
     121                                     **{'QUERY_STRING': 'action=foo'}) 
     122        req = Request(environ, None) 
     123        self.assertEqual('foo', req.args['action']) 
     124        environ = self._make_environ(method='POST', 
     125                                     **{'wsgi.input': StringIO('action=bar'), 
     126                                        'CONTENT_LENGTH': '10', 
     127                                        'CONTENT_TYPE': 'application/x-www-form-urlencoded', 
     128                                        'QUERY_STRING': 'action=foo'}) 
     129        req = Request(environ, None) 
     130        self.assertEqual('bar', req.args['action']) 
    116131 
     132 
    117133def suite(): 
    118134    suite = unittest.TestSuite() 
    119135    suite.addTest(unittest.makeSuite(RequestTestCase, 'test')) 
  • trac/util/tests/text.py

     
    3636        except ValueError, e: 
    3737            self.assertEquals(u, to_unicode(e)) 
    3838 
    39     def test_from_exception_using_str(self): 
    40         class PermissionError(StandardError): 
    41             def __str__(self): 
    42                 return u'acc\xe8s interdit' 
    43         try: 
    44             raise PermissionError() 
    45         except PermissionError, e: 
    46             self.assertEquals(u'acc\xe8s interdit', to_unicode(e)) 
    4739 
    4840class ExpandtabsTestCase(unittest.TestCase): 
    4941    def test_empty(self):