Skip to content

Commit

Permalink
Merge pull request #32 from adafruit/linting
Browse files Browse the repository at this point in the history
Fixed cyclic import
  • Loading branch information
brentru authored Mar 26, 2021
2 parents ca173b8 + c391f5f commit 0ac4cb0
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions adafruit_wiznet5k/adafruit_wiznet5k_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import gc
import time
from micropython import const
from adafruit_wiznet5k import adafruit_wiznet5k
import adafruit_wiznet5k as wiznet5k

_the_interface = None # pylint: disable=invalid-name

Expand Down Expand Up @@ -115,12 +115,12 @@ def __exit__(self, exc_type, exc_val, exc_tb):
if self._sock_type == SOCK_STREAM:
self.disconnect()
stamp = time.monotonic()
while self.status == adafruit_wiznet5k.SNSR_SOCK_FIN_WAIT:
while self.status == wiznet5k.adafruit_wiznet5k.SNSR_SOCK_FIN_WAIT:
if time.monotonic() - stamp > 1000:
raise RuntimeError("Failed to disconnect socket")
self.close()
stamp = time.monotonic()
while self.status != adafruit_wiznet5k.SNSR_SOCK_CLOSED:
while self.status != wiznet5k.adafruit_wiznet5k.SNSR_SOCK_CLOSED:
if time.monotonic() - stamp > 1000:
raise RuntimeError("Failed to close socket")

Expand All @@ -140,16 +140,19 @@ def connected(self):
if self.socknum >= _the_interface.max_sockets:
return False
status = _the_interface.socket_status(self.socknum)[0]
if status == adafruit_wiznet5k.SNSR_SOCK_CLOSE_WAIT and self.available() == 0:
if (
status == wiznet5k.adafruit_wiznet5k.SNSR_SOCK_CLOSE_WAIT
and self.available() == 0
):
result = False
else:
result = status not in (
adafruit_wiznet5k.SNSR_SOCK_CLOSED,
adafruit_wiznet5k.SNSR_SOCK_LISTEN,
adafruit_wiznet5k.SNSR_SOCK_TIME_WAIT,
adafruit_wiznet5k.SNSR_SOCK_FIN_WAIT,
wiznet5k.adafruit_wiznet5k.SNSR_SOCK_CLOSED,
wiznet5k.adafruit_wiznet5k.SNSR_SOCK_LISTEN,
wiznet5k.adafruit_wiznet5k.SNSR_SOCK_TIME_WAIT,
wiznet5k.adafruit_wiznet5k.SNSR_SOCK_FIN_WAIT,
)
if not result and status != adafruit_wiznet5k.SNSR_SOCK_LISTEN:
if not result and status != wiznet5k.adafruit_wiznet5k.SNSR_SOCK_LISTEN:
self.close()
return result

Expand Down Expand Up @@ -195,12 +198,12 @@ def accept(self):
"""
stamp = time.monotonic()
while self.status not in (
adafruit_wiznet5k.SNSR_SOCK_SYNRECV,
adafruit_wiznet5k.SNSR_SOCK_ESTABLISHED,
wiznet5k.adafruit_wiznet5k.SNSR_SOCK_SYNRECV,
wiznet5k.adafruit_wiznet5k.SNSR_SOCK_ESTABLISHED,
):
if self._timeout > 0 and time.monotonic() - stamp > self._timeout:
return None
if self.status == adafruit_wiznet5k.SNSR_SOCK_CLOSED:
if self.status == wiznet5k.adafruit_wiznet5k.SNSR_SOCK_CLOSED:
self.close()
self.listen()

Expand All @@ -212,7 +215,7 @@ def accept(self):
self._socknum = new_listen_socknum # pylint: disable=protected-access
self.bind((None, self._listen_port))
self.listen()
while self.status != adafruit_wiznet5k.SNSR_SOCK_LISTEN:
while self.status != wiznet5k.adafruit_wiznet5k.SNSR_SOCK_LISTEN:
raise RuntimeError("Failed to open new listening socket")
return client_sock, addr

Expand Down

0 comments on commit 0ac4cb0

Please sign in to comment.