~pythoneers/ubuntu/lucid/pygments/ltsppa

« back to all changes in this revision

Viewing changes to pygments/util.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt, Ubuntu Merge-o-Matic
  • Date: 2009-11-06 15:35:03 UTC
  • mfrom: (1.1.8 upstream) (2.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20091106153503-jj58ffh76rx68f8u
Tags: 1.1.1+dfsg-1ubuntu1
[ Ubuntu Merge-o-Matic ]
* Merge from debian testing, remaining changes:
  - Drop Recommends: on python-chardet to a Suggests:; this package is
    not in main and as encoding detection is heuristic anyway this isn't
    something we really want to recommend.
  - Call install with --install-layout=deb.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
    Utility functions.
7
7
 
8
 
    :copyright: 2006-2008 by Georg Brandl.
9
 
    :license: BSD, see LICENSE for more details.
 
8
    :copyright: Copyright 2006-2009 by the Pygments team, see AUTHORS.
 
9
    :license: BSD, see LICENSE for details.
10
10
"""
11
11
import re
 
12
import sys
12
13
 
13
14
 
14
15
split_path_re = re.compile(r'[/\\ ]')
196
197
        rv = tag_re.search(text[:1000]) is not None
197
198
        _looks_like_xml_cache[key] = rv
198
199
        return rv
 
200
 
 
201
# Python 2/3 compatibility
 
202
 
 
203
if sys.version_info < (3,0):
 
204
    b = bytes = str
 
205
    u_prefix = 'u'
 
206
    import StringIO, cStringIO
 
207
    BytesIO = cStringIO.StringIO
 
208
    StringIO = StringIO.StringIO
 
209
else:
 
210
    import builtins
 
211
    bytes = builtins.bytes
 
212
    u_prefix = ''
 
213
    def b(s):
 
214
        if isinstance(s, str):
 
215
            return bytes(map(ord, s))
 
216
        elif isinstance(s, bytes):
 
217
            return s
 
218
        else:
 
219
            raise TypeError("Invalid argument %r for b()" % (s,))
 
220
    import io
 
221
    BytesIO = io.BytesIO
 
222
    StringIO = io.StringIO