Commit ba9883cd authored by Jason Madden's avatar Jason Madden

Merge branch 'master' into select-errors

parents 8bd6e622 48202d1f
......@@ -34,7 +34,7 @@ def gevent_wait_callback(conn, timeout=None):
extensions.set_wait_callback(gevent_wait_callback)
class DatabaseConnectionPool(object):
class AbstractDatabaseConnectionPool(object):
def __init__(self, maxsize=100):
if not isinstance(maxsize, integer_types):
......@@ -43,6 +43,9 @@ class DatabaseConnectionPool(object):
self.pool = Queue()
self.size = 0
def create_connection(self):
raise NotImplementedError()
def get(self):
pool = self.pool
if self.size >= self.maxsize or pool.qsize():
......@@ -134,14 +137,14 @@ class DatabaseConnectionPool(object):
yield item
class PostgresConnectionPool(DatabaseConnectionPool):
class PostgresConnectionPool(AbstractDatabaseConnectionPool):
def __init__(self, *args, **kwargs):
self.connect = kwargs.pop('connect', connect)
maxsize = kwargs.pop('maxsize', None)
self.args = args
self.kwargs = kwargs
DatabaseConnectionPool.__init__(self, maxsize)
AbstractDatabaseConnectionPool.__init__(self, maxsize)
def create_connection(self):
return self.connect(*self.args, **self.kwargs)
......
......@@ -100,6 +100,8 @@ class socket(object):
to be aware of or may document a method the standard library does not.
"""
# pylint:disable=too-many-public-methods
def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, _sock=None):
if _sock is None:
self._sock = _realsocket(family, type, proto)
......@@ -463,6 +465,15 @@ class socket(object):
type = property(lambda self: self._sock.type)
proto = property(lambda self: self._sock.proto)
def fileno(self):
return self._sock.fileno()
def getsockname(self):
return self._sock.getsockname()
def getpeername(self):
return self._sock.getpeername()
# delegate the functions that we haven't implemented to the real socket object
_s = "def %s(self, *args): return self._sock.%s(*args)\n\n"
......
......@@ -178,8 +178,8 @@ class SSLSocket(socket):
if connected:
# create the SSL object
try:
self._sslobj = self.context._wrap_socket(self._sock, server_side,
server_hostname)
self._sslobj = self._context._wrap_socket(self._sock, server_side,
server_hostname)
if do_handshake_on_connect:
timeout = self.gettimeout()
if timeout == 0.0:
......@@ -487,7 +487,7 @@ class SSLSocket(socket):
raise
self._wait(self._write_event, timeout_exc=_SSLErrorHandshakeTimeout)
if self.context.check_hostname:
if self._context.check_hostname:
if not self.server_hostname:
raise ValueError("check_hostname needs server_hostname "
"argument")
......@@ -500,7 +500,7 @@ class SSLSocket(socket):
# connected at the time of the call. We connect it, then wrap it.
if self._connected:
raise ValueError("attempt to connect already-connected SSLSocket!")
self._sslobj = self.context._wrap_socket(self._sock, False, self.server_hostname)
self._sslobj = self._context._wrap_socket(self._sock, False, self.server_hostname)
try:
if connect_ex:
rc = socket.connect_ex(self, addr)
......@@ -532,10 +532,10 @@ class SSLSocket(socket):
SSL channel, and the address of the remote client."""
newsock, addr = socket.accept(self)
newsock = self.context.wrap_socket(newsock,
do_handshake_on_connect=self.do_handshake_on_connect,
suppress_ragged_eofs=self.suppress_ragged_eofs,
server_side=True)
newsock = self._context.wrap_socket(newsock,
do_handshake_on_connect=self.do_handshake_on_connect,
suppress_ragged_eofs=self.suppress_ragged_eofs,
server_side=True)
return newsock, addr
def get_channel_binding(self, cb_type="tls-unique"):
......
......@@ -572,7 +572,7 @@ class SSLSocket(socket):
raise
self._wait(self._write_event, timeout_exc=_SSLErrorHandshakeTimeout)
if self.context.check_hostname:
if self._context.check_hostname:
if not self.server_hostname:
raise ValueError("check_hostname needs server_hostname "
"argument")
......@@ -585,7 +585,7 @@ class SSLSocket(socket):
# connected at the time of the call. We connect it, then wrap it.
if self._connected:
raise ValueError("attempt to connect already-connected SSLSocket!")
self._sslobj = self.context._wrap_socket(self._sock, False, self.server_hostname, ssl_sock=self)
self._sslobj = self._context._wrap_socket(self._sock, False, self.server_hostname, ssl_sock=self)
try:
if connect_ex:
rc = socket.connect_ex(self, addr)
......@@ -617,10 +617,10 @@ class SSLSocket(socket):
SSL channel, and the address of the remote client."""
newsock, addr = socket.accept(self)
newsock = self.context.wrap_socket(newsock,
do_handshake_on_connect=self.do_handshake_on_connect,
suppress_ragged_eofs=self.suppress_ragged_eofs,
server_side=True)
newsock = self._context.wrap_socket(newsock,
do_handshake_on_connect=self.do_handshake_on_connect,
suppress_ragged_eofs=self.suppress_ragged_eofs,
server_side=True)
return newsock, addr
def makefile(self, mode='r', bufsize=-1):
......
......@@ -184,6 +184,9 @@ class BaseServer(object):
def do_close(self, *args):
pass
def do_read(self):
raise NotImplementedError()
def _do_read(self):
for _ in xrange(self.max_accept):
if self.full():
......
......@@ -4,6 +4,10 @@ Secure Sockets Layer (SSL/TLS) module.
from gevent._compat import PY2
from gevent._util import copy_globals
# things we expect to override, here for static analysis
def wrap_socket(sock, **kwargs): # pylint:disable=unused-argument
raise NotImplementedError()
if PY2:
if hasattr(__import__('ssl'), 'SSLContext'):
# It's not sufficient to check for >= 2.7.9; some distributions
......
......@@ -9,7 +9,7 @@ pipelining, and not supporting SSL.
Use :mod:`gevent.pywsgi`
"""
from gevent.pywsgi import * # pylint:disable=wildcard-import
from gevent.pywsgi import * # pylint:disable=wildcard-import,unused-wildcard-import
import gevent.pywsgi as _pywsgi
__all__ = _pywsgi.__all__
del _pywsgi
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment