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


Python URL.host方法代码示例

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


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

示例1: url

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import host [as 别名]
 def url(self, path='/', **query):
     url = URL(path)
     if not url.host():
         url = url.host(self.host)
     if not url.scheme():
         url = url.scheme('http')
     for k, v in query.items():
         url = url.query_param(k, v)
     return url
开发者ID:LinguList,项目名称:clldclient,代码行数:11,代码来源:database.py

示例2: get_bib

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import host [as 别名]
def get_bib(args):
    uploaded = load(args.data_file('repos', 'cdstar.json'))
    fname_to_cdstar = {}
    for type_ in ['texts', 'docs', 'data']:
        for hash_, paths in load(args.data_file('repos', type_ + '.json')).items():
            if hash_ in uploaded:
                for path in paths:
                    fname_to_cdstar[path.split('/')[-1]] = uploaded[hash_]
    for hash_, paths in load(args.data_file('repos', 'edmond.json')).items():
        if hash_ in uploaded:
            for path in paths:
                fname_to_cdstar[path.split('/')[-1]] = uploaded[hash_]
    db = Database.from_file(args.data_file('repos', 'Dogon.bib'), lowercase=True)
    for rec in db:
        doc = Document(rec)
        newurls = []
        for url in rec.get('url', '').split(';'):
            if not url.strip():
                continue
            if url.endswith('sequence=1'):
                newurls.append(url)
                continue
            url = URL(url.strip())
            if url.host() in ['dogonlanguages.org', 'github.com', '']:
                fname = url.path().split('/')[-1]
                doc.files.append((fname, fname_to_cdstar[fname]))
            else:
                newurls.append(url.as_string())
        doc.rec['url'] = '; '.join(newurls)
        yield doc
开发者ID:clld,项目名称:dogonlanguages,代码行数:32,代码来源:util.py

示例3: cc_link

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import host [as 别名]
def cc_link(req, license_url, button='regular'):
    if license_url == 'https://en.wikipedia.org/wiki/Public_domain':
        license_url = 'https://creativecommons.org/publicdomain/zero/1.0/'
    license_url = URL(license_url)
    if license_url.host() != 'creativecommons.org':
        return

    comps = license_url.path().split('/')
    if len(comps) < 3:
        return  # pragma: no cover

    known = {
        'zero': 'Public Domain',
        'by': 'Creative Commons Attribution License',
        'by-nc': 'Creative Commons Attribution-NonCommercial License',
        'by-nc-nd': 'Creative Commons Attribution-NonCommercial-NoDerivatives License',
        'by-nc-sa': 'Creative Commons Attribution-NonCommercial-ShareAlike License',
        'by-nd': 'Creative Commons Attribution-NoDerivatives License',
        'by-sa': 'Creative Commons Attribution-ShareAlike License'}
    if comps[2] not in known:
        return

    icon = 'cc-' + comps[2] + ('-small' if button == 'small' else '') + '.png'
    img_attrs = dict(
        alt=known[comps[2]],
        src=req.static_url('clld:web/static/images/' + icon))
    height, width = (15, 80) if button == 'small' else (30, 86)
    img_attrs.update(height=height, width=width)
    return HTML.a(HTML.img(**img_attrs), href=license_url, rel='license')
开发者ID:clld,项目名称:clld,代码行数:31,代码来源:helpers.py

示例4: cc_link

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import host [as 别名]
def cc_link(req, license_url, button="regular"):
    if license_url == "http://en.wikipedia.org/wiki/Public_domain":
        license_url = "http://creativecommons.org/publicdomain/zero/1.0/"
    license_url = URL(license_url)
    if license_url.host() != "creativecommons.org":
        return

    comps = license_url.path().split("/")
    if len(comps) < 3:
        return  # pragma: no cover

    known = {
        "zero": "Public Domain",
        "by": "Creative Commons Attribution License",
        "by-nc": "Creative Commons Attribution-NonCommercial License",
        "by-nc-nd": "Creative Commons Attribution-NonCommercial-NoDerivatives License",
        "by-nc-sa": "Creative Commons Attribution-NonCommercial-ShareAlike License",
        "by-nd": "Creative Commons Attribution-NoDerivatives License",
        "by-sa": "Creative Commons Attribution-ShareAlike License",
    }
    if comps[2] not in known:
        return

    icon = "cc-" + comps[2] + ("-small" if button == "small" else "") + ".png"
    img_attrs = dict(alt=known[comps[2]], src=req.static_url("clld:web/static/images/" + icon))
    height, width = (15, 80) if button == "small" else (30, 86)
    img_attrs.update(height=height, width=width)
    return HTML.a(HTML.img(**img_attrs), href=license_url, rel="license")
开发者ID:cevmartinez,项目名称:clld,代码行数:30,代码来源:helpers.py

示例5: __init__

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import host [as 别名]
    def __init__(self, url, save_dir='tmp'):
        """
        @url: full url of a site
        @save_dir: dir to save site
        """
        # log
        self.logger = logger('file', 'sitelog.log', save_dir)
        self.logger.info('-' * 20)
        self.logger.info('start')
        self.logger.info('start func: __init__')
        self.logger.info('url: %s' % url)

        save_time = datetime.strftime(datetime.now(), '%Y%m%d%H%M')
        self.save_time = save_time
        self.save_dir = os.path.abspath(os.path.join(save_dir, save_time))
        # create dir if not exist
        if not os.path.isdir(self.save_dir):
            os.makedirs(self.save_dir)

        self.url = url
        u = URL(url)
        # get host like: http://m.sohu.xom
        self.host = u.scheme() + '://' + u.host()
        print '%s: saving %s' % (save_time, self.url)
        self.logger.info('end func: __init__')
开发者ID:basicworld,项目名称:sitedownloader,代码行数:27,代码来源:main.py

示例6: info

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import host [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

示例7: maybe_license_link

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import host [as 别名]
def maybe_license_link(req, license, **kw):
    cc_link_ = cc_link(req, license, button=kw.pop('button', 'regular'))
    if cc_link_:
        return cc_link_
    license_url = URL(license)
    if license_url.host():
        return external_link(license_url, **kw)
    return license
开发者ID:clld,项目名称:clld,代码行数:10,代码来源:helpers.py

示例8: get_video_id_from_url

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import host [as 别名]
    def get_video_id_from_url(self, video_url):
        video_url = URL(video_url)

        if 'youtube' not in video_url.host():
            raise DownytError(
                'Provided URL is not from YouTube: {}'.format(video_url)
            )

        return video_url.query_param('v')
开发者ID:sesh,项目名称:downyt,代码行数:11,代码来源:cli.py

示例9: blog_feed

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import host [as 别名]
def blog_feed(request):
    """
    Proxy feeds from the blog, so they can be accessed via XHR requests.

    We also convert RSS to ATOM so that clld's javascript Feed component can read them.
    """
    if not request.params.get('path'):
        raise HTTPNotFound()
    path = URL(request.params['path'])
    assert not path.host()
    try:
        return atom_feed(request, request.blog.url(path.as_string()))
    except ConnectionError:
        raise HTTPNotFound()
开发者ID:clld,项目名称:wals3,代码行数:16,代码来源:views.py

示例10: license_name

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import host [as 别名]
def license_name(license_url):
    if license_url == "http://commons.wikimedia.org/wiki/GNU_Free_Documentation_License":
        return 'GNU Free Documentation License'
    if license_url == 'http://en.wikipedia.org/wiki/Public_domain':
        license_url = 'http://creativecommons.org/publicdomain/zero/1.0/'
    license_url_ = URL(license_url)
    if license_url_.host() != 'creativecommons.org':
        return license_url

    comps = license_url_.path().split('/')
    if len(comps) < 3:
        return license_url

    return {
        'zero': 'Public Domain',
    }.get(comps[2], '(CC) %s' % comps[2].upper())
开发者ID:afehn,项目名称:tsammalex,代码行数:18,代码来源:util.py

示例11: Segments

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import host [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

示例12: main

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import host [as 别名]
def main(args):
    if DBSession.bind.dialect.name == 'postgresql':
        Index('ducet', collkey(common.Value.name)).create(DBSession.bind)

    def data_file(*comps):
        return Path(args.data_repos).joinpath('tsammalexdata', 'data', *comps)

    data = Data()
    data.add(
        common.Dataset,
        'tsammalex',
        id="tsammalex",
        name="Tsammalex",
        description="Tsammalex: A lexical database on plants and animals",
        publisher_name="Max Planck Institute for the Science of Human History",
        publisher_place="Jena",
        publisher_url="http://www.shh.mpg.de",
        domain='tsammalex.clld.org',
        license='http://creativecommons.org/licenses/by/4.0/',
        contact='[email protected]',
        jsondata={
            'license_icon': 'cc-by.png',
            'license_name': 'Creative Commons Attribution 4.0 International License'})
    data.add(common.Contribution, 'tsammalex', name="Tsammalex", id="tsammalex")

    for rec in Database.from_file(data_file('sources.bib'), lowercase=True):
        data.add(models.Bibrec, rec.id, _obj=bibtex2source(rec, cls=models.Bibrec))

    load_ecoregions(data_file, data)
    load_countries(data)
    second_languages = {}

    def languoid_visitor(lang, row, _):
        add_language_codes(
            data, lang, lang.id.split('-')[0], None, glottocode=row[2] or None)
        second_languages[row[0]] = row[8]

    def habitat_visitor(cat, *_):
        cat.is_habitat = True

    def taxon_visitor(auto, taxon, *_):
        if auto.get(taxon.id):
            update_taxon_data(taxon, auto[taxon.id], data)
        else:
            print('--> missing in taxa.json:', taxon.id, taxon.name)
        taxon.countries_str = ' '.join([e.id for e in taxon.countries])
        taxon.ecoregions_str = ' '.join([e.id for e in taxon.ecoregions])

    auto = {s['id']: s for s in jsonload(data_file('taxa.json'))}
    for model, kw in [
        (models.Lineage, {}),
        (models.Use, {}),
        (models.TsammalexContributor, {}),
        (models.Languoid, dict(visitor=languoid_visitor)),
        (models.Category, dict(name='categories')),
        (models.Category, dict(name='habitats', visitor=habitat_visitor)),
        (models.Taxon, dict(visitor=partial(taxon_visitor, auto))),
        (models.Name, dict(filter_=lambda r: 'xxx' not in r[1])),
    ]:
        from_csv(data_file, model, data, **kw)

    for key, ids in second_languages.items():
        target = data['Languoid'][key]
        for lid in models.split_ids(ids):
            if lid in data['Languoid']:
                # we ignore 2nd languages which are not yet in Tsammalex.
                target.second_languages.append(data['Languoid'][lid])

    def image_url(source_url, type_):
        return re.sub('\.[a-zA-Z]+$', '.jpg', source_url).replace(
            '/original/', '/%s/' % type_)

    for fname in data_files(data_file, 'images.csv'):

        for image in reader(fname, namedtuples=True, delimiter=","):
            if image.taxa__id not in data['Taxon']:
                continue

            url = URL(image.source_url)
            if url.host() != 'edmond.mpdl.mpg.de':
                continue

            jsondata = dict(
                url=image.source_url,
                thumbnail=image_url(image.source_url, 'thumbnail'),
                web=image_url(image.source_url, 'web'))

            f = common.Parameter_files(
                object=data['Taxon'][image.taxa__id],
                id=image.id,
                name=image.tags,
                jsondata=jsondata,
                mime_type=image.mime_type)
            for k in 'source creator date place comments permission'.split():
                v = getattr(image, k)
                if v:
                    models.ImageData(key=k, value=v, image=f)
开发者ID:clld,项目名称:tsammalex,代码行数:99,代码来源:initializedb.py

示例13: get_image_info

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import host [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

示例14: url_parts

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

示例15: maybe_external_link

# 需要导入模块: from purl import URL [as 别名]
# 或者: from purl.URL import host [as 别名]
def maybe_external_link(text, **kw):
    url = URL(text)
    if url.host() and url.scheme() in ['http', 'https']:
        return external_link(text, **kw)
    return text
开发者ID:clld,项目名称:clld,代码行数:7,代码来源:helpers.py


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