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


Python URL.path_segments方法代码示例

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


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

示例1: Segments

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import path_segments [as 别名]
class Segments(object):
    def __init__(self, base, path, segments, defaults):
        self.base = PURL(base, path=path)
        self.segments = OrderedDict(zip(segments, defaults))

    def build(self):
        segments = self.base.path_segments() + tuple(self.segments.values())
        url = self.base.path_segments(segments)
        return url

    def __str__(self):
        return self.build().as_string()

    def _get_segment(self, segment):
        return self.segments[segment]

    def _set_segment(self, segment, value):
        self.segments[segment] = value

    @classmethod
    def _segment(cls, segment):
        return property(
                fget=lambda x: cls._get_segment(x, segment),
                fset=lambda x, v: cls._set_segment(x, segment, v),
                )
开发者ID:wcmckee,项目名称:pyatakl,代码行数:27,代码来源:utils.py

示例2: info

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import path_segments [as 别名]
    def info(self, url):
        """Interface method to be called when processing new images.

        This method ties together the DataProvider workflow.
        """
        url = URL(url)
        return self.postprocess(
            self.info_for_id(self.id_from_url(url, url.host(), url.path_segments())))
开发者ID:afehn,项目名称:tsammalex-data,代码行数:10,代码来源:image_providers.py

示例3: cached_path

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import path_segments [as 别名]
def cached_path(args, url, rel):
    if url.startswith('/'):
        return url
    url_ = URL(url)
    cached = args.data_file('edmond', url_.path_segments()[-1])
    if not cached.exists():
        fname, headers = urlretrieve(url, '%s' % cached)
    return str(cached)
开发者ID:afehn,项目名称:tsammalex,代码行数:10,代码来源:create_downloads.py

示例4: Segments

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import path_segments [as 别名]
class Segments(object):
    """
    URL segment handler, not intended for direct use. The URL is constructed by
    joining base, path and segments.
    """
    def __init__(self, base, path, segments, defaults):
        # Preserve the base URL
        self.base = PURL(base, path=path)
        # Map the segments and defaults lists to an ordered dict
        self.segments = OrderedDict(zip(segments, defaults))

    def build(self):
        # Join base segments and segments
        segments = self.base.path_segments() + tuple(self.segments.values())

        # Create a new URL with the segments replaced
        url = self.base.path_segments(segments)
        return url

    def full_path(self):
        full_path = self.build().as_string()
        full_path = full_path.replace(self.base.host(), '')
        full_path = full_path.replace(self.base.scheme(), '')
        return full_path[4:]

    def __str__(self):
        return self.build().as_string()

    def _get_segment(self, segment):
        return self.segments[segment]

    def _set_segment(self, segment, value):
        self.segments[segment] = value

    @classmethod
    def _segment(cls, segment):
        """
        Returns a property capable of setting and getting a segment.
        """
        return property(
            fget=lambda x: cls._get_segment(x, segment),
            fset=lambda x, v: cls._set_segment(x, segment, v),
        )
开发者ID:dr4ke616,项目名称:LazyTorrent,代码行数:45,代码来源:utils.py

示例5: get_links

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import path_segments [as 别名]
def get_links(instr):
    """
    Given a link-value, generate individual links as dict.
    """
    if instr:
        for link in [h.strip() for h in link_splitter.findall(instr)]:
            url, params = link.split(">", 1)
            url = URL(url[1:])
            fname = url.path_segments()[-1] if url.path_segments() else ''
            info = {
                'url': url.as_string(),
                'ext': fname.split('.', 1)[1] if '.' in fname else None,
                'rel': 'related',
                'type': 'application/octet-stream'}
            for param in _splitstring(params, PARAMETER, "\s*;\s*"):
                try:
                    a, v = param.split("=", 1)
                    info[a.lower()] = _unquotestring(v)
                except ValueError:  # pragma: no cover
                    info[param.lower()] = None
            yield info
开发者ID:LinguList,项目名称:clldclient,代码行数:23,代码来源:link_header.py

示例6: get

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import path_segments [as 别名]
 def get(self, url, **kw):
     url = URL(url)
     content = get_resource(
         url.path_segment(-1) if url.path_segments() else 'dataset', self.prefix)
     if content:
         return MagicMock(
             mimetype='application/rdf+xml',
             content=content,
             links=[dict(
                 url='{0}.html'.format(url.as_string),
                 ext='.html',
                 rel='alternate',
                 type='text/html')],
             canonical_url=url.as_string())
开发者ID:LinguList,项目名称:clldclient,代码行数:16,代码来源:util.py

示例7: __call__

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import path_segments [as 别名]
    def __call__(self, index, row):
        if index == 0:
            self.cols = {col: i for i, col in enumerate(row)}
            return row

        url = URL(row[self.cols['src']])
        try:
            for filename in url.path_segments():
                if filename in self.md:
                    if self.md[filename].get('source_url'):
                        row[self.cols['source']] = self.md[filename]['source_url']
                        self.count += 1
                        break
        except IndexError:
            pass
        return row
开发者ID:afehn,项目名称:tsammalex-data,代码行数:18,代码来源:add_source_url.py

示例8: url_parts

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import path_segments [as 别名]
 def url_parts(self, url):
     url = URL(url)
     return url, url.host(), url.path_segments()
开发者ID:clld,项目名称:tsammalex-data,代码行数:5,代码来源:base.py

示例9: get_image_info

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import path_segments [as 别名]
def get_image_info(img):
    for field in ['source', 'source_url', 'id']:
        for provider in PROVIDERS:
            url = URL(img[field])
            if provider.id_from_url(url, url.host(), url.path_segments()):
                return provider.info(img[field])
开发者ID:afehn,项目名称:tsammalex-data,代码行数:8,代码来源:image_providers.py


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