本文整理汇总了Python中IPython.core.error.UsageError方法的典型用法代码示例。如果您正苦于以下问题:Python error.UsageError方法的具体用法?Python error.UsageError怎么用?Python error.UsageError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPython.core.error
的用法示例。
在下文中一共展示了error.UsageError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: autosave
# 需要导入模块: from IPython.core import error [as 别名]
# 或者: from IPython.core.error import UsageError [as 别名]
def autosave(self, arg_s):
"""Set the autosave interval in the notebook (in seconds).
The default value is 120, or two minutes.
``%autosave 0`` will disable autosave.
This magic only has an effect when called from the notebook interface.
It has no effect when called in a startup file.
"""
try:
interval = int(arg_s)
except ValueError:
raise UsageError("%%autosave requires an integer, got %r" % arg_s)
# javascript wants milliseconds
milliseconds = 1000 * interval
display(Javascript("IPython.notebook.set_autosave_interval(%i)" % milliseconds),
include=['application/javascript']
)
if interval:
print("Autosaving every %i seconds" % interval)
else:
print("Autosave disabled")
示例2: pycat
# 需要导入模块: from IPython.core import error [as 别名]
# 或者: from IPython.core.error import UsageError [as 别名]
def pycat(self, parameter_s=''):
"""Show a syntax-highlighted file through a pager.
This magic is similar to the cat utility, but it will assume the file
to be Python source and will show it with syntax highlighting.
This magic command can either take a local filename, an url,
an history range (see %history) or a macro as argument ::
%pycat myscript.py
%pycat 7-27
%pycat myMacro
%pycat http://www.example.com/myscript.py
"""
if not parameter_s:
raise UsageError('Missing filename, URL, input history range, '
'or macro.')
try :
cont = self.shell.find_user_code(parameter_s, skip_encoding_cookie=False)
except (ValueError, IOError):
print "Error: no such file, variable, URL, history range or macro"
return
page.page(self.shell.pycolorize(source_to_unicode(cont)))
示例3: ecc
# 需要导入模块: from IPython.core import error [as 别名]
# 或者: from IPython.core.error import UsageError [as 别名]
def ecc(self, line, cell='', address=target_memory.shell_code):
"""Evaluate a 32-bit C++ expression on the target, and immediately start a console
To ensure we only display output that was generated during the command execution,
the console is sync'ed and unread output is discarded prior to running the command.
"""
d = self.shell.user_ns['d']
ConsoleBuffer(d).discard()
try:
return_value = evalc(d, line + cell, defines=all_defines(), includes=all_includes(), address=address, verbose=True)
except CodeError as e:
raise UsageError(str(e))
if return_value is not None:
display(return_value)
console_mainloop(d)
示例4: _parse_input_path
# 需要导入模块: from IPython.core import error [as 别名]
# 或者: from IPython.core.error import UsageError [as 别名]
def _parse_input_path(self, path_str):
"""
Parse formatted to path to swift container and object names
:param path_str: path string starts with "path:" prefix
:return (container, obj): Both container and obj are formatted
as string
:raise UsageError: if the path_str is not formatted as expected
"""
if not path_str.startswith('path:'):
raise UsageError(
'swift object path must have the format: '
'"path:/<container>/<object>"')
try:
src_container_obj = path_str[len('path:'):]
src_container, src_obj = src_container_obj.strip(
'/').split('/', 1)
return src_container, src_obj
except ValueError:
raise UsageError(
'swift object path must have the format: '
'"path:/<container>/<object>"')
示例5: test_storlet_auth_v3_no_enough_auth_info
# 需要导入模块: from IPython.core import error [as 别名]
# 或者: from IPython.core.error import UsageError [as 别名]
def test_storlet_auth_v3_no_enough_auth_info(self):
line = 'test.TestStorlet'
cell = ''
# OS_AUTH_URL, OS_USERNAME, OS_PASSWORD, OS_PROJECT_NAME are required
required = ('OS_AUTH_URL', 'OS_USERNAME',
'OS_PASSWORD', 'OS_PROJECT_NAME')
for combi_length in range(1, len(required) + 1):
for combination in itertools.combinations(required, combi_length):
# set full environ for auth
self._set_auth_environ()
# and delete specific required keys
for key in combination:
del os.environ[key]
with self.assertRaises(UsageError) as e:
self._call_storletapp(line, cell)
self.assertEqual(
"You need to set OS_AUTH_URL, OS_USERNAME, OS_PASSWORD "
"and OS_PROJECT_NAME for Swift authentication",
e.exception.args[0])
示例6: sospaste
# 需要导入模块: from IPython.core import error [as 别名]
# 或者: from IPython.core.error import UsageError [as 别名]
def sospaste(self, line):
'Magic that execute sos expression and statements from clipboard'
# get and print clipboard content
try:
block = self.shell.hooks.clipboard_get()
except ClipboardEmpty:
raise UsageError("The clipboard appears to be empty")
#
print(block.strip())
print('## -- End pasted text --')
try:
# is it an expression?
compile(block, '<string>', 'eval')
return SoS_eval(block)
except Exception:
# is it a list of statement?
try:
compile(block, '<string>', 'exec')
return SoS_exec(block)
except Exception:
return runfile(code=block, args=self.options + line.strip())
示例7: result
# 需要导入模块: from IPython.core import error [as 别名]
# 或者: from IPython.core.error import UsageError [as 别名]
def result(self, line=''):
"""Print the result of the last asynchronous %px command.
This lets you recall the results of %px computations after
asynchronous submission (block=False).
Examples
--------
::
In [23]: %px os.getpid()
Async parallel execution on engine(s): all
In [24]: %pxresult
Out[8:10]: 60920
Out[9:10]: 60921
Out[10:10]: 60922
Out[11:10]: 60923
"""
args = magic_arguments.parse_argstring(self.result, line)
if self.last_result is None:
raise UsageError(NO_LAST_RESULT)
self.last_result.get()
self.last_result.display_outputs(groupby=args.groupby)
示例8: less
# 需要导入模块: from IPython.core import error [as 别名]
# 或者: from IPython.core.error import UsageError [as 别名]
def less(self, arg_s):
"""Show a file through the pager.
Files ending in .py are syntax-highlighted."""
if not arg_s:
raise UsageError('Missing filename.')
cont = open(arg_s).read()
if arg_s.endswith('.py'):
cont = self.shell.pycolorize(openpy.read_py_file(arg_s, skip_encoding_cookie=False))
else:
cont = open(arg_s).read()
page.page(cont)
示例9: enable_gui
# 需要导入模块: from IPython.core import error [as 别名]
# 或者: from IPython.core.error import UsageError [as 别名]
def enable_gui(gui):
from .eventloops import enable_gui as real_enable_gui
try:
real_enable_gui(gui)
except ValueError as e:
raise UsageError("%s" % e)
示例10: enable_gui
# 需要导入模块: from IPython.core import error [as 别名]
# 或者: from IPython.core.error import UsageError [as 别名]
def enable_gui(gui=None, app=None):
"""Switch amongst GUI input hooks by name.
"""
# Deferred import
from IPython.lib.inputhook import enable_gui as real_enable_gui
try:
return real_enable_gui(gui, app)
except ValueError as e:
raise UsageError("%s" % e)
示例11: show_usage_error
# 需要导入模块: from IPython.core import error [as 别名]
# 或者: from IPython.core.error import UsageError [as 别名]
def show_usage_error(self, exc):
"""Show a short message for UsageErrors
These are special exceptions that shouldn't show a traceback.
"""
self.write_err("UsageError: %s" % exc)
示例12: run_cell_magic
# 需要导入模块: from IPython.core import error [as 别名]
# 或者: from IPython.core.error import UsageError [as 别名]
def run_cell_magic(self, magic_name, line, cell):
"""Execute the given cell magic.
Parameters
----------
magic_name : str
Name of the desired magic function, without '%' prefix.
line : str
The rest of the first input line as a single string.
cell : str
The body of the cell as a (possibly multiline) string.
"""
fn = self.find_cell_magic(magic_name)
if fn is None:
lm = self.find_line_magic(magic_name)
etpl = "Cell magic `%%{0}` not found{1}."
extra = '' if lm is None else (' (But line magic `%{0}` exists, '
'did you mean that instead?)'.format(magic_name))
error(etpl.format(magic_name, extra))
elif cell == '':
message = '%%{0} is a cell magic, but the cell body is empty.'.format(magic_name)
if self.find_line_magic(magic_name) is not None:
message += ' Did you mean the line magic %{0} (single %)?'.format(magic_name)
raise UsageError(message)
else:
# Note: this is the distance in the stack to the user's frame.
# This will need to be updated if the internal calling logic gets
# refactored, or else we'll be expanding the wrong variables.
stack_depth = 2
magic_arg_s = self.var_expand(line, stack_depth)
with self.builtin_trap:
result = fn(magic_arg_s, cell)
return result
示例13: error
# 需要导入模块: from IPython.core import error [as 别名]
# 或者: from IPython.core.error import UsageError [as 别名]
def error(self, message):
""" Raise a catchable error instead of exiting.
"""
raise UsageError(message)
示例14: unload_ext
# 需要导入模块: from IPython.core import error [as 别名]
# 或者: from IPython.core.error import UsageError [as 别名]
def unload_ext(self, module_str):
"""Unload an IPython extension by its module name.
Not all extensions can be unloaded, only those which define an
``unload_ipython_extension`` function.
"""
if not module_str:
raise UsageError('Missing module name.')
res = self.shell.extension_manager.unload_extension(module_str)
if res == 'no unload function':
print "The %s extension doesn't define how to unload it." % module_str
elif res == "not loaded":
print "The %s extension is not loaded." % module_str
示例15: reload_ext
# 需要导入模块: from IPython.core import error [as 别名]
# 或者: from IPython.core.error import UsageError [as 别名]
def reload_ext(self, module_str):
"""Reload an IPython extension by its module name."""
if not module_str:
raise UsageError('Missing module name.')
self.shell.extension_manager.reload_extension(module_str)