adafruit-circuitpython-httpserver 4.6.2__py3-none-any.whl → 4.6.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: adafruit-circuitpython-httpserver
3
- Version: 4.6.2
3
+ Version: 4.6.4
4
4
  Summary: Simple HTTP Server for CircuitPython
5
5
  Author-email: Adafruit Industries <circuitpython@adafruit.com>
6
6
  License: MIT
@@ -16,6 +16,7 @@ Description-Content-Type: text/x-rst
16
16
  License-File: LICENSE
17
17
  Requires-Dist: Adafruit-Blinka
18
18
  Provides-Extra: optional
19
+ Dynamic: license-file
19
20
 
20
21
  Introduction
21
22
  ============
@@ -36,9 +37,9 @@ Introduction
36
37
  :alt: Build Status
37
38
 
38
39
 
39
- .. image:: https://img.shields.io/badge/code%20style-black-000000.svg
40
- :target: https://github.com/psf/black
41
- :alt: Code Style: Black
40
+ .. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
41
+ :target: https://github.com/astral-sh/ruff
42
+ :alt: Code Style: Ruff
42
43
 
43
44
  HTTP Server for CircuitPython.
44
45
 
@@ -0,0 +1,17 @@
1
+ adafruit_circuitpython_httpserver-4.6.4.dist-info/licenses/LICENSE,sha256=gyhZwtwoqSsDGoSrV4MrLpKKWyG_jE3eROTZp1EjIUM,1102
2
+ adafruit_httpserver/__init__.py,sha256=h4qZ59AhOtDAlysy0E-bx04O-4rUQPFRf2ZtlbOTYpQ,1994
3
+ adafruit_httpserver/authentication.py,sha256=zBBFsAv3Qfl8meUjlS1jPQoSxhHWKNAPwbiS8MRagsg,2026
4
+ adafruit_httpserver/exceptions.py,sha256=tmOoUecGaSXY9kUIIV3Is5YoChrEIEJqVHl4QgmEvrg,1597
5
+ adafruit_httpserver/headers.py,sha256=8PnkazQmun6ARU9CQFdw6FVgSuqcZN9VMvU50F4hOec,4510
6
+ adafruit_httpserver/interfaces.py,sha256=WYfzr9dLQNPZ6JoKrSlECAUhU5opCot3kll-bBnVen4,4418
7
+ adafruit_httpserver/methods.py,sha256=9yGRro1r0y7Yt971TOmHv2kqkKrxWfEhlIjh3dK9AQE,363
8
+ adafruit_httpserver/mime_types.py,sha256=rGNoC9kop2O3hAzMAppb3Qt6qH6VsF8l9NzsZ8JjrVk,7149
9
+ adafruit_httpserver/request.py,sha256=uG4jfgruoknz41SYndV7wnDAXvTHAHoIk_z3IgLu80A,14823
10
+ adafruit_httpserver/response.py,sha256=H0I4RWXOiOUqDEX2Xvu_4NPD41CJJdbnycFfya52jFk,27532
11
+ adafruit_httpserver/route.py,sha256=C-2i1T_ykr2KAuDuREJ6P_1G5Llh3d-g0r_a1ETDMJc,6125
12
+ adafruit_httpserver/server.py,sha256=2Acjtz6DIhXr0U5nCErk4lwa9hSMHdjmYtaYyaEc4ew,22130
13
+ adafruit_httpserver/status.py,sha256=YyMleWebUadx4dwJDldYoo9aLEPDd6NVdvB2w4uY7sk,1825
14
+ adafruit_circuitpython_httpserver-4.6.4.dist-info/METADATA,sha256=rWJnsz75RKoVttZ5Op81K7b0SK2od1OTvujlyC2Q8xw,4878
15
+ adafruit_circuitpython_httpserver-4.6.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
16
+ adafruit_circuitpython_httpserver-4.6.4.dist-info/top_level.txt,sha256=N8L9ONfZQ9bILxcOPVWXOjUDA-BNLPKFir7KqAbMQbA,20
17
+ adafruit_circuitpython_httpserver-4.6.4.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.8.2)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -19,76 +19,76 @@ Implementation Notes
19
19
  https://github.com/adafruit/circuitpython/releases
20
20
  """
21
21
 
22
- __version__ = "4.6.2"
22
+ __version__ = "4.6.4"
23
23
  __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_HTTPServer.git"
24
24
 
25
25
 
26
26
  from .authentication import (
27
27
  Basic,
28
- Token,
29
28
  Bearer,
29
+ Token,
30
30
  check_authentication,
31
31
  require_authentication,
32
32
  )
33
33
  from .exceptions import (
34
- ServerStoppedError,
35
34
  AuthenticationError,
35
+ BackslashInPathError,
36
+ FileNotExistsError,
36
37
  InvalidPathError,
37
38
  ParentDirectoryReferenceError,
38
- BackslashInPathError,
39
+ ServerStoppedError,
39
40
  ServingFilesDisabledError,
40
- FileNotExistsError,
41
41
  )
42
42
  from .headers import Headers
43
43
  from .methods import (
44
- GET,
45
- POST,
46
- PUT,
44
+ CONNECT,
47
45
  DELETE,
48
- PATCH,
46
+ GET,
49
47
  HEAD,
50
48
  OPTIONS,
49
+ PATCH,
50
+ POST,
51
+ PUT,
51
52
  TRACE,
52
- CONNECT,
53
53
  )
54
54
  from .mime_types import MIMETypes
55
- from .request import QueryParams, FormData, Request
55
+ from .request import FormData, QueryParams, Request
56
56
  from .response import (
57
- Response,
58
- FileResponse,
59
57
  ChunkedResponse,
58
+ FileResponse,
60
59
  JSONResponse,
61
60
  Redirect,
61
+ Response,
62
62
  SSEResponse,
63
63
  Websocket,
64
64
  )
65
65
  from .route import Route, as_route
66
66
  from .server import (
67
- Server,
68
- NO_REQUEST,
69
67
  CONNECTION_TIMED_OUT,
68
+ NO_REQUEST,
70
69
  REQUEST_HANDLED_NO_RESPONSE,
71
70
  REQUEST_HANDLED_RESPONSE_SENT,
71
+ Server,
72
72
  )
73
73
  from .status import (
74
- Status,
75
- SWITCHING_PROTOCOLS_101,
76
- OK_200,
77
- CREATED_201,
78
74
  ACCEPTED_202,
79
- NO_CONTENT_204,
80
- PARTIAL_CONTENT_206,
81
- MOVED_PERMANENTLY_301,
82
- FOUND_302,
83
- TEMPORARY_REDIRECT_307,
84
- PERMANENT_REDIRECT_308,
85
75
  BAD_REQUEST_400,
86
- UNAUTHORIZED_401,
76
+ CREATED_201,
87
77
  FORBIDDEN_403,
88
- NOT_FOUND_404,
89
- METHOD_NOT_ALLOWED_405,
90
- TOO_MANY_REQUESTS_429,
78
+ FOUND_302,
91
79
  INTERNAL_SERVER_ERROR_500,
80
+ METHOD_NOT_ALLOWED_405,
81
+ MOVED_PERMANENTLY_301,
82
+ NO_CONTENT_204,
83
+ NOT_FOUND_404,
92
84
  NOT_IMPLEMENTED_501,
85
+ OK_200,
86
+ PARTIAL_CONTENT_206,
87
+ PERMANENT_REDIRECT_308,
93
88
  SERVICE_UNAVAILABLE_503,
89
+ SWITCHING_PROTOCOLS_101,
90
+ TEMPORARY_REDIRECT_307,
91
+ TOO_MANY_REQUESTS_429,
92
+ UNAUTHORIZED_401,
93
+ Status,
94
94
  )
@@ -8,7 +8,7 @@
8
8
  """
9
9
 
10
10
  try:
11
- from typing import Union, List
11
+ from typing import List, Union
12
12
  except ImportError:
13
13
  pass
14
14
 
@@ -40,15 +40,13 @@ class Token:
40
40
  return f"{self.prefix} {self._value}"
41
41
 
42
42
 
43
- class Bearer(Token): # pylint: disable=too-few-public-methods
43
+ class Bearer(Token):
44
44
  """Represents HTTP Bearer Token Authentication."""
45
45
 
46
46
  prefix = "Bearer"
47
47
 
48
48
 
49
- def check_authentication(
50
- request: Request, auths: List[Union[Basic, Token, Bearer]]
51
- ) -> bool:
49
+ def check_authentication(request: Request, auths: List[Union[Basic, Token, Bearer]]) -> bool:
52
50
  """
53
51
  Returns ``True`` if request is authorized by any of the authentications, ``False`` otherwise.
54
52
 
@@ -65,9 +63,7 @@ def check_authentication(
65
63
  return any(auth_header == str(auth) for auth in auths)
66
64
 
67
65
 
68
- def require_authentication(
69
- request: Request, auths: List[Union[Basic, Token, Bearer]]
70
- ) -> None:
66
+ def require_authentication(request: Request, auths: List[Union[Basic, Token, Bearer]]) -> None:
71
67
  """
72
68
  Checks if the request is authorized and raises ``AuthenticationError`` if not.
73
69
 
@@ -93,9 +93,7 @@ class Headers(_IFieldStorage):
93
93
  return default
94
94
  return header_value.split(";")[0].strip('" ')
95
95
 
96
- def get_parameter(
97
- self, name: str, parameter: str, default: str = None
98
- ) -> Union[str, None]:
96
+ def get_parameter(self, name: str, parameter: str, default: str = None) -> Union[str, None]:
99
97
  """
100
98
  Returns the value of the given parameter for the given header name, or default if not found.
101
99
 
@@ -124,16 +122,12 @@ class Headers(_IFieldStorage):
124
122
 
125
123
  def update(self, headers: Dict[str, str]):
126
124
  """Updates the headers with the given dict."""
127
- return self._storage.update(
128
- {key.lower(): [value] for key, value in headers.items()}
129
- )
125
+ return self._storage.update({key.lower(): [value] for key, value in headers.items()})
130
126
 
131
127
  def copy(self):
132
128
  """Returns a copy of the headers."""
133
129
  return Headers(
134
- "\r\n".join(
135
- f"{key}: {value}" for key in self.fields for value in self.get_list(key)
136
- )
130
+ "\r\n".join(f"{key}: {value}" for key in self.fields for value in self.get_list(key))
137
131
  )
138
132
 
139
133
  def __getitem__(self, name: str):
@@ -8,43 +8,34 @@
8
8
  """
9
9
 
10
10
  try:
11
- from typing import List, Tuple, Dict, Union, Any
11
+ from typing import Any, Dict, List, Tuple, Union
12
12
  except ImportError:
13
13
  pass
14
14
 
15
15
 
16
- class _ISocket: # pylint: disable=missing-function-docstring,no-self-use,unused-argument
16
+ class _ISocket:
17
17
  """A class for typing necessary methods for a socket object."""
18
18
 
19
- def accept(self) -> Tuple["_ISocket", Tuple[str, int]]:
20
- ...
19
+ def accept(self) -> Tuple["_ISocket", Tuple[str, int]]: ...
21
20
 
22
- def bind(self, address: Tuple[str, int]) -> None:
23
- ...
21
+ def bind(self, address: Tuple[str, int]) -> None: ...
24
22
 
25
- def setblocking(self, flag: bool) -> None:
26
- ...
23
+ def setblocking(self, flag: bool) -> None: ...
27
24
 
28
- def settimeout(self, value: "Union[float, None]") -> None:
29
- ...
25
+ def settimeout(self, value: "Union[float, None]") -> None: ...
30
26
 
31
- def setsockopt(self, level: int, optname: int, value: int) -> None:
32
- ...
27
+ def setsockopt(self, level: int, optname: int, value: int) -> None: ...
33
28
 
34
- def listen(self, backlog: int) -> None:
35
- ...
29
+ def listen(self, backlog: int) -> None: ...
36
30
 
37
- def send(self, data: bytes) -> int:
38
- ...
31
+ def send(self, data: bytes) -> int: ...
39
32
 
40
- def recv_into(self, buffer: memoryview, nbytes: int) -> int:
41
- ...
33
+ def recv_into(self, buffer: memoryview, nbytes: int) -> int: ...
42
34
 
43
- def close(self) -> None:
44
- ...
35
+ def close(self) -> None: ...
45
36
 
46
37
 
47
- class _ISocketPool: # pylint: disable=missing-function-docstring,no-self-use,unused-argument
38
+ class _ISocketPool:
48
39
  """A class to typing necessary methods and properties for a socket pool object."""
49
40
 
50
41
  AF_INET: int
@@ -52,15 +43,14 @@ class _ISocketPool: # pylint: disable=missing-function-docstring,no-self-use,un
52
43
  SOCK_STREAM: int
53
44
  SOL_SOCKET: int
54
45
 
55
- def socket( # pylint: disable=redefined-builtin
46
+ def socket(
56
47
  self,
57
48
  family: int = ...,
58
49
  type: int = ...,
59
50
  proto: int = ...,
60
- ) -> _ISocket:
61
- ...
51
+ ) -> _ISocket: ...
62
52
 
63
- def getaddrinfo( # pylint: disable=redefined-builtin,too-many-arguments
53
+ def getaddrinfo(
64
54
  self,
65
55
  host: str,
66
56
  port: int,
@@ -68,8 +58,7 @@ class _ISocketPool: # pylint: disable=missing-function-docstring,no-self-use,un
68
58
  type: int = ...,
69
59
  proto: int = ...,
70
60
  flags: int = ...,
71
- ) -> Tuple[int, int, int, str, Tuple[str, int]]:
72
- ...
61
+ ) -> Tuple[int, int, int, str, Tuple[str, int]]: ...
73
62
 
74
63
 
75
64
  class _IFieldStorage:
@@ -140,9 +129,7 @@ def _encode_html_entities(value: Union[str, None]) -> Union[str, None]:
140
129
 
141
130
 
142
131
  class _IXSSSafeFieldStorage(_IFieldStorage):
143
- def get(
144
- self, field_name: str, default: Any = None, *, safe=True
145
- ) -> Union[Any, None]:
132
+ def get(self, field_name: str, default: Any = None, *, safe=True) -> Union[Any, None]:
146
133
  if safe:
147
134
  return _encode_html_entities(super().get(field_name, default))
148
135
 
@@ -151,9 +138,7 @@ class _IXSSSafeFieldStorage(_IFieldStorage):
151
138
 
152
139
  def get_list(self, field_name: str, *, safe=True) -> List[Any]:
153
140
  if safe:
154
- return [
155
- _encode_html_entities(value) for value in super().get_list(field_name)
156
- ]
141
+ return [_encode_html_entities(value) for value in super().get_list(field_name)]
157
142
 
158
143
  _debug_warning_nonencoded_output()
159
144
  return super().get_list(field_name)
@@ -7,7 +7,6 @@
7
7
  * Author(s): Michał Pokusa
8
8
  """
9
9
 
10
-
11
10
  GET = "GET"
12
11
 
13
12
  POST = "POST"
@@ -8,7 +8,7 @@
8
8
  """
9
9
 
10
10
  try:
11
- from typing import List, Dict
11
+ from typing import Dict, List
12
12
  except ImportError:
13
13
  pass
14
14
 
@@ -8,7 +8,7 @@
8
8
  """
9
9
 
10
10
  try:
11
- from typing import List, Dict, Tuple, Union, Any, TYPE_CHECKING
11
+ from typing import TYPE_CHECKING, Any, Dict, List, Tuple, Union
12
12
 
13
13
  if TYPE_CHECKING:
14
14
  from .server import Server
@@ -18,8 +18,8 @@ except ImportError:
18
18
  import json
19
19
 
20
20
  from .headers import Headers
21
- from .interfaces import _ISocket, _IFieldStorage, _IXSSSafeFieldStorage
22
- from .methods import POST, PUT, PATCH, DELETE
21
+ from .interfaces import _IFieldStorage, _ISocket, _IXSSSafeFieldStorage
22
+ from .methods import DELETE, PATCH, POST, PUT
23
23
 
24
24
 
25
25
  class QueryParams(_IXSSSafeFieldStorage):
@@ -54,9 +54,7 @@ class QueryParams(_IXSSSafeFieldStorage):
54
54
  def _add_field_value(self, field_name: str, value: str) -> None:
55
55
  super()._add_field_value(field_name, value)
56
56
 
57
- def get(
58
- self, field_name: str, default: str = None, *, safe=True
59
- ) -> Union[str, None]:
57
+ def get(self, field_name: str, default: str = None, *, safe=True) -> Union[str, None]:
60
58
  return super().get(field_name, default, safe=safe)
61
59
 
62
60
  def get_list(self, field_name: str, *, safe=True) -> List[str]:
@@ -92,9 +90,7 @@ class File:
92
90
  content: Union[str, bytes]
93
91
  """Content of the file."""
94
92
 
95
- def __init__(
96
- self, filename: str, content_type: str, content: Union[str, bytes]
97
- ) -> None:
93
+ def __init__(self, filename: str, content_type: str, content: Union[str, bytes]) -> None:
98
94
  self.filename = filename
99
95
  self.content_type = content_type
100
96
  self.content = content
@@ -112,11 +108,7 @@ class File:
112
108
  with open(file.filename, "wb") as f:
113
109
  f.write(file.content_bytes)
114
110
  """
115
- return (
116
- self.content.encode("utf-8")
117
- if isinstance(self.content, str)
118
- else self.content
119
- )
111
+ return self.content.encode("utf-8") if isinstance(self.content, str) else self.content
120
112
 
121
113
  @property
122
114
  def size(self) -> int:
@@ -177,11 +169,11 @@ class FormData(_IXSSSafeFieldStorage):
177
169
 
178
170
  @staticmethod
179
171
  def _check_is_supported_content_type(content_type: str) -> None:
180
- return content_type in (
172
+ return content_type in {
181
173
  "application/x-www-form-urlencoded",
182
174
  "multipart/form-data",
183
175
  "text/plain",
184
- )
176
+ }
185
177
 
186
178
  def __init__(self, data: bytes, headers: Headers, *, debug: bool = False) -> None:
187
179
  self._storage = {}
@@ -231,9 +223,7 @@ class FormData(_IXSSSafeFieldStorage):
231
223
  # TODO: Other text content types (e.g. application/json) should be decoded as well and
232
224
 
233
225
  if filename is not None:
234
- self.files._add_field_value( # pylint: disable=protected-access
235
- field_name, File(filename, content_type, value)
236
- )
226
+ self.files._add_field_value(field_name, File(filename, content_type, value))
237
227
  else:
238
228
  self._add_field_value(field_name, value)
239
229
 
@@ -258,12 +248,10 @@ class FormData(_IXSSSafeFieldStorage):
258
248
 
259
249
  def __repr__(self) -> str:
260
250
  class_name = self.__class__.__name__
261
- return (
262
- f"<{class_name} {repr(self._storage)}, files={repr(self.files._storage)}>"
263
- )
251
+ return f"<{class_name} {repr(self._storage)}, files={repr(self.files._storage)}>"
264
252
 
265
253
 
266
- class Request: # pylint: disable=too-many-instance-attributes
254
+ class Request:
267
255
  """
268
256
  Incoming request, constructed from raw incoming bytes.
269
257
  It is passed as first argument to all route handlers.
@@ -367,9 +355,7 @@ class Request: # pylint: disable=too-many-instance-attributes
367
355
 
368
356
  return {
369
357
  name: value.strip('"')
370
- for name, value in [
371
- cookie.strip().split("=", 1) for cookie in cookie_header.split(";")
372
- ]
358
+ for name, value in [cookie.strip().split("=", 1) for cookie in cookie_header.split(";")]
373
359
  }
374
360
 
375
361
  @property
@@ -443,7 +429,7 @@ class Request: # pylint: disable=too-many-instance-attributes
443
429
  """
444
430
  return (
445
431
  json.loads(self.body)
446
- if (self.body and self.method in (POST, PUT, PATCH, DELETE))
432
+ if (self.body and self.method in {POST, PUT, PATCH, DELETE})
447
433
  else None
448
434
  )
449
435
 
@@ -467,9 +453,7 @@ class Request: # pylint: disable=too-many-instance-attributes
467
453
  ) -> Tuple[str, str, QueryParams, str, Headers]:
468
454
  """Parse HTTP Start line to method, path, query_params and http_version."""
469
455
 
470
- start_line, headers_string = (
471
- header_bytes.decode("utf-8").strip().split("\r\n", 1)
472
- )
456
+ start_line, headers_string = header_bytes.decode("utf-8").strip().split("\r\n", 1)
473
457
 
474
458
  method, path, http_version = start_line.strip().split()
475
459
 
@@ -8,14 +8,14 @@
8
8
  """
9
9
 
10
10
  try:
11
- from typing import Optional, Dict, Union, Tuple, Generator, Any
11
+ from typing import Any, Dict, Generator, Optional, Tuple, Union
12
12
  except ImportError:
13
13
  pass
14
14
 
15
- import os
16
15
  import json
16
+ import os
17
17
  from binascii import b2a_base64
18
- from errno import EAGAIN, ECONNRESET, ETIMEDOUT, ENOTCONN
18
+ from errno import EAGAIN, ECONNRESET, ENOTCONN, ETIMEDOUT
19
19
 
20
20
  try:
21
21
  try:
@@ -33,22 +33,22 @@ from .exceptions import (
33
33
  FileNotExistsError,
34
34
  ParentDirectoryReferenceError,
35
35
  )
36
+ from .headers import Headers
37
+ from .interfaces import _ISocket
36
38
  from .mime_types import MIMETypes
37
39
  from .request import Request
38
40
  from .status import (
39
- Status,
40
- SWITCHING_PROTOCOLS_101,
41
- OK_200,
42
- MOVED_PERMANENTLY_301,
43
41
  FOUND_302,
44
- TEMPORARY_REDIRECT_307,
42
+ MOVED_PERMANENTLY_301,
43
+ OK_200,
45
44
  PERMANENT_REDIRECT_308,
45
+ SWITCHING_PROTOCOLS_101,
46
+ TEMPORARY_REDIRECT_307,
47
+ Status,
46
48
  )
47
- from .headers import Headers
48
- from .interfaces import _ISocket
49
49
 
50
50
 
51
- class Response: # pylint: disable=too-few-public-methods
51
+ class Response:
52
52
  """
53
53
  Response to a given `Request`. Use in `Server.route` handler functions.
54
54
 
@@ -62,7 +62,7 @@ class Response: # pylint: disable=too-few-public-methods
62
62
  return Response(request, body='Some content', content_type="text/plain")
63
63
  """
64
64
 
65
- def __init__( # pylint: disable=too-many-arguments
65
+ def __init__(
66
66
  self,
67
67
  request: Request,
68
68
  body: Union[str, bytes] = "",
@@ -84,9 +84,7 @@ class Response: # pylint: disable=too-few-public-methods
84
84
  self._request = request
85
85
  self._body = body
86
86
  self._status = status if isinstance(status, Status) else Status(*status)
87
- self._headers = (
88
- headers.copy() if isinstance(headers, Headers) else Headers(headers)
89
- )
87
+ self._headers = headers.copy() if isinstance(headers, Headers) else Headers(headers)
90
88
  self._cookies = cookies.copy() if cookies else {}
91
89
  self._content_type = content_type
92
90
  self._size = 0
@@ -98,13 +96,9 @@ class Response: # pylint: disable=too-few-public-methods
98
96
  ) -> None:
99
97
  headers = self._headers.copy()
100
98
 
101
- response_message_header = (
102
- f"HTTP/1.1 {self._status.code} {self._status.text}\r\n"
103
- )
99
+ response_message_header = f"HTTP/1.1 {self._status.code} {self._status.text}\r\n"
104
100
 
105
- headers.setdefault(
106
- "Content-Type", content_type or self._content_type or MIMETypes.DEFAULT
107
- )
101
+ headers.setdefault("Content-Type", content_type or self._content_type or MIMETypes.DEFAULT)
108
102
  headers.setdefault("Content-Length", content_length)
109
103
  headers.setdefault("Connection", "close")
110
104
 
@@ -116,14 +110,10 @@ class Response: # pylint: disable=too-few-public-methods
116
110
  response_message_header += f"{header}: {value}\r\n"
117
111
  response_message_header += "\r\n"
118
112
 
119
- self._send_bytes(
120
- self._request.connection, response_message_header.encode("utf-8")
121
- )
113
+ self._send_bytes(self._request.connection, response_message_header.encode("utf-8"))
122
114
 
123
115
  def _send(self) -> None:
124
- encoded_body = (
125
- self._body.encode("utf-8") if isinstance(self._body, str) else self._body
126
- )
116
+ encoded_body = self._body.encode("utf-8") if isinstance(self._body, str) else self._body
127
117
 
128
118
  self._send_headers(len(encoded_body), self._content_type)
129
119
  self._send_bytes(self._request.connection, encoded_body)
@@ -155,7 +145,7 @@ class Response: # pylint: disable=too-few-public-methods
155
145
  pass
156
146
 
157
147
 
158
- class FileResponse(Response): # pylint: disable=too-few-public-methods
148
+ class FileResponse(Response):
159
149
  """
160
150
  Specialized version of `Response` class for sending files.
161
151
 
@@ -173,7 +163,7 @@ class FileResponse(Response): # pylint: disable=too-few-public-methods
173
163
  return FileResponse(request, filename='index.html', root_path='/www')
174
164
  """
175
165
 
176
- def __init__( # pylint: disable=too-many-arguments
166
+ def __init__(
177
167
  self,
178
168
  request: Request,
179
169
  filename: str = "index.html",
@@ -243,7 +233,7 @@ class FileResponse(Response): # pylint: disable=too-few-public-methods
243
233
  """
244
234
 
245
235
  # Check for backslashes
246
- if "\\" in file_path: # pylint: disable=anomalous-backslash-in-string
236
+ if "\\" in file_path:
247
237
  raise BackslashInPathError(file_path)
248
238
 
249
239
  # Check each component of the path for parent directory references
@@ -276,7 +266,7 @@ class FileResponse(Response): # pylint: disable=too-few-public-methods
276
266
  assert (st_mode & 0o170000) == 0o100000 # Check if it is a regular file
277
267
  return st_size
278
268
  except (OSError, AssertionError):
279
- raise FileNotExistsError(file_path) # pylint: disable=raise-missing-from
269
+ raise FileNotExistsError(file_path)
280
270
 
281
271
  def _send(self) -> None:
282
272
  self._send_headers(self._file_length, self._content_type)
@@ -288,7 +278,7 @@ class FileResponse(Response): # pylint: disable=too-few-public-methods
288
278
  self._close_connection()
289
279
 
290
280
 
291
- class ChunkedResponse(Response): # pylint: disable=too-few-public-methods
281
+ class ChunkedResponse(Response):
292
282
  """
293
283
  Specialized version of `Response` class for sending data using chunked transfer encoding.
294
284
 
@@ -308,7 +298,7 @@ class ChunkedResponse(Response): # pylint: disable=too-few-public-methods
308
298
  return ChunkedResponse(request, body, content_type="text/plain")
309
299
  """
310
300
 
311
- def __init__( # pylint: disable=too-many-arguments
301
+ def __init__(
312
302
  self,
313
303
  request: Request,
314
304
  body: Generator[Union[str, bytes], Any, Any],
@@ -356,7 +346,7 @@ class ChunkedResponse(Response): # pylint: disable=too-few-public-methods
356
346
  self._close_connection()
357
347
 
358
348
 
359
- class JSONResponse(Response): # pylint: disable=too-few-public-methods
349
+ class JSONResponse(Response):
360
350
  """
361
351
  Specialized version of `Response` class for sending JSON data.
362
352
 
@@ -403,7 +393,7 @@ class JSONResponse(Response): # pylint: disable=too-few-public-methods
403
393
  self._close_connection()
404
394
 
405
395
 
406
- class Redirect(Response): # pylint: disable=too-few-public-methods
396
+ class Redirect(Response):
407
397
  """
408
398
  Specialized version of `Response` class for redirecting to another URL.
409
399
 
@@ -448,9 +438,7 @@ class Redirect(Response): # pylint: disable=too-few-public-methods
448
438
  """
449
439
 
450
440
  if status is not None and (permanent or preserve_method):
451
- raise ValueError(
452
- "Cannot specify both status and permanent/preserve_method argument"
453
- )
441
+ raise ValueError("Cannot specify both status and permanent/preserve_method argument")
454
442
 
455
443
  if status is None:
456
444
  if preserve_method:
@@ -466,7 +454,7 @@ class Redirect(Response): # pylint: disable=too-few-public-methods
466
454
  self._close_connection()
467
455
 
468
456
 
469
- class SSEResponse(Response): # pylint: disable=too-few-public-methods
457
+ class SSEResponse(Response):
470
458
  """
471
459
  Specialized version of `Response` class for sending Server-Sent Events.
472
460
 
@@ -500,7 +488,7 @@ class SSEResponse(Response): # pylint: disable=too-few-public-methods
500
488
  sse.close()
501
489
  """
502
490
 
503
- def __init__( # pylint: disable=too-many-arguments
491
+ def __init__(
504
492
  self,
505
493
  request: Request,
506
494
  headers: Union[Headers, Dict[str, str]] = None,
@@ -523,11 +511,11 @@ class SSEResponse(Response): # pylint: disable=too-few-public-methods
523
511
  def _send(self) -> None:
524
512
  self._send_headers()
525
513
 
526
- def send_event( # pylint: disable=too-many-arguments
514
+ def send_event(
527
515
  self,
528
516
  data: str,
529
517
  event: str = None,
530
- id: int = None, # pylint: disable=redefined-builtin,invalid-name
518
+ id: int = None,
531
519
  retry: int = None,
532
520
  custom_fields: Dict[str, str] = None,
533
521
  ) -> None:
@@ -564,7 +552,7 @@ class SSEResponse(Response): # pylint: disable=too-few-public-methods
564
552
  self._close_connection()
565
553
 
566
554
 
567
- class Websocket(Response): # pylint: disable=too-few-public-methods
555
+ class Websocket(Response):
568
556
  """
569
557
  Specialized version of `Response` class for creating a websocket connection.
570
558
 
@@ -635,7 +623,7 @@ class Websocket(Response): # pylint: disable=too-few-public-methods
635
623
 
636
624
  return b2a_base64(response_key.digest()).strip().decode()
637
625
 
638
- def __init__( # pylint: disable=too-many-arguments
626
+ def __init__(
639
627
  self,
640
628
  request: Request,
641
629
  headers: Union[Headers, Dict[str, str]] = None,
@@ -693,7 +681,7 @@ class Websocket(Response): # pylint: disable=too-few-public-methods
693
681
  if fin != Websocket.FIN and opcode == Websocket.CONT:
694
682
  return Websocket.CONT, None
695
683
 
696
- payload = bytes()
684
+ payload = b""
697
685
  if fin == Websocket.FIN and opcode == Websocket.CLOSE:
698
686
  return Websocket.CLOSE, payload
699
687
 
@@ -746,9 +734,7 @@ class Websocket(Response): # pylint: disable=too-few-public-methods
746
734
  if self.closed:
747
735
  if fail_silently:
748
736
  return None
749
- raise RuntimeError(
750
- "Websocket connection is closed, cannot receive messages"
751
- )
737
+ raise RuntimeError("Websocket connection is closed, cannot receive messages")
752
738
 
753
739
  try:
754
740
  opcode, payload = self._read_frame()
@@ -8,7 +8,7 @@
8
8
  """
9
9
 
10
10
  try:
11
- from typing import Callable, Iterable, Union, Tuple, Literal, Dict, TYPE_CHECKING
11
+ from typing import TYPE_CHECKING, Callable, Dict, Iterable, Literal, Tuple, Union
12
12
 
13
13
  if TYPE_CHECKING:
14
14
  from .response import Response
@@ -52,9 +52,7 @@ class Route:
52
52
  self._validate_path(path, append_slash)
53
53
 
54
54
  self.path = path
55
- self.methods = (
56
- set(methods) if isinstance(methods, (set, list, tuple)) else set([methods])
57
- )
55
+ self.methods = set(methods) if isinstance(methods, (set, list, tuple)) else set([methods])
58
56
  self.handler = handler
59
57
  self.parameters_names = [
60
58
  name[1:-1] for name in re.compile(r"/[^<>]*/?").split(path) if name != ""
@@ -8,34 +8,34 @@
8
8
  """
9
9
 
10
10
  try:
11
- from typing import Callable, Union, List, Tuple, Dict, Iterable
11
+ from typing import Callable, Dict, Iterable, List, Tuple, Union
12
12
  except ImportError:
13
13
  pass
14
14
 
15
- from ssl import SSLContext, create_default_context
16
15
  from errno import EAGAIN, ECONNRESET, ETIMEDOUT
16
+ from ssl import SSLContext, create_default_context
17
17
  from sys import implementation
18
18
  from time import monotonic, sleep
19
19
  from traceback import print_exception
20
20
 
21
- from .authentication import Basic, Token, Bearer, require_authentication
21
+ from .authentication import Basic, Bearer, Token, require_authentication
22
22
  from .exceptions import (
23
- ServerStoppedError,
24
23
  AuthenticationError,
25
24
  FileNotExistsError,
26
25
  InvalidPathError,
26
+ ServerStoppedError,
27
27
  ServingFilesDisabledError,
28
28
  )
29
29
  from .headers import Headers
30
- from .interfaces import _ISocketPool, _ISocket
30
+ from .interfaces import _ISocket, _ISocketPool
31
31
  from .methods import GET, HEAD
32
32
  from .request import Request
33
- from .response import Response, FileResponse
33
+ from .response import FileResponse, Response
34
34
  from .route import Route
35
- from .status import BAD_REQUEST_400, UNAUTHORIZED_401, FORBIDDEN_403, NOT_FOUND_404
35
+ from .status import BAD_REQUEST_400, FORBIDDEN_403, NOT_FOUND_404, UNAUTHORIZED_401
36
36
 
37
37
  if implementation.name != "circuitpython":
38
- from ssl import Purpose, CERT_NONE, SSLError # pylint: disable=ungrouped-imports
38
+ from ssl import CERT_NONE, Purpose, SSLError
39
39
 
40
40
 
41
41
  NO_REQUEST = "no_request"
@@ -47,7 +47,7 @@ REQUEST_HANDLED_RESPONSE_SENT = "request_handled_response_sent"
47
47
  MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE = -30592
48
48
 
49
49
 
50
- class Server: # pylint: disable=too-many-instance-attributes
50
+ class Server:
51
51
  """A basic socket-based HTTP server."""
52
52
 
53
53
  host: str
@@ -134,7 +134,7 @@ class Server: # pylint: disable=too-many-instance-attributes
134
134
  else:
135
135
  self._ssl_context = None
136
136
 
137
- if root_path in ["", "/"] and debug:
137
+ if root_path in {"", "/"} and debug:
138
138
  _debug_warning_exposed_files(root_path)
139
139
  self.stopped = True
140
140
 
@@ -254,7 +254,7 @@ class Server: # pylint: disable=too-many-instance-attributes
254
254
  except KeyboardInterrupt: # Exit on Ctrl-C e.g. during development
255
255
  self.stop()
256
256
  return
257
- except Exception: # pylint: disable=broad-except
257
+ except Exception:
258
258
  pass # Ignore exceptions in handler function
259
259
 
260
260
  @staticmethod
@@ -292,9 +292,7 @@ class Server: # pylint: disable=too-many-instance-attributes
292
292
  self.host, self.port = host, port
293
293
 
294
294
  self.stopped = False
295
- self._sock = self._create_server_socket(
296
- self._socket_source, self._ssl_context, host, port
297
- )
295
+ self._sock = self._create_server_socket(self._socket_source, self._ssl_context, host, port)
298
296
 
299
297
  if self.debug:
300
298
  _debug_started_server(self)
@@ -315,7 +313,7 @@ class Server: # pylint: disable=too-many-instance-attributes
315
313
 
316
314
  def _receive_header_bytes(self, sock: _ISocket) -> bytes:
317
315
  """Receive bytes until a empty line is received."""
318
- received_bytes = bytes()
316
+ received_bytes = b""
319
317
  while b"\r\n\r\n" not in received_bytes:
320
318
  try:
321
319
  length = sock.recv_into(self._buffer, len(self._buffer))
@@ -367,15 +365,11 @@ class Server: # pylint: disable=too-many-instance-attributes
367
365
  received_body_bytes = request.body
368
366
 
369
367
  # Receiving remaining body bytes
370
- request.body = self._receive_body_bytes(
371
- sock, received_body_bytes, content_length
372
- )
368
+ request.body = self._receive_body_bytes(sock, received_body_bytes, content_length)
373
369
 
374
370
  return request
375
371
 
376
- def _find_handler( # pylint: disable=cell-var-from-loop
377
- self, method: str, path: str
378
- ) -> Union[Callable[..., "Response"], None]:
372
+ def _find_handler(self, method: str, path: str) -> Union[Callable[..., "Response"], None]:
379
373
  """
380
374
  Finds a handler for a given route.
381
375
 
@@ -419,7 +413,7 @@ class Server: # pylint: disable=too-many-instance-attributes
419
413
  raise ServingFilesDisabledError
420
414
 
421
415
  # Method is GET or HEAD, try to serve a file from the filesystem.
422
- if request.method in (GET, HEAD):
416
+ if request.method in {GET, HEAD}:
423
417
  return FileResponse(
424
418
  request,
425
419
  filename=request.path,
@@ -451,11 +445,9 @@ class Server: # pylint: disable=too-many-instance-attributes
451
445
 
452
446
  def _set_default_server_headers(self, response: Response) -> None:
453
447
  for name, value in self.headers.items():
454
- response._headers.setdefault( # pylint: disable=protected-access
455
- name, value
456
- )
448
+ response._headers.setdefault(name, value)
457
449
 
458
- def poll( # pylint: disable=too-many-branches,too-many-return-statements
450
+ def poll(
459
451
  self,
460
452
  ) -> str:
461
453
  """
@@ -494,7 +486,7 @@ class Server: # pylint: disable=too-many-instance-attributes
494
486
  self._set_default_server_headers(response)
495
487
 
496
488
  # Send the response
497
- response._send() # pylint: disable=protected-access
489
+ response._send()
498
490
 
499
491
  if self.debug:
500
492
  _debug_end_time = monotonic()
@@ -502,7 +494,7 @@ class Server: # pylint: disable=too-many-instance-attributes
502
494
 
503
495
  return REQUEST_HANDLED_RESPONSE_SENT
504
496
 
505
- except Exception as error: # pylint: disable=broad-except
497
+ except Exception as error:
506
498
  if isinstance(error, OSError):
507
499
  # There is no data available right now, try again later.
508
500
  if error.errno == EAGAIN:
@@ -635,7 +627,6 @@ def _debug_started_server(server: "Server"):
635
627
 
636
628
  def _debug_response_sent(response: "Response", time_elapsed: float):
637
629
  """Prints a message after a response is sent."""
638
- # pylint: disable=protected-access
639
630
  client_ip = response._request.client_address[0]
640
631
  method = response._request.method
641
632
  query_params = response._request.query_params
@@ -650,7 +641,7 @@ def _debug_response_sent(response: "Response", time_elapsed: float):
650
641
  )
651
642
 
652
643
 
653
- def _debug_stopped_server(server: "Server"): # pylint: disable=unused-argument
644
+ def _debug_stopped_server(server: "Server"):
654
645
  """Prints a message after the server stops."""
655
646
  print("Stopped development server")
656
647
 
@@ -8,7 +8,7 @@
8
8
  """
9
9
 
10
10
 
11
- class Status: # pylint: disable=too-few-public-methods
11
+ class Status:
12
12
  """HTTP status code."""
13
13
 
14
14
  def __init__(self, code: int, text: str):
@@ -1,17 +0,0 @@
1
- adafruit_httpserver/__init__.py,sha256=bZhXuFu1HGbpmJBcjPGaRIBVTXCrTCDXuqTfbu70r6A,1994
2
- adafruit_httpserver/authentication.py,sha256=cNWrsPUOAAepNFJzoP3r5ODLQx-X74LkMC_1CieMq2g,2080
3
- adafruit_httpserver/exceptions.py,sha256=tmOoUecGaSXY9kUIIV3Is5YoChrEIEJqVHl4QgmEvrg,1597
4
- adafruit_httpserver/headers.py,sha256=KT8hzJwf97lu3cT05ptm21soPVbywmOY23qdUC3NvVs,4576
5
- adafruit_httpserver/interfaces.py,sha256=7ByLLu1EOhF1EiaC7iqa53qPAxqiNPMZteSDC-hhtxQ,4791
6
- adafruit_httpserver/methods.py,sha256=6SnSWDFf2oDkxsfCUt07o00FgDQyiDACrNCK_XP82eI,364
7
- adafruit_httpserver/mime_types.py,sha256=zI2geYB7DHDK0rgpfHEJwybZXszX4lXgfCPZEyFD-mA,7149
8
- adafruit_httpserver/request.py,sha256=67tp_QjUpV7C_KrB9qE0OxbVPAcraU3kmWK7fmjsPUs,15099
9
- adafruit_httpserver/response.py,sha256=0-UZxj7C5k0CF2mSe3CjZrIM1bYZ4C1tWrOjH1x6XCc,28371
10
- adafruit_httpserver/route.py,sha256=VPWcfyJ196Jd8htWM8eTZRm66Su4qVUlL8iR31Xttas,6149
11
- adafruit_httpserver/server.py,sha256=Fj3BVTUw3GfsHgb1DcT5q45ONBa6foXPO0fpj-ISGMo,22619
12
- adafruit_httpserver/status.py,sha256=U3t5y3wXCYH3JUoWjta3Wd_ag05scK1njY0k-TLMBNM,1867
13
- adafruit_circuitpython_httpserver-4.6.2.dist-info/LICENSE,sha256=gyhZwtwoqSsDGoSrV4MrLpKKWyG_jE3eROTZp1EjIUM,1102
14
- adafruit_circuitpython_httpserver-4.6.2.dist-info/METADATA,sha256=mdrD7qLNMu_9GFNCAGKwh0RCsUbGy6SOzK_VW41E7EI,4800
15
- adafruit_circuitpython_httpserver-4.6.2.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
16
- adafruit_circuitpython_httpserver-4.6.2.dist-info/top_level.txt,sha256=N8L9ONfZQ9bILxcOPVWXOjUDA-BNLPKFir7KqAbMQbA,20
17
- adafruit_circuitpython_httpserver-4.6.2.dist-info/RECORD,,