Skip to content

Commit ddf0720

Browse files
author
vthriller
committed
fix py3k support patch
1 parent 1bcac86 commit ddf0720

1 file changed

Lines changed: 69 additions & 9 deletions

File tree

extras/py3k/fixes.diff

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,87 @@
1-
--- sqlparse/sql.py.orig 2012-03-29 12:09:46.660311410 +0200
2-
+++ sqlparse/sql.py 2012-03-29 12:11:04.924699486 +0200
3-
@@ -23,17 +23,13 @@
1+
diff -ru sqlparse.orig/lexer.py sqlparse/lexer.py
2+
--- sqlparse.orig/lexer.py 2012-11-15 02:15:39.179139370 +0400
3+
+++ sqlparse/lexer.py 2012-11-15 03:04:09.298963427 +0400
4+
@@ -219,15 +219,16 @@
5+
self.filters.append(filter_)
6+
7+
def _decode(self, text):
8+
- if self.encoding == 'guess':
9+
- try:
10+
- text = text.decode('utf-8')
11+
- if text.startswith('\ufeff'):
12+
- text = text[len('\ufeff'):]
13+
- except UnicodeDecodeError:
14+
- text = text.decode('latin1')
15+
- else:
16+
- text = text.decode(self.encoding)
17+
+ if not isinstance(text, str):
18+
+ if self.encoding == 'guess':
19+
+ try:
20+
+ text = text.decode('utf-8')
21+
+ if text.startswith('\ufeff'):
22+
+ text = text[len('\ufeff'):]
23+
+ except UnicodeDecodeError:
24+
+ text = text.decode('latin1')
25+
+ else:
26+
+ text = text.decode(self.encoding)
27+
28+
if self.tabsize > 0:
29+
text = text.expandtabs(self.tabsize)
30+
@@ -242,17 +243,17 @@
31+
Also preprocess the text, i.e. expand tabs and strip it if
32+
wanted and applies registered filters.
33+
"""
34+
- if isinstance(text, str):
35+
+ if isinstance(text, str) or isinstance(text, bytes):
36+
if self.stripall:
37+
text = text.strip()
38+
elif self.stripnl:
39+
text = text.strip('\n')
40+
41+
if isinstance(text, str):
42+
- text = StringIO(text.encode('utf-8'))
43+
- self.encoding = 'utf-8'
44+
- else:
45+
text = StringIO(text)
46+
+ else:
47+
+ text = StringIO(text.decode('utf-8'))
48+
+ self.encoding = 'utf-8'
49+
50+
def streamer():
51+
for i, t, v in self.get_tokens_unprocessed(text):
52+
diff -ru sqlparse.orig/sql.py sqlparse/sql.py
53+
--- sqlparse.orig/sql.py 2012-11-15 02:15:39.179139370 +0400
54+
+++ sqlparse/sql.py 2012-11-15 02:27:15.779097255 +0400
55+
@@ -25,24 +25,13 @@
456
self.parent = None
557

658
def __str__(self):
759
- return str(self).encode('utf-8')
860
+ return self.value or ''
961

1062
def __repr__(self):
11-
short = self._get_repr_value()
63+
- short = self._get_repr_value().encode('utf-8')
64+
+ short = self._get_repr_value()
1265
return '<%s \'%s\' at 0x%07x>' % (self._get_repr_name(),
1366
short, id(self))
1467

1568
- def __unicode__(self):
1669
- """Returns a unicode representation of this object."""
1770
- return self.value or ''
1871
-
19-
def to_unicode(self):
20-
"""Returns a unicode representation of this object.
21-
22-
@@ -139,7 +135,7 @@
72+
- def to_unicode(self):
73+
- """Returns a unicode representation of this object.
74+
-
75+
- @deprecated: please use __unicode__()
76+
- """
77+
- return str(self)
78+
-
79+
def _get_repr_name(self):
80+
return str(self.ttype).split('.')[-1]
81+
82+
@@ -149,7 +138,7 @@
2383
self.tokens = tokens
24-
Token.__init__(self, None, None)
84+
Token.__init__(self, None, str(self))
2585

2686
- def __unicode__(self):
2787
+ def __str__(self):

0 commit comments

Comments
 (0)