Fix CI issues: add workflow file and fix lint errors
Some checks failed
CI / test (push) Has been cancelled
Some checks failed
CI / test (push) Has been cancelled
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
"""Python code generator."""
|
{"""Python code generator."""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import base64
|
import base64
|
||||||
@@ -40,18 +40,14 @@ def generate_python(parsed: ParsedCurl) -> str:
|
|||||||
lines.append("headers = " + _format_dict(headers))
|
lines.append("headers = " + _format_dict(headers))
|
||||||
kwargs.append("headers=headers")
|
kwargs.append("headers=headers")
|
||||||
|
|
||||||
auth_tuple = None
|
|
||||||
if parsed.auth:
|
if parsed.auth:
|
||||||
auth_username, auth_password = parsed.auth
|
|
||||||
if ":" in parsed.auth[0]:
|
if ":" in parsed.auth[0]:
|
||||||
try:
|
try:
|
||||||
encoded = base64.b64encode(f"{parsed.auth[0]}:{parsed.auth[1]}".encode()).decode()
|
encoded = base64.b64encode(f"{parsed.auth[0]}:{parsed.auth[1]}".encode()).decode()
|
||||||
if "Authorization" not in headers:
|
if "Authorization" not in headers:
|
||||||
headers["Authorization"] = f"Basic {encoded}"
|
headers["Authorization"] = f"Basic {encoded}"
|
||||||
except Exception:
|
except Exception:
|
||||||
auth_tuple = parsed.auth
|
pass
|
||||||
else:
|
|
||||||
auth_tuple = parsed.auth
|
|
||||||
|
|
||||||
if parsed.data:
|
if parsed.data:
|
||||||
content_type = _detect_content_type(headers, parsed.data)
|
content_type = _detect_content_type(headers, parsed.data)
|
||||||
@@ -92,4 +88,4 @@ def _format_dict(d: dict) -> str:
|
|||||||
items = []
|
items = []
|
||||||
for k, v in d.items():
|
for k, v in d.items():
|
||||||
items.append(f" {repr(k)}: {repr(v)}")
|
items.append(f" {repr(k)}: {repr(v)}")
|
||||||
return "{\n" + ",\n".join(items) + "\n}"
|
return "{\n" + ",\n".join(items) + "\n}"
|
||||||
Reference in New Issue
Block a user