Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit

Permalink
updated packages.urllib3 with latest yieldfrom.urllib3
Browse files Browse the repository at this point in the history
  • Loading branch information
rdbhost committed Oct 12, 2014
1 parent f5aff6b commit fb91f1f
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 440 deletions.
8 changes: 2 additions & 6 deletions requests/packages/urllib3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class NullHandler(logging.Handler):
def emit(self, record):
pass

logger = logging.getLogger('one') #.addHandler(NullHandler())
logger.setLevel(logging.DEBUG)
logging.getLogger(__name__).addHandler(NullHandler())

def add_stderr_logger(level=logging.DEBUG):
"""
Expand All @@ -44,17 +43,14 @@ def add_stderr_logger(level=logging.DEBUG):
"""
# This method needs to be in this __init__.py to get the __name__ correct
# even if urllib3 is vendored within another package.
logger = logging.getLogger('one')
logger = logging.getLogger(__name__)
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s'))
logger.addHandler(handler)
logger.setLevel(level)
logger.debug('Added a stderr logging handler to logger: %s' % __name__)
return handler

add_stderr_logger(logging.DEBUG)
#logger.debug('added stderr logger')

# ... Clean up.
del NullHandler

Expand Down
8 changes: 1 addition & 7 deletions requests/packages/urllib3/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@
from .packages import six
import asyncio


from yieldfrom.httpclient import HTTPConnection as _HTTPConnection, HTTPSConnection as _HTTPSConnection, \
from yieldfrom.http.client import HTTPConnection as _HTTPConnection, HTTPSConnection as _HTTPSConnection, \
HTTPException, create_connection as _create_connection

#try: # Python 3
# from http.client import HTTPConnection as _HTTPConnection, HTTPException
#except ImportError:
# from httplib import HTTPConnection as _HTTPConnection, HTTPException


class DummyConnection(object):
"Used to detect a failed ConnectionCls import."
Expand Down
32 changes: 20 additions & 12 deletions requests/packages/urllib3/connectionpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import socket
import asyncio

from queue import LifoQueue, Empty, Full
#from queue import LifoQueue, Empty, Full
from asyncio.queues import LifoQueue, QueueEmpty, QueueFull

from .exceptions import (
ClosedPoolError,
Expand Down Expand Up @@ -161,7 +162,7 @@ def __init__(self, host, port=None, strict=False,

# Fill the queue up so that doing get() on it will block properly
for _ in xrange(maxsize):
self.pool.put(None)
self.pool.put_nowait(0) # None fools coroutine handler

# These are mostly for testing and debugging purposes.
self.num_connections = 0
Expand All @@ -187,6 +188,7 @@ def _new_conn(self):
strict=self.strict, **self.conn_kw)
return conn

@asyncio.coroutine
def _get_conn(self, timeout=None):
"""
Get a connection. Will return a pooled connection if one is available.
Expand All @@ -201,12 +203,18 @@ def _get_conn(self, timeout=None):
"""
conn = None
try:
conn = self.pool.get(block=self.block, timeout=timeout)
timeout = Timeout.from_float(timeout)
try:
conn = yield from asyncio.wait_for(self.pool.get(), timeout.connect_timeout)
pass

except AttributeError: # self.pool is None
raise ClosedPoolError(self, "Pool is closed.")

except AttributeError: # self.pool is None
raise ClosedPoolError(self, "Pool is closed.")
except asyncio.TimeoutError:
raise QueueEmpty

except Empty:
except QueueEmpty:
if self.block:
raise EmptyPoolError(self,
"Pool reached maximum size and no more "
Expand Down Expand Up @@ -240,12 +248,12 @@ def _put_conn(self, conn):
If the pool is closed, then the connection will be closed and discarded.
"""
try:
self.pool.put(conn, block=False)
self.pool.put_nowait(conn or 0)
return # Everything is dandy, done.
except AttributeError:
# self.pool is None.
pass
except Full:
except QueueFull:
# This should never happen if self.block == True
log.warning(
"Connection pool is full, discarding connection: %s" %
Expand Down Expand Up @@ -360,11 +368,11 @@ def close(self):

try:
while True:
conn = old_pool.get(block=False)
conn = old_pool.get_nowait()
if conn:
conn.close()

except Empty:
except QueueEmpty:
pass # Done.

def is_same_host(self, url):
Expand Down Expand Up @@ -498,7 +506,7 @@ def urlopen(self, method, url, body=None, headers=None, retries=None,

try:
# Request a connection from the queue.
conn = self._get_conn(timeout=pool_timeout)
conn = yield from self._get_conn(timeout=pool_timeout)

# Make the request on the httplib connection object.
httplib_response = yield from self._make_request(conn, method, url,
Expand Down Expand Up @@ -526,7 +534,7 @@ def urlopen(self, method, url, body=None, headers=None, retries=None,
# ``response.release_conn()`` is called (implicitly by
# ``response.read()``)

except Empty:
except QueueEmpty:
# Timed out by queue.
raise EmptyPoolError(self, "No pool connections are available.")

Expand Down
Empty file.
114 changes: 0 additions & 114 deletions requests/packages/urllib3/contrib/ntlmpool.py

This file was deleted.

Loading

0 comments on commit fb91f1f

Please sign in to comment.