|
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 @@ |
4 | 56 | self.parent = None |
5 | 57 |
|
6 | 58 | def __str__(self): |
7 | 59 | - return str(self).encode('utf-8') |
8 | 60 | + return self.value or '' |
9 | 61 |
|
10 | 62 | def __repr__(self): |
11 | | - short = self._get_repr_value() |
| 63 | +- short = self._get_repr_value().encode('utf-8') |
| 64 | ++ short = self._get_repr_value() |
12 | 65 | return '<%s \'%s\' at 0x%07x>' % (self._get_repr_name(), |
13 | 66 | short, id(self)) |
14 | 67 |
|
15 | 68 | - def __unicode__(self): |
16 | 69 | - """Returns a unicode representation of this object.""" |
17 | 70 | - return self.value or '' |
18 | 71 | - |
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 @@ |
23 | 83 | self.tokens = tokens |
24 | | - Token.__init__(self, None, None) |
| 84 | + Token.__init__(self, None, str(self)) |
25 | 85 |
|
26 | 86 | - def __unicode__(self): |
27 | 87 | + def __str__(self): |
|
0 commit comments