Skip to content

Commit 450c52e

Browse files
authored
Merge pull request #55 from Neradoc/fix-documentation-params
Fix documentation
2 parents e0574d7 + 6bfa0f3 commit 450c52e

6 files changed

+56
-40
lines changed

adafruit_wiznet5k/adafruit_wiznet5k.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131

132132
class WIZNET5K: # pylint: disable=too-many-public-methods
133133
"""Interface for WIZNET5K module.
134+
134135
:param ~busio.SPI spi_bus: The SPI bus the Wiznet module is connected to.
135136
:param ~digitalio.DigitalInOut cs: Chip select pin.
136137
:param ~digitalio.DigitalInOut rst: Optional reset pin.
@@ -139,7 +140,6 @@ class WIZNET5K: # pylint: disable=too-many-public-methods
139140
:param str hostname: The desired hostname, with optional {} to fill in MAC.
140141
:param int dhcp_timeout: Timeout in seconds for DHCP response.
141142
:param bool debug: Enable debugging output.
142-
143143
"""
144144

145145
TCP_MODE = const(0x21)
@@ -206,9 +206,9 @@ def set_dhcp(self, hostname=None, response_timeout=30):
206206
"""Initializes the DHCP client and attempts to retrieve
207207
and set network configuration from the DHCP server.
208208
Returns 0 if DHCP configured, -1 otherwise.
209+
209210
:param str hostname: The desired hostname, with optional {} to fill in MAC.
210211
:param int response_timeout: Time to wait for server to return packet, in seconds.
211-
212212
"""
213213
if self._debug:
214214
print("* Initializing DHCP")
@@ -290,8 +290,8 @@ def mac_address(self):
290290
@mac_address.setter
291291
def mac_address(self, address):
292292
"""Sets the hardware MAC address.
293-
:param tuple address: Hardware MAC address.
294293
294+
:param tuple address: Hardware MAC address.
295295
"""
296296
self.write(REG_SHAR, 0x04, address)
297297

@@ -311,8 +311,8 @@ def pretty_mac(self, mac): # pylint: disable=no-self-use, invalid-name
311311

312312
def remote_ip(self, socket_num):
313313
"""Returns the IP address of the host who sent the current incoming packet.
314-
:param int socket num: Desired socket.
315314
315+
:param int socket num: Desired socket.
316316
"""
317317
if socket_num >= self.max_sockets:
318318
return self._pbuff
@@ -441,15 +441,15 @@ def _read_mr(self):
441441

442442
def _write_mr(self, data):
443443
"""Writes to the mode register (MR).
444-
:param int data: Data to write to the mode register.
445444
445+
:param int data: Data to write to the mode register.
446446
"""
447447
self.write(REG_MR, 0x04, data)
448448

449449
def read(self, addr, callback, length=1, buffer=None):
450450
"""Reads data from a register address.
451-
:param int addr: Register address.
452451
452+
:param int addr: Register address.
453453
"""
454454
with self._device as bus_device:
455455
if self._chip_type == "w5500":
@@ -471,11 +471,11 @@ def read(self, addr, callback, length=1, buffer=None):
471471

472472
def write(self, addr, callback, data):
473473
"""Write data to a register address.
474+
474475
:param int addr: Destination address.
475476
:param int callback: Callback reference.
476477
:param int data: Data to write, as an integer.
477478
:param bytearray data: Data to write, as a bytearray.
478-
479479
"""
480480
with self._device as bus_device:
481481
if self._chip_type == "w5500":
@@ -602,9 +602,10 @@ def get_socket(self):
602602

603603
def socket_listen(self, socket_num, port, conn_mode=SNMR_TCP):
604604
"""Start listening on a socket (default TCP mode).
605-
:parm int socket_num: socket number
606-
:parm int port: port to listen on
607-
:parm int conn_mode: connection mode SNMR_TCP (default) or SNMR_UDP
605+
606+
:param int socket_num: socket number
607+
:param int port: port to listen on
608+
:param int conn_mode: connection mode SNMR_TCP (default) or SNMR_UDP
608609
"""
609610
assert self.link_status, "Ethernet cable disconnected!"
610611
if self._debug:
@@ -631,7 +632,8 @@ def socket_listen(self, socket_num, port, conn_mode=SNMR_TCP):
631632
def socket_accept(self, socket_num):
632633
"""Gets the dest IP and port from an incoming connection.
633634
Returns the next socket number so listening can continue
634-
:parm int socket_num: socket number
635+
636+
:param int socket_num: socket number
635637
"""
636638
dest_ip = self.remote_ip(socket_num)
637639
dest_port = self.remote_port(socket_num)
@@ -704,7 +706,6 @@ def socket_disconnect(self, socket_num):
704706
def socket_read(self, socket_num, length):
705707
"""Reads data from a socket into a buffer.
706708
Returns buffer.
707-
708709
"""
709710
assert self.link_status, "Ethernet cable disconnected!"
710711
assert socket_num <= self.max_sockets, "Provided socket exceeds max_sockets."
@@ -840,17 +841,13 @@ def socket_write(self, socket_num, buffer, timeout=0):
840841
while (
841842
self._read_socket(socket_num, REG_SNIR)[0] & SNIR_SEND_OK
842843
) != SNIR_SEND_OK:
843-
if (
844-
self.socket_status(socket_num)[0]
845-
in (
846-
SNSR_SOCK_CLOSED,
847-
SNSR_SOCK_TIME_WAIT,
848-
SNSR_SOCK_FIN_WAIT,
849-
SNSR_SOCK_CLOSE_WAIT,
850-
SNSR_SOCK_CLOSING,
851-
)
852-
or (timeout and time.monotonic() - stamp > timeout)
853-
):
844+
if self.socket_status(socket_num)[0] in (
845+
SNSR_SOCK_CLOSED,
846+
SNSR_SOCK_TIME_WAIT,
847+
SNSR_SOCK_FIN_WAIT,
848+
SNSR_SOCK_CLOSE_WAIT,
849+
SNSR_SOCK_CLOSING,
850+
) or (timeout and time.monotonic() - stamp > timeout):
854851
# self.socket_close(socket_num)
855852
return 0
856853
time.sleep(0.01)

adafruit_wiznet5k/adafruit_wiznet5k_dhcp.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080

8181
class DHCP:
8282
"""W5k DHCP Client implementation.
83+
8384
:param eth: Wiznet 5k object
8485
:param list mac_address: Hardware MAC.
8586
:param str hostname: The desired hostname, with optional {} to fill in MAC.
@@ -134,6 +135,7 @@ def __init__(
134135
# pylint: disable=too-many-statements
135136
def send_dhcp_message(self, state, time_elapsed, renew=False):
136137
"""Assemble and send a DHCP message packet to a socket.
138+
137139
:param int state: DHCP Message state.
138140
:param float time_elapsed: Number of seconds elapsed since DHCP process started
139141
:param bool renew: Set True for renew and rebind
@@ -470,14 +472,10 @@ def _dhcp_state_machine(self):
470472
if self._debug:
471473
print("* DHCP: Time to renew lease")
472474

473-
if (
474-
self._dhcp_state
475-
in (
476-
STATE_DHCP_DISCOVER,
477-
STATE_DHCP_REQUEST,
478-
)
479-
and time.monotonic() > (self._start_time + self._response_timeout)
480-
):
475+
if self._dhcp_state in (
476+
STATE_DHCP_DISCOVER,
477+
STATE_DHCP_REQUEST,
478+
) and time.monotonic() > (self._start_time + self._response_timeout):
481479
self._dhcp_state = STATE_DHCP_WAIT
482480
if self._sock is not None:
483481
self._sock.close()

adafruit_wiznet5k/adafruit_wiznet5k_dns.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def __init__(self, iface, dns_address, debug=False):
5858

5959
def gethostbyname(self, hostname):
6060
"""Translate a host name to IPv4 address format.
61+
6162
:param str hostname: Desired host name to connect to.
6263
6364
Returns the IPv4 address as a bytearray if successful, -1 otherwise.

adafruit_wiznet5k/adafruit_wiznet5k_ntp.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# SPDX-License-Identifier: MIT
44

55
"""
6-
`wiznet5k_ntp`
6+
`adafruit_wiznet5k_ntp`
77
================================================================================
88
99
Network Time Protocol (NTP) helper for CircuitPython
@@ -27,6 +27,7 @@
2727
class NTP:
2828
"""
2929
Wiznet5k NTP Client
30+
3031
:param iface: Wiznet 5k object
3132
:param str ntp_address: The hostname of the NTP server
3233
:param int utc: Numbers of hours to offset time from UTC
@@ -50,6 +51,7 @@ def __init__(self, iface, ntp_address, utc, debug=False):
5051
def get_time(self):
5152
"""
5253
Get the time from the NTP server
54+
5355
:return: time in seconds since the epoch
5456
"""
5557
self._sock.bind((None, 50001))

adafruit_wiznet5k/adafruit_wiznet5k_socket.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def getaddrinfo(host, port, family=0, socktype=0, proto=0, flags=0):
6464
def gethostbyname(hostname):
6565
"""Translate a host name to IPv4 address format. The IPv4 address
6666
is returned as a string.
67+
6768
:param str hostname: Desired hostname.
6869
"""
6970
addr = _the_interface.get_host_by_name(hostname)
@@ -73,6 +74,7 @@ def gethostbyname(hostname):
7374

7475
def is_ipv4(host):
7576
"""Checks if a host string is an IPv4 address.
77+
7678
:param str host: host's name or ip
7779
"""
7880
octets = host.split(".", 3)
@@ -88,9 +90,9 @@ def is_ipv4(host):
8890
class socket:
8991
"""A simplified implementation of the Python 'socket' class
9092
for connecting to a Wiznet5k module.
93+
9194
:param int family: Socket address (and protocol) family.
9295
:param int type: Socket type.
93-
9496
"""
9597

9698
# pylint: disable=redefined-builtin,unused-argument
@@ -162,8 +164,8 @@ def getpeername(self):
162164

163165
def inet_aton(self, ip_string):
164166
"""Convert an IPv4 address from dotted-quad string format.
165-
:param str ip_string: IP Address, as a dotted-quad string.
166167
168+
:param str ip_string: IP Address, as a dotted-quad string.
167169
"""
168170
self._buffer = b""
169171
self._buffer = [int(item) for item in ip_string.split(".")]
@@ -173,6 +175,7 @@ def inet_aton(self, ip_string):
173175
def bind(self, address):
174176
"""Bind the socket to the listen port, if host is specified the interface
175177
will be reconfigured to that IP.
178+
176179
:param tuple address: local socket as a (host, port) tuple.
177180
"""
178181
if address[0] is not None:
@@ -191,6 +194,7 @@ def bind(self, address):
191194

192195
def listen(self, backlog=None):
193196
"""Listen on the port specified by bind.
197+
194198
:param backlog: For compatibility but ignored.
195199
"""
196200
assert self._listen_port is not None, "Use bind to set the port before listen!"
@@ -228,6 +232,7 @@ def accept(self):
228232

229233
def connect(self, address, conntype=None):
230234
"""Connect to a remote socket at address.
235+
231236
:param tuple address: Remote socket as a (host, port) tuple.
232237
"""
233238
assert (
@@ -253,6 +258,7 @@ def connect(self, address, conntype=None):
253258
def send(self, data):
254259
"""Send data to the socket. The socket must be connected to
255260
a remote socket.
261+
256262
:param bytearray data: Desired data to send to the socket.
257263
"""
258264
_the_interface.socket_write(self.socknum, data, self._timeout)
@@ -261,6 +267,7 @@ def send(self, data):
261267
def sendto(self, data, address):
262268
"""Send data to the socket. The socket must be connected to
263269
a remote socket.
270+
264271
:param bytearray data: Desired data to send to the socket.
265272
:param tuple address: Remote socket as a (host, port) tuple.
266273
"""
@@ -269,6 +276,7 @@ def sendto(self, data, address):
269276

270277
def recv(self, bufsize=0, flags=0): # pylint: disable=too-many-branches
271278
"""Reads some bytes from the connected remote address.
279+
272280
:param int bufsize: Maximum number of bytes to receive.
273281
:param int flags: ignored, present for compatibility.
274282
"""
@@ -327,9 +335,10 @@ def recv(self, bufsize=0, flags=0): # pylint: disable=too-many-branches
327335

328336
def recvfrom(self, bufsize=0, flags=0):
329337
"""Reads some bytes from the connected remote address.
338+
330339
:param int bufsize: Maximum number of bytes to receive.
331340
: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)
333342
"""
334343
return (
335344
self.recv(bufsize),
@@ -341,10 +350,11 @@ def recvfrom(self, bufsize=0, flags=0):
341350

342351
def recv_into(self, buf, nbytes=0, flags=0):
343352
"""Reads some bytes from the connected remote address info the provided buffer.
353+
344354
:param bytearray buf: Data buffer
345355
:param nbytes: Maximum number of bytes to receive
346356
:param int flags: ignored, present for compatibility.
347-
:returns: the number of bytes received
357+
:return: the number of bytes received
348358
"""
349359
if nbytes == 0:
350360
nbytes = len(buf)
@@ -355,10 +365,11 @@ def recv_into(self, buf, nbytes=0, flags=0):
355365

356366
def recvfrom_into(self, buf, nbytes=0, flags=0):
357367
"""Reads some bytes from the connected remote address info the provided buffer.
368+
358369
:param bytearray buf: Data buffer
359370
:param nbytes: Maximum number of bytes to receive
360371
: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)
362373
"""
363374
return (
364375
self.recv_into(buf, nbytes),
@@ -371,7 +382,6 @@ def recvfrom_into(self, buf, nbytes=0, flags=0):
371382
def readline(self):
372383
"""Attempt to return as many bytes as we can up to \
373384
but not including '\r\n'.
374-
375385
"""
376386
stamp = time.monotonic()
377387
while b"\r\n" not in self._buffer:
@@ -407,8 +417,8 @@ def available(self):
407417

408418
def settimeout(self, value):
409419
"""Sets socket read timeout.
410-
:param int value: Socket read timeout, in seconds.
411420
421+
:param int value: Socket read timeout, in seconds.
412422
"""
413423
if value < 0:
414424
raise Exception("Timeout period should be non-negative.")
@@ -417,6 +427,5 @@ def settimeout(self, value):
417427
def gettimeout(self):
418428
"""Return the timeout in seconds (float) associated
419429
with socket operations, or None if no timeout is set.
420-
421430
"""
422431
return self._timeout

docs/api.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,12 @@
1212

1313
.. automodule:: adafruit_wiznet5k.adafruit_wiznet5k_dhcp
1414
:members:
15+
16+
.. automodule:: adafruit_wiznet5k.adafruit_wiznet5k_ntp
17+
:members:
18+
19+
.. automodule:: adafruit_wiznet5k.adafruit_wiznet5k_dns
20+
:members:
21+
22+
.. automodule:: adafruit_wiznet5k.adafruit_wiznet5k_wsgiserver
23+
:members:

0 commit comments

Comments
 (0)