Skip to content

Commit

Permalink
Ascii encoding everywhere.
Browse files Browse the repository at this point in the history
  • Loading branch information
mindflayer committed Oct 15, 2023
1 parent fd2e65a commit 8c1b945
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ services-down:

test-python:
@echo "Running Python tests"
wait-for-it --service httpbin.local:443 --service localhost:6379 --timeout 5 -- python run_tests.py || exit 1
wait-for-it --service httpbin.local:443 --service localhost:6379 --timeout 5 -- pytest tests/ || exit 1
@echo ""

lint-python:
Expand Down
13 changes: 6 additions & 7 deletions mocket/mockhttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

STATUS = {k: v[0] for k, v in BaseHTTPRequestHandler.responses.items()}
CRLF = "\r\n"
ASCII = "ascii"


class Protocol:
Expand All @@ -25,7 +26,7 @@ def __init__(self):
self.headers = {}

def on_header(self, name: bytes, value: bytes):
self.headers[name.decode("ascii")] = value.decode("ascii")
self.headers[name.decode(ASCII)] = value.decode(ASCII)

def on_body(self, body: bytes):
try:
Expand All @@ -34,7 +35,7 @@ def on_body(self, body: bytes):
self.body = body

def on_url(self, url: bytes):
self.url = url.decode("ascii")
self.url = url.decode(ASCII)


class Request:
Expand All @@ -51,7 +52,7 @@ def add_data(self, data):

@property
def method(self):
return self._parser.get_method().decode("ascii")
return self._parser.get_method().decode(ASCII)

@property
def path(self):
Expand Down Expand Up @@ -110,7 +111,7 @@ def get_protocol_data(self, str_format_fun_name="capitalize"):
for k, v in self.headers.items()
)
)
return "{0}\r\n{1}\r\n\r\n".format(status_line, header_lines).encode("utf-8")
return "{0}\r\n{1}\r\n\r\n".format(status_line, header_lines).encode(ENCODING)

def set_base_headers(self):
self.headers = {
Expand All @@ -121,7 +122,7 @@ def set_base_headers(self):
"Content-Length": str(len(self.body)),
}
if not self.is_file_object:
self.headers["Content-Type"] = "text/plain; charset=utf-8"
self.headers["Content-Type"] = f"text/plain; charset={ENCODING}"
elif self.magic:
self.headers["Content-Type"] = do_the_magic(self.magic, self.body)

Expand Down Expand Up @@ -237,7 +238,6 @@ def _parse_requestline(line):

@classmethod
def register(cls, method, uri, *responses, **config):

if "body" in config or "status" in config:
raise AttributeError("Did you mean `Entry.single_register(...)`?")

Expand All @@ -263,7 +263,6 @@ def single_register(
match_querystring=True,
exception=None,
):

response = (
exception
if exception
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ ignore-vcs = true

[tool.hatch.build.targets.sdist]
include = [
"run_tests.py",
"README.rst",
"LICENSE",
"pyproject.toml",
Expand Down
27 changes: 0 additions & 27 deletions run_tests.py

This file was deleted.

0 comments on commit 8c1b945

Please sign in to comment.