Fixes for pygments: version independent metaclass creation and library selection. Py2 comp.

Thu, 23 May 2013 19:58:41 +0200

author
T.Rzepka <Tobias.Rzepka@gmail.com>
date
Thu, 23 May 2013 19:58:41 +0200
branch
Py2 comp.
changeset 2669
11a6696ff868
parent 2607
e5115553185a
child 2670
e60ea6cb8e11

Fixes for pygments: version independent metaclass creation and library selection.

ThirdParty/Pygments/pygments/lexer.py file | annotate | diff | comparison | revisions
ThirdParty/Pygments/pygments/lexers/_luabuiltins.py file | annotate | diff | comparison | revisions
ThirdParty/Pygments/pygments/lexers/_phpbuiltins.py file | annotate | diff | comparison | revisions
ThirdParty/Pygments/pygments/lexers/_postgres_builtins.py file | annotate | diff | comparison | revisions
ThirdParty/Pygments/pygments/style.py file | annotate | diff | comparison | revisions
ThirdParty/Pygments/pygments/unistring.py file | annotate | diff | comparison | revisions
ThirdParty/Pygments/pygments/util.py file | annotate | diff | comparison | revisions
--- a/ThirdParty/Pygments/pygments/lexer.py	Sun Apr 21 20:30:56 2013 +0200
+++ b/ThirdParty/Pygments/pygments/lexer.py	Thu May 23 19:58:41 2013 +0200
@@ -8,9 +8,8 @@
     :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
     :license: BSD, see LICENSE for details.
 """
-from __future__ import unicode_literals    # __IGNORE_WARNING__
 try:
-    str = unicode
+    str = unicode   # __IGNORE_WARNING__
 except (NameError):
     pass
 
@@ -37,6 +36,14 @@
 _default_analyse = staticmethod(lambda x: 0.0)
 
 
+def with_metaclass(meta, base=object):
+    """
+    Python independent version to create a base class with a metaclass.
+    Taken from six 1.3.0 (http://pythonhosted.org/six)
+    """
+    return meta("NewBase", (base,), {})
+
+
 class LexerMeta(type):
     """
     This metaclass automagically converts ``analyse_text`` methods into
@@ -49,7 +56,7 @@
         return type.__new__(cls, name, bases, d)
 
 
-class Lexer(object, metaclass=LexerMeta):
+class Lexer(with_metaclass(LexerMeta, object)):
     """
     Lexer for a specific language.
 
@@ -538,7 +545,7 @@
         return type.__call__(cls, *args, **kwds)
 
 
-class RegexLexer(Lexer, metaclass=RegexLexerMeta):
+class RegexLexer(with_metaclass(RegexLexerMeta, Lexer)):
     """
     Base for simple stateful regular expression-based lexers.
     Simplifies the lexing process so that you need only
--- a/ThirdParty/Pygments/pygments/lexers/_luabuiltins.py	Sun Apr 21 20:30:56 2013 +0200
+++ b/ThirdParty/Pygments/pygments/lexers/_luabuiltins.py	Thu May 23 19:58:41 2013 +0200
@@ -144,7 +144,11 @@
 
 if __name__ == '__main__':
     import re
-    import urllib.request, urllib.parse, urllib.error
+    try:  # Py3
+        import urllib.request as request
+    except (ImportError):
+        import urllib2 as request   # __IGNORE_WARNING__
+
     import pprint
 
     # you can't generally find out what module a function belongs to if you
@@ -190,7 +194,7 @@
 
 
     def get_newest_version():
-        f = urllib.request.urlopen('http://www.lua.org/manual/')
+        f = request.urlopen('http://www.lua.org/manual/')
         r = re.compile(r'^<A HREF="(\d\.\d)/">Lua \1</A>')
         for line in f:
             m = r.match(line)
@@ -198,7 +202,7 @@
                 return m.groups()[0]
 
     def get_lua_functions(version):
-        f = urllib.request.urlopen('http://www.lua.org/manual/%s/' % version)
+        f = request.urlopen('http://www.lua.org/manual/%s/' % version)
         r = re.compile(r'^<A HREF="manual.html#pdf-(.+)">\1</A>')
         functions = []
         for line in f:
--- a/ThirdParty/Pygments/pygments/lexers/_phpbuiltins.py	Sun Apr 21 20:30:56 2013 +0200
+++ b/ThirdParty/Pygments/pygments/lexers/_phpbuiltins.py	Thu May 23 19:58:41 2013 +0200
@@ -3713,7 +3713,10 @@
     import re
     import shutil
     import tarfile
-    import urllib.request, urllib.parse, urllib.error
+    try:  # Py3
+        import urllib.request as request
+    except (ImportError):
+        import urllib2 as request   # __IGNORE_WARNING__
 
     PHP_MANUAL_URL     = 'http://us3.php.net/distributions/manual/php_manual_en.tar.gz'
     PHP_MANUAL_DIR     = './php-chunked-xhtml/'
@@ -3754,7 +3757,7 @@
         return modules
 
     def get_php_references():
-        download = urllib.request.urlretrieve(PHP_MANUAL_URL)
+        download = request.urlretrieve(PHP_MANUAL_URL)
         tar = tarfile.open(download[0])
         tar.extractall()
         tar.close()
--- a/ThirdParty/Pygments/pygments/lexers/_postgres_builtins.py	Sun Apr 21 20:30:56 2013 +0200
+++ b/ThirdParty/Pygments/pygments/lexers/_postgres_builtins.py	Thu May 23 19:58:41 2013 +0200
@@ -10,9 +10,13 @@
 """
 
 from __future__ import unicode_literals    # __IGNORE_WARNING__
+try:
+    str = unicode   # __IGNORE_WARNING__
+    import urllib2 as request
+except (NameError):
+    import urllib.request as request    # __IGNORE_WARNING__
 
 import re
-import urllib.request, urllib.parse, urllib.error
 
 # One man's constant is another man's variable.
 SOURCE_URL = 'https://github.com/postgres/postgres/raw/master'
@@ -99,7 +103,7 @@
     return dt
 
 def fetch(url):
-    return urllib.request.urlopen(url)
+    return request.urlopen(url)
 
 def update_consts(filename, constname, content):
     f = open(filename)
--- a/ThirdParty/Pygments/pygments/style.py	Sun Apr 21 20:30:56 2013 +0200
+++ b/ThirdParty/Pygments/pygments/style.py	Thu May 23 19:58:41 2013 +0200
@@ -13,6 +13,13 @@
 
 from pygments.token import Token, STANDARD_TYPES
 
+def with_metaclass(meta, base=object):
+    """
+    Python independent version to create a base class with a metaclass.
+    Taken from six 1.3.0 (http://pythonhosted.org/six)
+    """
+    return meta("NewBase", (base,), {})
+
 
 class StyleMeta(type):
 
@@ -106,7 +113,7 @@
         return len(cls._styles)
 
 
-class Style(object, metaclass=StyleMeta):
+class Style(with_metaclass(StyleMeta, object)):
     background_color = '#ffffff'
 
     #: highlight background color
--- a/ThirdParty/Pygments/pygments/unistring.py	Sun Apr 21 20:30:56 2013 +0200
+++ b/ThirdParty/Pygments/pygments/unistring.py	Thu May 23 19:58:41 2013 +0200
@@ -12,6 +12,10 @@
     :license: BSD, see LICENSE for details.
 """
 from __future__ import unicode_literals    # __IGNORE_WARNING__
+try: 
+    chr = unichr
+except (NameError):
+    pass
 
 from pygments.util import u_prefix
 
--- a/ThirdParty/Pygments/pygments/util.py	Sun Apr 21 20:30:56 2013 +0200
+++ b/ThirdParty/Pygments/pygments/util.py	Thu May 23 19:58:41 2013 +0200
@@ -10,6 +10,10 @@
 """
 
 from __future__ import unicode_literals    # __IGNORE_WARNING__
+try: 
+    chr = unichr
+except (NameError):
+    pass
 
 import re
 import sys
@@ -258,9 +262,9 @@
 if sys.version_info < (3,0):
     b = bytes = str
     u_prefix = 'u'
-    import io, io
-    BytesIO = io.StringIO
-    StringIO = io.StringIO
+    import StringIO, cStringIO
+    BytesIO = cStringIO.StringIO
+    StringIO = StringIO.StringIO
     uni_open = codecs.open
 else:
     import builtins

eric ide

mercurial