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


Python Link.wrap_iterable方法代码示例

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


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

示例1: test_link_wrapping

# 需要导入模块: from pex.link import Link [as 别名]
# 或者: from pex.link.Link import wrap_iterable [as 别名]
def test_link_wrapping():
    link = Link.wrap("https://www.google.com")
    assert link.url == "https://www.google.com"

    link = Link.wrap(Link.wrap("https://www.google.com"))
    assert link.url == "https://www.google.com"

    with pytest.raises(ValueError):
        Link.wrap(1234)

    with pytest.raises(ValueError):
        Link.wrap_iterable(1234)

    links = Link.wrap_iterable("https://www.google.com")
    assert len(links) == 1
    assert links[0].url == "https://www.google.com"

    links = Link.wrap_iterable(["https://www.google.com", Link("http://www.google.com")])
    assert set(links) == set([Link("http://www.google.com"), Link("https://www.google.com")])
开发者ID:Houzz,项目名称:pex,代码行数:21,代码来源:test_link.py

示例2: crawl

# 需要导入模块: from pex.link import Link [as 别名]
# 或者: from pex.link.Link import wrap_iterable [as 别名]
  def crawl(self, link_or_links, follow_links=False):
    links = list(Link.wrap_iterable(link_or_links))
    cache_key = self._make_cache_key(links, follow_links)

    # Memoize crawling to a global Memoizer (Crawler._CRAWL_CACHE).
    result = self._CRAWL_CACHE.get(cache_key)
    if result is None:
      result = self._crawl(links, follow_links)
      self._CRAWL_CACHE.store(cache_key, result)

    return result
开发者ID:jsirois,项目名称:pex,代码行数:13,代码来源:crawler.py

示例3: test_link_wrapping

# 需要导入模块: from pex.link import Link [as 别名]
# 或者: from pex.link.Link import wrap_iterable [as 别名]
def test_link_wrapping():
  link = Link.wrap('https://www.google.com')
  assert link.url == 'https://www.google.com'

  link = Link.wrap(Link.wrap('https://www.google.com'))
  assert link.url == 'https://www.google.com'

  with pytest.raises(ValueError):
    Link.wrap(1234)

  with pytest.raises(ValueError):
    Link.wrap_iterable(1234)

  links = Link.wrap_iterable('https://www.google.com')
  assert len(links) == 1
  assert links[0].url == 'https://www.google.com'

  links = Link.wrap_iterable(['https://www.google.com', Link('http://www.google.com')])
  assert set(links) == set([
      Link('http://www.google.com'),
      Link('https://www.google.com'),
  ])
开发者ID:mikekap,项目名称:pex,代码行数:24,代码来源:test_link.py


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