本文整理汇总了Python中pygments.util.get_choice_opt方法的典型用法代码示例。如果您正苦于以下问题:Python util.get_choice_opt方法的具体用法?Python util.get_choice_opt怎么用?Python util.get_choice_opt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygments.util
的用法示例。
在下文中一共展示了util.get_choice_opt方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from pygments import util [as 别名]
# 或者: from pygments.util import get_choice_opt [as 别名]
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.
# The RawTokenFormatter outputs only ASCII. Override here.
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)
示例2: test_getoptions
# 需要导入模块: from pygments import util [as 别名]
# 或者: from pygments.util import get_choice_opt [as 别名]
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')
示例3: __init__
# 需要导入模块: from pygments import util [as 别名]
# 或者: from pygments.util import get_choice_opt [as 别名]
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.linenos = options.get('linenos', False)
self._lineno = 0
示例4: __init__
# 需要导入模块: from pygments import util [as 别名]
# 或者: from pygments.util import get_choice_opt [as 别名]
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)
示例5: __init__
# 需要导入模块: from pygments import util [as 别名]
# 或者: from pygments.util import get_choice_opt [as 别名]
def __init__(self, **options):
self.compress = get_choice_opt(options, 'compress',
['', 'none', 'gz', 'bz2'], '')
Lexer.__init__(self, **options)
示例6: __init__
# 需要导入模块: from pygments import util [as 别名]
# 或者: from pygments.util import get_choice_opt [as 别名]
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