Skip to content

Commit 42ea3fb

Browse files
author
BiffoBear
committed
Edited doc-strings to compile in Sphinx. Added missing :return: in socket.
1 parent 06d7f47 commit 42ea3fb

File tree

4 files changed

+33
-33
lines changed

4 files changed

+33
-33
lines changed

adafruit_wiznet5k/adafruit_wiznet5k.py

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
2727
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
2828
"""
29+
30+
__version__ = "0.0.0+auto.0"
31+
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k.git"
32+
2933
# pylint: disable=too-many-lines
3034
try:
3135
from typing import Optional, Union, List, Tuple, Sequence
@@ -43,11 +47,6 @@
4347
import adafruit_wiznet5k.adafruit_wiznet5k_dhcp as dhcp
4448
import adafruit_wiznet5k.adafruit_wiznet5k_dns as dns
4549

46-
47-
__version__ = "0.0.0+auto.0"
48-
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k.git"
49-
50-
5150
# Wiznet5k Registers
5251
REG_MR = const(0x0000) # Mode
5352
REG_GAR = const(0x0001) # Gateway IP Address
@@ -223,7 +222,7 @@ def set_dhcp(
223222
:param Optional[str] hostname: The desired hostname for the DHCP server with optional {} to
224223
fill in the MAC address, defaults to None.
225224
:param float response_timeout: Time to wait for server to return packet in seconds,
226-
defaults to 30.
225+
defaults to 30.0.
227226
228227
:return int: 0 if DHCP configured, -1 otherwise.
229228
"""
@@ -359,7 +358,6 @@ def pretty_mac(
359358
:param bytearray mac: The MAC address.
360359
361360
:return str: Mac Address in the form 00:00:00:00:00:00
362-
363361
"""
364362
return "%s:%s:%s:%s:%s:%s" % (
365363
hex(mac[0]),
@@ -420,7 +418,7 @@ def ifconfig(
420418
Network configuration information.
421419
422420
:return Tuple[bytearray, bytearray, bytearray, Tuple[int, int, int, int]]: \
423-
The IP address, subnet mask, gateway address and DNS server address."""
421+
The IP address, subnet mask, gateway address and DNS server address."""
424422
return (
425423
self.ip_address,
426424
self.read(REG_SUBR, 0x00, 4),
@@ -435,8 +433,8 @@ def ifconfig(
435433
"""
436434
Set network configuration.
437435
438-
:params Tuple[bytearray, bytearray, bytearray, Tuple[int, int, int, int]]: \
439-
Configuration settings - (ip_address, subnet_mask, gateway_address, dns_server).
436+
:param Tuple[bytearray, bytearray, bytearray, Tuple[int, int, int, int]]:
437+
Configuration settings - (ip_address, subnet_mask, gateway_address, dns_server).
440438
"""
441439
ip_address, subnet_mask, gateway_address, dns_server = params
442440

@@ -606,12 +604,11 @@ def write(
606604

607605
def socket_available(self, socket_num: int, sock_type: int = SNMR_TCP) -> int:
608606
"""
609-
Return the number of bytes available to be read from the socket.
607+
Number of bytes available to be read from the socket.
610608
611609
:param int socket_num: Socket to check for available bytes.
612610
:param int sock_type: Socket type. Use SNMR_TCP for TCP or SNMR_UDP for UDP, \
613-
defaults to SNMR_TCP.
614-
611+
defaults to SNMR_TCP.
615612
:return int: Number of bytes available to read.
616613
"""
617614
if self._debug:
@@ -642,7 +639,7 @@ def socket_available(self, socket_num: int, sock_type: int = SNMR_TCP) -> int:
642639

643640
def socket_status(self, socket_num: int) -> Optional[bytearray]:
644641
"""
645-
Return the socket connection status.
642+
Socket connection status.
646643
647644
Can be: SNSR_SOCK_CLOSED, SNSR_SOCK_INIT, SNSR_SOCK_LISTEN, SNSR_SOCK_SYNSENT,
648645
SNSR_SOCK_SYNRECV, SNSR_SYN_SOCK_ESTABLISHED, SNSR_SOCK_FIN_WAIT,
@@ -671,7 +668,7 @@ def socket_connect(
671668
:param Union[bytes, bytearray] dest: The destination as a host name or IP address.
672669
:param int port: Port to connect to (0 - 65,536).
673670
:param int conn_mode: The connection mode. Use SNMR_TCP for TCP or SNMR_UDP for UDP,
674-
defaults to SNMR_TCP.
671+
defaults to SNMR_TCP.
675672
"""
676673
assert self.link_status, "Ethernet cable disconnected!"
677674
if self._debug:
@@ -712,7 +709,7 @@ def _send_socket_cmd(self, socket: int, cmd: int) -> None:
712709
def get_socket(self) -> int:
713710
"""Request, allocate and return a socket from the W5k chip.
714711
715-
Cycles through the sockets to find the first available one, if any.
712+
Cycle through the sockets to find the first available one, if any.
716713
717714
:return int: The first available socket. Returns 0xFF if no sockets are free.
718715
"""
@@ -773,7 +770,6 @@ def socket_accept(
773770
the IP address and port of the incoming connection.
774771
775772
:param int socket_num: Socket number with connection to check.
776-
777773
:return Tuple[int, Tuple[Union[str, bytearray], Union[int, bytearray]]]:
778774
If successful, the next (socket number, (destination IP address, destination port)).
779775
@@ -799,8 +795,7 @@ def socket_open(self, socket_num: int, conn_mode: int = SNMR_TCP) -> int:
799795
800796
:param int socket_num: The socket number to open.
801797
:param int conn_mode: The protocol to use. Use SNMR_TCP for TCP or SNMR_UDP for \
802-
UDP, defaults to SNMR_TCP.
803-
798+
UDP, defaults to SNMR_TCP.
804799
:return int: 1 if the socket was opened, 0 if not.
805800
"""
806801
assert self.link_status, "Ethernet cable disconnected!"
@@ -874,9 +869,9 @@ def socket_read(
874869
:param int length: The number of bytes to read from the socket.
875870
876871
:return Tuple[int, Union[int, bytearray]]: If the read was successful then the first
877-
item of the tuple is the length of the data and the second is the data. If the read
878-
was unsuccessful then both items equal an error code, 0 for no data waiting and -1
879-
for no connection to the socket.
872+
item of the tuple is the length of the data and the second is the data. If the read
873+
was unsuccessful then both items equal an error code, 0 for no data waiting and -1
874+
for no connection to the socket.
880875
"""
881876
assert self.link_status, "Ethernet cable disconnected!"
882877
assert socket_num <= self.max_sockets, "Provided socket exceeds max_sockets."

adafruit_wiznet5k/adafruit_wiznet5k_dhcp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ def parse_dhcp_response(
369369
# pylint: disable=too-many-branches, too-many-statements
370370
def _dhcp_state_machine(self) -> None:
371371
"""
372-
DHCP state machine without wait loops to enable cooperative multitasking
372+
DHCP state machine without wait loops to enable cooperative multitasking.
373373
This state machine is used both by the initial blocking lease request and
374374
the non-blocking DHCP maintenance function.
375375
"""

adafruit_wiznet5k/adafruit_wiznet5k_socket.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ def getaddrinfo(
8686
flags: int = 0,
8787
) -> List[Tuple[int, int, int, str, Tuple[str, int]]]:
8888
"""
89-
Translate the host/port argument into a sequence of 5-tuples that
90-
contain all the necessary arguments for creating a socket connected to that service.
89+
Translate the host/port argument into a sequence of 5-tuples that contain all the necessary
90+
arguments for creating a socket connected to that service.
9191
9292
:param str host: a domain name, a string representation of an IPv4/v6 address or
9393
None.
@@ -97,6 +97,8 @@ def getaddrinfo(
9797
for UDP, defaults to 0x00.
9898
:param int proto: Unused in this implementation of socket.
9999
:param int flags: Unused in this implementation of socket.
100+
101+
:return List[Tuple[int, int, int, str, Tuple[str, int]]]: Address info entries.
100102
"""
101103
if not isinstance(port, int):
102104
raise RuntimeError("Port must be an integer")
@@ -191,7 +193,7 @@ def socknum(self) -> int:
191193
"""
192194
Return the socket object's socket number.
193195
194-
:return int: The socket number
196+
:return int: Socket number.
195197
"""
196198
return self._socknum
197199

@@ -259,7 +261,7 @@ def bind(self, address: Tuple[Optional[str], int]) -> None:
259261
260262
:param Tuple[Optional[str], int] address: Address as a (host, port) tuple. The host
261263
may be an IPv4 address (a string of the form '255.255.255.255'), or None.
262-
The port number is in the range (0- 65536).
264+
The port number is in the range (0 - 65536).
263265
"""
264266
if address[0] is not None:
265267
ip_address = _the_interface.unpretty_ip(address[0])
@@ -279,7 +281,7 @@ def listen(self, backlog: Optional[Any] = None) -> None:
279281
"""
280282
Listen on the port specified by bind.
281283
282-
:param backlog: For compatibility but ignored.
284+
:param Optional[Any] backlog: Included for compatibility but ignored.
283285
"""
284286
assert self._listen_port is not None, "Use bind to set the port before listen!"
285287
_the_interface.socket_listen(self.socknum, self._listen_port)
@@ -373,7 +375,7 @@ def sendto(self, data: bytearray, address: [Tuple[str, int]]) -> None:
373375
"""
374376
Connect to a remote socket and send data.
375377
376-
:param bytearray data: Desired data to send to the socket.
378+
:param bytearray data: Data to send to the socket.
377379
:param tuple address: Remote socket as a (host, port) tuple.
378380
"""
379381
self.connect(address)
@@ -390,6 +392,8 @@ def recv(
390392
391393
:param int bufsize: Maximum number of bytes to receive.
392394
:param int flags: ignored, present for compatibility.
395+
396+
:return bytes: Data from the remote address.
393397
"""
394398
if self.status == wiznet5k.adafruit_wiznet5k.SNSR_SOCK_CLOSED:
395399
return b""
@@ -501,7 +505,7 @@ def recv_into(self, buf: bytearray, nbytes: int = 0, flags: Any = 0) -> int:
501505
:param nbytes: Maximum number of bytes to receive
502506
:param Any flags: ignored, present for compatibility.
503507
504-
:return: the number of bytes received
508+
:return int: the number of bytes received
505509
"""
506510
if nbytes == 0:
507511
nbytes = len(buf)
@@ -520,7 +524,8 @@ def recvfrom_into(
520524
:param int nbytes: Maximum number of bytes to receive.
521525
:param int flags: Unused, present for compatibility.
522526
523-
:return: A tuple (nbytes, address) where address is a tuple (ip, port)
527+
:return Tuple[int, Tuple[str, int]]: A tuple (nbytes, address) where address is a
528+
tuple (ip, port)
524529
"""
525530
return (
526531
self.recv_into(buf, nbytes),
@@ -534,7 +539,8 @@ def readline(self) -> bytes:
534539
"""
535540
Read a line from the socket.
536541
537-
Attempt to return as many bytes as we can up to but not including '\r\n'.
542+
Attempt to return as many bytes as we can up to but not including carriage return and
543+
linefeed charater pairs.
538544
539545
:return bytes: The data read from the socket.
540546
"""

adafruit_wiznet5k/adafruit_wiznet5k_wsgiserver.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
* Author(s): Matt Costi, Patrick Van Oosterwijck
2828
"""
2929
# pylint: disable=no-name-in-module
30-
# from __future__ import annotations
3130
try:
3231
from typing import Optional, List, Tuple, Dict
3332
from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K

0 commit comments

Comments
 (0)