Skip to content

Commit

Permalink
Make lint and typecheck happier
Browse files Browse the repository at this point in the history
  • Loading branch information
mnot committed Oct 15, 2023
1 parent b6dbfa6 commit e362051
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ method-rgx = "[a-z_][a-z0-9_]{1,30}$"
class-rgx = "[a-zA-Z0-9_]+$"

[tool.pylint.messages_control]
disable = "C0114,C0115,C0116,W0613"
disable = "C0114,C0115,C0116,W0613,R0903"

[tool.pylint.reports]
reports = false
Expand Down
4 changes: 2 additions & 2 deletions redbot/formatter/har.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def add_entry(self, resource: HttpResource, page_ref: int = None) -> None:
entry = {
"startedDateTime": isoformat(resource.request.start_time),
"time": int(
(resource.response.complete_time - resource.request.start_time) * 1000
(resource.response.finish_time - resource.request.start_time) * 1000
),
"_red_messages": self.format_notes(resource),
}
Expand Down Expand Up @@ -120,7 +120,7 @@ def add_entry(self, resource: HttpResource, page_ref: int = None) -> None:
(resource.response.start_time - resource.request.start_time) * 1000
),
"receive": int(
(resource.response.complete_time - resource.response.start_time) * 1000
(resource.response.finish_time - resource.response.start_time) * 1000
),
}

Expand Down
2 changes: 1 addition & 1 deletion redbot/formatter/html_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def feed(self, sample: bytes) -> None:
def start_output(self) -> None:
if self.resource:
uri = self.resource.request.uri or ""
req_headers = self.resource.request.headers
req_headers = self.resource.request.headers.text
else:
uri = ""
req_headers = []
Expand Down
2 changes: 1 addition & 1 deletion redbot/resource/active_check/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def check(self) -> None:
self.base.request.uri,
self.base.request.method,
modified_headers,
self.base.request.payload,
b"".join([chunk[1] for chunk in self.base.request.content_sample]),
)
RedFetcher.check(self)

Expand Down
6 changes: 3 additions & 3 deletions redbot/resource/active_check/conneg.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def preflight(self) -> bool:
k.lower() for (k, v) in self.base.request.headers.text
]:
return False
if self.base.response.status_code == "206":
if self.base.response.status_code == 206:
return False
return True

Expand All @@ -38,8 +38,8 @@ def done(self) -> None:
bare = self.base.response

if not negotiated.complete:
if self.http_error:
problem = self.http_error.desc
if self.fetch_error:
problem = self.fetch_error.desc
else:
problem = ""
self.add_base_note("", CONNEG_SUBREQ_PROBLEM, problem=problem)
Expand Down
4 changes: 2 additions & 2 deletions redbot/resource/active_check/etag_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def modify_request_headers(
return base_headers

def preflight(self) -> bool:
if self.base.response.status_code[0] == "3":
if 300 <= self.base.response.status_code <= 399:
return False
etag = self.base.response.headers.parsed.get("etag", None)
if etag:
Expand All @@ -46,7 +46,7 @@ def done(self) -> None:
self.add_base_note("", ETAG_SUBREQ_PROBLEM, problem=problem)
return

if self.response.status_code == "304":
if self.response.status_code == 304:
self.base.inm_support = True
self.add_base_note("header-etag", INM_304)
self.check_missing_hdrs(
Expand Down
4 changes: 2 additions & 2 deletions redbot/resource/active_check/lm_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def modify_request_headers(
return base_headers

def preflight(self) -> bool:
if self.base.response.status_code[0] == "3":
if 300 <= self.base.response.status_code <= 399:
return False
if self.base.response.headers.parsed.get("last-modified", None):
return True
Expand All @@ -74,7 +74,7 @@ def done(self) -> None:
self.add_base_note("", LM_SUBREQ_PROBLEM, problem=problem)
return

if self.response.status_code == "304":
if self.response.status_code == 304:
self.base.ims_support = True
self.add_base_note("header-last-modified", IMS_304)
self.check_missing_hdrs(
Expand Down
9 changes: 5 additions & 4 deletions redbot/resource/active_check/range.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import random
from typing import TYPE_CHECKING

from httplint.note import Note, categories, levels, display_bytes
from httplint.note import Note, categories, levels
from httplint.util import display_bytes

from redbot.resource.active_check.base import SubRequest
from redbot.formatter import f_num
Expand Down Expand Up @@ -42,9 +43,9 @@ def modify_request_headers(
return base_headers

def preflight(self) -> bool:
if self.base.response.status_code[0] == "3":
if 300 <= self.base.response.status_code <= 399:
return False
if self.base.response.status_code == "206":
if self.base.response.status_code == 206:
return False
if "bytes" in self.base.response.headers.parsed.get("accept-ranges", []):
if not self.base.response.content_sample:
Expand All @@ -65,7 +66,7 @@ def done(self) -> None:
self.add_base_note("", RANGE_SUBREQ_PROBLEM, problem=problem)
return

if self.response.status_code == "206":
if self.response.status_code == 206:
c_e = "content-encoding"
if ("gzip" in self.base.response.headers.parsed.get(c_e, [])) == (
"gzip" not in self.response.headers.parsed.get(c_e, [])
Expand Down
13 changes: 7 additions & 6 deletions redbot/resource/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from configparser import SectionProxy
import time
from typing import Any, Dict, List, Tuple, Type, Union
from typing import Any, Dict, List, Tuple

from httplint import HttpRequestLinter, HttpResponseLinter
from httplint.note import Notes, Note, categories, levels
Expand Down Expand Up @@ -61,9 +61,9 @@ def __init__(self, config: SectionProxy) -> None:
self.request = HttpRequestLinter(max_sample_size=0)
self.nonfinal_responses: List[HttpResponseLinter] = []
self.response = HttpResponseLinter()
self.exchange: HttpClientExchange = None
self.exchange: HttpClientExchange
self.fetch_started = False
self.http_error: httperr.HttpError = None
self.fetch_error: httperr.HttpError
self.fetch_done = False
self.setup_check_ip()

Expand Down Expand Up @@ -159,12 +159,12 @@ def check(self) -> None:
(k.encode("ascii", "replace"), v.encode("ascii", "replace"))
for (k, v) in self.request.headers.text
]
self.request.start_time = time.time()
self.exchange.request_start(
self.request.method.encode("ascii"),
self.request.uri.encode("ascii"),
req_hdrs,
)
self.request.start_time = int(time.time())
if not self.fetch_done: # the request could have immediately failed.
if self.request.content_sample:
for chunk in self.request.content_sample:
Expand All @@ -187,7 +187,7 @@ def _response_start(
self, status: bytes, phrase: bytes, res_headers: RawHeaderListType
) -> None:
"Process the response start-line and headers."
self.response.start_time = time.time()
self.response.start_time = int(time.time())
self.response.process_response_topline(
self.exchange.res_version, status, phrase
)
Expand All @@ -214,7 +214,7 @@ def _response_error(self, error: httperr.HttpError) -> None:
)
err_sample = error.detail[:40] or ""
if isinstance(error, httperr.ExtraDataError):
if self.response.status_code == "304":
if self.response.status_code == 304:
self.notes.add("body", BODY_NOT_ALLOWED, sample=err_sample)
else:
self.notes.add("body", EXTRA_DATA, sample=err_sample)
Expand All @@ -230,6 +230,7 @@ def _response_error(self, error: httperr.HttpError) -> None:
self._fetch_done()

def _fetch_done(self) -> None:
self.response.finish_time = time.time()
if not self.fetch_done:
self.fetch_done = True
self.exchange = None
Expand Down

0 comments on commit e362051

Please sign in to comment.