Skip to content

Commit

Permalink
Refactoring FakeSSLContext. (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
mindflayer authored Oct 20, 2024
1 parent 17fd151 commit ea5ad79
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions mocket/mocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

from .compat import basestring, byte_type, decode_from_bytes, encode_to_bytes, text_type
from .utils import (
SSL_PROTOCOL,
MocketMode,
MocketSocketCore,
get_mocketize,
Expand Down Expand Up @@ -98,20 +97,9 @@ def check_hostname(self):
def check_hostname(self, _):
self._check_hostname = False

def __init__(self, sock=None, server_hostname=None, _context=None, *args, **kwargs):
def __init__(self, *args, **kwargs):
self._set_dummy_methods()

if isinstance(sock, MocketSocket):
self.sock = sock
self.sock._host = server_hostname
self.sock.true_socket = true_ssl_socket(
sock=self.sock.true_socket,
server_hostname=server_hostname,
_context=true_ssl_context(protocol=SSL_PROTOCOL),
)
elif isinstance(sock, int) and true_ssl_context:
self.context = true_ssl_context(sock)

def _set_dummy_methods(self):
def dummy_method(*args, **kwargs):
pass
Expand All @@ -120,7 +108,7 @@ def dummy_method(*args, **kwargs):
setattr(self, m, dummy_method)

@staticmethod
def wrap_socket(sock=sock, *args, **kwargs):
def wrap_socket(sock, *args, **kwargs):
sock.kwargs = kwargs
sock._secure_socket = True
return sock
Expand All @@ -131,10 +119,6 @@ def wrap_bio(incoming, outcoming, *args, **kwargs):
ssl_obj._host = kwargs["server_hostname"]
return ssl_obj

def __getattr__(self, name):
if self.sock is not None:
return getattr(self.sock, name)


def create_connection(address, timeout=None, source_address=None):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP)
Expand Down

0 comments on commit ea5ad79

Please sign in to comment.