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


Python PoolManager.connection_from_url方法代码示例

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


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

示例1: test_http_pool_key_fields

# 需要导入模块: from urllib3.poolmanager import PoolManager [as 别名]
# 或者: from urllib3.poolmanager.PoolManager import connection_from_url [as 别名]
    def test_http_pool_key_fields(self):
        """Assert the HTTPPoolKey fields are honored when selecting a pool."""
        connection_pool_kw = {
            'timeout': timeout.Timeout(3.14),
            'retries': retry.Retry(total=6, connect=2),
            'block': True,
            'strict': True,
            'source_address': '127.0.0.1',
        }
        p = PoolManager()
        conn_pools = [
            p.connection_from_url('http://example.com/'),
            p.connection_from_url('http://example.com:8000/'),
            p.connection_from_url('http://other.example.com/'),
        ]

        for key, value in connection_pool_kw.items():
            p.connection_pool_kw[key] = value
            conn_pools.append(p.connection_from_url('http://example.com/'))

        assert all(
            x is not y
            for i, x in enumerate(conn_pools)
            for j, y in enumerate(conn_pools)
            if i != j
        )
        assert all(isinstance(key, PoolKey) for key in p.pools.keys())
开发者ID:NickMinnellaCS96,项目名称:urllib3,代码行数:29,代码来源:test_poolmanager.py

示例2: test_http_connection_from_url_case_insensitive

# 需要导入模块: from urllib3.poolmanager import PoolManager [as 别名]
# 或者: from urllib3.poolmanager.PoolManager import connection_from_url [as 别名]
    def test_http_connection_from_url_case_insensitive(self):
        """Assert scheme case is ignored when pooling HTTP connections."""
        p = PoolManager()
        pool = p.connection_from_url('http://example.com/')
        other_pool = p.connection_from_url('HTTP://EXAMPLE.COM/')

        assert 1 == len(p.pools)
        assert pool is other_pool
        assert all(isinstance(key, PoolKey) for key in p.pools.keys())
开发者ID:NickMinnellaCS96,项目名称:urllib3,代码行数:11,代码来源:test_poolmanager.py

示例3: test_https_connection_from_url_case_insensitive

# 需要导入模块: from urllib3.poolmanager import PoolManager [as 别名]
# 或者: from urllib3.poolmanager.PoolManager import connection_from_url [as 别名]
    def test_https_connection_from_url_case_insensitive(self):
        """Assert scheme case is ignored when pooling HTTPS connections."""
        p = PoolManager()
        self.addCleanup(p.clear)
        pool = p.connection_from_url('https://example.com/')
        other_pool = p.connection_from_url('HTTPS://EXAMPLE.COM/')

        self.assertEqual(1, len(p.pools))
        self.assertTrue(pool is other_pool)
        self.assertTrue(all(isinstance(key, PoolKey) for key in p.pools.keys()))
开发者ID:cloudera,项目名称:hue,代码行数:12,代码来源:test_poolmanager.py

示例4: test_custom_pool_key

# 需要导入模块: from urllib3.poolmanager import PoolManager [as 别名]
# 或者: from urllib3.poolmanager.PoolManager import connection_from_url [as 别名]
    def test_custom_pool_key(self):
        """Assert it is possible to define a custom key function."""
        p = PoolManager(10)

        p.key_fn_by_scheme['http'] = lambda x: tuple(x['key'])
        pool1 = p.connection_from_url(
            'http://example.com', pool_kwargs={'key': 'value'})
        pool2 = p.connection_from_url(
            'http://example.com', pool_kwargs={'key': 'other'})
        pool3 = p.connection_from_url(
            'http://example.com', pool_kwargs={'key': 'value', 'x': 'y'})

        assert 2 == len(p.pools)
        assert pool1 is pool3
        assert pool1 is not pool2
开发者ID:NickMinnellaCS96,项目名称:urllib3,代码行数:17,代码来源:test_poolmanager.py

示例5: test_override_pool_kwargs_url

# 需要导入模块: from urllib3.poolmanager import PoolManager [as 别名]
# 或者: from urllib3.poolmanager.PoolManager import connection_from_url [as 别名]
    def test_override_pool_kwargs_url(self):
        """Assert overriding pool kwargs works with connection_from_url."""
        p = PoolManager(strict=True)
        pool_kwargs = {'strict': False, 'retries': 100, 'block': True}

        default_pool = p.connection_from_url('http://example.com/')
        override_pool = p.connection_from_url(
            'http://example.com/', pool_kwargs=pool_kwargs)

        assert default_pool.strict
        assert retry.Retry.DEFAULT == default_pool.retries
        assert not default_pool.block

        assert not override_pool.strict
        assert 100 == override_pool.retries
        assert override_pool.block
开发者ID:NickMinnellaCS96,项目名称:urllib3,代码行数:18,代码来源:test_poolmanager.py

示例6: test_override_pool_kwargs_url

# 需要导入模块: from urllib3.poolmanager import PoolManager [as 别名]
# 或者: from urllib3.poolmanager.PoolManager import connection_from_url [as 别名]
    def test_override_pool_kwargs_url(self):
        """Assert overriding pool kwargs works with connection_from_url."""
        p = PoolManager(strict=True)
        pool_kwargs = {'strict': False, 'retries': 100, 'block': True}

        default_pool = p.connection_from_url('http://example.com/')
        override_pool = p.connection_from_url(
            'http://example.com/', pool_kwargs=pool_kwargs)

        self.assertTrue(default_pool.strict)
        self.assertEqual(retry.Retry.DEFAULT, default_pool.retries)
        self.assertFalse(default_pool.block)

        self.assertFalse(override_pool.strict)
        self.assertEqual(100, override_pool.retries)
        self.assertTrue(override_pool.block)
开发者ID:cloudera,项目名称:hue,代码行数:18,代码来源:test_poolmanager.py

示例7: test_custom_pool_key

# 需要导入模块: from urllib3.poolmanager import PoolManager [as 别名]
# 或者: from urllib3.poolmanager.PoolManager import connection_from_url [as 别名]
    def test_custom_pool_key(self):
        """Assert it is possible to define a custom key function."""
        p = PoolManager(10)
        self.addCleanup(p.clear)

        p.key_fn_by_scheme['http'] = lambda x: tuple(x['key'])
        pool1 = p.connection_from_url(
            'http://example.com', pool_kwargs={'key': 'value'})
        pool2 = p.connection_from_url(
            'http://example.com', pool_kwargs={'key': 'other'})
        pool3 = p.connection_from_url(
            'http://example.com', pool_kwargs={'key': 'value', 'x': 'y'})

        self.assertEqual(2, len(p.pools))
        self.assertTrue(pool1 is pool3)
        self.assertFalse(pool1 is pool2)
开发者ID:cloudera,项目名称:hue,代码行数:18,代码来源:test_poolmanager.py

示例8: test_assert_hostname_and_fingerprint_flag

# 需要导入模块: from urllib3.poolmanager import PoolManager [as 别名]
# 或者: from urllib3.poolmanager.PoolManager import connection_from_url [as 别名]
 def test_assert_hostname_and_fingerprint_flag(self):
     """Assert that pool manager can accept hostname and fingerprint flags."""
     fingerprint = '92:81:FE:85:F7:0C:26:60:EC:D6:B3:BF:93:CF:F9:71:CC:07:7D:0A'
     p = PoolManager(assert_hostname=True, assert_fingerprint=fingerprint)
     pool = p.connection_from_url('https://example.com/')
     assert 1 == len(p.pools)
     assert pool.assert_hostname
     assert fingerprint == pool.assert_fingerprint
开发者ID:NickMinnellaCS96,项目名称:urllib3,代码行数:10,代码来源:test_poolmanager.py

示例9: test_assert_hostname_and_fingerprint_flag

# 需要导入模块: from urllib3.poolmanager import PoolManager [as 别名]
# 或者: from urllib3.poolmanager.PoolManager import connection_from_url [as 别名]
 def test_assert_hostname_and_fingerprint_flag(self):
     """Assert that pool manager can accept hostname and fingerprint flags."""
     fingerprint = '92:81:FE:85:F7:0C:26:60:EC:D6:B3:BF:93:CF:F9:71:CC:07:7D:0A'
     p = PoolManager(assert_hostname=True, assert_fingerprint=fingerprint)
     self.addCleanup(p.clear)
     pool = p.connection_from_url('https://example.com/')
     self.assertEqual(1, len(p.pools))
     self.assertTrue(pool.assert_hostname)
     self.assertEqual(fingerprint, pool.assert_fingerprint)
开发者ID:cloudera,项目名称:hue,代码行数:11,代码来源:test_poolmanager.py

示例10: test_https_pool_key_fields

# 需要导入模块: from urllib3.poolmanager import PoolManager [as 别名]
# 或者: from urllib3.poolmanager.PoolManager import connection_from_url [as 别名]
    def test_https_pool_key_fields(self):
        """Assert the HTTPSPoolKey fields are honored when selecting a pool."""
        connection_pool_kw = {
            'timeout': timeout.Timeout(3.14),
            'retries': retry.Retry(total=6, connect=2),
            'block': True,
            'strict': True,
            'source_address': '127.0.0.1',
            'key_file': '/root/totally_legit.key',
            'cert_file': '/root/totally_legit.crt',
            'cert_reqs': 'CERT_REQUIRED',
            'ca_certs': '/root/path_to_pem',
            'ssl_version': 'SSLv23_METHOD',
        }
        p = PoolManager()
        self.addCleanup(p.clear)
        conn_pools = [
            p.connection_from_url('https://example.com/'),
            p.connection_from_url('https://example.com:4333/'),
            p.connection_from_url('https://other.example.com/'),
        ]
        # Asking for a connection pool with the same key should give us an
        # existing pool.
        dup_pools = []

        for key, value in connection_pool_kw.items():
            p.connection_pool_kw[key] = value
            conn_pools.append(p.connection_from_url('https://example.com/'))
            dup_pools.append(p.connection_from_url('https://example.com/'))

        self.assertTrue(
            all(
                x is not y
                for i, x in enumerate(conn_pools)
                for j, y in enumerate(conn_pools)
                if i != j
            )
        )
        self.assertTrue(all(pool in conn_pools for pool in dup_pools))
        self.assertTrue(
            all(
                isinstance(key, PoolKey)
                for key in p.pools.keys())
        )
开发者ID:cloudera,项目名称:hue,代码行数:46,代码来源:test_poolmanager.py

示例11: test_same_url

# 需要导入模块: from urllib3.poolmanager import PoolManager [as 别名]
# 或者: from urllib3.poolmanager.PoolManager import connection_from_url [as 别名]
    def test_same_url(self):
        # Convince ourselves that normally we don't get the same object
        conn1 = connection_from_url('http://localhost:8081/foo')
        conn2 = connection_from_url('http://localhost:8081/bar')

        assert conn1 != conn2

        # Now try again using the PoolManager
        p = PoolManager(1)

        conn1 = p.connection_from_url('http://localhost:8081/foo')
        conn2 = p.connection_from_url('http://localhost:8081/bar')

        assert conn1 == conn2

        # Ensure that FQDNs are handled separately from relative domains
        p = PoolManager(2)

        conn1 = p.connection_from_url('http://localhost.:8081/foo')
        conn2 = p.connection_from_url('http://localhost:8081/bar')

        assert conn1 != conn2
开发者ID:NickMinnellaCS96,项目名称:urllib3,代码行数:24,代码来源:test_poolmanager.py

示例12: test_same_url

# 需要导入模块: from urllib3.poolmanager import PoolManager [as 别名]
# 或者: from urllib3.poolmanager.PoolManager import connection_from_url [as 别名]
    def test_same_url(self):
        # Convince ourselves that normally we don't get the same object
        conn1 = connection_from_url('http://localhost:8081/foo')
        conn2 = connection_from_url('http://localhost:8081/bar')

        self.assertNotEqual(conn1, conn2)

        # Now try again using the PoolManager
        p = PoolManager(1)

        conn1 = p.connection_from_url('http://localhost:8081/foo')
        conn2 = p.connection_from_url('http://localhost:8081/bar')

        self.assertEqual(conn1, conn2)
开发者ID:poupas,项目名称:urllib3,代码行数:16,代码来源:test_poolmanager.py

示例13: test_manager_clear

# 需要导入模块: from urllib3.poolmanager import PoolManager [as 别名]
# 或者: from urllib3.poolmanager.PoolManager import connection_from_url [as 别名]
    def test_manager_clear(self):
        p = PoolManager(5)

        conn_pool = p.connection_from_url('http://google.com')
        self.assertEqual(len(p.pools), 1)

        conn = conn_pool._get_conn()

        p.clear()
        self.assertEqual(len(p.pools), 0)

        self.assertRaises(ClosedPoolError, conn_pool._get_conn)

        conn_pool._put_conn(conn)

        self.assertRaises(ClosedPoolError, conn_pool._get_conn)

        self.assertEqual(len(p.pools), 0)
开发者ID:Shootfast,项目名称:urllib3,代码行数:20,代码来源:test_poolmanager.py

示例14: test_manager_clear

# 需要导入模块: from urllib3.poolmanager import PoolManager [as 别名]
# 或者: from urllib3.poolmanager.PoolManager import connection_from_url [as 别名]
    def test_manager_clear(self):
        p = PoolManager(5)

        conn_pool = p.connection_from_url('http://google.com')
        assert len(p.pools) == 1

        conn = conn_pool._get_conn()

        p.clear()
        assert len(p.pools) == 0

        with pytest.raises(ClosedPoolError):
            conn_pool._get_conn()

        conn_pool._put_conn(conn)

        with pytest.raises(ClosedPoolError):
            conn_pool._get_conn()

        assert len(p.pools) == 0
开发者ID:NickMinnellaCS96,项目名称:urllib3,代码行数:22,代码来源:test_poolmanager.py

示例15: test_many_urls

# 需要导入模块: from urllib3.poolmanager import PoolManager [as 别名]
# 或者: from urllib3.poolmanager.PoolManager import connection_from_url [as 别名]
    def test_many_urls(self):
        urls = [
            "http://localhost:8081/foo",
            "http://www.google.com/mail",
            "http://localhost:8081/bar",
            "https://www.google.com/",
            "https://www.google.com/mail",
            "http://yahoo.com",
            "http://bing.com",
            "http://yahoo.com/",
        ]

        connections = set()

        p = PoolManager(10)

        for url in urls:
            conn = p.connection_from_url(url)
            connections.add(conn)

        assert len(connections) == 5
开发者ID:NickMinnellaCS96,项目名称:urllib3,代码行数:23,代码来源:test_poolmanager.py


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