diff -r bf5f777260a6 -r 21b0534faebc eric6/ThirdParty/Pygments/pygments/util.py --- a/eric6/ThirdParty/Pygments/pygments/util.py Tue Apr 21 19:44:19 2020 +0200 +++ b/eric6/ThirdParty/Pygments/pygments/util.py Tue Apr 21 19:47:10 2020 +0200 @@ -5,12 +5,13 @@ Utility functions. - :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ import re import sys +from io import TextIOWrapper split_path_re = re.compile(r'[/\\ ]') @@ -53,7 +54,7 @@ return string elif isinstance(string, int): return bool(string) - elif not isinstance(string, string_types): + elif not isinstance(string, str): raise OptionError('Invalid type %r for option %s; use ' '1/0, yes/no, true/false, on/off' % ( string, optname)) @@ -83,7 +84,7 @@ def get_list_opt(options, optname, default=None): val = options.get(optname, default) - if isinstance(val, string_types): + if isinstance(val, str): return val.split() elif isinstance(val, (list, tuple)): return list(val) @@ -173,7 +174,7 @@ Note that this method only checks the first part of a DOCTYPE. eg: 'html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"' """ - m = doctype_lookup_re.match(text) + m = doctype_lookup_re.search(text) if m is None: return False doctype = m.group(2) @@ -196,7 +197,7 @@ try: return _looks_like_xml_cache[key] except KeyError: - m = doctype_lookup_re.match(text) + m = doctype_lookup_re.search(text) if m is not None: return True rv = tag_re.search(text[:1000]) is not None @@ -224,7 +225,7 @@ if sys.maxunicode > 0xffff: # wide build - return u'[%s-%s]' % (unichr(a), unichr(b)) + return u'[%s-%s]' % (chr(a), chr(b)) else: # narrow build stores surrogates, and the 're' module handles them # (incorrectly) as characters. Since there is still ordering among @@ -232,24 +233,23 @@ # background in http://bugs.python.org/issue3665 and # http://bugs.python.org/issue12749 # - # Additionally, the lower constants are using unichr rather than + # Additionally, the lower constants are using chr rather than # literals because jython [which uses the wide path] can't load this # file if they are literals. ah, al = _surrogatepair(a) bh, bl = _surrogatepair(b) if ah == bh: - return u'(?:%s[%s-%s])' % (unichr(ah), unichr(al), unichr(bl)) + return u'(?:%s[%s-%s])' % (chr(ah), chr(al), chr(bl)) else: buf = [] - buf.append(u'%s[%s-%s]' % - (unichr(ah), unichr(al), - ah == bh and unichr(bl) or unichr(0xdfff))) + buf.append(u'%s[%s-%s]' % (chr(ah), chr(al), + ah == bh and chr(bl) or chr(0xdfff))) if ah - bh > 1: buf.append(u'[%s-%s][%s-%s]' % - unichr(ah+1), unichr(bh-1), unichr(0xdc00), unichr(0xdfff)) + chr(ah+1), chr(bh-1), chr(0xdc00), chr(0xdfff)) if ah != bh: buf.append(u'%s[%s-%s]' % - (unichr(bh), unichr(0xdc00), unichr(bl))) + (chr(bh), chr(0xdc00), chr(bl))) return u'(?:' + u'|'.join(buf) + u')' @@ -289,7 +289,7 @@ return lst -class Future(object): +class Future: """Generic class to defer some work. Handled specially in RegexLexerMeta, to support regex string construction at @@ -345,44 +345,7 @@ return locale.getpreferredencoding() -# Python 2/3 compatibility - -if sys.version_info < (3, 0): - unichr = unichr - xrange = xrange - string_types = (str, unicode) - text_type = unicode - u_prefix = 'u' - iteritems = dict.iteritems - itervalues = dict.itervalues - import StringIO - import cStringIO - # unfortunately, io.StringIO in Python 2 doesn't accept str at all - StringIO = StringIO.StringIO - BytesIO = cStringIO.StringIO -else: - unichr = chr - xrange = range - string_types = (str,) - text_type = str - u_prefix = '' - iteritems = dict.items - itervalues = dict.values - from io import StringIO, BytesIO, TextIOWrapper - - class UnclosingTextIOWrapper(TextIOWrapper): - # Don't close underlying buffer on destruction. - def close(self): - self.flush() - - -def add_metaclass(metaclass): - """Class decorator for creating a class with a metaclass.""" - def wrapper(cls): - orig_vars = cls.__dict__.copy() - orig_vars.pop('__dict__', None) - orig_vars.pop('__weakref__', None) - for slots_var in orig_vars.get('__slots__', ()): - orig_vars.pop(slots_var) - return metaclass(cls.__name__, cls.__bases__, orig_vars) - return wrapper +class UnclosingTextIOWrapper(TextIOWrapper): + # Don't close underlying buffer on destruction. + def close(self): + self.flush()