Skip to content

Commit 5fdfc22

Browse files
committed
Ran black, updated to pylint 2.x
1 parent eb332d8 commit 5fdfc22

File tree

8 files changed

+172
-146
lines changed

8 files changed

+172
-146
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
source actions-ci/install.sh
4141
- name: Pip install pylint, black, & Sphinx
4242
run: |
43-
pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme
43+
pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
4444
- name: Library version
4545
run: git describe --dirty --always --tags
4646
- name: PyLint

adafruit_requests.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,11 @@ def set_socket(sock, iface=None):
6767
global _the_sock # pylint: disable=invalid-name, global-statement
6868
_the_sock = sock
6969
if iface:
70-
global _the_interface # pylint: disable=invalid-name, global-statement
70+
global _the_interface # pylint: disable=invalid-name, global-statement
7171
_the_interface = iface
7272
_the_sock.set_interface(iface)
7373

74+
7475
class Response:
7576
"""The response from a request, contains all the headers/content"""
7677

@@ -125,6 +126,7 @@ def text(self):
125126

126127
def json(self):
127128
"""The HTTP content, parsed into a json dictionary"""
129+
# pylint: disable=import-outside-toplevel
128130
try:
129131
import json as json_module
130132
except ImportError:
@@ -192,7 +194,9 @@ def request(method, url, data=None, json=None, headers=None, stream=False, timeo
192194
else:
193195
conntype = _the_interface.TCP_MODE
194196
sock.connect(addr_info[-1], conntype)
195-
sock.send(b"%s /%s HTTP/1.0\r\n" % (bytes(method, "utf-8"), bytes(path, "utf-8")))
197+
sock.send(
198+
b"%s /%s HTTP/1.0\r\n" % (bytes(method, "utf-8"), bytes(path, "utf-8"))
199+
)
196200
if "Host" not in headers:
197201
sock.send(b"Host: %s\r\n" % bytes(host, "utf-8"))
198202
if "User-Agent" not in headers:
@@ -205,10 +209,12 @@ def request(method, url, data=None, json=None, headers=None, stream=False, timeo
205209
sock.send(b"\r\n")
206210
if json is not None:
207211
assert data is None
212+
# pylint: disable=import-outside-toplevel
208213
try:
209214
import json as json_module
210215
except ImportError:
211216
import ujson as json_module
217+
# pylint: enable=import-outside-toplevel
212218
data = json_module.dumps(json)
213219
sock.send(b"Content-Type: application/json\r\n")
214220
if data:
@@ -248,6 +254,7 @@ def request(method, url, data=None, json=None, headers=None, stream=False, timeo
248254
resp.reason = reason
249255
return resp
250256

257+
251258
def parse_headers(sock):
252259
"""
253260
Parses the header portion of an HTTP request/response from the socket.
@@ -261,18 +268,19 @@ def parse_headers(sock):
261268
if not line or line == b"\r\n":
262269
break
263270

264-
#print("**line: ", line)
265-
splits = line.split(b': ', 1)
271+
# print("**line: ", line)
272+
splits = line.split(b": ", 1)
266273
title = splits[0]
267-
content = ''
274+
content = ""
268275
if len(splits) > 1:
269276
content = splits[1]
270277
if title and content:
271-
title = str(title.lower(), 'utf-8')
272-
content = str(content, 'utf-8')
278+
title = str(title.lower(), "utf-8")
279+
content = str(content, "utf-8")
273280
headers[title] = content
274281
return headers
275282

283+
276284
def head(url, **kw):
277285
"""Send HTTP HEAD request"""
278286
return request("HEAD", url, **kw)

docs/conf.py

Lines changed: 65 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
import os
44
import sys
5-
sys.path.insert(0, os.path.abspath('..'))
5+
6+
sys.path.insert(0, os.path.abspath(".."))
67

78
# -- General configuration ------------------------------------------------
89

910
# Add any Sphinx extension module names here, as strings. They can be
1011
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
1112
# ones.
1213
extensions = [
13-
'sphinx.ext.autodoc',
14-
'sphinx.ext.intersphinx',
15-
'sphinx.ext.napoleon',
16-
'sphinx.ext.todo',
14+
"sphinx.ext.autodoc",
15+
"sphinx.ext.intersphinx",
16+
"sphinx.ext.napoleon",
17+
"sphinx.ext.todo",
1718
]
1819

1920
# TODO: Please Read!
@@ -23,29 +24,32 @@
2324
# autodoc_mock_imports = ["digitalio", "busio"]
2425

2526

26-
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
27+
intersphinx_mapping = {
28+
"python": ("https://docs.python.org/3.4", None),
29+
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
30+
}
2731

2832
# Add any paths that contain templates here, relative to this directory.
29-
templates_path = ['_templates']
33+
templates_path = ["_templates"]
3034

31-
source_suffix = '.rst'
35+
source_suffix = ".rst"
3236

3337
# The master toctree document.
34-
master_doc = 'index'
38+
master_doc = "index"
3539

3640
# General information about the project.
37-
project = u'Adafruit Requests Library'
38-
copyright = u'2019 ladyada'
39-
author = u'ladyada'
41+
project = u"Adafruit Requests Library"
42+
copyright = u"2019 ladyada"
43+
author = u"ladyada"
4044

4145
# The version info for the project you're documenting, acts as replacement for
4246
# |version| and |release|, also used in various other places throughout the
4347
# built documents.
4448
#
4549
# The short X.Y version.
46-
version = u'1.0'
50+
version = u"1.0"
4751
# The full version, including alpha/beta/rc tags.
48-
release = u'1.0'
52+
release = u"1.0"
4953

5054
# The language for content autogenerated by Sphinx. Refer to documentation
5155
# for a list of supported languages.
@@ -57,7 +61,7 @@
5761
# List of patterns, relative to source directory, that match files and
5862
# directories to ignore when looking for source files.
5963
# This patterns also effect to html_static_path and html_extra_path
60-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md']
64+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"]
6165

6266
# The reST default role (used for this markup: `text`) to use for all
6367
# documents.
@@ -69,7 +73,7 @@
6973
add_function_parentheses = True
7074

7175
# The name of the Pygments (syntax highlighting) style to use.
72-
pygments_style = 'sphinx'
76+
pygments_style = "sphinx"
7377

7478
# If true, `todo` and `todoList` produce output, else they produce nothing.
7579
todo_include_todos = False
@@ -84,68 +88,76 @@
8488
# The theme to use for HTML and HTML Help pages. See the documentation for
8589
# a list of builtin themes.
8690
#
87-
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
91+
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
8892

8993
if not on_rtd: # only import and set the theme if we're building docs locally
9094
try:
9195
import sphinx_rtd_theme
92-
html_theme = 'sphinx_rtd_theme'
93-
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.']
96+
97+
html_theme = "sphinx_rtd_theme"
98+
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."]
9499
except:
95-
html_theme = 'default'
96-
html_theme_path = ['.']
100+
html_theme = "default"
101+
html_theme_path = ["."]
97102
else:
98-
html_theme_path = ['.']
103+
html_theme_path = ["."]
99104

100105
# Add any paths that contain custom static files (such as style sheets) here,
101106
# relative to this directory. They are copied after the builtin static files,
102107
# so a file named "default.css" will overwrite the builtin "default.css".
103-
html_static_path = ['_static']
108+
html_static_path = ["_static"]
104109

105110
# The name of an image file (relative to this directory) to use as a favicon of
106111
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
107112
# pixels large.
108113
#
109-
html_favicon = '_static/favicon.ico'
114+
html_favicon = "_static/favicon.ico"
110115

111116
# Output file base name for HTML help builder.
112-
htmlhelp_basename = 'AdafruitRequestsLibrarydoc'
117+
htmlhelp_basename = "AdafruitRequestsLibrarydoc"
113118

114119
# -- Options for LaTeX output ---------------------------------------------
115120

116121
latex_elements = {
117-
# The paper size ('letterpaper' or 'a4paper').
118-
#
119-
# 'papersize': 'letterpaper',
120-
121-
# The font size ('10pt', '11pt' or '12pt').
122-
#
123-
# 'pointsize': '10pt',
124-
125-
# Additional stuff for the LaTeX preamble.
126-
#
127-
# 'preamble': '',
128-
129-
# Latex figure (float) alignment
130-
#
131-
# 'figure_align': 'htbp',
122+
# The paper size ('letterpaper' or 'a4paper').
123+
#
124+
# 'papersize': 'letterpaper',
125+
# The font size ('10pt', '11pt' or '12pt').
126+
#
127+
# 'pointsize': '10pt',
128+
# Additional stuff for the LaTeX preamble.
129+
#
130+
# 'preamble': '',
131+
# Latex figure (float) alignment
132+
#
133+
# 'figure_align': 'htbp',
132134
}
133135

134136
# Grouping the document tree into LaTeX files. List of tuples
135137
# (source start file, target name, title,
136138
# author, documentclass [howto, manual, or own class]).
137139
latex_documents = [
138-
(master_doc, 'AdafruitRequestsLibrary.tex', u'AdafruitRequests Library Documentation',
139-
author, 'manual'),
140+
(
141+
master_doc,
142+
"AdafruitRequestsLibrary.tex",
143+
u"AdafruitRequests Library Documentation",
144+
author,
145+
"manual",
146+
),
140147
]
141148

142149
# -- Options for manual page output ---------------------------------------
143150

144151
# One entry per manual page. List of tuples
145152
# (source start file, name, description, authors, manual section).
146153
man_pages = [
147-
(master_doc, 'AdafruitRequestslibrary', u'Adafruit Requests Library Documentation',
148-
[author], 1)
154+
(
155+
master_doc,
156+
"AdafruitRequestslibrary",
157+
u"Adafruit Requests Library Documentation",
158+
[author],
159+
1,
160+
)
149161
]
150162

151163
# -- Options for Texinfo output -------------------------------------------
@@ -154,7 +166,13 @@
154166
# (source start file, target name, title, author,
155167
# dir menu entry, description, category)
156168
texinfo_documents = [
157-
(master_doc, 'AdafruitRequestsLibrary', u'Adafruit Requests Library Documentation',
158-
author, 'AdafruitRequestsLibrary', 'One line description of project.',
159-
'Miscellaneous'),
169+
(
170+
master_doc,
171+
"AdafruitRequestsLibrary",
172+
u"Adafruit Requests Library Documentation",
173+
author,
174+
"AdafruitRequestsLibrary",
175+
"One line description of project.",
176+
"Miscellaneous",
177+
),
160178
]

examples/requests_advanced.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,32 @@
2121
print("Connecting to AP...")
2222
while not esp.is_connected:
2323
try:
24-
esp.connect_AP(b'MY_SSID_NAME', b'MY_SSID_PASSWORD')
24+
esp.connect_AP(b"MY_SSID_NAME", b"MY_SSID_PASSWORD")
2525
except RuntimeError as e:
26-
print("could not connect to AP, retrying: ",e)
26+
print("could not connect to AP, retrying: ", e)
2727
continue
28-
print("Connected to", str(esp.ssid, 'utf-8'), "\tRSSI:", esp.rssi)
28+
print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi)
2929

3030
# Initialize a requests object with a socket and esp32spi interface
3131
requests.set_socket(socket, esp)
3232

3333
JSON_GET_URL = "http://httpbin.org/get"
3434

3535
# Define a custom header as a dict.
36-
headers = {"user-agent" : "blinka/1.0.0"}
36+
headers = {"user-agent": "blinka/1.0.0"}
3737

38-
print("Fetching JSON data from %s..."%JSON_GET_URL)
38+
print("Fetching JSON data from %s..." % JSON_GET_URL)
3939
response = requests.get(JSON_GET_URL, headers=headers)
40-
print('-'*60)
40+
print("-" * 60)
4141

4242
json_data = response.json()
43-
headers = json_data['headers']
44-
print("Response's Custom User-Agent Header: {0}".format(headers['User-Agent']))
45-
print('-'*60)
43+
headers = json_data["headers"]
44+
print("Response's Custom User-Agent Header: {0}".format(headers["User-Agent"]))
45+
print("-" * 60)
4646

4747
# Read Response's HTTP status code
4848
print("Response HTTP Status Code: ", response.status_code)
49-
print('-'*60)
49+
print("-" * 60)
5050

5151
# Read Response, as raw bytes instead of pretty text
5252
print("Raw Response: ", response.content)

examples/requests_advanced_ethernet.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
JSON_GET_URL = "http://httpbin.org/get"
1818

19-
attempts = 3 # Number of attempts to retry each request
19+
attempts = 3 # Number of attempts to retry each request
2020
failure_count = 0
2121
response = None
2222

2323
# Define a custom header as a dict.
24-
headers = {"user-agent" : "blinka/1.0.0"}
24+
headers = {"user-agent": "blinka/1.0.0"}
2525

26-
print("Fetching JSON data from %s..."%JSON_GET_URL)
26+
print("Fetching JSON data from %s..." % JSON_GET_URL)
2727
while not response:
2828
try:
2929
response = requests.get(JSON_GET_URL, headers=headers)
@@ -32,19 +32,21 @@
3232
print("Request failed, retrying...\n", error)
3333
failure_count += 1
3434
if failure_count >= attempts:
35-
raise AssertionError("Failed to resolve hostname, \
36-
please check your router's DNS configuration.")
35+
raise AssertionError(
36+
"Failed to resolve hostname, \
37+
please check your router's DNS configuration."
38+
)
3739
continue
38-
print('-'*60)
40+
print("-" * 60)
3941

4042
json_data = response.json()
41-
headers = json_data['headers']
42-
print("Response's Custom User-Agent Header: {0}".format(headers['User-Agent']))
43-
print('-'*60)
43+
headers = json_data["headers"]
44+
print("Response's Custom User-Agent Header: {0}".format(headers["User-Agent"]))
45+
print("-" * 60)
4446

4547
# Read Response's HTTP status code
4648
print("Response HTTP Status Code: ", response.status_code)
47-
print('-'*60)
49+
print("-" * 60)
4850

4951
# Read Response, as raw bytes instead of pretty text
5052
print("Raw Response: ", response.content)

0 commit comments

Comments
 (0)