@@ -64,6 +64,7 @@ def getaddrinfo(host, port, family=0, socktype=0, proto=0, flags=0):
64
64
def gethostbyname (hostname ):
65
65
"""Translate a host name to IPv4 address format. The IPv4 address
66
66
is returned as a string.
67
+
67
68
:param str hostname: Desired hostname.
68
69
"""
69
70
addr = _the_interface .get_host_by_name (hostname )
@@ -73,6 +74,7 @@ def gethostbyname(hostname):
73
74
74
75
def is_ipv4 (host ):
75
76
"""Checks if a host string is an IPv4 address.
77
+
76
78
:param str host: host's name or ip
77
79
"""
78
80
octets = host .split ("." , 3 )
@@ -88,9 +90,9 @@ def is_ipv4(host):
88
90
class socket :
89
91
"""A simplified implementation of the Python 'socket' class
90
92
for connecting to a Wiznet5k module.
93
+
91
94
:param int family: Socket address (and protocol) family.
92
95
:param int type: Socket type.
93
-
94
96
"""
95
97
96
98
# pylint: disable=redefined-builtin,unused-argument
@@ -162,8 +164,8 @@ def getpeername(self):
162
164
163
165
def inet_aton (self , ip_string ):
164
166
"""Convert an IPv4 address from dotted-quad string format.
165
- :param str ip_string: IP Address, as a dotted-quad string.
166
167
168
+ :param str ip_string: IP Address, as a dotted-quad string.
167
169
"""
168
170
self ._buffer = b""
169
171
self ._buffer = [int (item ) for item in ip_string .split ("." )]
@@ -173,6 +175,7 @@ def inet_aton(self, ip_string):
173
175
def bind (self , address ):
174
176
"""Bind the socket to the listen port, if host is specified the interface
175
177
will be reconfigured to that IP.
178
+
176
179
:param tuple address: local socket as a (host, port) tuple.
177
180
"""
178
181
if address [0 ] is not None :
@@ -191,6 +194,7 @@ def bind(self, address):
191
194
192
195
def listen (self , backlog = None ):
193
196
"""Listen on the port specified by bind.
197
+
194
198
:param backlog: For compatibility but ignored.
195
199
"""
196
200
assert self ._listen_port is not None , "Use bind to set the port before listen!"
@@ -228,6 +232,7 @@ def accept(self):
228
232
229
233
def connect (self , address , conntype = None ):
230
234
"""Connect to a remote socket at address.
235
+
231
236
:param tuple address: Remote socket as a (host, port) tuple.
232
237
"""
233
238
assert (
@@ -253,6 +258,7 @@ def connect(self, address, conntype=None):
253
258
def send (self , data ):
254
259
"""Send data to the socket. The socket must be connected to
255
260
a remote socket.
261
+
256
262
:param bytearray data: Desired data to send to the socket.
257
263
"""
258
264
_the_interface .socket_write (self .socknum , data , self ._timeout )
@@ -261,6 +267,7 @@ def send(self, data):
261
267
def sendto (self , data , address ):
262
268
"""Send data to the socket. The socket must be connected to
263
269
a remote socket.
270
+
264
271
:param bytearray data: Desired data to send to the socket.
265
272
:param tuple address: Remote socket as a (host, port) tuple.
266
273
"""
@@ -269,6 +276,7 @@ def sendto(self, data, address):
269
276
270
277
def recv (self , bufsize = 0 , flags = 0 ): # pylint: disable=too-many-branches
271
278
"""Reads some bytes from the connected remote address.
279
+
272
280
:param int bufsize: Maximum number of bytes to receive.
273
281
:param int flags: ignored, present for compatibility.
274
282
"""
@@ -327,9 +335,10 @@ def recv(self, bufsize=0, flags=0): # pylint: disable=too-many-branches
327
335
328
336
def recvfrom (self , bufsize = 0 , flags = 0 ):
329
337
"""Reads some bytes from the connected remote address.
338
+
330
339
:param int bufsize: Maximum number of bytes to receive.
331
340
:param int flags: ignored, present for compatibility.
332
- :returns : a tuple (bytes, address) where address is a tuple (ip, port)
341
+ :return : a tuple (bytes, address) where address is a tuple (ip, port)
333
342
"""
334
343
return (
335
344
self .recv (bufsize ),
@@ -341,10 +350,11 @@ def recvfrom(self, bufsize=0, flags=0):
341
350
342
351
def recv_into (self , buf , nbytes = 0 , flags = 0 ):
343
352
"""Reads some bytes from the connected remote address info the provided buffer.
353
+
344
354
:param bytearray buf: Data buffer
345
355
:param nbytes: Maximum number of bytes to receive
346
356
:param int flags: ignored, present for compatibility.
347
- :returns : the number of bytes received
357
+ :return : the number of bytes received
348
358
"""
349
359
if nbytes == 0 :
350
360
nbytes = len (buf )
@@ -355,10 +365,11 @@ def recv_into(self, buf, nbytes=0, flags=0):
355
365
356
366
def recvfrom_into (self , buf , nbytes = 0 , flags = 0 ):
357
367
"""Reads some bytes from the connected remote address info the provided buffer.
368
+
358
369
:param bytearray buf: Data buffer
359
370
:param nbytes: Maximum number of bytes to receive
360
371
:param int flags: ignored, present for compatibility.
361
- :returns a tuple (nbytes, address) where address is a tuple (ip, port)
372
+ :return: a tuple (nbytes, address) where address is a tuple (ip, port)
362
373
"""
363
374
return (
364
375
self .recv_into (buf , nbytes ),
@@ -371,7 +382,6 @@ def recvfrom_into(self, buf, nbytes=0, flags=0):
371
382
def readline (self ):
372
383
"""Attempt to return as many bytes as we can up to \
373
384
but not including '\r \n '.
374
-
375
385
"""
376
386
stamp = time .monotonic ()
377
387
while b"\r \n " not in self ._buffer :
@@ -407,8 +417,8 @@ def available(self):
407
417
408
418
def settimeout (self , value ):
409
419
"""Sets socket read timeout.
410
- :param int value: Socket read timeout, in seconds.
411
420
421
+ :param int value: Socket read timeout, in seconds.
412
422
"""
413
423
if value < 0 :
414
424
raise Exception ("Timeout period should be non-negative." )
@@ -417,6 +427,5 @@ def settimeout(self, value):
417
427
def gettimeout (self ):
418
428
"""Return the timeout in seconds (float) associated
419
429
with socket operations, or None if no timeout is set.
420
-
421
430
"""
422
431
return self ._timeout
0 commit comments