本文整理汇总了Python中werkzeug._compat.reraise函数的典型用法代码示例。如果您正苦于以下问题:Python reraise函数的具体用法?Python reraise怎么用?Python reraise使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了reraise函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __exit__
def __exit__(self, exc_type, exc_value, tb):
exception_name = self.exc_type.__name__
if exc_type is None:
self.test_case.fail('Expected exception of type %r' %
exception_name)
elif not issubclass(exc_type, self.exc_type):
reraise(exc_type, exc_value, tb)
self.exc_value = exc_value
return True
开发者ID:0x19,项目名称:werkzeug,代码行数:9,代码来源:__init__.py
示例2: start_response
def start_response(status, response_headers, exc_info=None):
if exc_info:
try:
if headers_sent:
reraise(*exc_info)
finally:
exc_info = None
elif headers_set:
raise AssertionError('Headers already set')
headers_set[:] = [status, response_headers]
return write
开发者ID:popravich,项目名称:cantal_tools,代码行数:11,代码来源:werkzeug_serving.py
示例3: _handle_syntaxerror
def _handle_syntaxerror(self, exception, pkg, import_str):
"""
Properly handle an syntax error.
Pass through the error unless silent is set to True.
"""
if not self.silent:
reraise(
SyntaxError,
SyntaxError(*exception.args),
sys.exc_info()[2]
)
开发者ID:egabancho,项目名称:flask-registry,代码行数:12,代码来源:modulediscovery.py
示例4: import_string
def import_string(import_name, silent=False):
"""Imports an object based on a string. This is useful if you want to
use import paths as endpoints or something similar. An import path can
be specified either in dotted notation (``xml.sax.saxutils.escape``)
or with a colon as object delimiter (``xml.sax.saxutils:escape``).
If `silent` is True the return value will be `None` if the import fails.
:param import_name: the dotted name for the object to import.
:param silent: if set to `True` import errors are ignored and
`None` is returned instead.
:return: imported object
"""
# force the import name to automatically convert to strings
# __import__ is not able to handle unicode strings in the fromlist
# if the module is a package
import_name = str(import_name).replace(':', '.')
try:
try:
__import__(import_name)
except ImportError:
if '.' not in import_name:
raise
else:
return sys.modules[import_name]
module_name, obj_name = import_name.rsplit('.', 1)
try:
module = __import__(module_name, None, None, [obj_name])
except ImportError:
# support importing modules not yet set up by the parent module
# (or package for that matter)
module = import_string(module_name)
try:
return getattr(module, obj_name)
except AttributeError as e:
raise ImportError(e)
except ImportError as e:
if not silent:
reraise(
ImportStringError,
ImportStringError(import_name, e),
sys.exc_info()[2])
开发者ID:sherrycherish,项目名称:qiubai,代码行数:45,代码来源:utils.py
示例5: get_current_traceback
def get_current_traceback(ignore_system_exceptions=False,
show_hidden_frames=False, skip=0):
"""Get the current exception info as `Traceback` object. Per default
calling this method will reraise system exceptions such as generator exit,
system exit or others. This behavior can be disabled by passing `False`
to the function as first parameter.
"""
exc_type, exc_value, tb = sys.exc_info()
if ignore_system_exceptions and exc_type in system_exceptions:
reraise(exc_type, exc_value, tb)
for _ in range_type(skip):
if tb.tb_next is None:
break
tb = tb.tb_next
tb = Traceback(exc_type, exc_value, tb)
if not show_hidden_frames:
tb.filter_hidden_frames()
return tb
开发者ID:gaoussoucamara,项目名称:simens-cerpad,代码行数:18,代码来源:tbtools.py
示例6: _handle_importerror
def _handle_importerror(self, exception, pkg, import_str):
"""
Properly handle an import error
If a module does not exists, it's not an error, however an
ImportError generated from importing an existing module is an
error.
"""
try:
for found_module_name in find_modules(pkg):
if found_module_name == import_str:
reraise(
ImportError,
ImportError(*exception.args),
sys.exc_info()[2]
)
except ValueError:
# pkg doesn't exist or is not a package
pass
开发者ID:egabancho,项目名称:flask-registry,代码行数:19,代码来源:modulediscovery.py
示例7: import_string
def import_string(import_name, silent=False):
"""Imports an object based on a string. This is useful if you want to
use import paths as endpoints or something similar. An import path can
be specified either in dotted notation (``xml.sax.saxutils.escape``)
or with a colon as object delimiter (``xml.sax.saxutils:escape``).
If `silent` is True the return value will be `None` if the import fails.
:param import_name: the dotted name for the object to import.
:param silent: if set to `True` import errors are ignored and
`None` is returned instead.
:return: imported object
"""
#XXX: py3 review needed
assert isinstance(import_name, string_types)
# force the import name to automatically convert to strings
import_name = str(import_name)
try:
if ':' in import_name:
module, obj = import_name.split(':', 1)
elif '.' in import_name:
module, obj = import_name.rsplit('.', 1)
else:
return __import__(import_name)
# __import__ is not able to handle unicode strings in the fromlist
# if the module is a package
if PY2 and isinstance(obj, unicode):
obj = obj.encode('utf-8')
try:
return getattr(__import__(module, None, None, [obj]), obj)
except (ImportError, AttributeError):
# support importing modules not yet set up by the parent module
# (or package for that matter)
modname = module + '.' + obj
__import__(modname)
return sys.modules[modname]
except ImportError as e:
if not silent:
reraise(
ImportStringError,
ImportStringError(import_name, e),
sys.exc_info()[2])
开发者ID:08haozi,项目名称:uliweb,代码行数:42,代码来源:utils.py
示例8: _discover_module
def _discover_module(self, pkg):
"""
Method to discover a single module. May be overwritten by subclasses.
"""
import_str = pkg + '.' + self.module_name
try:
module = import_string(import_str, self.silent)
self.register(module)
except ImportError as e: # pylint: disable=C0103
# If a module does not exists, it's not an error, however an
# ImportError generated from importing an existing module is an
# error.
try:
for found_module_name in find_modules(pkg):
if found_module_name == import_str:
reraise(
ImportError,
ImportError(*e.args),
sys.exc_info()[2]
)
except ValueError:
# pkg doesn't exist or is not a package
pass
开发者ID:GiorgosPa,项目名称:flask-registry,代码行数:24,代码来源:modulediscovery.py
示例9: start_response
def start_response(status, headers, exc_info=None):
if exc_info is not None:
reraise(*exc_info)
response[:] = [status, headers]
return buffer.append
开发者ID:0x00xw,项目名称:wooyun,代码行数:5,代码来源:test.py
注:本文中的werkzeug._compat.reraise函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论