本文整理汇总了Python中sys.html方法的典型用法代码示例。如果您正苦于以下问题:Python sys.html方法的具体用法?Python sys.html怎么用?Python sys.html使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sys
的用法示例。
在下文中一共展示了sys.html方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_types_for_str
# 需要导入模块: import sys [as 别名]
# 或者: from sys import html [as 别名]
def get_types_for_str(tp_name, frame):
"""Get a list of candidate types from a string.
String corresponds to the tp_name as described in :
https://docs.python.org/2/c-api/typeobj.html#c.PyTypeObject.tp_name
as it is the name used in exception messages. It may include full path
with module, subpackage, package but this is just removed in current
implementation to search only based on the type name.
Lookup uses both class hierarchy and name lookup as the first may miss
old style classes on Python 2 and second does find them.
Just like get_types_for_str_using_inheritance, this needs to be called
as late as possible but because it requires a frame, there is not much
choice anyway.
"""
name = tp_name.split('.')[-1]
res = set.union(
get_types_for_str_using_inheritance(name),
get_types_for_str_using_names(name, frame))
assert all(inspect.isclass(t) and t.__name__ == name for t in res)
return res
示例2: add_hash_verification
# 需要导入模块: import sys [as 别名]
# 或者: from sys import html [as 别名]
def add_hash_verification(self, algorithm, hash):
'''
Adds hash verification to the download.
If hash is not correct, will try different mirrors. If all mirrors aren't
passing hash verification, `HashFailedException` Exception will be raised.
.. NOTE::
If downloaded file already exist on the destination, and hash matches, pySmartDL will not download it again.
.. WARNING::
The hashing algorithm must be supported on your system, as documented at `hashlib documentation page <http://docs.python.org/3/library/hashlib.html>`_.
:param algorithm: Hashing algorithm.
:type algorithm: string
:param hash: Hash code.
:type hash: string
'''
self.verify_hash = True
self.hash_algorithm = algorithm
self.hash_code = hash
示例3: load_wsgi
# 需要导入模块: import sys [as 别名]
# 或者: from sys import html [as 别名]
def load_wsgi(self):
try:
self.wsgi = self.app.wsgi()
except SyntaxError as e:
if not self.cfg.reload:
raise
self.log.exception(e)
# fix from PR #1228
# storing the traceback into exc_tb will create a circular reference.
# per https://docs.python.org/2/library/sys.html#sys.exc_info warning,
# delete the traceback after use.
try:
exc_type, exc_val, exc_tb = sys.exc_info()
self.reloader.add_extra_file(exc_val.filename)
tb_string = traceback.format_tb(exc_tb)
self.wsgi = util.make_fail_app(tb_string)
finally:
del exc_tb
示例4: chroot
# 需要导入模块: import sys [as 别名]
# 或者: from sys import html [as 别名]
def chroot(target):
"""
Chroot into a target directory. This also affects the working directory, make sure
to call os.chdir() afterwards.
"""
# We need to use pivot_root and not only chroot
# (cf. https://unix.stackexchange.com/a/456777/15398).
# These three steps together are the easiest way for calling pivot_root as chroot
# replacement (cf. the 'pivot_root(".", ".")' section of
# http://man7.org/linux/man-pages/man2/pivot_root.2.html).
os.chdir(target)
# Make "." (the target) our new root and put the old root at ".":
libc.pivot_root(b".", b".")
# Now both the host file system (old root) and the target are at "/" (stacked).
# We umount one of them, which will be the host file system, making it inaccessible:
libc.umount2(b"/", libc.MNT_DETACH)
示例5: _handle_exception
# 需要导入模块: import sys [as 别名]
# 或者: from sys import html [as 别名]
def _handle_exception():
"""Print exceptions raised by subscribers to stderr."""
# Heavily influenced by logging.Handler.handleError.
# See note here:
# https://docs.python.org/3.4/library/sys.html#sys.__stderr__
if sys.stderr:
einfo = sys.exc_info()
try:
traceback.print_exception(einfo[0], einfo[1], einfo[2],
None, sys.stderr)
except IOError:
pass
finally:
del einfo
# Note - to avoid bugs from forgetting which if these is all lowercase and
# which are camelCase, and at the same time avoid having to add a test for
# every command, use all lowercase here and test against command_name.lower().
示例6: add_hash_verification
# 需要导入模块: import sys [as 别名]
# 或者: from sys import html [as 别名]
def add_hash_verification(self, algorithm, hash):
'''
Adds hash verification to the download.
If hash is not correct, will try different mirrors. If all mirrors aren't
passing hash verification, `HashFailedException` Exception will be raised.
.. NOTE::
If downloaded file already exist on the destination, and hash matches, pySmartDL will not download it again.
.. WARNING::
The hashing algorithm must be supported on your system, as documented at `hashlib documentation page <http://docs.python.org/2/library/hashlib.html>`_.
:param algorithm: Hashing algorithm.
:type algorithm: string
:param hash: Hash code.
:type hash: string
'''
self.verify_hash = True
self.hash_algorithm = algorithm
self.hash_code = hash
示例7: printo
# 需要导入模块: import sys [as 别名]
# 或者: from sys import html [as 别名]
def printo(msg, encoding=None, errors='replace', std_type='stdout'):
"""Write msg on stdout. If no encoding is specified
the detected encoding of stdout is used. If the encoding
can't encode some chars they are replaced by '?'
:param msg: message
:type msg: unicode on python2 | str on python3
"""
std = getattr(sys, std_type, sys.stdout)
if encoding is None:
try:
encoding = std.encoding
except AttributeError:
encoding = None
# Fallback to ascii if no encoding is found
if encoding is None:
encoding = 'ascii'
# https://docs.python.org/3/library/sys.html#sys.stdout
# write in the binary buffer directly in python3
if hasattr(std, 'buffer'):
std = std.buffer
std.write(msg.encode(encoding, errors=errors))
std.write(b'\n')
std.flush()
示例8: _emit
# 需要导入模块: import sys [as 别名]
# 或者: from sys import html [as 别名]
def _emit(self, record):
# If there's no exception being processed,
# exc_info may be a 3-tuple of None
# http://docs.python.org/library/sys.html#sys.exc_info
if record.exc_info is True or (record.exc_info and all(record.exc_info)):
handler = self.client.get_handler("elasticapm.events.Exception")
exception = handler.capture(self.client, exc_info=record.exc_info)
else:
exception = None
return self.client.capture_message(
param_message={"message": compat.text_type(record.msg), "params": record.args},
exception=exception,
level=LOOKBOOK_LEVELS[record.level],
logger_name=record.channel,
custom=record.extra,
stack=record.kwargs.get("stack"),
)
示例9: view
# 需要导入模块: import sys [as 别名]
# 或者: from sys import html [as 别名]
def view(self,
name: Optional[str] = None,
model: Optional[Any] = None) -> Response:
"""
Returns a view rendered synchronously.
:param name: name of the template (path to the template file, optionally without '.html' extension
:param model: optional model, required to render the template.
:return: a Response object
"""
if not name:
name = self.get_default_view_name()
if model:
return view(self.templates, self.full_view_name(name), **model)
return view(self.templates, self.full_view_name(name))
示例10: view_async
# 需要导入模块: import sys [as 别名]
# 或者: from sys import html [as 别名]
def view_async(self,
name: Optional[str] = None,
model: Optional[Any] = None) -> Response:
"""
Returns a view rendered asynchronously.
:param name: name of the template (path to the template file, optionally without '.html' extension
:param model: optional model, required to render the template.
:return: a Response object
"""
if not name:
name = self.get_default_view_name()
if model:
return await view_async(self.templates, self.full_view_name(name), **model)
return await view_async(self.templates, self.full_view_name(name))
示例11: cli
# 需要导入模块: import sys [as 别名]
# 或者: from sys import html [as 别名]
def cli(args=None):
p = ArgumentParser(
description="{{ cookiecutter['project_short_description']}}",
conflict_handler='resolve'
)
p.add_argument(
'-V', '--version',
action='version',
help='Show the conda-prefix-replacement version number and exit.',
version="{{ cookiecutter['package_name']}} %s" % __version__,
)
args = p.parse_args(args)
# do something with the args
print("CLI template - fix me up!")
# No return value means no error.
# Return a value of 1 or higher to signify an error.
# See https://docs.python.org/3/library/sys.html#sys.exit
示例12: init_faulthandler
# 需要导入模块: import sys [as 别名]
# 或者: from sys import html [as 别名]
def init_faulthandler(fileobj=sys.__stderr__):
"""Enable faulthandler module if available.
This print a nice traceback on segfaults.
We use sys.__stderr__ instead of sys.stderr here so this will still work
when sys.stderr got replaced, e.g. by "Python Tools for Visual Studio".
Args:
fobj: An opened file object to write the traceback to.
"""
if fileobj is None:
# When run with pythonw.exe, sys.__stderr__ can be None:
# https://docs.python.org/3/library/sys.html#sys.__stderr__
# If we'd enable faulthandler in that case, we just get a weird
# exception, so we don't enable faulthandler if we have no stdout.
#
# Later when we have our data dir available we re-enable faulthandler
# to write to a file so we can display a crash to the user at the next
# start.
return
faulthandler.enable(fileobj)
if (hasattr(faulthandler, 'register') and hasattr(signal, 'SIGUSR1') and
sys.stderr is not None):
# If available, we also want a traceback on SIGUSR1.
# pylint: disable=no-member,useless-suppression
faulthandler.register(signal.SIGUSR1)
# pylint: enable=no-member,useless-suppression
示例13: get_data_hash
# 需要导入模块: import sys [as 别名]
# 或者: from sys import html [as 别名]
def get_data_hash(self, algorithm):
'''
Returns the downloaded data's hash. Will raise `RuntimeError` if it's
called when the download task is not finished yet.
:param algorithm: Hashing algorithm.
:type algorithm: bool
:rtype: string
.. WARNING::
The hashing algorithm must be supported on your system, as documented at `hashlib documentation page <http://docs.python.org/3/library/hashlib.html>`_.
'''
return hashlib.new(algorithm, self.get_data(binary=True)).hexdigest()
示例14: setup_user_mapping
# 需要导入模块: import sys [as 别名]
# 或者: from sys import html [as 别名]
def setup_user_mapping(
pid,
uid=os.getuid(), # noqa: B008
gid=os.getgid(), # noqa: B008
parent_uid=os.getuid(), # noqa: B008
parent_gid=os.getgid(), # noqa: B008
):
"""Write uid_map and gid_map in /proc to create a user mapping
that maps our user from outside the container to the same user inside the container
(and no other users are mapped).
@see: http://man7.org/linux/man-pages/man7/user_namespaces.7.html
@param pid: The PID of the process in the container.
@param uid: The UID that shall be used in the container.
@param gid: The GID that shall be used in the container.
@param parent_uid: The UID that is used in the parent namespace.
@param parent_gid: The GID that is used in the parent namespace.
"""
proc_child = os.path.join("/proc", str(pid))
try:
# map uid internally to our uid externally
uid_map = "{0} {1} 1".format(uid, parent_uid)
util.write_file(uid_map, proc_child, "uid_map")
except OSError as e:
logging.warning("Creating UID mapping into container failed: %s", e)
try:
util.write_file("deny", proc_child, "setgroups")
except OSError as e:
# Not all systems have this file (depends on the kernel version),
# but if it does not exist, we do not need to write to it.
if e.errno != errno.ENOENT:
logging.warning("Could not write to setgroups file in /proc: %s", e)
try:
# map gid internally to our gid externally
gid_map = "{0} {1} 1".format(gid, parent_gid)
util.write_file(gid_map, proc_child, "gid_map")
except OSError as e:
logging.warning("Creating GID mapping into container failed: %s", e)
示例15: _handle_exception
# 需要导入模块: import sys [as 别名]
# 或者: from sys import html [as 别名]
def _handle_exception():
"""Print exceptions raised by subscribers to stderr."""
# Heavily influenced by logging.Handler.handleError.
# See note here:
# https://docs.python.org/3.4/library/sys.html#sys.__stderr__
if sys.stderr:
einfo = sys.exc_info()
try:
traceback.print_exception(einfo[0], einfo[1], einfo[2],
None, sys.stderr)
except IOError:
pass
finally:
del einfo