Example #1
0
 def __init__(self, **options):
     Filter.__init__(self, **options)
     tags = get_list_opt(options, 'codetags',
                         ['XXX', 'TODO', 'BUG', 'NOTE'])
     self.tag_re = re.compile(r'\b(%s)\b' % '|'.join([
         re.escape(tag) for tag in tags if tag
     ]))
Example #2
0
    def __init__(self, **options):
        Formatter.__init__(self, **options)
        self.nowrap = get_bool_opt(options, 'nowrap', False)
        self.noclasses = get_bool_opt(options, 'noclasses', False)
        self.classprefix = options.get('classprefix', '')
        self.cssclass = options.get('cssclass', 'highlight')
        self.cssstyles = options.get('cssstyles', '')
        self.prestyles = options.get('prestyles', '')
        self.cssfile = options.get('cssfile', '')
        linenos = options.get('linenos', False)
        if linenos == 'inline':
            self.linenos = 2
        elif linenos:
            # compatibility with <= 0.7
            self.linenos = 1
        else:
            self.linenos = 0
        self.linenostart = abs(get_int_opt(options, 'linenostart', 1))
        self.linenostep = abs(get_int_opt(options, 'linenostep', 1))
        self.linenospecial = abs(get_int_opt(options, 'linenospecial', 0))
        self.nobackground = get_bool_opt(options, 'nobackground', False)
        self.lineseparator = options.get('lineseparator', '\n')
        self.lineanchors = options.get('lineanchors', '')
        self.hl_lines = set()
        for lineno in get_list_opt(options, 'hl_lines', []):
            try:
                self.hl_lines.add(int(lineno))
            except ValueError:
                pass

        self._class_cache = {}
        self._create_stylesheet()
Example #3
0
 def __init__(self, **options):
     Filter.__init__(self, **options)
     self.names = set(get_list_opt(options, 'names', []))
     tokentype = options.get('tokentype')
     if tokentype:
         self.tokentype = string_to_tokentype(tokentype)
     else:
         self.tokentype = Name.Function
Example #4
0
    def test_getoptions(self):
        raises = self.assertRaises
        equals = self.assertEquals

        equals(util.get_bool_opt({}, 'a', True), True)
        equals(util.get_bool_opt({}, 'a', 1), True)
        equals(util.get_bool_opt({}, 'a', 'true'), True)
        equals(util.get_bool_opt({}, 'a', 'no'), False)
        raises(util.OptionError, util.get_bool_opt, {}, 'a', [])
        raises(util.OptionError, util.get_bool_opt, {}, 'a', 'foo')

        equals(util.get_int_opt({}, 'a', 1), 1)
        raises(util.OptionError, util.get_int_opt, {}, 'a', [])
        raises(util.OptionError, util.get_int_opt, {}, 'a', 'bar')

        equals(util.get_list_opt({}, 'a', [1]), [1])
        equals(util.get_list_opt({}, 'a', '1 2'), ['1', '2'])
        raises(util.OptionError, util.get_list_opt, {}, 'a', 1)
Example #5
0
    def test_getoptions(self):
        raises = self.assertRaises
        equals = self.assertEqual

        equals(util.get_bool_opt({}, "a", True), True)
        equals(util.get_bool_opt({}, "a", 1), True)
        equals(util.get_bool_opt({}, "a", "true"), True)
        equals(util.get_bool_opt({}, "a", "no"), False)
        raises(util.OptionError, util.get_bool_opt, {}, "a", [])
        raises(util.OptionError, util.get_bool_opt, {}, "a", "foo")

        equals(util.get_int_opt({}, "a", 1), 1)
        raises(util.OptionError, util.get_int_opt, {}, "a", [])
        raises(util.OptionError, util.get_int_opt, {}, "a", "bar")

        equals(util.get_list_opt({}, "a", [1]), [1])
        equals(util.get_list_opt({}, "a", "1 2"), ["1", "2"])
        raises(util.OptionError, util.get_list_opt, {}, "a", 1)
Example #6
0
 def __init__(self, **options):
     self.options = options
     self.stripnl = get_bool_opt(options, 'stripnl', True)
     self.stripall = get_bool_opt(options, 'stripall', False)
     self.tabsize = get_int_opt(options, 'tabsize', 0)
     self.encoding = options.get('encoding', 'latin1')
     # self.encoding = options.get('inencoding', None) or self.encoding
     self.filters = []
     for filter_ in get_list_opt(options, 'filters', ()):
         self.add_filter(filter_)
Example #7
0
 def __init__(self, **options):
     """
     See the class docstring for explanation of options.
     """
     if not pil_available:
         raise PilNotAvailable(
             'Python Imaging Library is required for this formatter')
     Formatter.__init__(self, **options)
     self.encoding = 'latin1'  # let pygments.format() do the right thing
     # Read the style
     self.styles = dict(self.style)
     if self.style.background_color is None:
         self.background_color = '#fff'
     else:
         self.background_color = self.style.background_color
     # Image options
     self.image_format = get_choice_opt(
         options, 'image_format', ['png', 'jpeg', 'gif', 'bmp'],
         self.default_image_format, normcase=True)
     self.image_pad = get_int_opt(options, 'image_pad', 10)
     self.line_pad = get_int_opt(options, 'line_pad', 2)
     # The fonts
     fontsize = get_int_opt(options, 'font_size', 14)
     self.fonts = FontManager(options.get('font_name', ''), fontsize)
     self.fontw, self.fonth = self.fonts.get_char_size()
     # Line number options
     self.line_number_fg = options.get('line_number_fg', '#886')
     self.line_number_bg = options.get('line_number_bg', '#eed')
     self.line_number_chars = get_int_opt(options,
                                          'line_number_chars', 2)
     self.line_number_bold = get_bool_opt(options,
                                          'line_number_bold', False)
     self.line_number_italic = get_bool_opt(options,
                                            'line_number_italic', False)
     self.line_number_pad = get_int_opt(options, 'line_number_pad', 6)
     self.line_numbers = get_bool_opt(options, 'line_numbers', True)
     self.line_number_separator = get_bool_opt(options,
                                               'line_number_separator', True)
     self.line_number_step = get_int_opt(options, 'line_number_step', 1)
     self.line_number_start = get_int_opt(options, 'line_number_start', 1)
     if self.line_numbers:
         self.line_number_width = (self.fontw * self.line_number_chars +
                                   self.line_number_pad * 2)
     else:
         self.line_number_width = 0
     self.hl_lines = []
     hl_lines_str = get_list_opt(options, 'hl_lines', [])
     for line in hl_lines_str:
         try:
             self.hl_lines.append(int(line))
         except ValueError:
             pass
     self.hl_color = options.get('hl_color',
                                 self.style.highlight_color) or '#f90'
     self.drawables = []
Example #8
0
 def __init__(self, **options):
     self.options = options
     self.stripnl = get_bool_opt(options, "stripnl", True)
     self.stripall = get_bool_opt(options, "stripall", False)
     self.ensurenl = get_bool_opt(options, "ensurenl", True)
     self.tabsize = get_int_opt(options, "tabsize", 0)
     self.encoding = options.get("encoding", "utf-8")
     # self.encoding = options.get('inencoding', None) or self.encoding
     self.filters = []
     for filter_ in get_list_opt(options, "filters", ()):
         self.add_filter(filter_)
Example #9
0
    def __init__(self, **options):
        self.func_name_highlighting = get_bool_opt(
            options, 'func_name_highlighting', True)
        self.disabled_modules = get_list_opt(options, 'disabled_modules', [])

        self._functions = set()
        if self.func_name_highlighting:
            from pygments.lexers._lua_builtins import MODULES
            for mod, func in MODULES.iteritems():
                if mod not in self.disabled_modules:
                    self._functions.update(func)
        RegexLexer.__init__(self, **options)
 def __init__(self, **options):
     Lexer.__init__(self, **options)
     self.keywords = set()
     if get_bool_opt(options, 'turbopascal', True):
         self.keywords.update(self.TURBO_PASCAL_KEYWORDS)
     if get_bool_opt(options, 'delphi', True):
         self.keywords.update(self.DELPHI_KEYWORDS)
     if get_bool_opt(options, 'freepascal', True):
         self.keywords.update(self.FREE_PASCAL_KEYWORDS)
     self.builtins = set()
     for unit in get_list_opt(options, 'units', list(self.BUILTIN_UNITS)):
         self.builtins.update(self.BUILTIN_UNITS[unit])
Example #11
0
    def __init__(self, **options):
        Formatter.__init__(self, **options)
        self.docclass = options.get('docclass', 'article')
        self.preamble = options.get('preamble', '')
        self.linenos = get_bool_opt(options, 'linenos', False)
        self.linenostart = abs(get_int_opt(options, 'linenostart', 1))
        self.linenostep = abs(get_int_opt(options, 'linenostep', 1))
        self.verboptions = options.get('verboptions', '')
        self.nobackground = get_bool_opt(options, 'nobackground', False)
        self.commandprefix = options.get('commandprefix', 'PY')
        self.texcomments = get_bool_opt(options, 'texcomments', False)
        self.mathescape = get_bool_opt(options, 'mathescape', False)
	self.highlights = get_list_opt(options, 'highlights', [])
        self._create_stylesheet()
Example #12
0
    def __init__(self, **options):
        Formatter.__init__(self, **options)
        self.title = self._decodeifneeded(self.title)
        self.nowrap = get_bool_opt(options, 'nowrap', False)
        self.noclasses = get_bool_opt(options, 'noclasses', False)
        self.classprefix = options.get('classprefix', '')
        self.cssclass = self._decodeifneeded(
            options.get('cssclass', 'highlight'))
        self.cssstyles = self._decodeifneeded(options.get('cssstyles', ''))
        self.prestyles = self._decodeifneeded(options.get('prestyles', ''))
        self.cssfile = self._decodeifneeded(options.get('cssfile', ''))
        self.noclobber_cssfile = get_bool_opt(options, 'noclobber_cssfile',
                                              False)
        self.tagsfile = self._decodeifneeded(options.get('tagsfile', ''))
        self.tagurlformat = self._decodeifneeded(
            options.get('tagurlformat', ''))

        if self.tagsfile:
            if not ctags:
                raise RuntimeError('The "ctags" package must to be installed '
                                   'to be able to use the "tagsfile" feature.')
            self._ctags = ctags.CTags(self.tagsfile)

        linenos = options.get('linenos', False)
        if linenos == 'inline':
            self.linenos = 2
        elif linenos:
            # compatibility with <= 0.7
            self.linenos = 1
        else:
            self.linenos = 0
        self.linenostart = abs(get_int_opt(options, 'linenostart', 1))
        self.linenostep = abs(get_int_opt(options, 'linenostep', 1))
        self.linenospecial = abs(get_int_opt(options, 'linenospecial', 0))
        self.nobackground = get_bool_opt(options, 'nobackground', False)
        self.lineseparator = options.get('lineseparator', '\n')
        self.lineanchors = options.get('lineanchors', '')
        self.linespans = options.get('linespans', '')
        self.anchorlinenos = options.get('anchorlinenos', False)
        self.hl_lines = set()
        for lineno in get_list_opt(options, 'hl_lines', []):
            try:
                self.hl_lines.add(int(lineno))
            except ValueError:
                pass

        self._create_stylesheet()
Example #13
0
 def __init__(self, **options):
     """
     See the class docstring for explanation of options.
     """
     if not pil_available:
         raise PilNotAvailable("Python Imaging Library is required for this formatter")
     Formatter.__init__(self, **options)
     # Read the style
     self.styles = dict(self.style)
     if self.style.background_color is None:
         self.background_color = "#fff"
     else:
         self.background_color = self.style.background_color
     # Image options
     self.image_format = get_choice_opt(
         options, "image_format", ["png", "jpeg", "gif", "bmp"], self.default_image_format, normcase=True
     )
     self.image_pad = get_int_opt(options, "image_pad", 10)
     self.line_pad = get_int_opt(options, "line_pad", 2)
     # The fonts
     fontsize = get_int_opt(options, "font_size", 14)
     self.fonts = FontManager(options.get("font_name", ""), fontsize)
     self.fontw, self.fonth = self.fonts.get_char_size()
     # Line number options
     self.line_number_fg = options.get("line_number_fg", "#886")
     self.line_number_bg = options.get("line_number_bg", "#eed")
     self.line_number_chars = get_int_opt(options, "line_number_chars", 2)
     self.line_number_bold = get_bool_opt(options, "line_number_bold", False)
     self.line_number_italic = get_bool_opt(options, "line_number_italic", False)
     self.line_number_pad = get_int_opt(options, "line_number_pad", 6)
     self.line_numbers = get_bool_opt(options, "line_numbers", True)
     self.line_number_separator = get_bool_opt(options, "line_number_separator", True)
     self.line_number_step = get_int_opt(options, "line_number_step", 1)
     self.line_number_start = get_int_opt(options, "line_number_start", 1)
     if self.line_numbers:
         self.line_number_width = self.fontw * self.line_number_chars + self.line_number_pad * 2
     else:
         self.line_number_width = 0
     self.hl_lines = []
     hl_lines_str = get_list_opt(options, "hl_lines", [])
     for line in hl_lines_str:
         try:
             self.hl_lines.append(int(line))
         except ValueError:
             pass
     self.hl_color = options.get("hl_color", self.style.highlight_color) or "#f90"
     self.drawables = []
Example #14
0
    def __init__(self, **options):
        Formatter.__init__(self, **options)
        self.title = self._decodeifneeded(self.title)
        self.nowrap = get_bool_opt(options, 'nowrap', False)
        self.noclasses = get_bool_opt(options, 'noclasses', False)
        self.classprefix = options.get('classprefix', '')
        self.cssclass = self._decodeifneeded(options.get('cssclass', 'highlight'))
        self.cssstyles = self._decodeifneeded(options.get('cssstyles', ''))
        self.prestyles = self._decodeifneeded(options.get('prestyles', ''))
        self.cssfile = self._decodeifneeded(options.get('cssfile', ''))
        self.noclobber_cssfile = get_bool_opt(options, 'noclobber_cssfile', False)
        self.tagsfile = self._decodeifneeded(options.get('tagsfile', ''))
        self.tagurlformat = self._decodeifneeded(options.get('tagurlformat', ''))
        self.filename = self._decodeifneeded(options.get('filename', ''))
        self.wrapcode = get_bool_opt(options, 'wrapcode', False)

        if self.tagsfile:
            if not ctags:
                raise RuntimeError('The "ctags" package must to be installed '
                                   'to be able to use the "tagsfile" feature.')
            self._ctags = ctags.CTags(self.tagsfile)

        linenos = options.get('linenos', False)
        if linenos == 'inline':
            self.linenos = 2
        elif linenos:
            # compatibility with <= 0.7
            self.linenos = 1
        else:
            self.linenos = 0
        self.linenostart = abs(get_int_opt(options, 'linenostart', 1))
        self.linenostep = abs(get_int_opt(options, 'linenostep', 1))
        self.linenospecial = abs(get_int_opt(options, 'linenospecial', 0))
        self.nobackground = get_bool_opt(options, 'nobackground', False)
        self.lineseparator = options.get('lineseparator', '\n')
        self.lineanchors = options.get('lineanchors', '')
        self.linespans = options.get('linespans', '')
        self.anchorlinenos = options.get('anchorlinenos', False)
        self.hl_lines = set()
        for lineno in get_list_opt(options, 'hl_lines', []):
            try:
                self.hl_lines.add(int(lineno))
            except ValueError:
                pass

        self._create_stylesheet()
Example #15
0
    def __init__(self, **options):
        Formatter.__init__(self, **options)
        self.title = self._decodeifneeded(self.title)
        self.nowrap = get_bool_opt(options, "nowrap", False)
        self.noclasses = get_bool_opt(options, "noclasses", False)
        self.classprefix = options.get("classprefix", "")
        self.cssclass = self._decodeifneeded(options.get("cssclass", "highlight"))
        self.cssstyles = self._decodeifneeded(options.get("cssstyles", ""))
        self.prestyles = self._decodeifneeded(options.get("prestyles", ""))
        self.cssfile = self._decodeifneeded(options.get("cssfile", ""))
        self.noclobber_cssfile = get_bool_opt(options, "noclobber_cssfile", False)
        self.tagsfile = self._decodeifneeded(options.get("tagsfile", ""))
        self.tagurlformat = self._decodeifneeded(options.get("tagurlformat", ""))

        if self.tagsfile:
            if not ctags:
                raise RuntimeError(
                    'The "ctags" package must to be installed ' 'to be able to use the "tagsfile" feature.'
                )
            self._ctags = ctags.CTags(self.tagsfile)

        linenos = options.get("linenos", False)
        if linenos == "inline":
            self.linenos = 2
        elif linenos:
            # compatibility with <= 0.7
            self.linenos = 1
        else:
            self.linenos = 0
        self.linenostart = abs(get_int_opt(options, "linenostart", 1))
        self.linenostep = abs(get_int_opt(options, "linenostep", 1))
        self.linenospecial = abs(get_int_opt(options, "linenospecial", 0))
        self.nobackground = get_bool_opt(options, "nobackground", False)
        self.lineseparator = options.get("lineseparator", "\n")
        self.lineanchors = options.get("lineanchors", "")
        self.linespans = options.get("linespans", "")
        self.anchorlinenos = options.get("anchorlinenos", False)
        self.hl_lines = set()
        for lineno in get_list_opt(options, "hl_lines", []):
            try:
                self.hl_lines.add(int(lineno))
            except ValueError:
                pass

        self._create_stylesheet()
Example #16
0
    def __init__(self, **options):
        self.funcnamehighlighting = get_bool_opt(options, "funcnamehighlighting", True)
        self.disabledmodules = get_list_opt(options, "disabledmodules", ["unknown"])
        self.startinline = get_bool_opt(options, "startinline", False)

        # private option argument for the lexer itself
        if "_startinline" in options:
            self.startinline = options.pop("_startinline")

        # collect activated functions in a set
        self._functions = set()
        if self.funcnamehighlighting:
            from pygments.lexers._phpbuiltins import MODULES

            for key, value in MODULES.iteritems():
                if key not in self.disabledmodules:
                    self._functions.update(value)
        RegexLexer.__init__(self, **options)
Example #17
0
    def __init__(self, **options):
        self.funcnamehighlighting = get_bool_opt(options,
                                                 'funcnamehighlighting', True)
        self.disabledmodules = get_list_opt(options, 'disabledmodules',
                                            ['unknown'])
        self.startinline = get_bool_opt(options, 'startinline', False)

        # private option argument for the lexer itself
        if '_startinline' in options:
            self.startinline = options.pop('_startinline')

        # collect activated functions in a set
        self._functions = set()
        if self.funcnamehighlighting:
            from pygments.lexers._php_builtins import MODULES
            for key, value in MODULES.items():
                if key not in self.disabledmodules:
                    self._functions.update(value)
        RegexLexer.__init__(self, **options)
Example #18
0
File: php.py Project: axil/blog
    def __init__(self, **options):
        self.funcnamehighlighting = get_bool_opt(
            options, 'funcnamehighlighting', True)
        self.disabledmodules = get_list_opt(
            options, 'disabledmodules', ['unknown'])
        self.startinline = get_bool_opt(options, 'startinline', False)

        # private option argument for the lexer itself
        if '_startinline' in options:
            self.startinline = options.pop('_startinline')

        # collect activated functions in a set
        self._functions = set()
        if self.funcnamehighlighting:
            from pygments.lexers._php_builtins import MODULES
            for key, value in iteritems(MODULES):
                if key not in self.disabledmodules:
                    self._functions.update(value)
        RegexLexer.__init__(self, **options)
Example #19
0
    def __init__(self, **options):
        Formatter.__init__(self, **options)
        self.title = self._decodeifneeded(self.title)
        self.nowrap = get_bool_opt(options, 'nowrap', False)
        self.noclasses = get_bool_opt(options, 'noclasses', False)
        self.classprefix = options.get('classprefix', '')
        self.cssclass = self._decodeifneeded(
            options.get('cssclass', 'highlight'))
        self.cssstyles = self._decodeifneeded(options.get('cssstyles', ''))
        self.prestyles = self._decodeifneeded(options.get('prestyles', ''))
        self.cssfile = self._decodeifneeded(options.get('cssfile', ''))
        self.noclobber_cssfile = get_bool_opt(options, 'noclobber_cssfile',
                                              False)

        linenos = options.get('linenos', False)
        if linenos == 'inline':
            self.linenos = 2
        elif linenos:
            # compatibility with <= 0.7
            self.linenos = 1
        else:
            self.linenos = 0
        self.linenostart = abs(get_int_opt(options, 'linenostart', 1))
        self.linenostep = abs(get_int_opt(options, 'linenostep', 1))
        self.linenospecial = abs(get_int_opt(options, 'linenospecial', 0))
        self.nobackground = get_bool_opt(options, 'nobackground', False)
        self.lineseparator = options.get('lineseparator', '\n')
        self.lineanchors = options.get('lineanchors', '')
        self.anchorlinenos = options.get('anchorlinenos', False)
        self.hl_lines = set()
        for lineno in get_list_opt(options, 'hl_lines', []):
            try:
                self.hl_lines.add(int(lineno))
            except ValueError:
                pass

        self._class_cache = {}
        self._create_stylesheet()
Example #20
0
 def __init__(self, **options):
     Filter.__init__(self, **options)
     tags = get_list_opt(options, 'codetags',
                         ['XXX', 'TODO', 'BUG', 'NOTE'])
     self.tag_re = re.compile(
         r'\b(%s)\b' % '|'.join([re.escape(tag) for tag in tags if tag]))
Example #21
0
 def __init__(self, **options):
     Filter.__init__(self, **options)
     tags = get_list_opt(options, "codetags", ["XXX", "TODO", "BUG", "NOTE"])
     self.tag_re = re.compile(r"\b(%s)\b" % "|".join([re.escape(tag) for tag in tags if tag]))