Skip to content

Commit 5fa7b6f

Browse files
author
BiffoBear
committed
Took the _ off SOCK_STREAM and AF_INET in socket.socket as they are for users.
1 parent 011b14f commit 5fa7b6f

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

adafruit_wiznet5k/adafruit_wiznet5k_socket.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ def htons(x: int) -> int:
6969
return (((x) << 8) & 0xFF00) | (((x) >> 8) & 0xFF)
7070

7171

72-
_SOCK_STREAM = const(0x21) # TCP
72+
SOCK_STREAM = const(0x21) # TCP
7373
_TCP_MODE = 80
7474
SOCK_DGRAM = const(0x02) # UDP
75-
_AF_INET = const(3)
75+
AF_INET = const(3)
7676
_SOCKET_INVALID = const(255)
7777

7878

@@ -103,8 +103,8 @@ def getaddrinfo(
103103
if not isinstance(port, int):
104104
raise ValueError("Port must be an integer")
105105
if is_ipv4(host):
106-
return [(_AF_INET, socktype, proto, "", (host, port))]
107-
return [(_AF_INET, socktype, proto, "", (gethostbyname(host), port))]
106+
return [(AF_INET, socktype, proto, "", (host, port))]
107+
return [(AF_INET, socktype, proto, "", (gethostbyname(host), port))]
108108

109109

110110
def gethostbyname(hostname: str) -> str:
@@ -147,8 +147,8 @@ class socket:
147147
# pylint: disable=redefined-builtin,unused-argument
148148
def __init__(
149149
self,
150-
family: int = _AF_INET,
151-
type: int = _SOCK_STREAM,
150+
family: int = AF_INET,
151+
type: int = SOCK_STREAM,
152152
proto: int = 0,
153153
fileno: Optional[int] = None,
154154
socknum: Optional[int] = None,
@@ -161,7 +161,7 @@ def __init__(
161161
:param Optional[int] fileno: Unused, retained for compatibility.
162162
:param Optional[int] socknum: Unused, retained for compatibility.
163163
"""
164-
if family != _AF_INET:
164+
if family != AF_INET:
165165
raise RuntimeError("Only AF_INET family supported by W5K modules.")
166166
self._sock_type = type
167167
self._buffer = b""
@@ -176,7 +176,7 @@ def __enter__(self):
176176
return self
177177

178178
def __exit__(self, exc_type, exc_val, exc_tb) -> None:
179-
if self._sock_type == _SOCK_STREAM:
179+
if self._sock_type == SOCK_STREAM:
180180
self.disconnect()
181181
stamp = time.monotonic()
182182
while self.status == wiznet5k.adafruit_wiznet5k._SNSR_SOCK_FIN_WAIT:
@@ -407,7 +407,7 @@ def recv(
407407
while True:
408408
avail = self.available()
409409
if avail:
410-
if self._sock_type == _SOCK_STREAM:
410+
if self._sock_type == SOCK_STREAM:
411411
self._buffer += _the_interface.socket_read(self.socknum, avail)[
412412
1
413413
]
@@ -429,7 +429,7 @@ def recv(
429429
avail = self.available()
430430
if avail:
431431
stamp = time.monotonic()
432-
if self._sock_type == _SOCK_STREAM:
432+
if self._sock_type == SOCK_STREAM:
433433
recv = _the_interface.socket_read(
434434
self.socknum, min(to_read, avail)
435435
)[1]
@@ -470,7 +470,7 @@ def embed_recv(
470470
ret = None
471471
avail = self.available()
472472
if avail:
473-
if self._sock_type == _SOCK_STREAM:
473+
if self._sock_type == SOCK_STREAM:
474474
self._buffer += _the_interface.socket_read(self.socknum, avail)[1]
475475
elif self._sock_type == SOCK_DGRAM:
476476
self._buffer += _the_interface.read_udp(self.socknum, avail)[1]
@@ -552,7 +552,7 @@ def readline(self) -> bytes:
552552
while b"\r\n" not in self._buffer:
553553
avail = self.available()
554554
if avail:
555-
if self._sock_type == _SOCK_STREAM:
555+
if self._sock_type == SOCK_STREAM:
556556
self._buffer += _the_interface.socket_read(self.socknum, avail)[1]
557557
elif self._sock_type == SOCK_DGRAM:
558558
self._buffer += _the_interface.read_udp(self.socknum, avail)[1]
@@ -569,7 +569,7 @@ def readline(self) -> bytes:
569569

570570
def disconnect(self) -> None:
571571
"""Disconnect a TCP socket."""
572-
if self._sock_type != _SOCK_STREAM:
572+
if self._sock_type != SOCK_STREAM:
573573
raise RuntimeError("Socket must be a TCP socket.")
574574
_the_interface.socket_disconnect(self.socknum)
575575

0 commit comments

Comments
 (0)