Skip to content

Instantly share code, notes, and snippets.

@slingamn
Created August 16, 2012 10:26
Show Gist options
  • Select an option

  • Save slingamn/3369110 to your computer and use it in GitHub Desktop.

Select an option

Save slingamn/3369110 to your computer and use it in GitHub Desktop.

Revisions

  1. slingamn created this gist Aug 16, 2012.
    60 changes: 60 additions & 0 deletions gistfile1.diff
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@
    diff --git a/requests/packages/urllib3/connectionpool.py b/requests/packages/urllib3/connectionpool.py
    index 97da544..fd324fd 100644
    --- a/requests/packages/urllib3/connectionpool.py
    +++ b/requests/packages/urllib3/connectionpool.py
    @@ -189,6 +189,7 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods):
    self.num_connections += 1
    log.info("Starting new HTTP connection (%d): %s" %
    (self.num_connections, self.host))
    + print "adding new connection for", self.host
    return HTTPConnection(host=self.host, port=self.port)

    def _get_conn(self, timeout=None):
    @@ -220,6 +221,7 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods):
    # If this is a persistent connection, check if it got disconnected
    if conn and is_connection_dropped(conn):
    log.info("Resetting dropped connection: %s" % self.host)
    + print "Resetting dropped connection: %s" % self.host
    conn.close()

    return conn or self._new_conn()
    @@ -239,6 +241,7 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods):
    If the pool is closed, then the connection will be closed and discarded.
    """
    try:
    + print "returning to pool:", self.host, repr(conn.sock.fileno())
    self.pool.put(conn, block=False)
    return # Everything is dandy, done.
    except AttributeError:
    @@ -294,9 +297,11 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods):
    while True:
    conn = old_pool.get(block=False)
    if conn:
    + print "Closing FD", self.host, conn.sock.fileno()
    conn.close()

    except Empty:
    + print "Pool is empty:", self.host
    pass # Done.

    def is_same_host(self, url):
    @@ -529,6 +534,7 @@ class HTTPSConnectionPool(HTTPConnectionPool):

    return HTTPSConnection(host=self.host, port=self.port)

    + print "adding new https connection for", self.host
    connection = VerifiedHTTPSConnection(host=self.host, port=self.port)
    connection.set_cert(key_file=self.key_file, cert_file=self.cert_file,
    cert_reqs=self.cert_reqs, ca_certs=self.ca_certs)
    diff --git a/requests/sessions.py b/requests/sessions.py
    index 73c7b17..b9a99f9 100644
    --- a/requests/sessions.py
    +++ b/requests/sessions.py
    @@ -113,6 +113,7 @@ class Session(object):
    Currently, this just closes the PoolManager, which closes pooled
    connections.
    """
    + print "closing requests.sessions.Session"
    self.poolmanager.clear()

    def request(self, method, url,