Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Laika committed Jul 8, 2024
1 parent 76adca9 commit 45181cf
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 16 deletions.
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ dependencies = [
"libtmux>=0.37.0",
"lief>=0.14.1",
"rzpipe>=0.6.0",
"pillow>=10.3.0",
"py7zr>=0.21.0",
"pillow>=10.4.0",
"py7zr>=0.21.1",
"flask>=3.0.3",
"rich>=13.7.1",
"setuptools>=70.1.1",
"setuptools>=70.2.0",
]

[build-system]
Expand Down
7 changes: 4 additions & 3 deletions requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# features: []
# all-features: false
# with-sources: false
# generate-hashes: false

-e file:.
blinker==1.8.2
Expand Down Expand Up @@ -35,11 +36,11 @@ mdurl==0.1.2
# via markdown-it-py
multivolumefile==0.2.3
# via py7zr
pillow==10.3.0
pillow==10.4.0
# via toyotama
psutil==5.9.8
# via py7zr
py7zr==0.21.0
py7zr==0.21.1
# via toyotama
pybcj==1.0.2
# via py7zr
Expand All @@ -56,7 +57,7 @@ rich==13.7.1
ruff==0.4.9
rzpipe==0.6.0
# via toyotama
setuptools==70.1.1
setuptools==70.2.0
# via toyotama
texttable==1.7.0
# via py7zr
Expand Down
7 changes: 4 additions & 3 deletions requirements.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# features: []
# all-features: false
# with-sources: false
# generate-hashes: false

-e file:.
blinker==1.8.2
Expand Down Expand Up @@ -35,11 +36,11 @@ mdurl==0.1.2
# via markdown-it-py
multivolumefile==0.2.3
# via py7zr
pillow==10.3.0
pillow==10.4.0
# via toyotama
psutil==5.9.8
# via py7zr
py7zr==0.21.0
py7zr==0.21.1
# via toyotama
pybcj==1.0.2
# via py7zr
Expand All @@ -55,7 +56,7 @@ rich==13.7.1
# via toyotama
rzpipe==0.6.0
# via toyotama
setuptools==70.1.1
setuptools==70.2.0
# via toyotama
texttable==1.7.0
# via py7zr
Expand Down
3 changes: 0 additions & 3 deletions toyotama/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@

logger = logging.getLogger("toyotama")
logger.setLevel(getenv("TOYOTAMA_LOG_LEVEL", "INFO").upper())
# handler = StreamHandler()
# formatter = CustomFormatter(colored=bool(getenv("TOYOTAMA_LOG_COLORED", True)))
# handler.setFormatter(formatter)
handler = RichHandler(rich_tracebacks=True)
handler.setFormatter(logging.Formatter("%(message)s"))
logger.addHandler(handler)
Expand Down
18 changes: 16 additions & 2 deletions toyotama/connect/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,24 @@


class Socket(Tube):
def __init__(self, target: str, timeout: float = 30.0):
def __init__(
self,
target: str,
timeout: float = 30.0,
ssl: bool = False,
ssl_context = None,
ssl_args = None,
*args,
**kwargs,
):
"""Create a socket connection to a remote host.
Args:
target (str): The target host and port. Example: "nc localhost 1234"
timeout (float, optional): Timeout in seconds. Defaults to 30.0.
"""

super().__init__()
super().__init__(*args, **kwargs)
_, host, port = target.split()
self.host: str = host
self.port: int = int(port)
Expand All @@ -25,6 +34,11 @@ def __init__(self, target: str, timeout: float = 30.0):
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.settimeout(timeout)
self.sock.connect((self.host, self.port))
if ssl:
import ssl as ssl_
ssl_args = ssl_args or {}
ssl_context = ssl_context or ssl_.SSLContext(ssl_.PROTOCOL_TLSv1_2)
self.sock = ssl_context.wrap_socket(self.sock, **ssl_args)

def _socket(self):
return self.sock
Expand Down
9 changes: 7 additions & 2 deletions toyotama/util/bytes_.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,24 @@ def __xor__(self, other: Self) -> Self:
logger.warning("XOR: length of bytes is not equal")
return Bytes(x ^ y for x, y in zip(self, other))

def __rxor__(self, other: bytes) -> Self:
if isinstance(other, bytes):
return Bytes(self.__xor__(other))
raise NotImplemented

def __or__(self, other: Self) -> Self:
if isinstance(other, Bytes):
return Bytes(super().__add__(other))
elif isinstance(other, bytes):
return Bytes(super().__add__(other))
return NotImplemented
raise NotImplemented

def __ror__(self, other: Self) -> Self:
if isinstance(other, Bytes):
return Bytes(other.__add__(self))
elif isinstance(other, bytes):
return Bytes(other.__add__(self))
return NotImplemented
raise NotImplemented

def __getitem__(self, key: int | slice) -> Self:
return Bytes(super().__getitem__(key))
Expand Down

0 comments on commit 45181cf

Please sign in to comment.