diff -r b0996e4a289e -r 1d8dd9706f46 ThirdParty/Pygments/pygments/lexer.py --- a/ThirdParty/Pygments/pygments/lexer.py Fri Jan 01 16:11:36 2010 +0000 +++ b/ThirdParty/Pygments/pygments/lexer.py Sat Jan 02 15:11:35 2010 +0000 @@ -41,7 +41,7 @@ return type.__new__(cls, name, bases, d) -class Lexer(object): +class Lexer(object, metaclass=LexerMeta): """ Lexer for a specific language. @@ -76,8 +76,6 @@ #: mime types mimetypes = [] - __metaclass__ = LexerMeta - def __init__(self, **options): self.options = options self.stripnl = get_bool_opt(options, 'stripnl', True) @@ -127,12 +125,12 @@ Also preprocess the text, i.e. expand tabs and strip it if wanted and applies registered filters. """ - if not isinstance(text, unicode): + if not isinstance(text, str): if self.encoding == 'guess': try: text = text.decode('utf-8') - if text.startswith(u'\ufeff'): - text = text[len(u'\ufeff'):] + if text.startswith('\ufeff'): + text = text[len('\ufeff'):] except UnicodeDecodeError: text = text.decode('latin1') elif self.encoding == 'chardet': @@ -367,11 +365,11 @@ try: rex = re.compile(tdef[0], rflags).match - except Exception, err: + except Exception as err: raise ValueError("uncompilable regex %r in state %r of %r: %s" % (tdef[0], state, cls, err)) - assert type(tdef[1]) is _TokenType or callable(tdef[1]), \ + assert type(tdef[1]) is _TokenType or hasattr(tdef[1], '__call__'), \ 'token type must be simple type or callable, not %r' % (tdef[1],) if len(tdef) == 2: @@ -416,7 +414,7 @@ def process_tokendef(cls, name, tokendefs=None): processed = cls._all_tokens[name] = {} tokendefs = tokendefs or cls.tokens[name] - for state in tokendefs.keys(): + for state in list(tokendefs.keys()): cls._process_state(tokendefs, processed, state) return processed @@ -433,13 +431,12 @@ return type.__call__(cls, *args, **kwds) -class RegexLexer(Lexer): +class RegexLexer(Lexer, metaclass=RegexLexerMeta): """ Base for simple stateful regular expression-based lexers. Simplifies the lexing process so that you need only provide a list of states and regular expressions. """ - __metaclass__ = RegexLexerMeta #: Flags for compiling the regular expressions. #: Defaults to MULTILINE. @@ -510,7 +507,7 @@ pos += 1 statestack = ['root'] statetokens = tokendefs['root'] - yield pos, Text, u'\n' + yield pos, Text, '\n' continue yield pos, Error, text[pos] pos += 1 @@ -588,7 +585,7 @@ ctx.pos += 1 ctx.stack = ['root'] statetokens = tokendefs['root'] - yield ctx.pos, Text, u'\n' + yield ctx.pos, Text, '\n' continue yield ctx.pos, Error, text[ctx.pos] ctx.pos += 1 @@ -612,7 +609,7 @@ """ insertions = iter(insertions) try: - index, itokens = insertions.next() + index, itokens = next(insertions) except StopIteration: # no insertions for item in tokens: @@ -638,7 +635,7 @@ realpos += len(it_value) oldi = index - i try: - index, itokens = insertions.next() + index, itokens = next(insertions) except StopIteration: insleft = False break # not strictly necessary