本文整理汇总了Python中tornado.options.Error方法的典型用法代码示例。如果您正苦于以下问题:Python options.Error方法的具体用法?Python options.Error怎么用?Python options.Error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.options
的用法示例。
在下文中一共展示了options.Error方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_subcommand
# 需要导入模块: from tornado import options [as 别名]
# 或者: from tornado.options import Error [as 别名]
def test_subcommand(self):
base_options = OptionParser()
base_options.define("verbose", default=False)
sub_options = OptionParser()
sub_options.define("foo", type=str)
rest = base_options.parse_command_line(
["main.py", "--verbose", "subcommand", "--foo=bar"])
self.assertEqual(rest, ["subcommand", "--foo=bar"])
self.assertTrue(base_options.verbose)
rest2 = sub_options.parse_command_line(rest)
self.assertEqual(rest2, [])
self.assertEqual(sub_options.foo, "bar")
# the two option sets are distinct
try:
orig_stderr = sys.stderr
sys.stderr = StringIO()
with self.assertRaises(Error):
sub_options.parse_command_line(["subcommand", "--verbose"])
finally:
sys.stderr = orig_stderr
示例2: test_subcommand
# 需要导入模块: from tornado import options [as 别名]
# 或者: from tornado.options import Error [as 别名]
def test_subcommand(self):
base_options = OptionParser()
base_options.define("verbose", default=False)
sub_options = OptionParser()
sub_options.define("foo", type=str)
rest = base_options.parse_command_line(
["main.py", "--verbose", "subcommand", "--foo=bar"]
)
self.assertEqual(rest, ["subcommand", "--foo=bar"])
self.assertTrue(base_options.verbose)
rest2 = sub_options.parse_command_line(rest)
self.assertEqual(rest2, [])
self.assertEqual(sub_options.foo, "bar")
# the two option sets are distinct
try:
orig_stderr = sys.stderr
sys.stderr = StringIO()
with self.assertRaises(Error):
sub_options.parse_command_line(["subcommand", "--verbose"])
finally:
sys.stderr = orig_stderr
示例3: test_error_redefine_underscore
# 需要导入模块: from tornado import options [as 别名]
# 或者: from tornado.options import Error [as 别名]
def test_error_redefine_underscore(self):
# Ensure that the dash/underscore normalization doesn't
# interfere with the redefinition error.
tests = [
("foo-bar", "foo-bar"),
("foo_bar", "foo_bar"),
("foo-bar", "foo_bar"),
("foo_bar", "foo-bar"),
]
for a, b in tests:
with subTest(self, a=a, b=b):
options = OptionParser()
options.define(a)
with self.assertRaises(Error) as cm:
options.define(b)
self.assertRegexpMatches(
str(cm.exception), "Option.*foo.bar.*already defined"
)
示例4: parse_environment
# 需要导入模块: from tornado import options [as 别名]
# 或者: from tornado.options import Error [as 别名]
def parse_environment(self, final=True):
for name in os.environ:
normalized = self._normalize_name(name)
normalized = normalized.lower()
if normalized in self._options:
option = self._options[normalized]
if option.multiple:
if not isinstance(os.environ[name], (list, str)):
raise Error("Option %r is required to be a list of %s "
"or a comma-separated string" %
(option.name, option.type.__name__))
if type(os.environ[name]) == str and option.type != str:
option.parse(os.environ[name])
else:
option.set(os.environ[name])
示例5: parse_config_file
# 需要导入模块: from tornado import options [as 别名]
# 或者: from tornado.options import Error [as 别名]
def parse_config_file(self, path, section, final=True):
config_parser = configparser.ConfigParser()
if not config_parser.read(path):
raise IOError('Config file at path "{}" not found'.format(path))
try:
config = config_parser.items(section)
except KeyError:
raise ValueError('Config file does not have [{}] section]'.format(section))
for (name, value) in config:
normalized = self._normalize_name(name)
normalized = normalized.lower()
if normalized in self._options:
option = self._options[normalized]
if option.multiple:
if not isinstance(value, (list, str)):
raise Error("Option %r is required to be a list of %s "
"or a comma-separated string" %
(option.name, option.type.__name__))
if type(value) == str and option.type != str:
option.parse(value)
else:
option.set(value)
示例6: test_error_redefine_underscore
# 需要导入模块: from tornado import options [as 别名]
# 或者: from tornado.options import Error [as 别名]
def test_error_redefine_underscore(self):
# Ensure that the dash/underscore normalization doesn't
# interfere with the redefinition error.
tests = [
('foo-bar', 'foo-bar'),
('foo_bar', 'foo_bar'),
('foo-bar', 'foo_bar'),
('foo_bar', 'foo-bar'),
]
for a, b in tests:
with subTest(self, a=a, b=b):
options = OptionParser()
options.define(a)
with self.assertRaises(Error) as cm:
options.define(b)
self.assertRegexpMatches(str(cm.exception),
'Option.*foo.bar.*already defined')
示例7: test_setattr_type_check
# 需要导入模块: from tornado import options [as 别名]
# 或者: from tornado.options import Error [as 别名]
def test_setattr_type_check(self):
# setattr requires that options be the right type and doesn't
# parse from string formats.
options = OptionParser()
options.define('foo', default=1, type=int)
with self.assertRaises(Error):
options.foo = '2'
示例8: test_error_redefine
# 需要导入模块: from tornado import options [as 别名]
# 或者: from tornado.options import Error [as 别名]
def test_error_redefine(self):
options = OptionParser()
options.define('foo')
with self.assertRaises(Error) as cm:
options.define('foo')
self.assertRegexpMatches(str(cm.exception),
'Option.*foo.*already defined')
示例9: test_setattr_type_check
# 需要导入模块: from tornado import options [as 别名]
# 或者: from tornado.options import Error [as 别名]
def test_setattr_type_check(self):
# setattr requires that options be the right type and doesn't
# parse from string formats.
options = OptionParser()
options.define("foo", default=1, type=int)
with self.assertRaises(Error):
options.foo = "2"
示例10: test_error_redefine
# 需要导入模块: from tornado import options [as 别名]
# 或者: from tornado.options import Error [as 别名]
def test_error_redefine(self):
options = OptionParser()
options.define("foo")
with self.assertRaises(Error) as cm:
options.define("foo")
self.assertRegexpMatches(str(cm.exception), "Option.*foo.*already defined")
示例11: apply_cli_overrides
# 需要导入模块: from tornado import options [as 别名]
# 或者: from tornado.options import Error [as 别名]
def apply_cli_overrides(go_settings):
"""
Updates *go_settings* in-place with values given on the command line.
"""
# Figure out which options are being overridden on the command line
arguments = []
non_options = [
# These are things that don't really belong in settings
'new_api_key', 'help', 'kill', 'config', 'combine_js', 'combine_css',
'combine_css_container', 'version', 'configure'
]
for arg in list(sys.argv)[1:]:
if not arg.startswith('-'):
break
else:
arguments.append(arg.lstrip('-').split('=', 1)[0])
go_settings['cli_overrides'] = arguments
for argument in arguments:
if argument in non_options:
continue
if argument in list(options):
go_settings[argument] = options[argument]
# Update Tornado's options from our settings.
# NOTE: For options given on the command line this step should be redundant.
for key, value in go_settings.items():
if key in non_options:
continue
if key in list(options):
if key in ('origins', 'api_keys'):
# These two settings are special and taken care of elsewhere
continue
try:
setattr(options, key, value)
except Error:
if isinstance(value, str):
if str == bytes: # Python 2
setattr(options, key, unicode(value))
else:
setattr(options, key, str(value))
示例12: swap_terminals
# 需要导入模块: from tornado import options [as 别名]
# 或者: from tornado.options import Error [as 别名]
def swap_terminals(self, settings):
"""
Swaps the numbers of *settings['term1']* and *settings['term2']*.
"""
term1 = int(settings.get('term1', 0))
term2 = int(settings.get('term2', 0))
if not term1 or not term2:
return # Nothing to do
missing_msg = _("Error: Terminal {term} does not exist.")
if term1 not in self.loc_terms:
self.ws.send_message(missing_msg.format(term=term1))
return
if term2 not in self.loc_terms:
self.ws.send_message(missing_msg.format(term=term2))
return
term1_dict = self.loc_terms.pop(term1)
term2_dict = self.loc_terms.pop(term2)
self.remove_terminal_callbacks(
term1_dict['multiplex'], self.callback_id)
self.remove_terminal_callbacks(
term2_dict['multiplex'], self.callback_id)
self.loc_terms.update({term1: term2_dict})
self.loc_terms.update({term2: term1_dict})
self.add_terminal_callbacks(
term1, term2_dict['multiplex'], self.callback_id)
self.add_terminal_callbacks(
term2, term1_dict['multiplex'], self.callback_id)
self.trigger("terminal:swap_terminals", term1, term2)
#@require(authenticated(), policies('terminal'))
示例13: get_permissions
# 需要导入模块: from tornado import options [as 别名]
# 或者: from tornado.options import Error [as 别名]
def get_permissions(self, term):
"""
Sends the client an object representing the permissions of the given
*term*. Example JavaScript:
.. code-block:: javascript
GateOne.ws.send(JSON.stringify({
"terminal:get_permissions": 1
}));
"""
if 'shared' not in self.ws.persist['terminal']:
error_msg = _("Error: Invalid share ID.")
self.ws.send_message(error_msg)
return
out_dict = {'result': 'Success'}
term_obj = self.loc_terms.get(term, None)
if not term_obj:
return # Term doesn't exist
shared_terms = self.ws.persist['terminal']['shared']
for share_id, share_dict in shared_terms.items():
if share_dict['term_obj'] == term_obj:
out_dict['write'] = share_dict['write']
out_dict['read'] = share_dict['read']
out_dict['share_id'] = share_id
break
message = {'terminal:sharing_permissions': out_dict}
self.write_message(json_encode(message))
self.trigger("terminal:get_sharing_permissions", term)
#@require(authenticated(), policies('terminal'))