當前位置: 首頁>>代碼示例>>Python>>正文


Python sys.html方法代碼示例

本文整理匯總了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 
開發者ID:SylvainDe,項目名稱:DidYouMean-Python,代碼行數:23,代碼來源:didyoumean_internal.py

示例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 
開發者ID:iTaybb,項目名稱:pySmartDL,代碼行數:24,代碼來源:pySmartDL.py

示例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 
開發者ID:jpush,項目名稱:jbox,代碼行數:23,代碼來源:base.py

示例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) 
開發者ID:sosy-lab,項目名稱:benchexec,代碼行數:18,代碼來源:container.py

示例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(). 
開發者ID:leancloud,項目名稱:satori,代碼行數:21,代碼來源:monitoring.py

示例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 
開發者ID:KanoComputing,項目名稱:kano-burners,代碼行數:24,代碼來源:pySmartDL.py

示例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() 
開發者ID:eonpatapon,項目名稱:contrail-api-cli,代碼行數:26,代碼來源:utils.py

示例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"),
        ) 
開發者ID:elastic,項目名稱:apm-agent-python,代碼行數:20,代碼來源:logbook.py

示例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)) 
開發者ID:RobertoPrevato,項目名稱:BlackSheep,代碼行數:18,代碼來源:controllers.py

示例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)) 
開發者ID:RobertoPrevato,項目名稱:BlackSheep,代碼行數:18,代碼來源:controllers.py

示例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 
開發者ID:conda,項目名稱:cookiecutter-conda-python,代碼行數:22,代碼來源:cli.py

示例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 
開發者ID:qutebrowser,項目名稱:qutebrowser,代碼行數:30,代碼來源:earlyinit.py

示例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() 
開發者ID:iTaybb,項目名稱:pySmartDL,代碼行數:15,代碼來源:pySmartDL.py

示例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) 
開發者ID:sosy-lab,項目名稱:benchexec,代碼行數:41,代碼來源:container.py

示例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 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:17,代碼來源:helpers.py


注:本文中的sys.html方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。