summaryrefslogtreecommitdiff
path: root/pygments/util.py
diff options
context:
space:
mode:
authorgbrandl <devnull@localhost>2009-03-31 10:26:55 -0500
committergbrandl <devnull@localhost>2009-03-31 10:26:55 -0500
commit7b95efab48d9ec79e995bf4d6db10fd049e3395a (patch)
tree48fc9b840dab83976a85af85d1c705dbaa051a0b /pygments/util.py
parentf12c878ed096137c91658a0f62f0070e08c2afea (diff)
downloadpygments-7b95efab48d9ec79e995bf4d6db10fd049e3395a.tar.gz
Port Pygments to Python 3.1.
Diffstat (limited to 'pygments/util.py')
-rw-r--r--pygments/util.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/pygments/util.py b/pygments/util.py
index 476027aa..ac9babc1 100644
--- a/pygments/util.py
+++ b/pygments/util.py
@@ -9,6 +9,7 @@
:license: BSD, see LICENSE for details.
"""
import re
+import sys
split_path_re = re.compile(r'[/\\ ]')
@@ -196,3 +197,26 @@ def looks_like_xml(text):
rv = tag_re.search(text[:1000]) is not None
_looks_like_xml_cache[key] = rv
return rv
+
+# Python 2/3 compatibility
+
+if sys.version_info < (3,0):
+ b = bytes = str
+ u_prefix = 'u'
+ import StringIO, cStringIO
+ BytesIO = cStringIO.StringIO
+ StringIO = StringIO.StringIO
+else:
+ import builtins
+ bytes = builtins.bytes
+ u_prefix = ''
+ def b(s):
+ if isinstance(s, str):
+ return bytes(map(ord, s))
+ elif isinstance(s, bytes):
+ return s
+ else:
+ raise TypeError("Invalid argument %r for b()" % (s,))
+ import io
+ BytesIO = io.BytesIO
+ StringIO = io.StringIO