当前位置: 首页>>代码示例>>Python>>正文


Python request.url2pathname方法代码示例

本文整理汇总了Python中urllib.request.url2pathname方法的典型用法代码示例。如果您正苦于以下问题:Python request.url2pathname方法的具体用法?Python request.url2pathname怎么用?Python request.url2pathname使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在urllib.request的用法示例。


在下文中一共展示了request.url2pathname方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_logs_for_status

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url2pathname [as 别名]
def test_logs_for_status(bep_file, status):
    targets = []
    with open(bep_file, encoding="utf-8") as f:
        raw_data = f.read()
    decoder = json.JSONDecoder()

    pos = 0
    while pos < len(raw_data):
        try:
            bep_obj, size = decoder.raw_decode(raw_data[pos:])
        except ValueError as e:
            eprint("JSON decoding error: " + str(e))
            return targets
        if "testSummary" in bep_obj:
            test_target = bep_obj["id"]["testSummary"]["label"]
            test_status = bep_obj["testSummary"]["overallStatus"]
            if test_status in status:
                outputs = bep_obj["testSummary"]["failed"]
                test_logs = []
                for output in outputs:
                    test_logs.append(url2pathname(urlparse(output["uri"]).path))
                targets.append((test_target, test_logs))
        pos += size + 1
    return targets 
开发者ID:bazelbuild,项目名称:continuous-integration,代码行数:26,代码来源:bazelci.py

示例2: playAction

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url2pathname [as 别名]
def playAction(cls, action):
        if not cls.useSounds:
            return

        if isinstance(action, str):
            key_no = cls.actionToKeyNo[action]
        else:
            key_no = action
        typ = cls.soundcombo[key_no]
        if typ == SOUND_BEEP:
            sys.stdout.write("\a")
            sys.stdout.flush()
        elif typ == SOUND_URI:
            uri = cls.sounduri[key_no]
            if not os.path.isfile(url2pathname(uri[5:])):
                conf.set("soundcombo%d" % key_no, SOUND_MUTE)
                return
            cls.getPlayer().play(uri) 
开发者ID:pychess,项目名称:pychess,代码行数:20,代码来源:preferencesDialog.py

示例3: get_partial_names_for_template

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url2pathname [as 别名]
def get_partial_names_for_template(template=None, get_all=True, requested_partials=None):
    template = template or settings.DJANGOCMS_SPA_DEFAULT_TEMPLATE

    if requested_partials:
        # Transform the requested partials into a list
        requested_partials = url2pathname(requested_partials).split(',')
    else:
        requested_partials = []

    try:
        partials = settings.DJANGOCMS_SPA_TEMPLATES[template]['partials']
    except KeyError:
        try:
            default_template_path = settings.DJANGOCMS_SPA_DEFAULT_TEMPLATE
            partials = settings.DJANGOCMS_SPA_TEMPLATES[default_template_path]['partials']
        except KeyError:
            partials = []

    if get_all:
        return partials
    else:
        return [partial for partial in partials if partial in requested_partials] 
开发者ID:dreipol,项目名称:djangocms-spa,代码行数:24,代码来源:content_helpers.py

示例4: file_path

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url2pathname [as 别名]
def file_path(self, url):
        """Return the relative path to the file on disk for the given URL."""
        relative_url = url[len(self.base_url[2]):]
        return url2pathname(relative_url) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:6,代码来源:testcases.py

示例5: file_path

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url2pathname [as 别名]
def file_path(self, url):
        """
        Return the relative path to the media file on disk for the given URL.
        """
        relative_url = url[len(self.base_url[2]):]
        return url2pathname(relative_url) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:8,代码来源:handlers.py

示例6: play

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url2pathname [as 别名]
def play(self, uri):
            try:
                winsound.PlaySound(None, 0)
                winsound.PlaySound(
                    url2pathname(uri[5:]), winsound.SND_FILENAME | winsound.SND_ASYNC)
            except RuntimeError:
                log.error("ERROR: RuntimeError while playing %s." %
                          url2pathname(uri[5:])) 
开发者ID:pychess,项目名称:pychess,代码行数:10,代码来源:gstreamer.py

示例7: on_recent_game_activated

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url2pathname [as 别名]
def on_recent_game_activated(self, uri):
        if isinstance(uri, str):
            path = url2pathname(uri)
            recent_manager.add_item("file:" + pathname2url(path))

    # Drag 'n' Drop 
开发者ID:pychess,项目名称:pychess,代码行数:8,代码来源:Main.py

示例8: update_recent

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url2pathname [as 别名]
def update_recent(self, gamemodel, uri):
        if isinstance(uri, str):
            path = url2pathname(uri)
            recent_manager.add_item("file:" + pathname2url(path)) 
开发者ID:pychess,项目名称:pychess,代码行数:6,代码来源:Main.py

示例9: s3_open

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url2pathname [as 别名]
def s3_open(self, req):
        # The implementation was inspired mainly by the code behind
        # urllib.request.FileHandler.file_open().

        bucket_name = req.host
        key_name = url2pathname(req.selector)[1:]

        if not bucket_name or not key_name:
            raise URLError('url must be in the format s3://<bucket>/<key>')

        try:
            conn = self._conn
        except AttributeError:
            conn = self._conn = boto.s3.connection.S3Connection()

        bucket = conn.get_bucket(bucket_name, validate=False)
        key = bucket.get_key(key_name)

        origurl = 's3://{}/{}'.format(bucket_name, key_name)

        if key is None:
            raise URLError('no such resource: {}'.format(origurl))

        headers = [
            ('Content-type', key.content_type),
            ('Content-encoding', key.content_encoding),
            ('Content-language', key.content_language),
            ('Content-length', key.size),
            ('Etag', key.etag),
            ('Last-modified', key.last_modified),
        ]

        headers = email.message_from_string(
            '\n'.join('{}: {}'.format(key, value) for key, value in headers
                      if value is not None))

        return addinfourl(_FileLikeKey(key), headers, origurl) 
开发者ID:ActiveState,项目名称:code,代码行数:39,代码来源:recipe-578957.py

示例10: uri_to_filename

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url2pathname [as 别名]
def uri_to_filename(uri: str) -> str:
    if os.name == 'nt':
        # url2pathname does not understand %3A (VS Code's encoding forced on all servers :/)
        return url2pathname(urlparse(uri).path).strip('\\')
    else:
        return url2pathname(urlparse(uri).path) 
开发者ID:sublimelsp,项目名称:LSP,代码行数:8,代码来源:url.py

示例11: url2path

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url2pathname [as 别名]
def url2path(path):
    """Path to URL."""

    return url2pathname(path) 
开发者ID:V1EngineeringInc,项目名称:V1EngineeringInc-Docs,代码行数:6,代码来源:util.py

示例12: nativejoin

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url2pathname [as 别名]
def nativejoin(base, path):
    """
    Joins two paths - returning a native file path.

    Given a base path and a relative location, (in posix format)
    return a file path in a (relatively) OS native way.
    """
    return url2pathname(pathjoin(base, path)) 
开发者ID:amir-zeldes,项目名称:rstWeb,代码行数:10,代码来源:urlpath.py

示例13: s3_open

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url2pathname [as 别名]
def s3_open(self, req):
        # The implementation was inspired mainly by the code behind
        # urllib.request.FileHandler.file_open().
        #
        # recipe copied from:
        # http://code.activestate.com/recipes/578957-urllib-handler-for-amazon-s3-buckets/
        # converted to boto3

        if version_info[0] < 3:
            bucket_name = req.get_host()
            key_name = url2pathname(req.get_selector())[1:]
        else:
            bucket_name = req.host
            key_name = url2pathname(req.selector)[1:]

        if not bucket_name or not key_name:
            raise URLError('url must be in the format s3://<bucket>/<key>')

        s3 = boto3.resource('s3')

        key = s3.Object(bucket_name, key_name)

        client = boto3.client('s3')
        obj = client.get_object(Bucket=bucket_name, Key=key_name)
        filelike = _FileLikeKey(obj['Body'])

        origurl = 's3://{}/{}'.format(bucket_name, key_name)

        if key is None:
            raise URLError('no such resource: {}'.format(origurl))

        headers = [
            ('Content-type', key.content_type),
            ('Content-encoding', key.content_encoding),
            ('Content-language', key.content_language),
            ('Content-length', key.content_length),
            ('Etag', key.e_tag),
            ('Last-modified', key.last_modified),
        ]

        headers = email.message_from_string(
            '\n'.join('{}: {}'.format(key, value) for key, value in headers
                      if value is not None))
        return addinfourl(filelike, headers, origurl) 
开发者ID:lunardog,项目名称:kelner,代码行数:46,代码来源:utils.py

示例14: process_single_item

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url2pathname [as 别名]
def process_single_item(
    item: Union[bytes, str],
    args: IcatCLIOptions,
    parsed_opts: ParsedOpts,
    url_pat: Optional[Pattern] = None,
    maybe_dir: bool = True
) -> None:
    is_tempfile = False
    file_removed = False
    try:
        if isinstance(item, bytes):
            tf = NamedTemporaryFile(prefix='stdin-image-data-', delete=False)
            tf.write(item), tf.close()
            item = tf.name
            is_tempfile = True
        if url_pat is not None and url_pat.match(item) is not None:
            from urllib.request import urlretrieve
            with NamedTemporaryFile(prefix='url-image-data-', delete=False) as tf:
                try:
                    with socket_timeout(30):
                        urlretrieve(item, filename=tf.name)
                except Exception as e:
                    raise SystemExit('Failed to download image at URL: {} with error: {}'.format(item, e))
                item = tf.name
            is_tempfile = True
            file_removed = process(item, args, parsed_opts, is_tempfile)
        elif item.lower().startswith('file://'):
            from urllib.parse import urlparse
            from urllib.request import url2pathname
            pitem = urlparse(item)
            if os.sep == '\\':
                item = pitem.netloc + pitem.path
            else:
                item = pitem.path
            item = url2pathname(item)
            file_removed = process(item, args, parsed_opts, is_tempfile)
        else:
            if maybe_dir and os.path.isdir(item):
                for (x, mt) in scan(item):
                    process_single_item(x, args, parsed_opts, url_pat=None, maybe_dir=False)
            else:
                file_removed = process(item, args, parsed_opts, is_tempfile)
    finally:
        if is_tempfile and not file_removed:
            os.remove(item) 
开发者ID:kovidgoyal,项目名称:kitty,代码行数:47,代码来源:main.py


注:本文中的urllib.request.url2pathname方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。