Mercurial > genshi > mirror
comparison genshi/compat.py @ 1022:500573200533 trunk
Add isstring helper.
author | hodgestar |
---|---|
date | Sun, 16 Feb 2014 18:43:20 +0000 |
parents | 3f8fb83045b9 |
children |
comparison
equal
deleted
inserted
replaced
1021:323d592690da | 1022:500573200533 |
---|---|
32 else: | 32 else: |
33 def stringrepr(string): | 33 def stringrepr(string): |
34 raise RuntimeError( | 34 raise RuntimeError( |
35 'Python 2 compatibility function. Not usable in Python 3.') | 35 'Python 2 compatibility function. Not usable in Python 3.') |
36 | 36 |
37 | |
38 # We need to test if an object is an instance of a string type in places | |
39 | |
40 if IS_PYTHON2: | |
41 def isstring(obj): | |
42 return isinstance(obj, basestring) | |
43 else: | |
44 def isstring(obj): | |
45 return isinstance(obj, str) | |
37 | 46 |
38 # We need to differentiate between StringIO and BytesIO in places | 47 # We need to differentiate between StringIO and BytesIO in places |
39 | 48 |
40 if IS_PYTHON2: | 49 if IS_PYTHON2: |
41 from StringIO import StringIO | 50 from StringIO import StringIO |
110 def all(S): | 119 def all(S): |
111 for x in S: | 120 for x in S: |
112 if not x: | 121 if not x: |
113 return False | 122 return False |
114 return True | 123 return True |
115 |