PKD6r r pygments/style.py# -*- coding: utf-8 -*- """ pygments.style ~~~~~~~~~~~~~~ Basic style object. :copyright: 2006-2007 by Georg Brandl. :license: BSD, see LICENSE for more details. """ from pygments.token import Token, STANDARD_TYPES class StyleMeta(type): def __new__(mcs, name, bases, dct): obj = type.__new__(mcs, name, bases, dct) for token in STANDARD_TYPES: if token not in obj.styles: obj.styles[token] = '' def colorformat(text): if text[0:1] == '#': col = text[1:] if len(col) == 6: return col elif len(col) == 3: return col[0]+'0'+col[1]+'0'+col[2]+'0' elif text == '': return '' assert False, "wrong color format %r" % text _styles = obj._styles = {} for ttype in obj.styles: for token in ttype.split(): if token in _styles: continue ndef = _styles.get(token.parent, None) styledefs = obj.styles.get(token, '').split() if not ndef or token is None: ndef = ['', 0, 0, 0, '', ''] elif 'noinherit' in styledefs and token is not Token: ndef = _styles[Token][:] else: ndef = ndef[:] _styles[token] = ndef for styledef in obj.styles.get(token, '').split(): if styledef == 'noinherit': pass elif styledef == 'bold': ndef[1] = 1 elif styledef == 'nobold': ndef[1] = 0 elif styledef == 'italic': ndef[2] = 1 elif styledef == 'noitalic': ndef[2] = 0 elif styledef == 'underline': ndef[3] = 1 elif styledef == 'nounderline': ndef[3] = 0 elif styledef[:3] == 'bg:': ndef[4] = colorformat(styledef[3:]) elif styledef[:7] == 'border:': ndef[5] = colorformat(styledef[7:]) else: ndef[0] = colorformat(styledef) return obj def style_for_token(cls, token): t = cls._styles[token] return { 'color': t[0] or None, 'bold': bool(t[1]), 'italic': bool(t[2]), 'underline': bool(t[3]), 'bgcolor': t[4] or None, 'border': t[5] or None } def list_styles(cls): return list(cls) def __iter__(cls): for token in cls._styles: yield token, cls.style_for_token(token) def __len__(cls): return len(cls._styles) class Style(object): __metaclass__ = StyleMeta #: overall background color (``None`` means transparent) background_color = '#ffffff' #: Style definitions for individual token types. styles = {} PKD6i4}u  pygments/scanner.py# -*- coding: utf-8 -*- """ pygments.scanner ~~~~~~~~~~~~~~~~ This library implements a regex based scanner. Some languages like Pascal are easy to parse but have some keywords that depend on the context. Because of this it's impossible to lex that just by using a regular expression lexer like the `RegexLexer`. Have a look at the `DelphiLexer` to get an idea of how to use this scanner. :copyright: 2006-2007 by Armin Ronacher. :license: BSD, see LICENSE for more details. """ import re class EndOfText(RuntimeError): """ Raise if end of text is reached and the user tried to call a match function. """ class Scanner(object): """ Simple scanner All method patterns are regular expression strings (not compiled expressions!) """ def __init__(self, text, flags=0): """ :param text: The text which should be scanned :param flags: default regular expression flags """ self.data = text self.data_length = len(text) self.start_pos = 0 self.pos = 0 self.flags = flags self.last = None self.match = None self._re_cache = {} def eos(self): """`True` if the scanner reached the end of text.""" return self.pos >= self.data_length eos = property(eos, eos.__doc__) def check(self, pattern): """ Apply `pattern` on the current position and return the match object. (Doesn't touch pos). Use this for lookahead. """ if self.eos: raise EndOfText() if pattern not in self._re_cache: self._re_cache[pattern] = re.compile(pattern, self.flags) return self._re_cache[pattern].match(self.data, self.pos) def test(self, pattern): """Apply a pattern on the current position and check if it patches. Doesn't touch pos.""" return self.check(pattern) is not None def scan(self, pattern): """ Scan the text for the given pattern and update pos/match and related fields. The return value is a boolen that indicates if the pattern matched. The matched value is stored on the instance as ``match``, the last value is stored as ``last``. ``start_pos`` is the position of the pointer before the pattern was matched, ``pos`` is the end position. """ if self.eos: raise EndOfText() if pattern not in self._re_cache: self._re_cache[pattern] = re.compile(pattern, self.flags) self.last = self.match m = self._re_cache[pattern].match(self.data, self.pos) if m is None: return False self.start_pos = m.start() self.pos = m.end() self.match = m.group() return True def get_char(self): """Scan exactly one char.""" self.scan('.') def __repr__(self): return '<%s %d/%d>' % ( self.__class__.__name__, self.pos, self.data_length ) PKbN6 e[o)o)pygments/cmdline.pyc; FEc@sdZdkZdkZdklZdklZlZlZdk l Z l Z l Z dk lZlZlZlZdklZlZlZlZlZdklZlZdklZlZd Zd Zd Z d Z!d Z"dZ#dS(s pygments.cmdline ~~~~~~~~~~~~~~~~ Command line interface. :copyright: 2006-2007 by Georg Brandl. :license: BSD, see LICENSE for more details. N(sdedent(s __version__s __author__s highlight(s ClassNotFounds OptionErrorsdocstring_headline(sget_all_lexerssget_lexer_by_namesget_lexer_for_filenamesfind_lexer_class(sget_all_formatterssget_formatter_by_namesget_formatter_for_filenamesfind_formatter_classsTerminalFormatter(sget_all_filterssfind_filter_class(sget_all_stylessget_style_by_namesPUsage: %s [-l ] [-F [:] [-O ] [-o ] [] %s -S

%(title)s

s5 %(title)s

%(title)s

s sMtd.linenos { background-color: #f0f0f0; padding-right: 10px; } %(styledefs)s cBstZdZdZdgZddgZdZdZdZdd Z d Z d Z d Z d Z dZdZdZRS(ss Format tokens as HTML 4 ```` tags within a ``
`` tag, wrapped
    in a ``
`` tag. The ``
``'s CSS class can be set by the `cssclass` option. If the `linenos` option is given and true, the ``
`` is additionally
    wrapped inside a ```` which has one row and two cells: one
    containing the line numbers and one containing the code. Example:

    .. sourcecode:: html

        
1
            2
def foo(bar):
              pass
            
(whitespace added to improve clarity). Wrapping can be disabled using the `nowrap` option. With the `full` option, a complete HTML 4 document is output, including the style definitions inside a ``

%(title)s

''' DOC_HEADER_EXTERNALCSS = '''\ %(title)s

%(title)s

''' DOC_FOOTER = '''\ ''' CSSFILE_TEMPLATE = '''\ td.linenos { background-color: #f0f0f0; padding-right: 10px; } %(styledefs)s ''' class HtmlFormatter(Formatter): r""" Format tokens as HTML 4 ```` tags within a ``
`` tag, wrapped
    in a ``
`` tag. The ``
``'s CSS class can be set by the `cssclass` option. If the `linenos` option is given and true, the ``
`` is additionally
    wrapped inside a ```` which has one row and two cells: one
    containing the line numbers and one containing the code. Example:

    .. sourcecode:: html

        
1
            2
def foo(bar):
              pass
            
(whitespace added to improve clarity). Wrapping can be disabled using the `nowrap` option. With the `full` option, a complete HTML 4 document is output, including the style definitions inside a ``