Skip to content

Commit 6585d3f

Browse files
committed
Resolving rest of pylint and black errors
1 parent 21e20b6 commit 6585d3f

File tree

8 files changed

+107
-101
lines changed

8 files changed

+107
-101
lines changed

adafruit_httpserver/methods.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
* Author(s): Michał Pokusa
88
"""
99

10-
class HTTPMethod:
10+
11+
class HTTPMethod: # pylint: disable=too-few-public-methods
1112
"""Enum with HTTP methods."""
1213

1314
GET = "GET"

adafruit_httpserver/mime_type.py

Lines changed: 81 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -7,92 +7,94 @@
77
* Author(s): Dan Halbert, Michał Pokusa
88
"""
99

10+
1011
class MIMEType:
1112
"""Common MIME types.
1213
From https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
1314
"""
1415

15-
AAC = "audio/aac"
16-
ABW = "application/x-abiword"
17-
ARC = "application/x-freearc"
18-
AVI = "video/x-msvideo"
19-
AZW = "application/vnd.amazon.ebook"
20-
BIN = "application/octet-stream"
21-
BMP = "image/bmp"
22-
BZ = "application/x-bzip"
23-
BZ2 = "application/x-bzip2"
24-
CSH = "application/x-csh"
25-
CSS = "text/css"
26-
CSV = "text/csv"
27-
DOC = "application/msword"
28-
DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
29-
EOT = "application/vnd.ms-fontobject"
30-
EPUB = "application/epub+zip"
31-
GZ = "application/gzip"
32-
GIF = "image/gif"
33-
HTML = "text/html"
34-
HTM = "text/html"
35-
ICO = "image/vnd.microsoft.icon"
36-
ICS = "text/calendar"
37-
JAR = "application/java-archive"
38-
JPEG = "image/jpeg"
39-
JPG = "image/jpeg"
40-
JS = "text/javascript"
41-
JSON = "application/json"
42-
JSONLD = "application/ld+json"
43-
MID = "audio/midi"
44-
MIDI = "audio/midi"
45-
MJS = "text/javascript"
46-
MP3 = "audio/mpeg"
47-
CDA = "application/x-cdf"
48-
MP4 = "video/mp4"
49-
MPEG = "video/mpeg"
50-
MPKG = "application/vnd.apple.installer+xml"
51-
ODP = "application/vnd.oasis.opendocument.presentation"
52-
ODS = "application/vnd.oasis.opendocument.spreadsheet"
53-
ODT = "application/vnd.oasis.opendocument.text"
54-
OGA = "audio/ogg"
55-
OGV = "video/ogg"
56-
OGX = "application/ogg"
57-
OPUS = "audio/opus"
58-
OTF = "font/otf"
59-
PNG = "image/png"
60-
PDF = "application/pdf"
61-
PHP = "application/x-httpd-php"
62-
PPT = "application/vnd.ms-powerpoint"
63-
PPTX = "application/vnd.openxmlformats-officedocument.presentationml.presentation"
64-
RAR = "application/vnd.rar"
65-
RTF = "application/rtf"
66-
SH = "application/x-sh"
67-
SVG = "image/svg+xml"
68-
SWF = "application/x-shockwave-flash"
69-
TAR = "application/x-tar"
70-
TIFF = "image/tiff"
71-
TIF = "image/tiff"
72-
TS = "video/mp2t"
73-
TTF = "font/ttf"
74-
TXT = "text/plain"
75-
VSD = "application/vnd.visio"
76-
WAV = "audio/wav"
77-
WEBA = "audio/webm"
78-
WEBM = "video/webm"
79-
WEBP = "image/webp"
80-
WOFF = "font/woff"
81-
WOFF2 = "font/woff2"
82-
XHTML = "application/xhtml+xml"
83-
XLS = "application/vnd.ms-excel"
84-
XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
85-
XML = "application/xml"
86-
XUL = "application/vnd.mozilla.xul+xml"
87-
ZIP = "application/zip"
88-
_7Z = "application/x-7z-compressed"
16+
TYPE_AAC = "audio/aac"
17+
TYPE_ABW = "application/x-abiword"
18+
TYPE_ARC = "application/x-freearc"
19+
TYPE_AVI = "video/x-msvideo"
20+
TYPE_AZW = "application/vnd.amazon.ebook"
21+
TYPE_BIN = "application/octet-stream"
22+
TYPE_BMP = "image/bmp"
23+
TYPE_BZ = "application/x-bzip"
24+
TYPE_BZ2 = "application/x-bzip2"
25+
TYPE_CSH = "application/x-csh"
26+
TYPE_CSS = "text/css"
27+
TYPE_CSV = "text/csv"
28+
TYPE_DOC = "application/msword"
29+
TYPE_DOCX = (
30+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
31+
)
32+
TYPE_EOT = "application/vnd.ms-fontobject"
33+
TYPE_EPUB = "application/epub+zip"
34+
TYPE_GZ = "application/gzip"
35+
TYPE_GIF = "image/gif"
36+
TYPE_HTML = "text/html"
37+
TYPE_HTM = "text/html"
38+
TYPE_ICO = "image/vnd.microsoft.icon"
39+
TYPE_ICS = "text/calendar"
40+
TYPE_JAR = "application/java-archive"
41+
TYPE_JPEG = "image/jpeg"
42+
TYPE_JPG = "image/jpeg"
43+
TYPE_JS = "text/javascript"
44+
TYPE_JSON = "application/json"
45+
TYPE_JSONLD = "application/ld+json"
46+
TYPE_MID = "audio/midi"
47+
TYPE_MIDI = "audio/midi"
48+
TYPE_MJS = "text/javascript"
49+
TYPE_MP3 = "audio/mpeg"
50+
TYPE_CDA = "application/x-cdf"
51+
TYPE_MP4 = "video/mp4"
52+
TYPE_MPEG = "video/mpeg"
53+
TYPE_MPKG = "application/vnd.apple.installer+xml"
54+
TYPE_ODP = "application/vnd.oasis.opendocument.presentation"
55+
TYPE_ODS = "application/vnd.oasis.opendocument.spreadsheet"
56+
TYPE_ODT = "application/vnd.oasis.opendocument.text"
57+
TYPE_OGA = "audio/ogg"
58+
TYPE_OGV = "video/ogg"
59+
TYPE_OGX = "application/ogg"
60+
TYPE_OPUS = "audio/opus"
61+
TYPE_OTF = "font/otf"
62+
TYPE_PNG = "image/png"
63+
TYPE_PDF = "application/pdf"
64+
TYPE_PHP = "application/x-httpd-php"
65+
TYPE_PPT = "application/vnd.ms-powerpoint"
66+
TYPE_PPTX = (
67+
"application/vnd.openxmlformats-officedocument.presentationml.presentation"
68+
)
69+
TYPE_RAR = "application/vnd.rar"
70+
TYPE_RTF = "application/rtf"
71+
TYPE_SH = "application/x-sh"
72+
TYPE_SVG = "image/svg+xml"
73+
TYPE_SWF = "application/x-shockwave-flash"
74+
TYPE_TAR = "application/x-tar"
75+
TYPE_TIFF = "image/tiff"
76+
TYPE_TIF = "image/tiff"
77+
TYPE_TS = "video/mp2t"
78+
TYPE_TTF = "font/ttf"
79+
TYPE_TXT = "text/plain"
80+
TYPE_VSD = "application/vnd.visio"
81+
TYPE_WAV = "audio/wav"
82+
TYPE_WEBA = "audio/webm"
83+
TYPE_WEBM = "video/webm"
84+
TYPE_WEBP = "image/webp"
85+
TYPE_WOFF = "font/woff"
86+
TYPE_WOFF2 = "font/woff2"
87+
TYPE_XHTML = "application/xhtml+xml"
88+
TYPE_XLS = "application/vnd.ms-excel"
89+
TYPE_XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
90+
TYPE_XML = "application/xml"
91+
TYPE_XUL = "application/vnd.mozilla.xul+xml"
92+
TYPE_ZIP = "application/zip"
93+
TYPE_7Z = "application/x-7z-compressed"
8994

9095
@staticmethod
9196
def from_file_name(filename: str):
9297
"""Return the mime type for the given filename. If not known, return "text/plain"."""
93-
attr_name = filename.split(".")[-1].upper()
94-
95-
if attr_name[0].isdigit():
96-
attr_name = "_" + attr_name
98+
attr_name = "TYPE_" + filename.split(".")[-1].upper()
9799

98-
return getattr(MIMEType, attr_name, MIMEType.TXT)
100+
return getattr(MIMEType, attr_name, MIMEType.TYPE_TXT)

adafruit_httpserver/request.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
pass
1414

1515

16-
class HTTPRequest:
16+
class HTTPRequest: # pylint: disable=too-few-public-methods
1717
"""
18-
Incoming request, constructed from raw incoming bytes, that is passed as first argument to route handlers.
18+
Incoming request, constructed from raw incoming bytes.
19+
It is passed as first argument to route handlers.
1920
"""
2021

2122
method: str
@@ -56,10 +57,15 @@ def __init__(self, raw_request: bytes = None) -> None:
5657
empty_line_index = raw_request.find(b"\r\n\r\n")
5758

5859
header_bytes = raw_request[:empty_line_index]
59-
body_bytes = raw_request[empty_line_index + 4:]
60+
body_bytes = raw_request[empty_line_index + 4 :]
6061

6162
try:
62-
self.method, self.path, self.query_params, self.http_version = self._parse_start_line(header_bytes)
63+
(
64+
self.method,
65+
self.path,
66+
self.query_params,
67+
self.http_version,
68+
) = self._parse_start_line(header_bytes)
6369
self.headers = self._parse_headers(header_bytes)
6470
self.body = body_bytes
6571
except Exception as error:

adafruit_httpserver/response.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,20 @@ class HTTPResponse:
3535

3636
body: str
3737

38-
def __init__(
38+
def __init__( # pylint: disable=too-many-arguments
3939
self,
4040
status: HTTPStatus = CommonHTTPStatus.OK_200,
4141
body: str = "",
4242
headers: Dict[str, str] = None,
43-
content_type: str = MIMEType.TXT,
43+
content_type: str = MIMEType.TYPE_TXT,
4444
filename: Optional[str] = None,
4545
root_path: str = "",
4646
http_version: str = "HTTP/1.1",
4747
) -> None:
4848
"""
4949
Creates an HTTP response.
5050
51-
Returns `body` if `filename` is `None`, otherwise returns the contents of `filename`.
51+
Returns ``body`` if ``filename`` is ``None``, otherwise returns contents of ``filename``.
5252
"""
5353

5454
self.status = status
@@ -60,10 +60,10 @@ def __init__(
6060
self.http_version = http_version
6161

6262
@staticmethod
63-
def _construct_response_bytes(
63+
def _construct_response_bytes( # pylint: disable=too-many-arguments
6464
http_version: str = "HTTP/1.1",
6565
status: HTTPStatus = CommonHTTPStatus.OK_200,
66-
content_type: str = MIMEType.TXT,
66+
content_type: str = MIMEType.TYPE_TXT,
6767
content_length: Union[int, None] = None,
6868
headers: Dict[str, str] = None,
6969
body: str = "",
@@ -104,7 +104,7 @@ def send(self, conn: Union["SocketPool.Socket", "socket.socket"]) -> None:
104104
self._send_response(
105105
conn,
106106
status=CommonHTTPStatus.NOT_FOUND_404,
107-
content_type=MIMEType.TXT,
107+
content_type=MIMEType.TYPE_TXT,
108108
body=f"{CommonHTTPStatus.NOT_FOUND_404} {self.filename}",
109109
)
110110
else:
@@ -116,7 +116,7 @@ def send(self, conn: Union["SocketPool.Socket", "socket.socket"]) -> None:
116116
body=self.body,
117117
)
118118

119-
def _send_response(
119+
def _send_response( # pylint: disable=too-many-arguments
120120
self,
121121
conn: Union["SocketPool.Socket", "socket.socket"],
122122
status: HTTPStatus,
@@ -134,7 +134,7 @@ def _send_response(
134134
),
135135
)
136136

137-
def _send_file_response(
137+
def _send_file_response( # pylint: disable=too-many-arguments
138138
self,
139139
conn: Union["SocketPool.Socket", "socket.socket"],
140140
filename: str,

adafruit_httpserver/route.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# SPDX-License-Identifier: MIT
44
"""
5-
`adafruit_httpserver.route.HTTPRoute`
5+
`adafruit_httpserver.route._HTTPRoute`
66
====================================================
77
* Author(s): Dan Halbert, Michał Pokusa
88
"""
@@ -11,7 +11,7 @@
1111

1212

1313
class _HTTPRoute:
14-
"""Route definition for different paths, see `HTTPServer.route`."""
14+
"""Route definition for different paths, see `adafruit_httpserver.server.HTTPServer.route`."""
1515

1616
def __init__(self, path: str = "", method: HTTPMethod = HTTPMethod.GET) -> None:
1717

adafruit_httpserver/server.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ def poll(self):
120120

121121
# If no handler exists and request method is not GET, return 400 Bad Request.
122122
else:
123-
response = HTTPResponse(
124-
status=CommonHTTPStatus.BAD_REQUEST_400
125-
)
123+
response = HTTPResponse(status=CommonHTTPStatus.BAD_REQUEST_400)
126124

127125
response.send(conn)
128126
except OSError as ex:

adafruit_httpserver/status.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Author(s): Dan Halbert, Michał Pokusa
88
"""
99

10+
1011
class HTTPStatus: # pylint: disable=too-few-public-methods
1112
"""HTTP status codes."""
1213

@@ -26,7 +27,8 @@ def __str__(self):
2627
return f"{self.code} {self.text}"
2728

2829

29-
class CommonHTTPStatus(HTTPStatus):
30+
class CommonHTTPStatus(HTTPStatus): # pylint: disable=too-few-public-methods
31+
"""Common HTTP status codes."""
3032

3133
OK_200 = HTTPStatus(200, "OK")
3234
"""200 OK"""

docs/api.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
.. automodule:: adafruit_httpserver.response
2020
:members:
2121

22-
.. automodule:: adafruit_httpserver.route
23-
:private-members:
24-
2522
.. automodule:: adafruit_httpserver.server
2623
:members:
2724

0 commit comments

Comments
 (0)