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


Python link.Link类代码示例

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


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

示例1: test_requests_context

def test_requests_context():
  context = RequestsContext(verify=False)

  with make_url(BLOB, make_md5(BLOB)) as url:
    assert context.read(Link.wrap(url)) == BLOB

  with make_url(BLOB, make_md5(BLOB)) as url:
    filename = context.fetch(Link.wrap(url))
    with open(filename, 'rb') as fp:
      assert fp.read() == BLOB

  # test local reading
  with named_temporary_file() as tf:
    tf.write(b'goop')
    tf.flush()
    assert context.read(Link.wrap(tf.name)) == b'goop'
开发者ID:Houzz,项目名称:pex,代码行数:16,代码来源:test_http.py

示例2: test_urllib_context_utf8_encoding

def test_urllib_context_utf8_encoding():
  BYTES = b'this is a decoded utf8 string'

  with named_temporary_file() as tf:
    tf.write(BYTES)
    tf.flush()
    local_link = Link.wrap(tf.name)

    # Trick UrllibContext into thinking this is a remote link
    class MockUrllibContext(UrllibContext):
      def open(self, link):
        return super(MockUrllibContext, self).open(local_link)

    context = MockUrllibContext()
    assert context.content(Link.wrap('http://www.google.com')) == BYTES.decode(
        UrllibContext.DEFAULT_ENCODING)
开发者ID:Houzz,项目名称:pex,代码行数:16,代码来源:test_http.py

示例3: crawl

  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,代码行数:11,代码来源:crawler.py

示例4: test_requests_context_retries_connect_timeout

def test_requests_context_retries_connect_timeout():
  with mock.patch.object(
      requests.packages.urllib3.connectionpool.HTTPConnectionPool,
      '_make_request') as mock_make_request:

    url, mock_make_request.side_effect = timeout_side_effect()

    context = RequestsContext(verify=False)

    data = context.read(Link.wrap(url))
    assert data == BLOB
开发者ID:Houzz,项目名称:pex,代码行数:11,代码来源:test_http.py

示例5: test_requests_context_retries_connect_timeout_retries_exhausted

def test_requests_context_retries_connect_timeout_retries_exhausted():
  with mock.patch.object(
      requests.packages.urllib3.connectionpool.HTTPConnectionPool,
      '_make_request') as mock_make_request:

    url, mock_make_request.side_effect = timeout_side_effect(num_timeouts=3)

    context = RequestsContext(verify=False, max_retries=2)

    with pytest.raises(Context.Error):
      context.read(Link.wrap(url))
开发者ID:ewdurbin,项目名称:pex,代码行数:11,代码来源:test_http.py

示例6: test_requests_context_retries_connect_timeout_retries_exhausted

def test_requests_context_retries_connect_timeout_retries_exhausted():
  with mock.patch.object(
      requests.packages.urllib3.connectionpool.HTTPConnectionPool,
      '_make_request') as mock_make_request:

    url, mock_make_request.side_effect = timeout_side_effect(num_timeouts=3)
    env = Variables(environ={'PEX_HTTP_RETRIES': '2'})

    context = RequestsContext(verify=False, env=env)

    with pytest.raises(Context.Error):
      context.read(Link.wrap(url))
开发者ID:Houzz,项目名称:pex,代码行数:12,代码来源:test_http.py

示例7: test_crawler_local

def test_crawler_local():
  FL = ('a.txt', 'b.txt', 'c.txt')
  with temporary_dir() as td:
    for fn in FL:
      with open(os.path.join(td, fn), 'w'):
        pass
    for dn in (1, 2):
      os.mkdir(os.path.join(td, 'dir%d' % dn))
      for fn in FL:
        with open(os.path.join(td, 'dir%d' % dn, fn), 'w'):
          pass

    # basic file / dir rel splitting
    links, rels = Crawler.crawl_local(Link.wrap(td))
    assert set(links) == set(Link.wrap(os.path.join(td, fn)) for fn in FL)
    assert set(rels) == set(Link.wrap(os.path.join(td, 'dir%d' % n)) for n in (1, 2))

    # recursive crawling, single vs multi-threaded
    for caching in (False, True):
      for threads in (1, 2, 3):
        links = Crawler(threads=threads).crawl([td], follow_links=True)
        expect_links = (set(Link.wrap(os.path.join(td, fn)) for fn in FL) |
                        set(Link.wrap(os.path.join(td, 'dir1', fn)) for fn in FL) |
                        set(Link.wrap(os.path.join(td, 'dir2', fn)) for fn in FL))
        assert set(links) == expect_links
开发者ID:pfmoore,项目名称:pex,代码行数:25,代码来源:test_crawler.py

示例8: test_link_wrapping

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,代码行数:19,代码来源:test_link.py

示例9: test_link_wrapping

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,代码行数:22,代码来源:test_link.py

示例10: from_href

  def from_href(cls, href, **kw):
    """Convert from a url to Package.

    :param href: The url to parse
    :type href: string
    :returns: A Package object if a valid concrete implementation exists, otherwise None.
    """
    package = cls._HREF_TO_PACKAGE_CACHE.get(href)
    if package is not None:
      return package
    link_href = Link.wrap(href)
    for package_type in cls._REGISTRY:
      try:
        package = package_type(link_href.url, **kw)
        break
      except package_type.InvalidPackage:
        continue
    if package is not None:
      cls._HREF_TO_PACKAGE_CACHE.store(href, package)
    return package
开发者ID:jsirois,项目名称:pex,代码行数:20,代码来源:package.py

示例11: test_stream_filelike_without_md5

def test_stream_filelike_without_md5():
  with make_url(BLOB) as url:
    request = requests.get(url)
    filelike = StreamFilelike(request, Link.wrap(url))
    assert filelike.read() == BLOB
开发者ID:Houzz,项目名称:pex,代码行数:5,代码来源:test_http.py

示例12: test_stream_filelike_with_incorrect_md5

def test_stream_filelike_with_incorrect_md5():
  with make_url(BLOB, 'f' * 32) as url:
    request = requests.get(url)
    filelike = StreamFilelike(request, Link.wrap(url))
    with pytest.raises(Context.Error):
      filelike.read()
开发者ID:Houzz,项目名称:pex,代码行数:6,代码来源:test_http.py

示例13: test_link_join

def test_link_join():
  link = Link('https://www.google.com/bar/')
  assert link.join('/foo').url == 'https://www.google.com/foo'
  assert link.join('#foo').url == 'https://www.google.com/bar/#foo'
  assert link.join('foo').url == 'https://www.google.com/bar/foo'
开发者ID:mikekap,项目名称:pex,代码行数:5,代码来源:test_link.py

示例14: test_link_join

def test_link_join():
    link = Link("https://www.google.com/bar/")
    assert link.join("/foo").url == "https://www.google.com/foo"
    assert link.join("#foo").url == "https://www.google.com/bar/#foo"
    assert link.join("foo").url == "https://www.google.com/bar/foo"
开发者ID:Houzz,项目名称:pex,代码行数:5,代码来源:test_link.py


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