@@ -69,10 +69,10 @@ def htons(x: int) -> int:
69
69
return (((x ) << 8 ) & 0xFF00 ) | (((x ) >> 8 ) & 0xFF )
70
70
71
71
72
- _SOCK_STREAM = const (0x21 ) # TCP
72
+ SOCK_STREAM = const (0x21 ) # TCP
73
73
_TCP_MODE = 80
74
74
SOCK_DGRAM = const (0x02 ) # UDP
75
- _AF_INET = const (3 )
75
+ AF_INET = const (3 )
76
76
_SOCKET_INVALID = const (255 )
77
77
78
78
@@ -103,8 +103,8 @@ def getaddrinfo(
103
103
if not isinstance (port , int ):
104
104
raise ValueError ("Port must be an integer" )
105
105
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 ))]
108
108
109
109
110
110
def gethostbyname (hostname : str ) -> str :
@@ -147,8 +147,8 @@ class socket:
147
147
# pylint: disable=redefined-builtin,unused-argument
148
148
def __init__ (
149
149
self ,
150
- family : int = _AF_INET ,
151
- type : int = _SOCK_STREAM ,
150
+ family : int = AF_INET ,
151
+ type : int = SOCK_STREAM ,
152
152
proto : int = 0 ,
153
153
fileno : Optional [int ] = None ,
154
154
socknum : Optional [int ] = None ,
@@ -161,7 +161,7 @@ def __init__(
161
161
:param Optional[int] fileno: Unused, retained for compatibility.
162
162
:param Optional[int] socknum: Unused, retained for compatibility.
163
163
"""
164
- if family != _AF_INET :
164
+ if family != AF_INET :
165
165
raise RuntimeError ("Only AF_INET family supported by W5K modules." )
166
166
self ._sock_type = type
167
167
self ._buffer = b""
@@ -176,7 +176,7 @@ def __enter__(self):
176
176
return self
177
177
178
178
def __exit__ (self , exc_type , exc_val , exc_tb ) -> None :
179
- if self ._sock_type == _SOCK_STREAM :
179
+ if self ._sock_type == SOCK_STREAM :
180
180
self .disconnect ()
181
181
stamp = time .monotonic ()
182
182
while self .status == wiznet5k .adafruit_wiznet5k ._SNSR_SOCK_FIN_WAIT :
@@ -407,7 +407,7 @@ def recv(
407
407
while True :
408
408
avail = self .available ()
409
409
if avail :
410
- if self ._sock_type == _SOCK_STREAM :
410
+ if self ._sock_type == SOCK_STREAM :
411
411
self ._buffer += _the_interface .socket_read (self .socknum , avail )[
412
412
1
413
413
]
@@ -429,7 +429,7 @@ def recv(
429
429
avail = self .available ()
430
430
if avail :
431
431
stamp = time .monotonic ()
432
- if self ._sock_type == _SOCK_STREAM :
432
+ if self ._sock_type == SOCK_STREAM :
433
433
recv = _the_interface .socket_read (
434
434
self .socknum , min (to_read , avail )
435
435
)[1 ]
@@ -470,7 +470,7 @@ def embed_recv(
470
470
ret = None
471
471
avail = self .available ()
472
472
if avail :
473
- if self ._sock_type == _SOCK_STREAM :
473
+ if self ._sock_type == SOCK_STREAM :
474
474
self ._buffer += _the_interface .socket_read (self .socknum , avail )[1 ]
475
475
elif self ._sock_type == SOCK_DGRAM :
476
476
self ._buffer += _the_interface .read_udp (self .socknum , avail )[1 ]
@@ -552,7 +552,7 @@ def readline(self) -> bytes:
552
552
while b"\r \n " not in self ._buffer :
553
553
avail = self .available ()
554
554
if avail :
555
- if self ._sock_type == _SOCK_STREAM :
555
+ if self ._sock_type == SOCK_STREAM :
556
556
self ._buffer += _the_interface .socket_read (self .socknum , avail )[1 ]
557
557
elif self ._sock_type == SOCK_DGRAM :
558
558
self ._buffer += _the_interface .read_udp (self .socknum , avail )[1 ]
@@ -569,7 +569,7 @@ def readline(self) -> bytes:
569
569
570
570
def disconnect (self ) -> None :
571
571
"""Disconnect a TCP socket."""
572
- if self ._sock_type != _SOCK_STREAM :
572
+ if self ._sock_type != SOCK_STREAM :
573
573
raise RuntimeError ("Socket must be a TCP socket." )
574
574
_the_interface .socket_disconnect (self .socknum )
575
575
0 commit comments