Skip to content

Commit 14478af

Browse files
authored
Refactor rename ssl classes (#266)
* refactor: rename MocketSocketCore to MocketSocketIO * refactor: rename FakeSSLContext to MocketSSLContext
1 parent 8e7b3b6 commit 14478af

File tree

7 files changed

+23
-19
lines changed

7 files changed

+23
-19
lines changed

mocket/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22
from mocket.entry import MocketEntry
33
from mocket.mocket import Mocket
44
from mocket.mocketizer import Mocketizer, mocketize
5-
from mocket.ssl.context import FakeSSLContext
5+
from mocket.ssl.context import MocketSSLContext
6+
7+
# NOTE this is here for backwards-compat to keep old import-paths working
8+
from mocket.ssl.context import MocketSSLContext as FakeSSLContext
69

710
__all__ = (
811
"async_mocketize",
912
"mocketize",
1013
"Mocket",
1114
"MocketEntry",
1215
"Mocketizer",
16+
"MocketSSLContext",
1317
"FakeSSLContext",
1418
)
1519

mocket/inject.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def enable(
2929
mock_socketpair,
3030
mock_urllib3_match_hostname,
3131
)
32-
from mocket.ssl.context import FakeSSLContext
32+
from mocket.ssl.context import MocketSSLContext
3333

3434
Mocket._namespace = namespace
3535
Mocket._truesocket_recording_dir = truesocket_recording_dir
@@ -48,21 +48,21 @@ def enable(
4848
socket.gethostbyname = socket.__dict__["gethostbyname"] = mock_gethostbyname
4949
socket.getaddrinfo = socket.__dict__["getaddrinfo"] = mock_getaddrinfo
5050
socket.socketpair = socket.__dict__["socketpair"] = mock_socketpair
51-
ssl.wrap_socket = ssl.__dict__["wrap_socket"] = FakeSSLContext.wrap_socket
52-
ssl.SSLContext = ssl.__dict__["SSLContext"] = FakeSSLContext
51+
ssl.wrap_socket = ssl.__dict__["wrap_socket"] = MocketSSLContext.wrap_socket
52+
ssl.SSLContext = ssl.__dict__["SSLContext"] = MocketSSLContext
5353
socket.inet_pton = socket.__dict__["inet_pton"] = mock_inet_pton
5454
urllib3.util.ssl_.wrap_socket = urllib3.util.ssl_.__dict__["wrap_socket"] = (
55-
FakeSSLContext.wrap_socket
55+
MocketSSLContext.wrap_socket
5656
)
5757
urllib3.util.ssl_.ssl_wrap_socket = urllib3.util.ssl_.__dict__[
5858
"ssl_wrap_socket"
59-
] = FakeSSLContext.wrap_socket
59+
] = MocketSSLContext.wrap_socket
6060
urllib3.util.ssl_wrap_socket = urllib3.util.__dict__["ssl_wrap_socket"] = (
61-
FakeSSLContext.wrap_socket
61+
MocketSSLContext.wrap_socket
6262
)
6363
urllib3.connection.ssl_wrap_socket = urllib3.connection.__dict__[
6464
"ssl_wrap_socket"
65-
] = FakeSSLContext.wrap_socket
65+
] = MocketSSLContext.wrap_socket
6666
urllib3.connection.match_hostname = urllib3.connection.__dict__[
6767
"match_hostname"
6868
] = mock_urllib3_match_hostname

mocket/io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from mocket.mocket import Mocket
55

66

7-
class MocketSocketCore(io.BytesIO):
7+
class MocketSocketIO(io.BytesIO):
88
def __init__(self, address) -> None:
99
self._address = address
1010
super().__init__()

mocket/plugins/aiohttp_connector.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import contextlib
22

3-
from mocket import FakeSSLContext
3+
from mocket import MocketSSLContext
44

55
with contextlib.suppress(ModuleNotFoundError):
66
from aiohttp import ClientRequest
@@ -14,5 +14,5 @@ class MocketTCPConnector(TCPConnector):
1414
slightly patching the `ClientSession` while testing.
1515
"""
1616

17-
def _get_ssl_context(self, req: ClientRequest) -> FakeSSLContext:
18-
return FakeSSLContext()
17+
def _get_ssl_context(self, req: ClientRequest) -> MocketSSLContext:
18+
return MocketSSLContext()

mocket/socket.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from mocket.compat import decode_from_bytes, encode_to_bytes
2020
from mocket.entry import MocketEntry
21-
from mocket.io import MocketSocketCore
21+
from mocket.io import MocketSocketIO
2222
from mocket.mocket import Mocket
2323
from mocket.mode import MocketMode
2424
from mocket.types import (
@@ -148,9 +148,9 @@ def proto(self) -> int:
148148
return self._proto
149149

150150
@property
151-
def io(self) -> MocketSocketCore:
151+
def io(self) -> MocketSocketIO:
152152
if self._io is None:
153-
self._io = MocketSocketCore((self._host, self._port))
153+
self._io = MocketSocketIO((self._host, self._port))
154154
return self._io
155155

156156
def fileno(self) -> int:
@@ -196,7 +196,7 @@ def connect(self, address: Address) -> None:
196196
self._address = self._host, self._port = address
197197
Mocket._address = address
198198

199-
def makefile(self, mode: str = "r", bufsize: int = -1) -> MocketSocketCore:
199+
def makefile(self, mode: str = "r", bufsize: int = -1) -> MocketSocketIO:
200200
return self.io
201201

202202
def get_entry(self, data: bytes) -> MocketEntry | None:

mocket/ssl/context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
true_urllib3_wrap_socket = urllib3_wrap_socket
2828

2929

30-
class SuperFakeSSLContext:
30+
class _MocketSSLContext:
3131
"""For Python 3.6 and newer."""
3232

3333
class FakeSetter(int):
@@ -40,7 +40,7 @@ def __set__(self, *args: Any) -> None:
4040
verify_flags = FakeSetter()
4141

4242

43-
class FakeSSLContext(SuperFakeSSLContext):
43+
class MocketSSLContext(_MocketSSLContext):
4444
DUMMY_METHODS = (
4545
"load_default_certs",
4646
"load_verify_locations",

mocket/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from mocket.compat import decode_from_bytes, encode_to_bytes
88

99
# NOTE this is here for backwards-compat to keep old import-paths working
10-
from mocket.io import MocketSocketCore as MocketSocketCore
10+
from mocket.io import MocketSocketIO as MocketSocketCore
1111

1212
# NOTE this is here for backwards-compat to keep old import-paths working
1313
from mocket.mode import MocketMode as MocketMode

0 commit comments

Comments
 (0)