Reformat all Python code using Black

This commit is contained in:
adisbladis 2022-01-12 18:25:02 +13:00
parent b4d2477b1f
commit 8078110a7f
6 changed files with 39 additions and 32 deletions

View file

@ -63,30 +63,36 @@ context.verify_mode = ssl.CERT_NONE
req = urllib.request.Request(index_url)
if username and password:
import base64
password_b64 = base64.b64encode(bytes(f"{username}:{password}", "utf-8")).decode("utf-8")
password_b64 = base64.b64encode(bytes(f"{username}:{password}", "utf-8")).decode(
"utf-8"
)
req.add_header("Authorization", f"Basic {password_b64}")
response = urllib.request.urlopen(
req,
context=context)
response = urllib.request.urlopen(req, context=context)
index = response.read()
parser = Pep503()
parser.feed(str(index))
if package_filename not in parser.sources:
print("The file %s has not be found in the index %s" % (
package_filename, index_url))
print(
"The file %s has not be found in the index %s" % (package_filename, index_url)
)
exit(1)
package_file = open(package_filename, "wb")
# Sometimes the href is a relative path
if urlparse(parser.sources[package_filename]).netloc == '':
if urlparse(parser.sources[package_filename]).netloc == "":
parsed_url = urlparse(index_url)
package_url = urlunparse((
package_url = urlunparse(
(
parsed_url.scheme,
parsed_url.netloc,
parsed_url.path + "/" + parser.sources[package_filename],
None, None, None,
))
None,
None,
None,
)
)
else:
package_url = parser.sources[package_filename]
@ -107,9 +113,7 @@ print("Downloading %s" % real_package_url)
req = urllib.request.Request(real_package_url)
if username and password:
req.add_unredirected_header("Authorization", f"Basic {password_b64}")
response = urllib.request.urlopen(
req,
context=context)
response = urllib.request.urlopen(req, context=context)
with response as r:
shutil.copyfileobj(r, package_file)

View file

@ -6,10 +6,10 @@
from poetry.packages.utils.utils import SUPPORTED_EXTENSIONS
import json
EXT_FILE = 'extensions.json'
EXT_FILE = "extensions.json"
if __name__ == '__main__':
with open(EXT_FILE, 'w') as f:
ext = set(ext.lstrip('.') for ext in SUPPORTED_EXTENSIONS)
ext.add('egg')
f.write(json.dumps(sorted(ext), indent=2) + '\n')
if __name__ == "__main__":
with open(EXT_FILE, "w") as f:
ext = set(ext.lstrip(".") for ext in SUPPORTED_EXTENSIONS)
ext.add("egg")
f.write(json.dumps(sorted(ext), indent=2) + "\n")

View file

@ -25,7 +25,9 @@ def main(input, output, fields_to_remove):
# Set ensure_ascii to False because TOML is valid UTF-8 so text that can't
# be represented in ASCII is perfectly legitimate
# HACK: Setting ensure_asscii to False breaks Python2 for some dependencies (like cachy==0.3.0)
json.dump(data, output, separators=(",", ":"), ensure_ascii=sys.version_info.major < 3)
json.dump(
data, output, separators=(",", ":"), ensure_ascii=sys.version_info.major < 3
)
if __name__ == "__main__":

View file

@ -1,10 +1,10 @@
def app(environ, start_response):
"""Simplest possible application object"""
data = b'Hello, World!\n'
status = '200 OK'
data = b"Hello, World!\n"
status = "200 OK"
response_headers = [
('Content-type', 'text/plain'),
('Content-Length', str(len(data)))
("Content-type", "text/plain"),
("Content-Length", str(len(data))),
]
start_response(status, response_headers)
return iter([data])

View file

@ -1,13 +1,14 @@
def app(environ, start_response):
"""Simplest possible application object"""
data = b'Original\n'
status = '200 OK'
data = b"Original\n"
status = "200 OK"
response_headers = [
('Content-type', 'text/plain'),
('Content-Length', str(len(data)))
("Content-type", "text/plain"),
("Content-Length", str(len(data))),
]
start_response(status, response_headers)
return iter([data])
def app_factory(global_config, **local_conf):
return app

View file

@ -5,5 +5,5 @@ def main():
print("egg-test")
if __name__ == '__main__':
if __name__ == "__main__":
main()