|
| 1 | +From 5804d7a276ef156dd0e977228b631dd1f543ca96 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Johann Schmitz <johann@j-schmitz.net> |
| 3 | +Date: Sat, 5 Dec 2015 07:15:18 +0100 |
| 4 | +Subject: [PATCH] Python3 support (via 2to3). May need some extra work. |
| 5 | + |
| 6 | +--- |
| 7 | + httpheader.py | 23 ++++++++++++++--------- |
| 8 | + 1 file changed, 14 insertions(+), 9 deletions(-) |
| 9 | + |
| 10 | +diff --git a/httpheader.py b/httpheader.py |
| 11 | +index e07bff4..abc5a6e 100644 |
| 12 | +--- a/httpheader.py |
| 13 | ++++ b/httpheader.py |
| 14 | +@@ -100,6 +100,8 @@ |
| 15 | + DIGIT = '0123456789' |
| 16 | + HEX = '0123456789ABCDEFabcdef' |
| 17 | + |
| 18 | ++import sys |
| 19 | ++ |
| 20 | + # Try to get a set/frozenset implementation if possible |
| 21 | + try: |
| 22 | + type(frozenset) |
| 23 | +@@ -126,7 +128,7 @@ |
| 24 | + |
| 25 | + def _is_string( obj ): |
| 26 | + """Returns True if the object is a string or unicode type.""" |
| 27 | +- return isinstance(obj,str) or isinstance(obj,unicode) |
| 28 | ++ return isinstance(obj, str) or isinstance(obj, unicode) if sys.version_info.major == 2 else isinstance(obj, str) |
| 29 | + |
| 30 | + |
| 31 | + def http_datetime( dt=None ): |
| 32 | +@@ -496,10 +498,10 @@ def _test_comments(): |
| 33 | + def _testrm( a, b, collapse ): |
| 34 | + b2 = remove_comments( a, collapse ) |
| 35 | + if b != b2: |
| 36 | +- print 'Comment test failed:' |
| 37 | +- print ' remove_comments( %s, collapse_spaces=%s ) -> %s' \ |
| 38 | +- % (repr(a), repr(collapse), repr(b2)) |
| 39 | +- print ' expected %s' % repr(b) |
| 40 | ++ print('Comment test failed:') |
| 41 | ++ print(' remove_comments( %s, collapse_spaces=%s ) -> %s' \ |
| 42 | ++ % (repr(a), repr(collapse), repr(b2))) |
| 43 | ++ print(' expected %s' % repr(b)) |
| 44 | + return 1 |
| 45 | + return 0 |
| 46 | + failures = 0 |
| 47 | +@@ -1333,6 +1335,9 @@ def _set_minor(self, s): |
| 48 | + minor = property(_get_minor,_set_minor,doc="Minor media sub-classification") |
| 49 | + |
| 50 | + def __nonzero__(self): |
| 51 | ++ return self.__bool__() |
| 52 | ++ |
| 53 | ++ def __bool__(self): |
| 54 | + return True |
| 55 | + |
| 56 | + def __str__(self): |
| 57 | +@@ -1340,13 +1345,13 @@ def __str__(self): |
| 58 | + s = '%s/%s' % (self.major, self.minor) |
| 59 | + if self.parmdict: |
| 60 | + extra = '; '.join([ '%s=%s' % (a[0],quote_string(a[1],False)) \ |
| 61 | +- for a in self.parmdict.items()]) |
| 62 | ++ for a in list(self.parmdict.items())]) |
| 63 | + s += '; ' + extra |
| 64 | + return s |
| 65 | + |
| 66 | + def __unicode__(self): |
| 67 | + """Unicode string value.""" |
| 68 | +- return unicode(self.__str__()) |
| 69 | ++ return str(self.__str__()) |
| 70 | + |
| 71 | + def __repr__(self): |
| 72 | + """Python representation of this object.""" |
| 73 | +@@ -1509,7 +1514,7 @@ def acceptable_content_type( accept_header, content_types, ignore_wildcard=True |
| 74 | + elif client_ct.minor == server_ct.minor: # something/something is a 3 |
| 75 | + matchlen = 3 |
| 76 | + # must make sure all the parms match too |
| 77 | +- for pname, pval in client_ct.parmdict.items(): |
| 78 | ++ for pname, pval in list(client_ct.parmdict.items()): |
| 79 | + sval = server_ct.parmdict.get(pname) |
| 80 | + if pname == 'charset': |
| 81 | + # special case for charset to match aliases |
| 82 | +@@ -1764,7 +1769,7 @@ def __str__(self): |
| 83 | + |
| 84 | + def __unicode__(self): |
| 85 | + """The unicode string form of this language tag.""" |
| 86 | +- return unicode(self.__str__()) |
| 87 | ++ return str(self.__str__()) |
| 88 | + |
| 89 | + def __repr__(self): |
| 90 | + """The python representation of this language tag.""" |
0 commit comments