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


Python urllib3.connection方法代码示例

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


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

示例1: _new_conn

# 需要导入模块: import urllib3 [as 别名]
# 或者: from urllib3 import connection [as 别名]
def _new_conn(self):
		extra_kw = {
			"family": self.family
		}
		if self.source_address:
			extra_kw['source_address'] = self.source_address

		if self.socket_options:
			extra_kw['socket_options'] = self.socket_options

		try:
			dns_host = getattr(self, "_dns_host", self.host)
			conn = create_connection(
				(dns_host, self.port), self.timeout, **extra_kw)
		except socket.timeout:
			raise urllib3.exceptions.ConnectTimeoutError(
				self, "Connection to %s timed out. (connect timeout=%s)" %
				(self.host, self.timeout))
		except OSError as e:
			raise urllib3.exceptions.NewConnectionError(
				self, "Failed to establish a new connection: %s" % e)

		return conn 
开发者ID:ipfs-shipyard,项目名称:py-ipfs-http-client,代码行数:25,代码来源:requests_wrapper.py

示例2: _send_request

# 需要导入模块: import urllib3 [as 别名]
# 或者: from urllib3 import connection [as 别名]
def _send_request(wrapped, instance, args, kwargs):
    def decompose_args(method, url, body, headers, encode_chunked=False):
        # skip httplib tracing for SDK built-in centralized sampling pollers
        if (('/GetSamplingRules' in args or '/SamplingTargets' in args) and
                type(instance).__name__ == 'botocore.awsrequest.AWSHTTPConnection'):
            return wrapped(*args, **kwargs)

        # Only injects headers when the subsegment for the outgoing
        # calls are opened successfully.
        subsegment = None
        try:
            subsegment = xray_recorder.current_subsegment()
        except SegmentNotFoundException:
            pass
        if subsegment:
            inject_trace_header(headers, subsegment)

        if issubclass(instance.__class__, urllib3.connection.HTTPSConnection):
            ssl_cxt = getattr(instance, 'ssl_context', None)
        elif issubclass(instance.__class__, httplib.HTTPSConnection):
            ssl_cxt = getattr(instance, '_context', None)
        else:
            # In this case, the patcher can't determine which module the connection instance is from.
            # We default to it to check ssl_context but may be None so that the default scheme would be
            # (and may falsely be) http.
            ssl_cxt = getattr(instance, 'ssl_context', None)
        scheme = 'https' if ssl_cxt and type(ssl_cxt).__name__ == 'SSLContext' else 'http'
        xray_url = '{}://{}{}'.format(scheme, instance.host, url)
        xray_data = _XRay_Data(method, instance.host, xray_url)
        setattr(instance, _XRAY_PROP, xray_data)

        # we add a segment here in case connect fails
        return xray_recorder.record_subsegment(
            wrapped, instance, args, kwargs,
            name=get_hostname(xray_data.url),
            namespace='remote',
            meta_processor=http_send_request_processor
        )

    return decompose_args(*args, **kwargs) 
开发者ID:aws,项目名称:aws-xray-sdk-python,代码行数:42,代码来源:patch.py

示例3: status

# 需要导入模块: import urllib3 [as 别名]
# 或者: from urllib3 import connection [as 别名]
def status(self):
        ret = dict(last_getinfo=self.last_getinfo,
                   connections=[])
        for connection in self._conn.pool.queue:
            if connection is None:
                continue
            ret['connections'].append(connection.status)
        return ret 
开发者ID:simplecrypto,项目名称:powerpool,代码行数:10,代码来源:base.py

示例4: __init__

# 需要导入模块: import urllib3 [as 别名]
# 或者: from urllib3 import connection [as 别名]
def __init__(self):
        self._down_connections = []  # list of RPC conns that are down
        self._poll_connection = None  # our currently active RPC connection
        self._live_connections = []  # list of live RPC connections
        self._connected = Event()  # An event type status flag 
开发者ID:simplecrypto,项目名称:powerpool,代码行数:7,代码来源:base.py

示例5: _monitor_nodes

# 需要导入模块: import urllib3 [as 别名]
# 或者: from urllib3 import connection [as 别名]
def _monitor_nodes(self):
        remlist = []
        for conn in self._down_connections:
            try:
                conn.getinfo()
            except (urllib3.exceptions.HTTPError, CoinRPCException, ValueError):
                self.logger.warn("RPC connection {} still down!".format(conn.name))
                continue

            self._live_connections.append(conn)
            remlist.append(conn)
            self.logger.info("Now connected to {} RPC Server {}."
                             .format(self.config['currency'], conn.name))

            # if this connection has a higher priority than current
            if self._poll_connection is not None:
                curr_poll = self._poll_connection.config['poll_priority']
                if conn.config['poll_priority'] > curr_poll:
                    self.logger.info("RPC connection {} has higher poll priority than "
                                     "current poll connection, switching..."
                                     .format(conn.name))
                    self._poll_connection = conn
            else:
                self._connected.set()
                self._poll_connection = conn
                self.logger.info("RPC connection {} defaulting poll connection"
                                 .format(conn.name))

        for conn in remlist:
            self._down_connections.remove(conn) 
开发者ID:simplecrypto,项目名称:powerpool,代码行数:32,代码来源:base.py

示例6: down_connection

# 需要导入模块: import urllib3 [as 别名]
# 或者: from urllib3 import connection [as 别名]
def down_connection(self, conn):
        """ Called when a connection goes down. Removes if from the list of
        live connections and recomputes a new. """
        if not conn:
            self.logger.warn("Tried to down a NoneType connection")
            return

        if conn in self._live_connections:
            self._live_connections.remove(conn)

        if self._poll_connection is conn:
            # find the next best poll connection
            try:
                self._poll_connection = min(self._live_connections,
                                            key=lambda x: x.config['poll_priority'])
            except ValueError:
                self._poll_connection = None
                self._connected.clear()
                self.logger.error("No RPC connections available for polling!!!")
            else:
                self.logger.warn("RPC connection {} switching to poll_connection "
                                 "after {} went down!"
                                 .format(self._poll_connection.name, conn.name))

        if conn not in self._down_connections:
            self.logger.info("Server at {} now reporting down".format(conn.name))
            self._down_connections.append(conn) 
开发者ID:simplecrypto,项目名称:powerpool,代码行数:29,代码来源:base.py

示例7: create_connection

# 需要导入模块: import urllib3 [as 别名]
# 或者: from urllib3 import connection [as 别名]
def create_connection(address, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
                      source_address=None, socket_options=None,
                      family=socket.AF_UNSPEC):
	host, port = address
	if host.startswith('['):
		host = host.strip('[]')
	err = None

	if not family or family == socket.AF_UNSPEC:
		family = urllib3.util.connection.allowed_gai_family()

	for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
		af, socktype, proto, canonname, sa = res
		sock = None
		try:
			sock = socket.socket(af, socktype, proto)

			# If provided, set socket level options before connecting.
			if socket_options is not None:
				for opt in socket_options:
					sock.setsockopt(*opt)

			if timeout is not socket._GLOBAL_DEFAULT_TIMEOUT:
				sock.settimeout(timeout)
			if source_address:
				sock.bind(source_address)
			sock.connect(sa)
			return sock
		except OSError as e:
			err = e
			if sock is not None:
				sock.close()
				sock = None

	if err is not None:
		raise err

	raise OSError("getaddrinfo returns an empty list")


# Override the `urllib3` low-level Connection objects that do the actual work
# of speaking HTTP 
开发者ID:ipfs-shipyard,项目名称:py-ipfs-http-client,代码行数:44,代码来源:requests_wrapper.py


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