OLD | NEW |
(Empty) | |
| 1 import sys |
| 2 |
| 3 __all__ = ['b', 'basestring_', 'bytes', 'next', 'is_unicode'] |
| 4 |
| 5 if sys.version < "3": |
| 6 b = bytes = str |
| 7 basestring_ = basestring |
| 8 else: |
| 9 |
| 10 def b(s): |
| 11 if isinstance(s, str): |
| 12 return s.encode('latin1') |
| 13 return bytes(s) |
| 14 basestring_ = (bytes, str) |
| 15 bytes = bytes |
| 16 text = str |
| 17 |
| 18 if sys.version < "3": |
| 19 |
| 20 def next(obj): |
| 21 return obj.next() |
| 22 else: |
| 23 next = next |
| 24 |
| 25 if sys.version < "3": |
| 26 |
| 27 def is_unicode(obj): |
| 28 return isinstance(obj, unicode) |
| 29 else: |
| 30 |
| 31 def is_unicode(obj): |
| 32 return isinstance(obj, str) |
| 33 |
| 34 |
| 35 def coerce_text(v): |
| 36 if not isinstance(v, basestring_): |
| 37 if sys.version < "3": |
| 38 attr = '__unicode__' |
| 39 else: |
| 40 attr = '__str__' |
| 41 if hasattr(v, attr): |
| 42 return unicode(v) |
| 43 else: |
| 44 return bytes(v) |
| 45 return v |
OLD | NEW |