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): ...@@ -34,7 +34,7 @@ def gevent_wait_callback(conn, timeout=None):
extensions.set_wait_callback(gevent_wait_callback) extensions.set_wait_callback(gevent_wait_callback)
class DatabaseConnectionPool(object): class AbstractDatabaseConnectionPool(object):
def __init__(self, maxsize=100): def __init__(self, maxsize=100):
if not isinstance(maxsize, integer_types): if not isinstance(maxsize, integer_types):
...@@ -43,6 +43,9 @@ class DatabaseConnectionPool(object): ...@@ -43,6 +43,9 @@ class DatabaseConnectionPool(object):
self.pool = Queue() self.pool = Queue()
self.size = 0 self.size = 0
def create_connection(self):
raise NotImplementedError()
def get(self): def get(self):
pool = self.pool pool = self.pool
if self.size >= self.maxsize or pool.qsize(): if self.size >= self.maxsize or pool.qsize():
...@@ -134,14 +137,14 @@ class DatabaseConnectionPool(object): ...@@ -134,14 +137,14 @@ class DatabaseConnectionPool(object):
yield item yield item
class PostgresConnectionPool(DatabaseConnectionPool): class PostgresConnectionPool(AbstractDatabaseConnectionPool):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.connect = kwargs.pop('connect', connect) self.connect = kwargs.pop('connect', connect)
maxsize = kwargs.pop('maxsize', None) maxsize = kwargs.pop('maxsize', None)
self.args = args self.args = args
self.kwargs = kwargs self.kwargs = kwargs
DatabaseConnectionPool.__init__(self, maxsize) AbstractDatabaseConnectionPool.__init__(self, maxsize)
def create_connection(self): def create_connection(self):
return self.connect(*self.args, **self.kwargs) return self.connect(*self.args, **self.kwargs)
......
...@@ -100,6 +100,8 @@ class socket(object): ...@@ -100,6 +100,8 @@ class socket(object):
to be aware of or may document a method the standard library does not. 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): def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, _sock=None):
if _sock is None: if _sock is None:
self._sock = _realsocket(family, type, proto) self._sock = _realsocket(family, type, proto)
...@@ -463,6 +465,15 @@ class socket(object): ...@@ -463,6 +465,15 @@ class socket(object):
type = property(lambda self: self._sock.type) type = property(lambda self: self._sock.type)
proto = property(lambda self: self._sock.proto) 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 # 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" _s = "def %s(self, *args): return self._sock.%s(*args)\n\n"
......
...@@ -178,7 +178,7 @@ class SSLSocket(socket): ...@@ -178,7 +178,7 @@ class SSLSocket(socket):
if connected: if connected:
# create the SSL object # create the SSL object
try: try:
self._sslobj = self.context._wrap_socket(self._sock, server_side, self._sslobj = self._context._wrap_socket(self._sock, server_side,
server_hostname) server_hostname)
if do_handshake_on_connect: if do_handshake_on_connect:
timeout = self.gettimeout() timeout = self.gettimeout()
...@@ -487,7 +487,7 @@ class SSLSocket(socket): ...@@ -487,7 +487,7 @@ class SSLSocket(socket):
raise raise
self._wait(self._write_event, timeout_exc=_SSLErrorHandshakeTimeout) self._wait(self._write_event, timeout_exc=_SSLErrorHandshakeTimeout)
if self.context.check_hostname: if self._context.check_hostname:
if not self.server_hostname: if not self.server_hostname:
raise ValueError("check_hostname needs server_hostname " raise ValueError("check_hostname needs server_hostname "
"argument") "argument")
...@@ -500,7 +500,7 @@ class SSLSocket(socket): ...@@ -500,7 +500,7 @@ class SSLSocket(socket):
# connected at the time of the call. We connect it, then wrap it. # connected at the time of the call. We connect it, then wrap it.
if self._connected: if self._connected:
raise ValueError("attempt to connect already-connected SSLSocket!") 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: try:
if connect_ex: if connect_ex:
rc = socket.connect_ex(self, addr) rc = socket.connect_ex(self, addr)
...@@ -532,7 +532,7 @@ class SSLSocket(socket): ...@@ -532,7 +532,7 @@ class SSLSocket(socket):
SSL channel, and the address of the remote client.""" SSL channel, and the address of the remote client."""
newsock, addr = socket.accept(self) newsock, addr = socket.accept(self)
newsock = self.context.wrap_socket(newsock, newsock = self._context.wrap_socket(newsock,
do_handshake_on_connect=self.do_handshake_on_connect, do_handshake_on_connect=self.do_handshake_on_connect,
suppress_ragged_eofs=self.suppress_ragged_eofs, suppress_ragged_eofs=self.suppress_ragged_eofs,
server_side=True) server_side=True)
......
...@@ -572,7 +572,7 @@ class SSLSocket(socket): ...@@ -572,7 +572,7 @@ class SSLSocket(socket):
raise raise
self._wait(self._write_event, timeout_exc=_SSLErrorHandshakeTimeout) self._wait(self._write_event, timeout_exc=_SSLErrorHandshakeTimeout)
if self.context.check_hostname: if self._context.check_hostname:
if not self.server_hostname: if not self.server_hostname:
raise ValueError("check_hostname needs server_hostname " raise ValueError("check_hostname needs server_hostname "
"argument") "argument")
...@@ -585,7 +585,7 @@ class SSLSocket(socket): ...@@ -585,7 +585,7 @@ class SSLSocket(socket):
# connected at the time of the call. We connect it, then wrap it. # connected at the time of the call. We connect it, then wrap it.
if self._connected: if self._connected:
raise ValueError("attempt to connect already-connected SSLSocket!") 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: try:
if connect_ex: if connect_ex:
rc = socket.connect_ex(self, addr) rc = socket.connect_ex(self, addr)
...@@ -617,7 +617,7 @@ class SSLSocket(socket): ...@@ -617,7 +617,7 @@ class SSLSocket(socket):
SSL channel, and the address of the remote client.""" SSL channel, and the address of the remote client."""
newsock, addr = socket.accept(self) newsock, addr = socket.accept(self)
newsock = self.context.wrap_socket(newsock, newsock = self._context.wrap_socket(newsock,
do_handshake_on_connect=self.do_handshake_on_connect, do_handshake_on_connect=self.do_handshake_on_connect,
suppress_ragged_eofs=self.suppress_ragged_eofs, suppress_ragged_eofs=self.suppress_ragged_eofs,
server_side=True) server_side=True)
......
...@@ -184,6 +184,9 @@ class BaseServer(object): ...@@ -184,6 +184,9 @@ class BaseServer(object):
def do_close(self, *args): def do_close(self, *args):
pass pass
def do_read(self):
raise NotImplementedError()
def _do_read(self): def _do_read(self):
for _ in xrange(self.max_accept): for _ in xrange(self.max_accept):
if self.full(): if self.full():
......
...@@ -4,6 +4,10 @@ Secure Sockets Layer (SSL/TLS) module. ...@@ -4,6 +4,10 @@ Secure Sockets Layer (SSL/TLS) module.
from gevent._compat import PY2 from gevent._compat import PY2
from gevent._util import copy_globals 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 PY2:
if hasattr(__import__('ssl'), 'SSLContext'): if hasattr(__import__('ssl'), 'SSLContext'):
# It's not sufficient to check for >= 2.7.9; some distributions # It's not sufficient to check for >= 2.7.9; some distributions
......
...@@ -9,7 +9,7 @@ pipelining, and not supporting SSL. ...@@ -9,7 +9,7 @@ pipelining, and not supporting SSL.
Use :mod:`gevent.pywsgi` 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 import gevent.pywsgi as _pywsgi
__all__ = _pywsgi.__all__ __all__ = _pywsgi.__all__
del _pywsgi 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