Commits

Anonymous committed 8aaa1fe

[svn] More pylint fixes, update BBcode formatter to new style API.

Comments (0)

Files changed (17)

pygments/__init__.py

 
         info = []
         maxlen = 0
-        for mod, fullname, names, exts in LEXERS.itervalues():
+        for _, fullname, names, exts in LEXERS.itervalues():
             tup = (', '.join(names)+':', fullname,
                    exts and '(extensions ' + ', '.join(exts) + ')' or '')
             info.append(tup)
     try:
         highlight(code, lexer, fmter, outfile)
     except Exception, err:
-        raise
         print >>sys.stderr, 'Error while highlighting:', err
         return 1
     return 0

pygments/formatter.py

 """
 
 from pygments.util import get_bool_opt
-from pygments.style import Style
 from pygments.styles import get_style_by_name
 
 __all__ = ['Formatter']

pygments/formatters/bbcode.py

 
     def __init__(self, **options):
         Formatter.__init__(self, **options)
-        self._make_styles()
         self._code = get_bool_opt(options, 'codetag', False)
         self._mono = get_bool_opt(options, 'monofont', False)
 
+        self.styles = {} 
+        self._make_styles()
+
     def _make_styles(self):
-        self.styles = {}
-        for token, style in self.style._styles.iteritems():
+        for ttype, ndef in self.style:
             start = end = ''
-            color, bold, italic, underline, bg, border = style
-            if color:
-                start += '[color=#%s]' % color
+            if ndef['color']:
+                start += '[color=#%s]' % ndef['color']
                 end = '[/color]' + end
-            if bold:
+            if ndef['bold']:
                 start += '[b]'
                 end = '[/b]' + end
-            if italic:
+            if ndef['italic']:
                 start += '[i]'
                 end = '[/i]' + end
-            if underline:
+            if ndef['underline']:
                 start += '[u]'
                 end = '[/u]' + end
             # there are no common BBcodes for background-color and border

pygments/formatters/html.py

 
 from pygments.formatter import Formatter
 from pygments.token import Token, Text, STANDARD_TYPES
-from pygments.util import get_bool_opt, get_int_opt, get_list_opt
+from pygments.util import get_bool_opt, get_int_opt
 
 
 __all__ = ['HtmlFormatter']

pygments/formatters/latex.py

                           if cmndef != '#1'])
 
     def format(self, tokensource, outfile):
-        #XXX: add support for background colors!!!!!!!111!1
+        # TODO: add support for background colors
 
         if self.full:
             realoutfile = outfile

pygments/formatters/other.py

 """
 
 from pygments.formatter import Formatter
-import StringIO
+
 
 __all__ = ['NullFormatter', 'RawTokenFormatter']
 

pygments/lexer.py

 except NameError:
     from sets import Set as set
 
-from types import FunctionType
 from pygments.token import Error, Text, Other, _TokenType
 from pygments.util import get_bool_opt, get_int_opt, make_analysator
 
     #: current one.
     tokens = {}
 
-    def get_tokens_unprocessed(self, text, stack=['root']):
+    def get_tokens_unprocessed(self, text, stack=('root',)):
         """
         Split ``text`` into (tokentype, text) pairs.
 
         ``stack`` is the inital stack (default: ``['root']``)
         """
         pos = 0
-        statestack = stack[:]
+        statestack = list(stack)
         statetokens = self._tokens[statestack[-1]]
         while 1:
             for rex, action, new_state in statetokens:

pygments/lexers/__init__.py

     fn = basename(_fn)
     for modname, name, _, filenames, _ in LEXERS.itervalues():
         for filename in filenames:
-            if fnmatch.fnmatch(_fn, filename):
+            if fnmatch.fnmatch(fn, filename):
                 if name not in _lexer_cache:
                     _load_lexers(modname)
                 return _lexer_cache[name](**options)
     for cls in find_plugin_lexers():
         for filename in cls.filenames:
-            if fnmatch.fnmatch(_fn, filename):
+            if fnmatch.fnmatch(fn, filename):
                 return cls(**options)
     raise ValueError('no lexer for filename %r found' % _fn)
 

pygments/lexers/_phpbuiltins.py

 
 if __name__ == '__main__':
     import pprint
-    import sys
-    import os
     import re
     import urllib
     _function_re = re.compile('<B\s+CLASS="function"\s*>(.*?)\(\)</B\s*>(?uism)')
 
     def get_php_functions():
-        f = urllib.urlopen('http://de.php.net/manual/en/index.functions.php')
-        data = f.read()
-        f.close()
+        uf = urllib.urlopen('http://de.php.net/manual/en/index.functions.php')
+        data = uf.read()
+        uf.close()
         results = set()
         for match in _function_re.finditer(data):
             fn = match.group(1)
         results.sort()
         return results
 
-    def get_function_module(function_name):
-        fn = function_name.replace('_', '-')
-        f = urllib.urlopen('http://de.php.net/manual/en/function.%s.php' % fn)
+    def get_function_module(func_name):
+        fn = func_name.replace('_', '-')
+        uf = urllib.urlopen('http://de.php.net/manual/en/function.%s.php' % fn)
         regex = re.compile('<li class="header up">'
                            '<a href="ref\..*?\.php">([a-zA-Z0-9\s]+)</a></li>')
-        for line in f:
-            m = regex.search(line)
-            if m is not None:
-                return m.group(1)
+        for line in uf:
+            match = regex.search(line)
+            if match:
+                return match.group(1)
 
     print '>> Downloading Function Index'
     functions = get_php_functions()

pygments/lexers/other.py

 
 import re
 
-from pygments.lexer import Lexer, RegexLexer, include
-from pygments.token import Token, Error, \
+from pygments.lexer import RegexLexer, include
+from pygments.token import Error, \
      Text, Comment, Operator, Keyword, Name, String, Number
 
 

pygments/lexers/special.py

 import re
 import cStringIO
 
-from pygments.lexer import Lexer, RegexLexer
-from pygments.token import Token, Error, \
-     Text, Comment, Operator, Keyword, Name, String, Number
+from pygments.lexer import Lexer
+from pygments.token import Token, Error, Text
 
 
 __all__ = ['TextLexer', 'RawTokenLexer']

pygments/lexers/templates.py

 from pygments.lexers.web import \
      PhpLexer, HtmlLexer, XmlLexer, JavascriptLexer, CssLexer
 from pygments.lexers.agile import PythonLexer
-from pygments.lexer import \
-     Lexer, DelegatingLexer, RegexLexer, do_insertions, bygroups, \
+from pygments.lexer import Lexer, DelegatingLexer, RegexLexer, bygroups, \
      include, using
 from pygments.token import Error, \
      Text, Comment, Operator, Keyword, Name, String, Number, Other

pygments/lexers/web.py

 except NameError:
     from sets import Set as set
 
-from pygments.lexer import Lexer, RegexLexer, do_insertions, bygroups, using
+from pygments.lexer import Lexer, RegexLexer, bygroups, using
 from pygments.token import \
      Text, Comment, Operator, Keyword, Name, String, Number, Other
 from pygments.util import get_bool_opt, get_list_opt, looks_like_xml, \
             for key, value in MODULES.iteritems():
                 if key not in self.disabledmodules:
                     self._functions.update(value)
-        Lexer.__init__(self, **options)
+        RegexLexer.__init__(self, **options)
 
     def get_tokens_unprocessed(self, text):
         stack = ['root']

pygments/styles/native.py

 
 from pygments.style import Style
 from pygments.token import Keyword, Name, Comment, String, Error, \
-     Number, Operator, Generic, Text, Token
+     Number, Operator, Generic, Token
 
 
 class NativeStyle(Style):

pygments/styles/trac.py

         Comment:                'italic #999988',
         Comment.Preproc:        'bold noitalic #999999',
 
+        Operator:               'bold',
+
         String:                 '#bb8844',
         String.Regex:           '#808000',
 

pygments/token.py

     parent = None
 
     def split(self):
-        buffer = []
+        buf = []
         node = self
         while node is not None:
-            buffer.append(node)
+            buf.append(node)
             node = node.parent
-        buffer.reverse()
-        return buffer
+        buf.reverse()
+        return buf
 
     def __getattr__(self, val):
         if not val or not val[0].isupper():
     Note that this method automatically searches the whole string (eg:
     the regular expression is wrapped in ``'^$'``)
     """
-    if '\n' in text:
-        first_line = text[:text.index('\n')].lower()
+    index = text.find('\n')
+    if index >= 0:
+        first_line = text[:index].lower()
     else:
         first_line = text.lower()
     if first_line.startswith('#!'):