Commits

Henning Schröder committed 2ed48df

pep8

Comments (0)

Files changed (11)

create_python_hl.py

 from __future__ import print_function
 import sys
 from keyword import kwlist as python_keywords
-python_builtins = [str(name) for name in dir(__builtins__) if not name.startswith('_') or name in ("__import__",)]
-
+python_builtins = [str(name)
+                   for name in dir(__builtins__) if not name.startswith('_') or name in ("__import__",)]
 
 
 python_syntax = {
-  "partitions": [
-      # name, start, end, is_multiline
-      ("comment", "#", "\n"),
-      ("string", "[bruBRU]?'''", "'''", True),
-      ("string", "[bruBRU]?'", "'"),
-      ("string", '[bruBRU]?"""', '"""', True),
-      ("string", '[bruBRU]?"', '"'),
-  ],
-  "scanner": {
-      # parition-name (None=default): tokens
-      None: [
-         # (name, token-pattern-regexp, prefix, suffix)
-         ("hexnumber", "(0x)([0-9a-fA-F])+?",),
-         ("number", "\d+(\.\d*)?",),
-         ("keyword", python_keywords, "(^|[\b\W])", "[\b\W]"),
-         ("builtin", python_builtins, "(^|[^\.\w])", "[\b\W]"),
-         ("ident", "[A-Za-z_][A-Za-z_0-9]*",)
-      ]
-  },
-  "formats": {
-     #name: value
-     "keyword": "%(syntax_keyword)s",
-     "builtin": "%(syntax_builtin)s",
-     "comment": "%(syntax_comment)s",
-     "string":  "%(syntax_string)s",
-     "hexnumber":  "%(syntax_number)s",
-     "number":  "%(syntax_number)s",
-  }
+    "partitions": [
+        # name, start, end, is_multiline
+        ("comment", "#", "\n"),
+        ("string", "[bruBRU]?'''", "'''", True),
+        ("string", "[bruBRU]?'", "'"),
+        ("string", '[bruBRU]?"""', '"""', True),
+        ("string", '[bruBRU]?"', '"'),
+    ],
+    "scanner": {
+        # parition-name (None=default): tokens
+        None: [
+            # (name, token-pattern-regexp, prefix, suffix)
+            ("hexnumber", "(0x)([0-9a-fA-F])+?",),
+            ("number", "\d+(\.\d*)?",),
+            ("keyword", python_keywords, "(^|[\b\W])", "[\b\W]"),
+            ("builtin", python_builtins, "(^|[^\.\w])", "[\b\W]"),
+            ("ident", "[A-Za-z_][A-Za-z_0-9]*",)
+        ]
+    },
+    "formats": {
+        # name: value
+        "keyword": "%(syntax_keyword)s",
+        "builtin": "%(syntax_builtin)s",
+        "comment": "%(syntax_comment)s",
+        "string":  "%(syntax_string)s",
+        "hexnumber":  "%(syntax_number)s",
+        "number":  "%(syntax_number)s",
+    }
 }
 
 
 import pprint
 print("#Python version", sys.version)
-print("syntax = ", pprint.pformat(python_syntax))
+print("syntax = ", pprint.pformat(python_syntax))
 #from highlighter.js import syntax
 
 scheme = {
-  "syntax_comment": dict(color="green", italic=True),
-  "syntax_string": "magenta",
-  "syntax_builtin": "red",
-  "syntax_keyword": ("darkred", True),
-  "syntax_number": "blue",
+    "syntax_comment": dict(color="green", italic=True),
+    "syntax_string": "magenta",
+    "syntax_builtin": "red",
+    "syntax_keyword": ("darkred", True),
+    "syntax_number": "blue",
 }
 
 
 class MainWindow(QMainWindow):
 
-
     def __init__(self):
         QMainWindow.__init__(self)
         self.resize(800, 600)
         self.edit = QPlainTextEdit(self)
         self.setCentralWidget(self.edit)
         self.edit.setPlainText(src)
-        self.edit.cursorPositionChanged.connect(self.on_cursor_position_changed)
+        self.edit.cursorPositionChanged.connect(
+            self.on_cursor_position_changed)
         font = QFont()
         font.setFamily("Courier")
         font.setPointSize(10)
         self.edit.setFont(font)
         parts_scanner, code_scanner, formats = load_syntax(syntax, scheme)
         self.hl = SyntaxHighlighter(self.edit.document(),
-            parts_scanner, code_scanner, formats, default_font=font)
-
+                                    parts_scanner, code_scanner, formats, default_font=font)
 
     def on_cursor_position_changed(self):
         tc = self.edit.textCursor()
         self.setWindowTitle("cf: %s (%s,%s)" % (name, row, col))
 
 
-
 if __name__ == "__main__":
     app = QApplication(sys.argv)
     win = MainWindow()
     win.show()
     sys.exit(app.exec_() or 0)
-
-
 # All configuration values have a default; values that are commented out
 # serve to show the default.
 
-import sys, os
+import sys
+import os
 
 # If extensions (or modules to document with autodoc) are in another directory,
 # add these directories to sys.path here. If the directory is relative to the
 # documentation root, use os.path.abspath to make it absolute, like shown here.
 #sys.path.insert(0, os.path.abspath('.'))
 
-# -- General configuration -----------------------------------------------------
+# -- General configuration -----------------------------------------------
 
 # If your documentation needs a minimal Sphinx version, state it here.
 #needs_sphinx = '1.0'
 #modindex_common_prefix = []
 
 
-# -- Options for HTML output ---------------------------------------------------
+# -- Options for HTML output ---------------------------------------------
 
 # The theme to use for HTML and HTML Help pages.  See the documentation for
 # a list of builtin themes.
 htmlhelp_basename = 'SyntaxHighlighterforPyQtdoc'
 
 
-# -- Options for LaTeX output --------------------------------------------------
+# -- Options for LaTeX output --------------------------------------------
 
 latex_elements = {
-# The paper size ('letterpaper' or 'a4paper').
-#'papersize': 'letterpaper',
+    # The paper size ('letterpaper' or 'a4paper').
+    #'papersize': 'letterpaper',
 
-# The font size ('10pt', '11pt' or '12pt').
-#'pointsize': '10pt',
+    # The font size ('10pt', '11pt' or '12pt').
+    #'pointsize': '10pt',
 
-# Additional stuff for the LaTeX preamble.
-#'preamble': '',
+    # Additional stuff for the LaTeX preamble.
+    #'preamble': '',
 }
 
 # Grouping the document tree into LaTeX files. List of tuples
 # (source start file, target name, title, author, documentclass [howto/manual]).
 latex_documents = [
-  ('index', 'SyntaxHighlighterforPyQt.tex', u'SyntaxHighlighter for PyQt Documentation',
-   u'Henning Schröder', 'manual'),
+    ('index', 'SyntaxHighlighterforPyQt.tex', u'SyntaxHighlighter for PyQt Documentation',
+     u'Henning Schröder', 'manual'),
 ]
 
 # The name of an image file (relative to this directory) to place at the top of
 #latex_domain_indices = True
 
 
-# -- Options for manual page output --------------------------------------------
+# -- Options for manual page output --------------------------------------
 
 # One entry per manual page. List of tuples
 # (source start file, name, description, authors, manual section).
 #man_show_urls = False
 
 
-# -- Options for Texinfo output ------------------------------------------------
+# -- Options for Texinfo output ------------------------------------------
 
 # Grouping the document tree into Texinfo files. List of tuples
 # (source start file, target name, title, author,
 #  dir menu entry, description, category)
 texinfo_documents = [
-  ('index', 'SyntaxHighlighterforPyQt', u'SyntaxHighlighter for PyQt Documentation',
-   u'Henning Schröder', 'SyntaxHighlighterforPyQt', 'One line description of project.',
-   'Miscellaneous'),
+    ('index', 'SyntaxHighlighterforPyQt', u'SyntaxHighlighter for PyQt Documentation',
+     u'Henning Schröder', 'SyntaxHighlighterforPyQt', 'One line description of project.',
+     'Miscellaneous'),
 ]
 
 # Documents to append as an appendix to all manuals.

highlighter/__init__.py

 
     __slots__ = ("name", "tcf")
 
-
     def __init__(self, name, color=None, bold=None, italic=None, base_format=None):
         self.name = name
         tcf = TextCharFormat()
 
     __slots__ = ("name", "start", "end", "is_multiline", "search_end")
 
-
     def __init__(self, name, start, end, is_multiline=False):
         self.name = name
         self.start = start
         self.end = end
         self.is_multiline = is_multiline
         try:
-            self.search_end = re.compile(end, re.M|re.S).search
+            self.search_end = re.compile(end, re.M | re.S).search
         except Exception, exc:
             raise HighlighterError("%s: %s %s" % (exc, name, end))
 
 
-
 class PartitionScanner(object):
     # The idea to partition the source into different contexts comes from Eclipse.
     # http://wiki.eclipse.org/FAQ_What_is_a_document_partition%3F
 
-
     def __init__(self, partitions):
         start_groups = []
         self.partitions = []
             elif isinstance(p, dict):
                 p = Partition(**p)
             else:
-                assert isinstance(p, Partition), "Partition expected, got %r" % p
+                assert isinstance(
+                    p, Partition), "Partition expected, got %r" % p
             self.partitions.append(p)
             start_groups.append("(?P<g%s_%s>%s)" % (i, p.name, p.start))
         start_pat = "|".join(start_groups)
         try:
-            self.search_start = re.compile(start_pat, re.M|re.S).search
+            self.search_start = re.compile(start_pat, re.M | re.S).search
         except Exception, exc:
             raise HighlighterError("%s: %s" % (exc, start_pat))
 
-        
     def scan(self, current_state, text):
         last_pos = 0
         length = len(text)
         yield length, length, None, current_state, False
 
 
-
-
 class Token(object):
     __slots__ = ("name", "pattern", "prefix", "suffix")
 
-
     def __init__(self, name, pattern, prefix="", suffix=""):
         self.name = name
         if isinstance(pattern, list):
         self.suffix = suffix
 
 
-
 class Scanner(object):
     __slots__ = ("tokens", "search")
 
                 t = Token(**t)
             else:
                 assert isinstance(t, Token), "Token expected, got %r" % t
-            gdef = "?P<%s>"  % t.name
+            gdef = "?P<%s>" % t.name
             if gdef in t.pattern:
                 p = t.pattern
             else:
         pat = "|".join(groups)
         self.search = re.compile(pat).search
 
-
     def scan(self, s):
         search = self.search
         #length = len(s)
                 break
 
 
-
 class SyntaxHighlighter(QSyntaxHighlighter):
 
-
     def __init__(self, parent, partition_scanner, scanner, formats, default_font=None):
         """
         :param parent: QDocument or QTextEdit/QPlainTextEdit instance
         if isinstance(partition_scanner, (list, tuple)):
             partition_scanner = PartitionScanner(partition_scanner)
         else:
-            assert isinstance(partition_scanner, PartitionScanner), "PartitionScanner expected, got %r" % partition_scanner
+            assert isinstance(
+                partition_scanner, PartitionScanner), "PartitionScanner expected, got %r" % partition_scanner
         self.partition_scanner = partition_scanner
 
         self.scanner = scanner
                 inside_scanner = Scanner(inside_scanner)
                 self.scanner[inside_part] = inside_scanner
             else:
-                assert isinstance(inside_scanner, Scanner), "Scanner expected, got %r" % f
-
+                assert isinstance(
+                    inside_scanner, Scanner), "Scanner expected, got %r" % f
 
         self.formats = {}
         for f in formats:
             if isinstance(f, tuple):
                 fname, f = f
             else:
-                assert isinstance(f, (Format,dict)), "Format expected, got %r" % f
+                assert isinstance(
+                    f, (Format, dict)), "Format expected, got %r" % f
             if isinstance(f, basestring):
                 f = (f,)  # only color specified
             if isinstance(f, (tuple, list)):
             f.tcf.setFontFamily(parent.defaultFont().family())
             self.formats[f.name] = f.tcf
 
-
         # reduce name look-ups for better speed
         scan_inside = {}
         for inside_part, inside_scanner in self.scanner.items():
         self.scan_partitions = partition_scanner.scan
         self.get_format = self.formats.get
 
-
     def highlightBlock(self, text):
         "automatically called by Qt"
         text = unicode(text) + "\n"
                     for token, token_pos, token_end in scan(text[start:end]):
                         f = get_format(token)
                         if f:
-                            set_format(start + token_pos, token_end - token_pos, f)
+                            set_format(
+                                start + token_pos, token_end - token_pos, f)
 
         self.setCurrentBlockState(new_state)
 
 
-
-
-
 def load_syntax(syntax, context=None):
     context = context or {}
 
 
 
 __all__ = [
-  "Format", "Partition", "PartitionScanner", "Token", "Scanner", "SynxtaxHighlighter", "load_syntax"
+    "Format", "Partition", "PartitionScanner", "Token", "Scanner", "SynxtaxHighlighter", "load_syntax"
 ]

highlighter/customhighlighter.py

             elif isinstance(parent, QTextDocument):
                 self.add_to_document(parent)
 
-
     def add_to_document(self, doc):
-        self.connect(doc, SIGNAL("contentsChange(int, int, int)"), self.highlight)
-        QTimer.singleShot(0, lambda:self._rehighlight_all(doc))
-        
+        self.connect(
+            doc, SIGNAL("contentsChange(int, int, int)"), self.highlight)
+        QTimer.singleShot(0, lambda: self._rehighlight_all(doc))
 
     def _rehighlight_all(self, doc):
         block = doc.begin()
         while block and block.isValid():
             self._highlight_block(block)
             block = block.next()
-        
+
     # slot for QTextDocument::contentsChange(int,int,int) signal
     def highlight(self, position, removed, added):
         doc = self.sender()
-    
+
         block = doc.findBlock(position)
         if not block.isValid():
             return
-    
+
         endBlock = QTextBlock()
         if added > removed:
             endBlock = doc.findBlock(position + added)
         else:
             endBlock = block
-    
+
         # XXX: why highlight whole block only if some chars changed?
         while block.isValid() and not (endBlock < block):
             self._highlight_block(block)
             block = block.next()
 
-            
     def setFormat(self, pos, length, format, _FormatRange=QTextLayout.FormatRange):
         trange = _FormatRange()
         trange.start = pos
         trange.length = length
         trange.format = format
         self._add_override(trange)
-        
 
     def _highlight_block(self, block):
         del self._overrides[:]
 
         while block and block.isValid():
             state = block.previous().userState() or -1
-            self.previousBlockState = lambda : state
+            self.previousBlockState = lambda: state
             self.setCurrentBlockState = block.setUserState
-        
+
             layout = block.layout()
             text = block.text()
-    
+
             self.highlightBlock(text)
-            
+
             length += block.length()
             if (block.userState() == state):
-                break # state did not change
-             
+                break  # state did not change
+
             block = block.next()
-        
+
         layout.setAdditionalFormats(self._overrides)
         block.document().markContentsDirty(pos, length)
-    
-            
+
     def highlightBlock(self, text):
         pass

highlighter/js.py

 keywords = [
- 'break',
- 'for',
- 'throw',
- 'case',
- 'function',
- 'try',
- 'catch',
- 'if',
- 'typeof',
- 'continue',
- 'in',
- 'var',
- 'default',
- 'instanceof',
- 'void',
- 'delete',
- 'new',
- 'undefined',
- 'do',
- 'return',
- 'while',
- 'else',
- 'switch',
- 'with',
- 'finally',
- 'this',
- 'NaN',
- 'Infinity',
- 'undefined',
- 'print',
- 'parseInt',
- 'parseFloat',
- 'isNaN',
- 'isFinite',
- 'decodeURI',
- 'decodeURIComponent',
- 'encodeURI',
- 'encodeURIComponent',
- 'escape',
- 'unescape',
- 'version',
- 'gc',
- 'Object',
- 'Function',
- 'Number',
- 'Boolean',
- 'String',
- 'Date',
- 'Array',
- 'RegExp',
- 'Error',
- 'EvalError',
- 'RangeError',
- 'ReferenceError',
- 'SyntaxError',
- 'TypeError',
- 'URIError',
- 'eval',
- 'Math',
- 'Enumeration',
- 'Variant',
- 'QObject',
- 'QMetaObject']
+    'break',
+    'for',
+    'throw',
+    'case',
+    'function',
+    'try',
+    'catch',
+    'if',
+    'typeof',
+    'continue',
+    'in',
+    'var',
+    'default',
+    'instanceof',
+    'void',
+    'delete',
+    'new',
+    'undefined',
+    'do',
+    'return',
+    'while',
+    'else',
+    'switch',
+    'with',
+    'finally',
+    'this',
+    'NaN',
+    'Infinity',
+    'undefined',
+    'print',
+    'parseInt',
+    'parseFloat',
+    'isNaN',
+    'isFinite',
+    'decodeURI',
+    'decodeURIComponent',
+    'encodeURI',
+    'encodeURIComponent',
+    'escape',
+    'unescape',
+    'version',
+    'gc',
+    'Object',
+    'Function',
+    'Number',
+    'Boolean',
+    'String',
+    'Date',
+    'Array',
+    'RegExp',
+    'Error',
+    'EvalError',
+    'RangeError',
+    'ReferenceError',
+    'SyntaxError',
+    'TypeError',
+    'URIError',
+    'eval',
+    'Math',
+    'Enumeration',
+    'Variant',
+    'QObject',
+    'QMetaObject']
 
 
-syntax =  {'formats': {'builtin': '%(syntax_builtin)s',
-             'comment': '%(syntax_comment)s',
-             'hexnumber': '%(syntax_number)s',
-             'keyword': '%(syntax_keyword)s',
-             'number': '%(syntax_number)s',
-             'string': '%(syntax_string)s'},
- 'partitions': [('comment', '//', '\n'),
-                ('comment', "/\*", "\*/", True),
-               ],
- 'scanner': {None: [('hexnumber', '(0x)([0-9a-fA-F])+?'),
-                    ('number', '\\d+(\\.\\d*)?'),
-                    ('keyword', keywords, '(^|[^\\.\\w])', '[\x08\\W]'),
-					('ident', r'[A-Za-z_][A-Za-z_0-9]*')]}}
-			
+syntax = {'formats': {'builtin': '%(syntax_builtin)s',
+                      'comment': '%(syntax_comment)s',
+                      'hexnumber': '%(syntax_number)s',
+                      'keyword': '%(syntax_keyword)s',
+                      'number': '%(syntax_number)s',
+                      'string': '%(syntax_string)s'},
+          'partitions': [('comment', '//', '\n'),
+                         ('comment', "/\*", "\*/", True),
+                         ],
+          'scanner': {None: [('hexnumber', '(0x)([0-9a-fA-F])+?'),
+                             ('number', '\\d+(\\.\\d*)?'),
+                             ('keyword', keywords,
+                              '(^|[^\\.\\w])', '[\x08\\W]'),
+                             ('ident', r'[A-Za-z_][A-Za-z_0-9]*')]}}
+
 
 if __name__ == "__main__":
-	import pprint
-	pprint.pprint(syntax)
+    import pprint
+    pprint.pprint(syntax)

highlighter/python27.py

-syntax =  {'formats': {'builtin': '%(syntax_builtin)s',
-             'comment': '%(syntax_comment)s',
-             'hexnumber': '%(syntax_number)s',
-             'keyword': '%(syntax_keyword)s',
-             'number': '%(syntax_number)s',
-             'string': '%(syntax_string)s'},
- 'partitions': [('comment', '#', '\n'),
-                ('string', "[bruBRU]?'''", "'''", True),
-                ('string', "[bruBRU]?'", "'"),
-                ('string', '[bruBRU]?"""', '"""', True),
-                ('string', '[bruBRU]?"', '"')],
- 'scanner': {None: [('hexnumber', '(0x)([0-9a-fA-F])+?'),
-                    ('number', '\\d+(\\.\\d*)?'),
-                    ('keyword',
-                     ['and',
-                      'as',
-                      'assert',
-                      'break',
-                      'class',
-                      'continue',
-                      'def',
-                      'del',
-                      'elif',
-                      'else',
-                      'except',
-                      'exec',
-                      'finally',
-                      'for',
-                      'from',
-                      'global',
-                      'if',
-                      'import',
-                      'in',
-                      'is',
-                      'lambda',
-                      'not',
-                      'or',
-                      'pass',
-                      'print',
-                      'raise',
-                      'return',
-                      'try',
-                      'while',
-                      'with',
-                      'yield'],
-                     '(^|[\x08\\W])',
-                     '[\x08\\W]'),
-                    ('builtin',
-                     ['ArithmeticError',
-                      'AssertionError',
-                      'AttributeError',
-                      'BaseException',
-                      'BufferError',
-                      'BytesWarning',
-                      'DeprecationWarning',
-                      'EOFError',
-                      'Ellipsis',
-                      'EnvironmentError',
-                      'Exception',
-                      'False',
-                      'FloatingPointError',
-                      'FutureWarning',
-                      'GeneratorExit',
-                      'IOError',
-                      'ImportError',
-                      'ImportWarning',
-                      'IndentationError',
-                      'IndexError',
-                      'KeyError',
-                      'KeyboardInterrupt',
-                      'LookupError',
-                      'MemoryError',
-                      'NameError',
-                      'None',
-                      'NotImplemented',
-                      'NotImplementedError',
-                      'OSError',
-                      'OverflowError',
-                      'PendingDeprecationWarning',
-                      'ReferenceError',
-                      'RuntimeError',
-                      'RuntimeWarning',
-                      'StandardError',
-                      'StopIteration',
-                      'SyntaxError',
-                      'SyntaxWarning',
-                      'SystemError',
-                      'SystemExit',
-                      'TabError',
-                      'True',
-                      'TypeError',
-                      'UnboundLocalError',
-                      'UnicodeDecodeError',
-                      'UnicodeEncodeError',
-                      'UnicodeError',
-                      'UnicodeTranslateError',
-                      'UnicodeWarning',
-                      'UserWarning',
-                      'ValueError',
-                      'Warning',
-                      'ZeroDivisionError',
-                      '__import__',
-                      'abs',
-                      'all',
-                      'any',
-                      'apply',
-                      'basestring',
-                      'bin',
-                      'bool',
-                      'buffer',
-                      'bytearray',
-                      'bytes',
-                      'callable',
-                      'chr',
-                      'classmethod',
-                      'cmp',
-                      'coerce',
-                      'compile',
-                      'complex',
-                      'copyright',
-                      'credits',
-                      'delattr',
-                      'dict',
-                      'dir',
-                      'divmod',
-                      'enumerate',
-                      'eval',
-                      'execfile',
-                      'exit',
-                      'file',
-                      'filter',
-                      'float',
-                      'format',
-                      'frozenset',
-                      'getattr',
-                      'globals',
-                      'hasattr',
-                      'hash',
-                      'help',
-                      'hex',
-                      'id',
-                      'input',
-                      'int',
-                      'intern',
-                      'isinstance',
-                      'issubclass',
-                      'iter',
-                      'len',
-                      'license',
-                      'list',
-                      'locals',
-                      'long',
-                      'map',
-                      'max',
-                      'memoryview',
-                      'min',
-                      'next',
-                      'object',
-                      'oct',
-                      'open',
-                      'ord',
-                      'pow',
-                      'print',
-                      'property',
-                      'quit',
-                      'range',
-                      'raw_input',
-                      'reduce',
-                      'reload',
-                      'repr',
-                      'reversed',
-                      'round',
-                      'set',
-                      'setattr',
-                      'slice',
-                      'sorted',
-                      'staticmethod',
-                      'str',
-                      'sum',
-                      'super',
-                      'tuple',
-                      'type',
-                      'unichr',
-                      'unicode',
-                      'vars',
-                      'xrange',
-                      'zip'],
-                     '(^|[^\\.\\w])',
-                     '[\x08\\W]'),
-                    ('ident', '[A-Za-z_][A-Za-z_0-9]*')]}}
+syntax = {'formats': {'builtin': '%(syntax_builtin)s',
+          'comment': '%(syntax_comment)s',
+                      'hexnumber': '%(syntax_number)s',
+                      'keyword': '%(syntax_keyword)s',
+                      'number': '%(syntax_number)s',
+                      'string': '%(syntax_string)s'},
+          'partitions': [('comment', '#', '\n'),
+                         ('string', "[bruBRU]?'''", "'''", True),
+                         ('string', "[bruBRU]?'", "'"),
+                         ('string', '[bruBRU]?"""', '"""', True),
+                         ('string', '[bruBRU]?"', '"')],
+          'scanner': {None: [('hexnumber', '(0x)([0-9a-fA-F])+?'),
+                             ('number', '\\d+(\\.\\d*)?'),
+                             ('keyword',
+                              ['and',
+                               'as',
+                               'assert',
+                               'break',
+                               'class',
+                               'continue',
+                               'def',
+                               'del',
+                               'elif',
+                               'else',
+                               'except',
+                               'exec',
+                               'finally',
+                               'for',
+                               'from',
+                               'global',
+                               'if',
+                               'import',
+                               'in',
+                               'is',
+                               'lambda',
+                               'not',
+                               'or',
+                               'pass',
+                               'print',
+                               'raise',
+                               'return',
+                               'try',
+                               'while',
+                               'with',
+                               'yield'],
+                              '(^|[\x08\\W])',
+                              '[\x08\\W]'),
+                             ('builtin',
+                              ['ArithmeticError',
+                               'AssertionError',
+                               'AttributeError',
+                               'BaseException',
+                               'BufferError',
+                               'BytesWarning',
+                               'DeprecationWarning',
+                               'EOFError',
+                               'Ellipsis',
+                               'EnvironmentError',
+                               'Exception',
+                               'False',
+                               'FloatingPointError',
+                               'FutureWarning',
+                               'GeneratorExit',
+                               'IOError',
+                               'ImportError',
+                               'ImportWarning',
+                               'IndentationError',
+                               'IndexError',
+                               'KeyError',
+                               'KeyboardInterrupt',
+                               'LookupError',
+                               'MemoryError',
+                               'NameError',
+                               'None',
+                               'NotImplemented',
+                               'NotImplementedError',
+                               'OSError',
+                               'OverflowError',
+                               'PendingDeprecationWarning',
+                               'ReferenceError',
+                               'RuntimeError',
+                               'RuntimeWarning',
+                               'StandardError',
+                               'StopIteration',
+                               'SyntaxError',
+                               'SyntaxWarning',
+                               'SystemError',
+                               'SystemExit',
+                               'TabError',
+                               'True',
+                               'TypeError',
+                               'UnboundLocalError',
+                               'UnicodeDecodeError',
+                               'UnicodeEncodeError',
+                               'UnicodeError',
+                               'UnicodeTranslateError',
+                               'UnicodeWarning',
+                               'UserWarning',
+                               'ValueError',
+                               'Warning',
+                               'ZeroDivisionError',
+                               '__import__',
+                               'abs',
+                               'all',
+                               'any',
+                               'apply',
+                               'basestring',
+                               'bin',
+                               'bool',
+                               'buffer',
+                               'bytearray',
+                               'bytes',
+                               'callable',
+                               'chr',
+                               'classmethod',
+                               'cmp',
+                               'coerce',
+                               'compile',
+                               'complex',
+                               'copyright',
+                               'credits',
+                               'delattr',
+                               'dict',
+                               'dir',
+                               'divmod',
+                               'enumerate',
+                               'eval',
+                               'execfile',
+                               'exit',
+                               'file',
+                               'filter',
+                               'float',
+                               'format',
+                               'frozenset',
+                               'getattr',
+                               'globals',
+                               'hasattr',
+                               'hash',
+                               'help',
+                               'hex',
+                               'id',
+                               'input',
+                               'int',
+                               'intern',
+                               'isinstance',
+                               'issubclass',
+                               'iter',
+                               'len',
+                               'license',
+                               'list',
+                               'locals',
+                               'long',
+                               'map',
+                               'max',
+                               'memoryview',
+                               'min',
+                               'next',
+                               'object',
+                               'oct',
+                               'open',
+                               'ord',
+                               'pow',
+                               'print',
+                               'property',
+                               'quit',
+                               'range',
+                               'raw_input',
+                               'reduce',
+                               'reload',
+                               'repr',
+                               'reversed',
+                               'round',
+                               'set',
+                               'setattr',
+                               'slice',
+                               'sorted',
+                               'staticmethod',
+                               'str',
+                               'sum',
+                               'super',
+                               'tuple',
+                               'type',
+                               'unichr',
+                               'unicode',
+                               'vars',
+                               'xrange',
+                               'zip'],
+                              '(^|[^\\.\\w])',
+                              '[\x08\\W]'),
+                             ('ident', '[A-Za-z_][A-Za-z_0-9]*')]}}

highlighter/python32.py

-syntax =  {'formats': {'builtin': '%(syntax_builtin)s',
-             'comment': '%(syntax_comment)s',
-             'keyword': '%(syntax_keyword)s',
-             'number': '%(syntax_number)s',
-             'string': '%(syntax_string)s'},
- 'partitions': [('comment', '#', '\n'),
-                ('string', "'''", "'''", True),
-                ('string', "'", "'"),
-                ('string', '"""', '"""', True),
-                ('string', '"', '"')],
- 'scanner': {None: [('number', '(0x)?\\d+(\\.\\d*)?'),
-                    ('keyword',
-                     ['False',
-                      'None',
-                      'True',
-                      'and',
-                      'as',
-                      'assert',
-                      'break',
-                      'class',
-                      'continue',
-                      'def',
-                      'del',
-                      'elif',
-                      'else',
-                      'except',
-                      'finally',
-                      'for',
-                      'from',
-                      'global',
-                      'if',
-                      'import',
-                      'in',
-                      'is',
-                      'lambda',
-                      'nonlocal',
-                      'not',
-                      'or',
-                      'pass',
-                      'raise',
-                      'return',
-                      'try',
-                      'while',
-                      'with',
-                      'yield'],
-                     '(^|[\x08\\W])',
-                     '[\x08\\W]'),
-                    ('builtin',
-                     ['ArithmeticError',
-                      'AssertionError',
-                      'AttributeError',
-                      'BaseException',
-                      'BufferError',
-                      'BytesWarning',
-                      'DeprecationWarning',
-                      'EOFError',
-                      'Ellipsis',
-                      'EnvironmentError',
-                      'Exception',
-                      'False',
-                      'FloatingPointError',
-                      'FutureWarning',
-                      'GeneratorExit',
-                      'IOError',
-                      'ImportError',
-                      'ImportWarning',
-                      'IndentationError',
-                      'IndexError',
-                      'KeyError',
-                      'KeyboardInterrupt',
-                      'LookupError',
-                      'MemoryError',
-                      'NameError',
-                      'None',
-                      'NotImplemented',
-                      'NotImplementedError',
-                      'OSError',
-                      'OverflowError',
-                      'PendingDeprecationWarning',
-                      'ReferenceError',
-                      'ResourceWarning',
-                      'RuntimeError',
-                      'RuntimeWarning',
-                      'StopIteration',
-                      'SyntaxError',
-                      'SyntaxWarning',
-                      'SystemError',
-                      'SystemExit',
-                      'TabError',
-                      'True',
-                      'TypeError',
-                      'UnboundLocalError',
-                      'UnicodeDecodeError',
-                      'UnicodeEncodeError',
-                      'UnicodeError',
-                      'UnicodeTranslateError',
-                      'UnicodeWarning',
-                      'UserWarning',
-                      'ValueError',
-                      'Warning',
-                      'ZeroDivisionError',
-                      '__import__',
-                      'abs',
-                      'all',
-                      'any',
-                      'ascii',
-                      'bin',
-                      'bool',
-                      'bytearray',
-                      'bytes',
-                      'callable',
-                      'chr',
-                      'classmethod',
-                      'compile',
-                      'complex',
-                      'copyright',
-                      'credits',
-                      'delattr',
-                      'dict',
-                      'dir',
-                      'divmod',
-                      'enumerate',
-                      'eval',
-                      'exec',
-                      'exit',
-                      'filter',
-                      'float',
-                      'format',
-                      'frozenset',
-                      'getattr',
-                      'globals',
-                      'hasattr',
-                      'hash',
-                      'help',
-                      'hex',
-                      'id',
-                      'input',
-                      'int',
-                      'isinstance',
-                      'issubclass',
-                      'iter',
-                      'len',
-                      'license',
-                      'list',
-                      'locals',
-                      'map',
-                      'max',
-                      'memoryview',
-                      'min',
-                      'next',
-                      'object',
-                      'oct',
-                      'open',
-                      'ord',
-                      'pow',
-                      'print',
-                      'property',
-                      'quit',
-                      'range',
-                      'repr',
-                      'reversed',
-                      'round',
-                      'set',
-                      'setattr',
-                      'slice',
-                      'sorted',
-                      'staticmethod',
-                      'str',
-                      'sum',
-                      'super',
-                      'tuple',
-                      'type',
-                      'vars',
-                      'zip'],
-                     '([^\\.]|^)',
-                     '[\x08\\W]'),
-                    ('ident', '[A-Za-z_][A-Za-z_0-9]*')]}}
+syntax = {'formats': {'builtin': '%(syntax_builtin)s',
+          'comment': '%(syntax_comment)s',
+                      'keyword': '%(syntax_keyword)s',
+                      'number': '%(syntax_number)s',
+                      'string': '%(syntax_string)s'},
+          'partitions': [('comment', '#', '\n'),
+                         ('string', "'''", "'''", True),
+                         ('string', "'", "'"),
+                         ('string', '"""', '"""', True),
+                         ('string', '"', '"')],
+          'scanner': {None: [('number', '(0x)?\\d+(\\.\\d*)?'),
+                             ('keyword',
+                              ['False',
+                               'None',
+                               'True',
+                               'and',
+                               'as',
+                               'assert',
+                               'break',
+                               'class',
+                               'continue',
+                               'def',
+                               'del',
+                               'elif',
+                               'else',
+                               'except',
+                               'finally',
+                               'for',
+                               'from',
+                               'global',
+                               'if',
+                               'import',
+                               'in',
+                               'is',
+                               'lambda',
+                               'nonlocal',
+                               'not',
+                               'or',
+                               'pass',
+                               'raise',
+                               'return',
+                               'try',
+                               'while',
+                               'with',
+                               'yield'],
+                              '(^|[\x08\\W])',
+                              '[\x08\\W]'),
+                             ('builtin',
+                              ['ArithmeticError',
+                               'AssertionError',
+                               'AttributeError',
+                               'BaseException',
+                               'BufferError',
+                               'BytesWarning',
+                               'DeprecationWarning',
+                               'EOFError',
+                               'Ellipsis',
+                               'EnvironmentError',
+                               'Exception',
+                               'False',
+                               'FloatingPointError',
+                               'FutureWarning',
+                               'GeneratorExit',
+                               'IOError',
+                               'ImportError',
+                               'ImportWarning',
+                               'IndentationError',
+                               'IndexError',
+                               'KeyError',
+                               'KeyboardInterrupt',
+                               'LookupError',
+                               'MemoryError',
+                               'NameError',
+                               'None',
+                               'NotImplemented',
+                               'NotImplementedError',
+                               'OSError',
+                               'OverflowError',
+                               'PendingDeprecationWarning',
+                               'ReferenceError',
+                               'ResourceWarning',
+                               'RuntimeError',
+                               'RuntimeWarning',
+                               'StopIteration',
+                               'SyntaxError',
+                               'SyntaxWarning',
+                               'SystemError',
+                               'SystemExit',
+                               'TabError',
+                               'True',
+                               'TypeError',
+                               'UnboundLocalError',
+                               'UnicodeDecodeError',
+                               'UnicodeEncodeError',
+                               'UnicodeError',
+                               'UnicodeTranslateError',
+                               'UnicodeWarning',
+                               'UserWarning',
+                               'ValueError',
+                               'Warning',
+                               'ZeroDivisionError',
+                               '__import__',
+                               'abs',
+                               'all',
+                               'any',
+                               'ascii',
+                               'bin',
+                               'bool',
+                               'bytearray',
+                               'bytes',
+                               'callable',
+                               'chr',
+                               'classmethod',
+                               'compile',
+                               'complex',
+                               'copyright',
+                               'credits',
+                               'delattr',
+                               'dict',
+                               'dir',
+                               'divmod',
+                               'enumerate',
+                               'eval',
+                               'exec',
+                               'exit',
+                               'filter',
+                               'float',
+                               'format',
+                               'frozenset',
+                               'getattr',
+                               'globals',
+                               'hasattr',
+                               'hash',
+                               'help',
+                               'hex',
+                               'id',
+                               'input',
+                               'int',
+                               'isinstance',
+                               'issubclass',
+                               'iter',
+                               'len',
+                               'license',
+                               'list',
+                               'locals',
+                               'map',
+                               'max',
+                               'memoryview',
+                               'min',
+                               'next',
+                               'object',
+                               'oct',
+                               'open',
+                               'ord',
+                               'pow',
+                               'print',
+                               'property',
+                               'quit',
+                               'range',
+                               'repr',
+                               'reversed',
+                               'round',
+                               'set',
+                               'setattr',
+                               'slice',
+                               'sorted',
+                               'staticmethod',
+                               'str',
+                               'sum',
+                               'super',
+                               'tuple',
+                               'type',
+                               'vars',
+                               'zip'],
+                              '([^\\.]|^)',
+                              '[\x08\\W]'),
+                             ('ident', '[A-Za-z_][A-Za-z_0-9]*')]}}
 from highlighter import Format, Partition, PartitionScanner, Token, Scanner, SyntaxHighlighter
 
 comment_fmt = Format("comment", color="#a0a0a0", italic=True)
-tag_fmt     = Format("tag", color="blue", bold=True)
-attr_fmt    = Format("attr", color="lightblue")
-value_fmt   = Format("value", color="lightblue", italic=True)
-text_fmt    = Format("text", color="black")
+tag_fmt = Format("tag", color="blue", bold=True)
+attr_fmt = Format("attr", color="lightblue")
+value_fmt = Format("value", color="lightblue", italic=True)
+text_fmt = Format("text", color="black")
 
 comment_part = Partition("comment", "<!--", "-->", is_multiline=True)
-tag_part     = Partition("tag", "<", ">", is_multiline=True)
+tag_part = Partition("tag", "<", ">", is_multiline=True)
 
 ps = PartitionScanner([comment_part, tag_part])
 
-attr_token    = Token("attr", "[A-Za-z_]\w*")
-equals_token  = Token("equals", "=")
-value_token   = Token("value", '"[^"]*"')
+attr_token = Token("attr", "[A-Za-z_]\w*")
+equals_token = Token("equals", "=")
+value_token = Token("value", '"[^"]*"')
 tag_scanner = Scanner([attr_token, equals_token, value_token])
 
 
     from PyQt4.QtGui import QApplication, QPlainTextEdit
     app = QApplication([])
     edit = QPlainTextEdit(None)
-    sh = SyntaxHighlighter(edit.document(), ps, {"tag":tag_scanner}, [
-          comment_fmt, tag_fmt, text_fmt, attr_fmt, value_fmt], default_font=edit.font())
+    sh = SyntaxHighlighter(edit.document(), ps, {"tag": tag_scanner}, [
+                           comment_fmt, tag_fmt, text_fmt, attr_fmt, value_fmt], default_font=edit.font())
     edit.resize(800, 600)
     edit.setPlainText('<!-- comment--> text <tag attr="value">')
     edit.show()
-    app.exec_()
+    app.exec_()
 from highlighter import PartitionScanner, Token, Scanner, SyntaxHighlighter
 
 formats = [
-  ("comment", ("#a0a0a0", False, True)),
-  ("tag", ("blue", True)),
-  ("attr", ("lightblue")),
-  ("value", dict(color="lightblue", italic=True)),
-  ("text", ("black",))
+    ("comment", ("#a0a0a0", False, True)),
+    ("tag", ("blue", True)),
+    ("attr", ("lightblue")),
+    ("value", dict(color="lightblue", italic=True)),
+    ("text", ("black",))
 ]
 
 parts = [
-  ("comment", "<!--", "-->", True),
-  ("tag", "<", ">", True)
+    ("comment", "<!--", "-->", True),
+    ("tag", "<", ">", True)
 ]
 
 
 tag_scanner = [
-  ("attr", "[A-Za-z_]\w*"),
-  ("equals", "="),
-  ("value", '"[^"]*"')
+    ("attr", "[A-Za-z_]\w*"),
+    ("equals", "="),
+    ("value", '"[^"]*"')
 ]
 
 
-
 if __name__ == "__main__":
-	from PyQt4.QtGui import QApplication, QPlainTextEdit
-	app = QApplication([])
-	edit = QPlainTextEdit(None)
-	sh = SyntaxHighlighter(edit.document(), parts, {"tag":tag_scanner}, formats)
-	edit.resize(800, 600)
-	edit.setPlainText('<!-- comment--> text <tag attr="value">')
-	edit.show()
-	app.exec_()
+    from PyQt4.QtGui import QApplication, QPlainTextEdit
+    app = QApplication([])
+    edit = QPlainTextEdit(None)
+    sh = SyntaxHighlighter(
+        edit.document(), parts, {"tag": tag_scanner}, formats)
+    edit.resize(800, 600)
+    edit.setPlainText('<!-- comment--> text <tag attr="value">')
+    edit.show()
+    app.exec_()
 from setuptools import setup, find_packages
 
 if __name__ == "__main__":
-	setup(
-	name = "syntaxhighlighter",
-	version = "0.1",
-	description="",
-	author="Henning Schroeder",
-	author_email="henning.schroeder@gmail.com",
-	url="https://bitbucket.org/henning/syntaxhighlighter",
-	zip_safe=True,
-	license="GPL2",
-	keywords="pyqt pyqt4 syntax highlighter qsyntaxhighlighter widget",
-	packages = find_packages(),
-	)
+    setup(
+        name="syntaxhighlighter",
+        version="0.1",
+        description="",
+        author="Henning Schroeder",
+        author_email="henning.schroeder@gmail.com",
+        url="https://bitbucket.org/henning/syntaxhighlighter",
+        zip_safe=True,
+        license="GPL2",
+        keywords="pyqt pyqt4 syntax highlighter qsyntaxhighlighter widget",
+        packages=find_packages(),
+    )