diff options
author | gbrandl <devnull@localhost> | 2009-03-31 10:26:55 -0500 |
---|---|---|
committer | gbrandl <devnull@localhost> | 2009-03-31 10:26:55 -0500 |
commit | 7b95efab48d9ec79e995bf4d6db10fd049e3395a (patch) | |
tree | 48fc9b840dab83976a85af85d1c705dbaa051a0b /pygments/lexers/__init__.py | |
parent | f12c878ed096137c91658a0f62f0070e08c2afea (diff) | |
download | pygments-7b95efab48d9ec79e995bf4d6db10fd049e3395a.tar.gz |
Port Pygments to Python 3.1.
Diffstat (limited to 'pygments/lexers/__init__.py')
-rw-r--r-- | pygments/lexers/__init__.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/pygments/lexers/__init__.py b/pygments/lexers/__init__.py index 33571b0e..d9d475f7 100644 --- a/pygments/lexers/__init__.py +++ b/pygments/lexers/__init__.py @@ -8,6 +8,7 @@ :copyright: Copyright 2006-2009 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ +import sys import fnmatch import types from os.path import basename @@ -19,7 +20,7 @@ except NameError: from pygments.lexers._mapping import LEXERS from pygments.plugin import find_plugin_lexers -from pygments.util import ClassNotFound +from pygments.util import ClassNotFound, bytes __all__ = ['get_lexer_by_name', 'get_lexer_for_filename', 'find_lexer_class', @@ -102,6 +103,10 @@ def get_lexer_for_filename(_fn, code=None, **options): if fnmatch.fnmatch(fn, filename): matches.append(cls) + if sys.version_info > (3,) and isinstance(code, bytes): + # decode it, since all analyse_text functions expect unicode + code = code.decode('latin1') + def get_rating(cls): # The class _always_ defines analyse_text because it's included in # the Lexer class. The default implementation returns None which |