• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python connectionpool.connection_from_url函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_same_host

    def test_same_host(self):
        same_host = [
            ('http://google.com/', '/'),
            ('http://google.com/', 'http://google.com/'),
            ('http://google.com/', 'http://google.com'),
            ('http://google.com/', 'http://google.com/abra/cadabra'),
            ('http://google.com:42/', 'http://google.com:42/abracadabra'),
            # Test comparison using default ports
            ('http://google.com:80/', 'http://google.com/abracadabra'),
            ('http://google.com/', 'http://google.com:80/abracadabra'),
            ('https://google.com:443/', 'https://google.com/abracadabra'),
            ('https://google.com/', 'https://google.com:443/abracadabra'),
            ('http://[2607:f8b0:4005:805::200e%25eth0]/',
             'http://[2607:f8b0:4005:805::200e%eth0]/'),
            ('https://[2607:f8b0:4005:805::200e%25eth0]:443/',
             'https://[2607:f8b0:4005:805::200e%eth0]:443/'),
            ('http://[::1]/', 'http://[::1]'),
            ('http://[2001:558:fc00:200:f816:3eff:fef9:b954%lo]/',
             'http://[2001:558:fc00:200:f816:3eff:fef9:b954%25lo]')
        ]

        for a, b in same_host:
            c = connection_from_url(a)
            self.addCleanup(c.close)
            self.assertTrue(c.is_same_host(b), "%s =? %s" % (a, b))

        not_same_host = [
            ('https://google.com/', 'http://google.com/'),
            ('http://google.com/', 'https://google.com/'),
            ('http://yahoo.com/', 'http://google.com/'),
            ('http://google.com:42', 'https://google.com/abracadabra'),
            ('http://google.com', 'https://google.net/'),
            # Test comparison with default ports
            ('http://google.com:42', 'http://google.com'),
            ('https://google.com:42', 'https://google.com'),
            ('http://google.com:443', 'http://google.com'),
            ('https://google.com:80', 'https://google.com'),
            ('http://google.com:443', 'https://google.com'),
            ('https://google.com:80', 'http://google.com'),
            ('https://google.com:443', 'http://google.com'),
            ('http://google.com:80', 'https://google.com'),
            # Zone identifiers are unique connection end points and should
            # never be equivalent.
            ('http://[dead::beef]', 'https://[dead::beef%en5]/'),
        ]

        for a, b in not_same_host:
            c = connection_from_url(a)
            self.addCleanup(c.close)
            self.assertFalse(c.is_same_host(b), "%s =? %s" % (a, b))
            c = connection_from_url(b)
            self.addCleanup(c.close)
            self.assertFalse(c.is_same_host(a), "%s =? %s" % (b, a))
开发者ID:Lukasa,项目名称:urllib3,代码行数:53,代码来源:test_connectionpool.py


示例2: test_pool_close

    def test_pool_close(self):
        pool = connection_from_url('http://google.com:80')

        # Populate with some connections
        conn1 = pool._get_conn()
        conn2 = pool._get_conn()
        conn3 = pool._get_conn()
        pool._put_conn(conn1)
        pool._put_conn(conn2)

        old_pool_queue = pool.pool

        pool.close()
        self.assertEqual(pool.pool, None)

        with self.assertRaises(ClosedPoolError):
            pool._get_conn()

        pool._put_conn(conn3)

        with self.assertRaises(ClosedPoolError):
            pool._get_conn()

        with self.assertRaises(Empty):
            old_pool_queue.get(block=False)
开发者ID:thatguystone,项目名称:urllib3,代码行数:25,代码来源:test_connectionpool.py


示例3: test_cleanup_on_extreme_connection_error

    def test_cleanup_on_extreme_connection_error(self):
        """
        This test validates that we clean up properly even on exceptions that
        we'd not otherwise catch, i.e. those that inherit from BaseException
        like KeyboardInterrupt or gevent.Timeout. See #805 for more details.
        """
        class RealBad(BaseException):
            pass

        def kaboom(*args, **kwargs):
            raise RealBad()

        c = connection_from_url('http://localhost:80')
        c._make_request = kaboom

        initial_pool_size = c.pool.qsize()

        try:
            # We need to release_conn this way or we'd put it away regardless.
            c.urlopen('GET', '/', release_conn=False)
        except RealBad:
            pass

        new_pool_size = c.pool.qsize()
        self.assertEqual(initial_pool_size, new_pool_size)
开发者ID:adamchainz,项目名称:urllib3,代码行数:25,代码来源:test_connectionpool.py


示例4: test_oldapi

    def test_oldapi(self):
        http = ProxyManager(connection_from_url(self.proxy_url))

        r = http.request('GET', '%s/' % self.http_url)
        self.assertEqual(r.status, 200)

        r = http.request('GET', '%s/' % self.https_url)
        self.assertEqual(r.status, 200)
开发者ID:fredthomsen,项目名称:urllib3,代码行数:8,代码来源:test_proxy_poolmanager.py


示例5: test_oldapi

    def test_oldapi(self):
        http = ProxyManager(connection_from_url(self.proxy_url), ca_certs=DEFAULT_CA)
        self.addCleanup(http.clear)

        r = http.request('GET', '%s/' % self.http_url)
        self.assertEqual(r.status, 200)

        r = http.request('GET', '%s/' % self.https_url)
        self.assertEqual(r.status, 200)
开发者ID:jonparrott,项目名称:urllib3,代码行数:9,代码来源:test_proxy_poolmanager.py


示例6: test_same_host

    def test_same_host(self):
        same_host = [
            ('http://google.com/', '/'),
            ('http://google.com/', 'http://google.com/'),
            ('http://google.com/', 'http://google.com'),
            ('http://google.com/', 'http://google.com/abra/cadabra'),
            ('http://google.com:42/', 'http://google.com:42/abracadabra'),
            # Test comparison using default ports
            ('http://google.com:80/', 'http://google.com/abracadabra'),
            ('http://google.com/', 'http://google.com:80/abracadabra'),
            ('https://google.com:443/', 'https://google.com/abracadabra'),
            ('https://google.com/', 'https://google.com:443/abracadabra'),
        ]

        for a, b in same_host:
            c = connection_from_url(a)
            self.assertTrue(c.is_same_host(b), "%s =? %s" % (a, b))

        not_same_host = [
            ('https://google.com/', 'http://google.com/'),
            ('http://google.com/', 'https://google.com/'),
            ('http://yahoo.com/', 'http://google.com/'),
            ('http://google.com:42', 'https://google.com/abracadabra'),
            ('http://google.com', 'https://google.net/'),
            # Test comparison with default ports
            ('http://google.com:42', 'http://google.com'),
            ('https://google.com:42', 'https://google.com'),
            ('http://google.com:443', 'http://google.com'),
            ('https://google.com:80', 'https://google.com'),
            ('http://google.com:443', 'https://google.com'),
            ('https://google.com:80', 'http://google.com'),
            ('https://google.com:443', 'http://google.com'),
            ('http://google.com:80', 'https://google.com'),
        ]

        for a, b in not_same_host:
            c = connection_from_url(a)
            self.assertFalse(c.is_same_host(b), "%s =? %s" % (a, b))
            c = connection_from_url(b)
            self.assertFalse(c.is_same_host(a), "%s =? %s" % (b, a))
开发者ID:09Hero,项目名称:urllib3,代码行数:40,代码来源:test_connectionpool.py


示例7: test_same_host

    def test_same_host(self):
        same_host = [
            ('http://google.com/', '/'),
            ('http://google.com/', 'http://google.com/'),
            ('http://google.com/', 'http://google.com'),
            ('http://google.com/', 'http://google.com/abra/cadabra'),
            ('http://google.com:42/', 'http://google.com:42/abracadabra'),
        ]

        for a, b in same_host:
            c = connection_from_url(a)
            self.assertTrue(c.is_same_host(b), "%s =? %s" % (a, b))

        not_same_host = [
            ('http://yahoo.com/', 'http://google.com/'),
            ('http://google.com:42', 'https://google.com/abracadabra'),
            ('http://google.com', 'https://google.net/'),
        ]

        for a, b in not_same_host:
            c = connection_from_url(a)
            self.assertFalse(c.is_same_host(b), "%s =? %s" % (a, b))
开发者ID:jandre,项目名称:urllib3,代码行数:22,代码来源:test_connectionpool.py


示例8: test_pool_close_twice

    def test_pool_close_twice(self):
        pool = connection_from_url('http://google.com:80')

        # Populate with some connections
        conn1 = pool._get_conn()
        conn2 = pool._get_conn()
        pool._put_conn(conn1)
        pool._put_conn(conn2)

        pool.close()
        assert pool.pool is None

        try:
            pool.close()
        except AttributeError:
            pytest.fail("Pool of the ConnectionPool is None and has no attribute get.")
开发者ID:NickMinnellaCS96,项目名称:urllib3,代码行数:16,代码来源:test_connectionpool.py


示例9: test_contextmanager

    def test_contextmanager(self):
        with connection_from_url('http://google.com:80') as pool:
            # Populate with some connections
            conn1 = pool._get_conn()
            conn2 = pool._get_conn()
            conn3 = pool._get_conn()
            pool._put_conn(conn1)
            pool._put_conn(conn2)

            old_pool_queue = pool.pool

        self.assertEqual(pool.pool, None)
        self.assertRaises(ClosedPoolError, pool._get_conn)

        pool._put_conn(conn3)
        self.assertRaises(ClosedPoolError, pool._get_conn)
        self.assertRaises(Empty, old_pool_queue.get, block=False)
开发者ID:adamchainz,项目名称:urllib3,代码行数:17,代码来源:test_connectionpool.py


示例10: test_contextmanager

    def test_contextmanager(self):
        with connection_from_url('http://google.com:80') as pool:
            # Populate with some connections
            conn1 = pool._get_conn()
            conn2 = pool._get_conn()
            conn3 = pool._get_conn()
            pool._put_conn(conn1)
            pool._put_conn(conn2)

            old_pool_queue = pool.pool

        assert pool.pool is None
        with pytest.raises(ClosedPoolError):
            pool._get_conn()

        pool._put_conn(conn3)
        with pytest.raises(ClosedPoolError):
            pool._get_conn()
        with pytest.raises(Empty):
            old_pool_queue.get(block=False)
开发者ID:cloudera,项目名称:hue,代码行数:20,代码来源:test_connectionpool.py


示例11: test_absolute_url

 def test_absolute_url(self):
     with connection_from_url('http://google.com:80') as c:
         assert 'http://google.com:80/path?query=foo' == c._absolute_url('path?query=foo')
开发者ID:cloudera,项目名称:hue,代码行数:3,代码来源:test_connectionpool.py


示例12: get

#!/usr/bin/env python
# coding:utf-8

import threading, logging
from urllib3 import connectionpool

connectionpool.log.setLevel(logging.DEBUG)
connectionpool.log.addHandler(logging.StreamHandler())
#pool = connectionpool.connection_from_url('http://5uproxy.net/http_fast.html', maxsize=10)
#
#def get():
#	for i in range(3):
#		pool.get_url('http://5uproxy.net/http_fast.html')
#
#for i in range(10):
#	threading.Thread(target=get).start()

pool = connectionpool.connection_from_url('www.python.org', maxsize=1)
pool.urlopen('GET', '/')
pool.urlopen('HEAD', '/')
pool.urlopen('HEAD', '/')
pool.urlopen('HEAD', '/')
pool.urlopen('HEAD', '/')
pool.urlopen('HEAD', '/')
开发者ID:ichuan,项目名称:yc-lib,代码行数:24,代码来源:urllib3test.py


示例13: test_ca_certs_default_cert_required

 def test_ca_certs_default_cert_required(self):
     with connection_from_url('https://google.com:80', ca_certs='/etc/ssl/certs/custom.pem') as pool:
         conn = pool._get_conn()
         self.assertEqual(conn.cert_reqs, 'CERT_REQUIRED')
开发者ID:adamchainz,项目名称:urllib3,代码行数:4,代码来源:test_connectionpool.py


示例14: test_absolute_url

 def test_absolute_url(self):
     c = connection_from_url('http://google.com:80')
     self.assertEqual(
             'http://google.com:80/path?query=foo',
             c._absolute_url('path?query=foo'))
开发者ID:adamchainz,项目名称:urllib3,代码行数:5,代码来源:test_connectionpool.py


示例15: _make_request

                return self._follow_redirect(resp, request)
            except Exception, e:
                raise e

        return resp

    def _make_request(self, request):

        try:
            request = self._handlers.dispatch("request_prepare", request)
        except Exception, e:
            response = Response(status=400, message="Bad request", request=request)
            return response

        url = request.url
        conn = connectionpool.connection_from_url(str(url))

        headers = self._merge_headers(request.headers)

        try:
            dispatch_response = self._handlers.dispatch("request_send", request)
            if isinstance(dispatch_response, Response):
                return dispatch_response
        except Exception, e:
            raise e

        # XXX fix in Url
        path = str(request.url.path) or "/"
        r = conn.urlopen(
            method=request.method, url=path, headers=headers, timeout=self.timeout, body=request.content, redirect=False
        )
开发者ID:samv,项目名称:fluffyhttp,代码行数:31,代码来源:client.py


示例16: test_not_same_host

    def test_not_same_host(self, a, b):
        with connection_from_url(a) as c:
            assert not c.is_same_host(b)

        with connection_from_url(b) as c:
            assert not c.is_same_host(a)
开发者ID:cloudera,项目名称:hue,代码行数:6,代码来源:test_connectionpool.py


示例17: test_connection_refused

 def test_connection_refused(self):
     # Assume that port 31456 is not bound to by any server.
     pool = connection_from_url('http://localhost:31456')
     with self.assertRaises(MaxRetryError):
         pool.request('GET', '/')
开发者ID:PeterScott,项目名称:urllib3,代码行数:5,代码来源:test_connectionpool.py


示例18: test_assert_same_host

    def test_assert_same_host(self):
        c = connection_from_url('http://google.com:80')

        self.assertRaises(HostChangedError, c.request,
                          'GET', 'http://yahoo.com:80', assert_same_host=True)
开发者ID:09Hero,项目名称:urllib3,代码行数:5,代码来源:test_connectionpool.py


示例19: test_assert_same_host

 def test_assert_same_host(self):
     with connection_from_url('http://google.com:80') as c:
         with pytest.raises(HostChangedError):
             c.request('GET', 'http://yahoo.com:80', assert_same_host=True)
开发者ID:cloudera,项目名称:hue,代码行数:4,代码来源:test_connectionpool.py


示例20: test_ca_certs_default_cert_required

 def test_ca_certs_default_cert_required(self):
     with connection_from_url('https://google.com:80', ca_certs=DEFAULT_CA) as pool:
         conn = pool._get_conn()
         assert conn.cert_reqs == 'CERT_REQUIRED'
开发者ID:cloudera,项目名称:hue,代码行数:4,代码来源:test_connectionpool.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python connectionpool.HTTPConnectionPool类代码示例发布时间:2022-05-27
下一篇:
Python urllib3.HTTPSConnectionPool类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap