Skip to content

Commit

Permalink
Wrap SSL adapter base interface with ABC
Browse files Browse the repository at this point in the history
  • Loading branch information
webknjaz committed Mar 17, 2017
1 parent 894b08d commit 4a70039
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
28 changes: 26 additions & 2 deletions cheroot/ssl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
"""Implementation of the SSL adapter base interface."""

from abc import ABCMeta, abstractmethod

from six import add_metaclass


@add_metaclass(ABCMeta)
class Adapter(object):
"""Base class for SSL driver library adapters.
Expand All @@ -8,15 +16,31 @@ class Adapter(object):
socket file object``
"""

@abstractmethod
def __init__(self, certificate, private_key, certificate_chain=None, ciphers=None):
"""Set up certificates, private key ciphers and reset context."""
self.certificate = certificate
self.private_key = private_key
self.certificate_chain = certificate_chain
self.ciphers = ciphers
self.context = None

@abstractmethod
def bind(self, sock):
"""Wrap and return the given socket."""
return sock

@abstractmethod
def wrap(self, sock):
raise NotImplemented
"""Wrap and return the given socket, plus WSGI environ entries."""
raise NotImplementedError

@abstractmethod
def get_environ(self):
"""Return WSGI environ entries to be merged into each request."""
raise NotImplementedError

@abstractmethod
def makefile(self, sock, mode='r', bufsize=-1):
raise NotImplemented
"""Return socket file object."""
raise NotImplementedError
4 changes: 2 additions & 2 deletions cheroot/ssl/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class BuiltinSSLAdapter(Adapter):
"""The ciphers list of SSL."""

def __init__(self, certificate, private_key, certificate_chain=None, ciphers=None):
"""Set up context and ciphers in addition to base class properties if available."""
"""Set up context in addition to base class properties if available."""
if ssl is None:
raise ImportError('You must install the ssl module to use HTTPS.')

Expand All @@ -65,7 +65,7 @@ def __init__(self, certificate, private_key, certificate_chain=None, ciphers=Non

def bind(self, sock):
"""Wrap and return the given socket."""
return sock
return super(BuiltinSSLAdapter, self).bind(sock)

def wrap(self, sock):
"""Wrap and return the given socket, plus WSGI environ entries."""
Expand Down
1 change: 1 addition & 0 deletions cheroot/ssl/pyopenssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def get_environ(self):
return ssl_environ

def makefile(self, sock, mode='r', bufsize=-1):
"""Return socket file object."""
if SSL and isinstance(sock, SSL.ConnectionType):
timeout = sock.gettimeout()
f = SSL_fileobject(sock, mode, bufsize)
Expand Down

0 comments on commit 4a70039

Please sign in to comment.