Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / cython / src / Cython / Tempita / compat3.py
blob5e18fa011de26d1b6c2028a9593984057e0ce864
1 import sys
3 __all__ = ['b', 'basestring_', 'bytes', 'next', 'is_unicode']
5 if sys.version < "3":
6 b = bytes = str
7 basestring_ = basestring
8 else:
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
18 if sys.version < "3":
20 def next(obj):
21 return obj.next()
22 else:
23 next = next
25 if sys.version < "3":
27 def is_unicode(obj):
28 return isinstance(obj, unicode)
29 else:
31 def is_unicode(obj):
32 return isinstance(obj, str)
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