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


Python warnings.py方法代碼示例

本文整理匯總了Python中warnings.py方法的典型用法代碼示例。如果您正苦於以下問題:Python warnings.py方法的具體用法?Python warnings.py怎麽用?Python warnings.py使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在warnings的用法示例。


在下文中一共展示了warnings.py方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: monkeypatch_proxied_specials

# 需要導入模塊: import warnings [as 別名]
# 或者: from warnings import py [as 別名]
def monkeypatch_proxied_specials(into_cls, from_cls, skip=None, only=None,
                                 name='self.proxy', from_instance=None):
    """Automates delegation of __specials__ for a proxying type."""

    if only:
        dunders = only
    else:
        if skip is None:
            skip = ('__slots__', '__del__', '__getattribute__',
                    '__metaclass__', '__getstate__', '__setstate__')
        dunders = [m for m in dir(from_cls)
                   if (m.startswith('__') and m.endswith('__') and
                       not hasattr(into_cls, m) and m not in skip)]

    for method in dunders:
        try:
            fn = getattr(from_cls, method)
            if not hasattr(fn, '__call__'):
                continue
            fn = getattr(fn, 'im_func', fn)
        except AttributeError:
            continue
        try:
            spec = compat.inspect_getargspec(fn)
            fn_args = inspect.formatargspec(spec[0])
            d_args = inspect.formatargspec(spec[0][1:])
        except TypeError:
            fn_args = '(self, *args, **kw)'
            d_args = '(*args, **kw)'

        py = ("def %(method)s%(fn_args)s: "
              "return %(name)s.%(method)s%(d_args)s" % locals())

        env = from_instance is not None and {name: from_instance} or {}
        compat.exec_(py, env)
        try:
            env[method].__defaults__ = fn.__defaults__
        except AttributeError:
            pass
        setattr(into_cls, method, env[method]) 
開發者ID:jpush,項目名稱:jbox,代碼行數:42,代碼來源:langhelpers.py

示例2: monkeypatch_proxied_specials

# 需要導入模塊: import warnings [as 別名]
# 或者: from warnings import py [as 別名]
def monkeypatch_proxied_specials(into_cls, from_cls, skip=None, only=None,
                                 name='self.proxy', from_instance=None):
    """Automates delegation of __specials__ for a proxying type."""

    if only:
        dunders = only
    else:
        if skip is None:
            skip = ('__slots__', '__del__', '__getattribute__',
                    '__metaclass__', '__getstate__', '__setstate__')
        dunders = [m for m in dir(from_cls)
                   if (m.startswith('__') and m.endswith('__') and
                       not hasattr(into_cls, m) and m not in skip)]

    for method in dunders:
        try:
            fn = getattr(from_cls, method)
            if not hasattr(fn, '__call__'):
                continue
            fn = getattr(fn, 'im_func', fn)
        except AttributeError:
            continue
        try:
            spec = compat.inspect_getargspec(fn)
            fn_args = compat.inspect_formatargspec(spec[0])
            d_args = compat.inspect_formatargspec(spec[0][1:])
        except TypeError:
            fn_args = '(self, *args, **kw)'
            d_args = '(*args, **kw)'

        py = ("def %(method)s%(fn_args)s: "
              "return %(name)s.%(method)s%(d_args)s" % locals())

        env = from_instance is not None and {name: from_instance} or {}
        compat.exec_(py, env)
        try:
            env[method].__defaults__ = fn.__defaults__
        except AttributeError:
            pass
        setattr(into_cls, method, env[method]) 
開發者ID:bkerler,項目名稱:android_universal,代碼行數:42,代碼來源:langhelpers.py

示例3: warning

# 需要導入模塊: import warnings [as 別名]
# 或者: from warnings import py [as 別名]
def warning(message):
    # We disable caching of this helper so it can be used multiple times.
    # https://github.com/python/cpython/blob/9a4758550d96030ee7e7f7c7c68b435db1a2a825/Lib/warnings.py#L362
    with warnings.catch_warnings():
        warnings.warn(message, stacklevel=2) 
開發者ID:DataDog,項目名稱:integrations-core,代碼行數:7,代碼來源:warn.py

示例4: _formatwarning

# 需要導入模塊: import warnings [as 別名]
# 或者: from warnings import py [as 別名]
def _formatwarning(message, category, filename, lineno, line=None):
    # Shorten output for occurrences during E2E to just what is necessary for a nice display.
    if e2e_active():
        return '{}\n'.format(message)

    return _original_formatwarning(message, category, filename, lineno, line=line)


# We can't override `showwarning` as usual because pytest already overrides that for logs.
# https://github.com/pytest-dev/pytest/blob/b76104e722f41ce367765cd988ee8314d45b20b5/src/_pytest/warnings.py#L75 
開發者ID:DataDog,項目名稱:integrations-core,代碼行數:12,代碼來源:warn.py

示例5: generate_dir_rst

# 需要導入模塊: import warnings [as 別名]
# 或者: from warnings import py [as 別名]
def generate_dir_rst(src_dir, target_dir, gallery_conf, seen_backrefs):
    """Generate the gallery reStructuredText for an example directory."""
    head_ref = os.path.relpath(target_dir, gallery_conf['src_dir'])
    fhindex = """\n\n.. _sphx_glr_{0}:\n\n""".format(
        head_ref.replace(os.path.sep, '_'))

    fname = _get_readme(src_dir, gallery_conf)
    with codecs.open(fname, 'r', encoding='utf-8') as fid:
        fhindex += fid.read()
    # Add empty lines to avoid bug in issue #165
    fhindex += "\n\n"

    if not os.path.exists(target_dir):
        os.makedirs(target_dir)
    # get filenames
    listdir = [fname for fname in os.listdir(src_dir)
               if fname.endswith('.py')]
    # limit which to look at based on regex (similar to filename_pattern)
    listdir = [fname for fname in listdir
               if re.search(gallery_conf['ignore_pattern'],
                            os.path.normpath(os.path.join(src_dir, fname)))
               is None]
    # sort them
    sorted_listdir = sorted(
        listdir, key=gallery_conf['within_subsection_order'](src_dir))
    entries_text = []
    costs = []
    build_target_dir = os.path.relpath(target_dir, gallery_conf['src_dir'])
    iterator = sphinx_compatibility.status_iterator(
        sorted_listdir,
        'generating gallery for %s... ' % build_target_dir,
        length=len(sorted_listdir))
    for fname in iterator:
        intro, title, cost = generate_file_rst(
            fname, target_dir, src_dir, gallery_conf, seen_backrefs)
        src_file = os.path.normpath(os.path.join(src_dir, fname))
        costs.append((cost, src_file))
        this_entry = _thumbnail_div(target_dir, gallery_conf['src_dir'],
                                    fname, intro, title) + """

.. toctree::
   :hidden:

   /%s\n""" % os.path.join(build_target_dir, fname[:-3]).replace(os.sep, '/')
        entries_text.append(this_entry)

    for entry_text in entries_text:
        fhindex += entry_text

    # clear at the end of the section
    fhindex += """.. raw:: html\n
    <div class="sphx-glr-clear"></div>\n\n"""

    return fhindex, costs 
開發者ID:sphinx-gallery,項目名稱:sphinx-gallery,代碼行數:56,代碼來源:gen_rst.py

示例6: save_rst_example

# 需要導入模塊: import warnings [as 別名]
# 或者: from warnings import py [as 別名]
def save_rst_example(example_rst, example_file, time_elapsed,
                     memory_used, gallery_conf):
    """Saves the rst notebook to example_file including header & footer

    Parameters
    ----------
    example_rst : str
        rst containing the executed file content
    example_file : str
        Filename with full path of python example file in documentation folder
    time_elapsed : float
        Time elapsed in seconds while executing file
    memory_used : float
        Additional memory used during the run.
    gallery_conf : dict
        Sphinx-Gallery configuration dictionary
    """

    ref_fname = os.path.relpath(example_file, gallery_conf['src_dir'])
    ref_fname = ref_fname.replace(os.path.sep, "_")

    binder_conf = check_binder_conf(gallery_conf.get('binder'))

    binder_text = (" or to run this example in your browser via Binder"
                   if len(binder_conf) else "")
    example_rst = (".. only:: html\n\n"
                   "    .. note::\n"
                   "        :class: sphx-glr-download-link-note\n\n"
                   "        Click :ref:`here <sphx_glr_download_{0}>` "
                   "    to download the full example code{1}\n"
                   "    .. rst-class:: sphx-glr-example-title\n\n"
                   "    .. _sphx_glr_{0}:\n\n"
                   ).format(ref_fname, binder_text) + example_rst

    if time_elapsed >= gallery_conf["min_reported_time"]:
        time_m, time_s = divmod(time_elapsed, 60)
        example_rst += TIMING_CONTENT.format(time_m, time_s)
    if gallery_conf['show_memory']:
        example_rst += ("**Estimated memory usage:** {0: .0f} MB\n\n"
                        .format(memory_used))

    # Generate a binder URL if specified
    binder_badge_rst = ''
    if len(binder_conf) > 0:
        binder_badge_rst += gen_binder_rst(example_file, binder_conf,
                                           gallery_conf)

    fname = os.path.basename(example_file)
    example_rst += CODE_DOWNLOAD.format(fname,
                                        replace_py_ipynb(fname),
                                        binder_badge_rst,
                                        ref_fname)
    example_rst += SPHX_GLR_SIG

    write_file_new = re.sub(r'\.py$', '.rst.new', example_file)
    with codecs.open(write_file_new, 'w', encoding="utf-8") as f:
        f.write(example_rst)
    # in case it wasn't in our pattern, only replace the file if it's
    # still stale.
    _replace_md5(write_file_new) 
開發者ID:sphinx-gallery,項目名稱:sphinx-gallery,代碼行數:62,代碼來源:gen_rst.py

示例7: monkeypatch_proxied_specials

# 需要導入模塊: import warnings [as 別名]
# 或者: from warnings import py [as 別名]
def monkeypatch_proxied_specials(
    into_cls,
    from_cls,
    skip=None,
    only=None,
    name="self.proxy",
    from_instance=None,
):
    """Automates delegation of __specials__ for a proxying type."""

    if only:
        dunders = only
    else:
        if skip is None:
            skip = (
                "__slots__",
                "__del__",
                "__getattribute__",
                "__metaclass__",
                "__getstate__",
                "__setstate__",
            )
        dunders = [
            m
            for m in dir(from_cls)
            if (
                m.startswith("__")
                and m.endswith("__")
                and not hasattr(into_cls, m)
                and m not in skip
            )
        ]

    for method in dunders:
        try:
            fn = getattr(from_cls, method)
            if not hasattr(fn, "__call__"):
                continue
            fn = getattr(fn, "im_func", fn)
        except AttributeError:
            continue
        try:
            spec = compat.inspect_getfullargspec(fn)
            fn_args = compat.inspect_formatargspec(spec[0])
            d_args = compat.inspect_formatargspec(spec[0][1:])
        except TypeError:
            fn_args = "(self, *args, **kw)"
            d_args = "(*args, **kw)"

        py = (
            "def %(method)s%(fn_args)s: "
            "return %(name)s.%(method)s%(d_args)s" % locals()
        )

        env = from_instance is not None and {name: from_instance} or {}
        compat.exec_(py, env)
        try:
            env[method].__defaults__ = fn.__defaults__
        except AttributeError:
            pass
        setattr(into_cls, method, env[method]) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:63,代碼來源:langhelpers.py


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