Skip to content

Commit

Permalink
refactor: move SocketMocketCore from mocket.utils to mocket.io
Browse files Browse the repository at this point in the history
  • Loading branch information
betaboon committed Nov 17, 2024
1 parent 1df405c commit 207778a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
17 changes: 17 additions & 0 deletions mocket/io.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import io
import os


class MocketSocketCore(io.BytesIO):
def __init__(self, address) -> None:
self._address = address
super().__init__()

def write(self, content):
from mocket import Mocket

super().write(content)

_, w_fd = Mocket.get_pair(self._address)
if w_fd:
os.write(w_fd, content)
7 changes: 2 additions & 5 deletions mocket/mocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@


from mocket.compat import decode_from_bytes, encode_to_bytes
from mocket.io import MocketSocketCore
from mocket.mode import MocketMode
from mocket.utils import (
MocketSocketCore,
hexdump,
hexload,
)
from mocket.utils import hexdump, hexload

xxh32 = None
try:
Expand Down
20 changes: 3 additions & 17 deletions mocket/utils.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,20 @@
from __future__ import annotations

import binascii
import io
import os
import ssl
from typing import Callable

from mocket.compat import decode_from_bytes, encode_to_bytes

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

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

SSL_PROTOCOL = ssl.PROTOCOL_TLSv1_2


class MocketSocketCore(io.BytesIO):
def __init__(self, address) -> None:
self._address = address
super().__init__()

def write(self, content):
from mocket import Mocket

super().write(content)

_, w_fd = Mocket.get_pair(self._address)
if w_fd:
os.write(w_fd, content)


def hexdump(binary_string: bytes) -> str:
r"""
>>> hexdump(b"bar foobar foo") == decode_from_bytes(encode_to_bytes("62 61 72 20 66 6F 6F 62 61 72 20 66 6F 6F"))
Expand Down

0 comments on commit 207778a

Please sign in to comment.