def __init__(self, **options): Formatter.__init__(self, **options) self.darkbg = get_choice_opt(options, 'bg', ['light', 'dark'], 'light') == 'dark' self.colorscheme = options.get('colorscheme', None) or COMMAND_COLORS self.linenos = options.get('linenos', False) self._lineno = 0
def __init__(self, **options): Formatter.__init__(self, **options) self.darkbg = (get_choice_opt(options, "bg", ["light", "dark"], "light") == "dark") self.colorscheme = options.get("colorscheme", None) or COMMAND_COLORS self.linenos = options.get("linenos", False) self._lineno = 0
def __init__(self, **options): Formatter.__init__(self, **options) self.darkbg = get_choice_opt(options, 'bg', ['light', 'dark'], 'light') == 'dark' self.colorscheme = options.get('colorscheme', None) or IRC_COLORS self.linenos = options.get('linenos', False) self._lineno = 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 = []
def __init__(self, **options): level = get_choice_opt(options, 'unicodelevel', list(self.tokens), 'basic') if level not in self._all_tokens: # compile the regexes now self._tokens = self.__class__.process_tokendef(level) else: self._tokens = self._all_tokens[level] RegexLexer.__init__(self, **options)
def __init__(self, **options): level = get_choice_opt(options, 'unicodelevel', self.tokens.keys(), 'basic') if level not in self._all_tokens: # compile the regexes now self._tokens = self.__class__.process_tokendef(level) else: self._tokens = self._all_tokens[level] RegexLexer.__init__(self, **options)
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 = []
def __init__(self, **options): Formatter.__init__(self, **options) self.darkbg = (get_choice_opt(options, "bg", ["light", "dark"], "light") != "dark") self.colorscheme = options.get("colorscheme", None) or color_scheme self.width = options.get("width", 80) self.verbatim = False self.in_list = False self.column = 1 self.last_was_nl = False return
def __init__(self, **options): Formatter.__init__(self, **options) self.darkbg = get_choice_opt(options, 'bg', ['light', 'dark'], 'light') == 'dark' self.colorscheme = options.get('colorscheme', None) or TERMINAL_COLORS self.width = options.get('width', 80) self.verbatim = False self.in_list = False self.column = 1 self.last_was_nl = False return
def test_getoptions(): assert util.get_bool_opt({}, 'a', True) is True assert util.get_bool_opt({}, 'a', 1) is True assert util.get_bool_opt({}, 'a', 'true') is True assert util.get_bool_opt({}, 'a', 'no') is False assert raises(util.OptionError, util.get_bool_opt, {}, 'a', []) assert raises(util.OptionError, util.get_bool_opt, {}, 'a', 'foo') assert util.get_int_opt({}, 'a', 1) == 1 assert raises(util.OptionError, util.get_int_opt, {}, 'a', []) assert raises(util.OptionError, util.get_int_opt, {}, 'a', 'bar') assert util.get_list_opt({}, 'a', [1]) == [1] assert util.get_list_opt({}, 'a', '1 2') == ['1', '2'] assert raises(util.OptionError, util.get_list_opt, {}, 'a', 1) assert util.get_choice_opt({}, 'a', ['foo', 'bar'], 'bar') == 'bar' assert util.get_choice_opt({}, 'a', ['foo', 'bar'], 'Bar', True) == 'bar' assert raises(util.OptionError, util.get_choice_opt, {}, 'a', ['foo', 'bar'], 'baz')
def __init__(self, **options): Formatter.__init__(self, **options) self.darkbg = get_choice_opt(options, 'bg', ['light', 'dark'], 'light') != 'dark' self.colorscheme = options.get('colorscheme', None) or color_scheme self.width = options.get('width', 80) self.verbatim = False self.in_list = False self.column = 1 self.last_was_nl = False return
def __init__(self, **options): Formatter.__init__(self, **options) self.compress = get_choice_opt(options, 'compress', ['', 'none', 'gz', 'bz2'], '') self.error_color = options.get('error_color', None) if self.error_color is True: self.error_color = 'red' if self.error_color is not None: try: colorize(self.error_color, '') except KeyError: raise ValueError("Invalid color %r specified" % self.error_color)
def __init__(self, **options): Formatter.__init__(self, **options) if self.encoding: raise OptionError("the raw formatter does not support the " "encoding option") self.encoding = "utf-8" # let pygments.format() do the right thing self.compress = get_choice_opt(options, "compress", ["", "none", "gz", "bz2"], "") self.error_color = options.get("error_color", None) if self.error_color is True: self.error_color = "red" if self.error_color is not None: try: colorize(self.error_color, "") except KeyError: raise ValueError("Invalid color %r specified" % self.error_color)
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) equals(util.get_choice_opt({}, 'a', ['foo', 'bar'], 'bar'), 'bar') equals(util.get_choice_opt({}, 'a', ['foo', 'bar'], 'Bar', True), 'bar') raises(util.OptionError, util.get_choice_opt, {}, 'a', ['foo', 'bar'], 'baz')
def __init__(self, **options): Formatter.__init__(self, **options) # We ignore self.encoding if it is set, since it gets set for lexer # and formatter if given with -Oencoding on the command line. self.encoding = 'ascii' # let pygments.format() do the right thing self.compress = get_choice_opt(options, 'compress', ['', 'none', 'gz', 'bz2'], '') self.error_color = options.get('error_color', None) if self.error_color is True: self.error_color = 'red' if self.error_color is not None: try: colorize(self.error_color, '') except KeyError: raise ValueError("Invalid color %r specified" % self.error_color)
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) 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.drawables = []
def __init__(self, **options): Formatter.__init__(self, **options) if self.encoding: raise OptionError('the raw formatter does not support the ' 'encoding option') self.encoding = 'ascii' # let pygments.format() do the right thing self.compress = get_choice_opt(options, 'compress', ['', 'none', 'gz', 'bz2'], '') self.error_color = options.get('error_color', None) if self.error_color is True: self.error_color = 'red' if self.error_color is not None: try: colorize(self.error_color, '') except KeyError: raise ValueError("Invalid color %r specified" % self.error_color)
def __init__(self, **options): Filter.__init__(self, **options) case = get_choice_opt(options, 'case', ['lower', 'upper', 'capitalize'], 'lower') self.convert = getattr(str, case)
def __init__(self, **options): Formatter.__init__(self, **options) self.compress = get_choice_opt(options, 'compress', ['', 'none', 'gz', 'bz2'], '')
def __init__(self, **options): Filter.__init__(self, **options) lang = get_choice_opt(options, 'lang', ['isabelle', 'latex'], 'isabelle') self.symbols = self.lang_map[lang]
def __init__(self, **options): Formatter.__init__(self, **options) self.darkbg = get_choice_opt(options, 'bg', ['light', 'dark'], 'light') == 'dark' self.colorscheme = options.get('colorscheme', None) or TERMINAL_COLORS