python类pathname2url()的实例源码

common_imports.py 文件源码 项目:tichu-tournament 作者: aragos 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def path2url(path):
    return urlparse.urljoin(
        'file:', pathname2url(path))
url.py 文件源码 项目:LSP 作者: tomv564 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def filename_to_uri(path: str) -> str:
    return urljoin('file:', pathname2url(path))
util.py 文件源码 项目:rowgenerators 作者: Metatab 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def path2url(path):
    "Convert a pathname to a file URL"

    from urllib.parse import urljoin
    from urllib.request import pathname2url


    return urljoin('file:', pathname2url(path))
audio_gstplayer_modified.py 文件源码 项目:mmplayer 作者: Bakterija 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def load(self, uri):
        self.unload()

        if not uri:
            return
        if not '://' in uri:
            uri = 'file:' + pathname2url(realpath(uri))

        self.player = GstPlayer(uri, None, self._on_gst_eos_sync,
                                _on_gstplayer_message)
        self.player.load()
        return self
whatstyle.py 文件源码 项目:whatstyle 作者: mikr 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def show_diffs(formatter,          # type: CodeFormatter
               filenames,          # type: List[str]
               style,              # type: Style
               ansi,               # type: bool
               ansihtml,           # type: bool
               html,               # type: bool
               nopager,            # type: bool
               numlines,           # type: int
               wrapcolumn=0,       # type: int
               linenumbers=False,  # type: bool
               enc='utf-8'         # type: str
               ):
    # type: (...) -> None
    """Show the differences between the current and reformatted sources.
    """
    if not ansi and not html:
        if supports_color():
            ansi = True
        else:
            html = True
    pairs = []
    for filename in filenames:
        sourcedata = get_cached_file(filename)
        content = formatter.formatcode(style, sourcedata, filename=filename)
        pairs.append((sourcedata, content))

    unifilenames = '\n'.join([unifilename(f) for f in filenames]) + '\n'
    htmldiffer = HtmlMultiDiff(tabsize=4, wrapcolumn=wrapcolumn)
    table = htmldiffer.table_from_pairs(pairs,
                                        enc,
                                        fromdesc='',
                                        todesc='',
                                        context=True,
                                        numlines=numlines)
    headerhtml = '<pre>\n' + unifilenames + '</pre>'
    customhtml = make_custom_html(htmldiffer, headerhtml, [table], enc=enc)
    htmldata = unescape_ill_surrencode(customhtml, enc=enc)
    htmldata = translate_non_sgml_chars(htmldata, enc=enc)
    headerdata = yellow(unifilenames)
    if html or ansihtml:
        if ansihtml:
            htmldata = html2ansihtml(
                surrdecode(htmldata, enc=enc),
                header=headerdata,
                enc=enc,
                linenumbers=linenumbers)
        fd, tempname = tempfile.mkstemp(suffix='.html', prefix='whatstyle_')
        os.write(fd, htmldata)
        os.close(fd)
        url = urljoin('file:', pathname2url(tempname))
        webbrowser.open(url)
    elif ansi:
        with pagercontext(not nopager) as fp:
            outline(headerdata, fp=fp)
            htmldiff2ansi(customhtml, enc, linenumbers=linenumbers, fp=fp)
__init__.py 文件源码 项目:segno 作者: heuer 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def show(self, delete_after=20, scale=10, border=None, color='#000',
             background='#fff'):  # pragma: no cover
        """\
        Displays this QR code.

        This method is mainly intended for debugging purposes.

        This method saves the output of the :py:meth:`png` method (by default
        with a scaling factor of 10) to a temporary file and opens it with the
        standard PNG viewer application or within the standard webbrowser.
        The temporary file is deleted afterwards (unless `delete_after` is set
        to ``None``).

        If this method does not show any result, try to increase the
        `delete_after` value or set it to ``None``

        :param delete_after: Time in seconds to wait till the temporary file is
                deleted.
        """
        import os
        import time
        import tempfile
        import webbrowser
        import threading
        try:  # Python 2
            from urlparse import urljoin
            from urllib import pathname2url
        except ImportError:  # Python 3
            from urllib.parse import urljoin
            from urllib.request import pathname2url

        def delete_file(name):
            time.sleep(delete_after)
            try:
                os.unlink(name)
            except OSError:
                pass

        f = tempfile.NamedTemporaryFile('wb', suffix='.png', delete=False)
        try:
            self.save(f, scale=scale, color=color, background=background,
                      border=border)
        except:
            f.close()
            os.unlink(f.name)
            raise
        f.close()
        webbrowser.open_new_tab(urljoin('file:', pathname2url(f.name)))
        if delete_after is not None:
            t = threading.Thread(target=delete_file, args=(f.name,))
            t.start()
modulegraph.py 文件源码 项目:driveboardapp 作者: nortd 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def create_xref(self, out=None):
        global header, footer, entry, contpl, contpl_linked, imports
        if out is None:
            out = sys.stdout
        scripts = []
        mods = []
        for mod in self.flatten():
            name = os.path.basename(mod.identifier)
            if isinstance(mod, Script):
                scripts.append((name, mod))
            else:
                mods.append((name, mod))
        scripts.sort()
        mods.sort()
        scriptnames = [name for name, m in scripts]
        scripts.extend(mods)
        mods = scripts

        title = "modulegraph cross reference for "  + ', '.join(scriptnames)
        print(header % {"TITLE": title}, file=out)

        def sorted_namelist(mods):
            lst = [os.path.basename(mod.identifier) for mod in mods if mod]
            lst.sort()
            return lst
        for name, m in mods:
            content = ""
            if isinstance(m, BuiltinModule):
                content = contpl % {"NAME": name,
                                    "TYPE": "<i>(builtin module)</i>"}
            elif isinstance(m, Extension):
                content = contpl % {"NAME": name,\
                                    "TYPE": "<tt>%s</tt>" % m.filename}
            else:
                url = pathname2url(m.filename or "")
                content = contpl_linked % {"NAME": name, "URL": url,
                                           'TYPE': m.__class__.__name__}
            oute, ince = map(sorted_namelist, self.get_edges(m))
            if oute:
                links = ""
                for n in oute:
                    links += """  <a href="#%s">%s</a>\n""" % (n, n)
                content += imports % {"HEAD": "imports", "LINKS": links}
            if ince:
                links = ""
                for n in ince:
                    links += """  <a href="#%s">%s</a>\n""" % (n, n)
                content += imports % {"HEAD": "imported by", "LINKS": links}
            print(entry % {"NAME": name,"CONTENT": content}, file=out)
        print(footer, file=out)
modulegraph.py 文件源码 项目:mac-package-build 作者: persepolisdm 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def create_xref(self, out=None):
        global header, footer, entry, contpl, contpl_linked, imports
        if out is None:
            out = sys.stdout
        scripts = []
        mods = []
        for mod in self.flatten():
            name = os.path.basename(mod.identifier)
            if isinstance(mod, Script):
                scripts.append((name, mod))
            else:
                mods.append((name, mod))
        scripts.sort()
        mods.sort()
        scriptnames = [name for name, m in scripts]
        scripts.extend(mods)
        mods = scripts

        title = "modulegraph cross reference for "  + ', '.join(scriptnames)
        print(header % {"TITLE": title}, file=out)

        def sorted_namelist(mods):
            lst = [os.path.basename(mod.identifier) for mod in mods if mod]
            lst.sort()
            return lst
        for name, m in mods:
            content = ""
            if isinstance(m, BuiltinModule):
                content = contpl % {"NAME": name,
                                    "TYPE": "<i>(builtin module)</i>"}
            elif isinstance(m, Extension):
                content = contpl % {"NAME": name,\
                                    "TYPE": "<tt>%s</tt>" % m.filename}
            else:
                url = pathname2url(m.filename or "")
                content = contpl_linked % {"NAME": name, "URL": url,
                                           'TYPE': m.__class__.__name__}
            oute, ince = map(sorted_namelist, self.get_edges(m))
            if oute:
                links = ""
                for n in oute:
                    links += """  <a href="#%s">%s</a>\n""" % (n, n)
                content += imports % {"HEAD": "imports", "LINKS": links}
            if ince:
                links = ""
                for n in ince:
                    links += """  <a href="#%s">%s</a>\n""" % (n, n)
                content += imports % {"HEAD": "imported by", "LINKS": links}
            print(entry % {"NAME": name,"CONTENT": content}, file=out)
        print(footer, file=out)


问题


面经


文章

微信
公众号

扫码关注公众号