本文整理汇总了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")])
示例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
示例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'),
])