當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。