Skip to content
Myr

Refactor `httpx/_utils.py` (#1943)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Removes unnecessary call to keys() when iterating over a dictionary * Simplify conditionals into a form like a switch statement * Merge else clause's nested if statement into elif * Update httpx/_utils.py * Update httpx/_utils.py

authored by Yasser Tahiri · committed by GitHub · parent 7d3a534 · Browse files · 1 file+11 added−12 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Tom Christie <tom@tomchristie.com>

Diff stats

1 file+11 added−12 removed

  • other:+11 added−12 removed

1 file+11 added−12 removed

modified:httpx/_utils.py+11 added-12 removed
470 unmodified lines
471 self.host = "" if url.host == "*" else url.host472 self.port = url.port473 if not url.host or url.host == "*":474 self.host_regex: typing.Optional[typing.Pattern[str]] = None475 elif url.host.startswith("*."):476 # *.example.com should match "www.example.com", but not "example.com"477 domain = re.escape(url.host[2:])478 self.host_regex = re.compile(f"^.+\\.{domain}$")479 elif url.host.startswith("*"):480 # *example.com should match "www.example.com" and "example.com"481 domain = re.escape(url.host[1:])482 self.host_regex = re.compile(f"^(.+\\.)?{domain}$")483 else:476 if url.host.startswith("*."):477 # *.example.com should match "www.example.com", but not "example.com"478 domain = re.escape(url.host[2:])479 self.host_regex = re.compile(f"^.+\\.{domain}$")480 elif url.host.startswith("*"):481 # *example.com should match "www.example.com" and "example.com"482 domain = re.escape(url.host[1:])483 self.host_regex = re.compile(f"^(.+\\.)?{domain}$")484 else:485 # example.com should match "example.com" but not "www.example.com"486 domain = re.escape(url.host)487 self.host_regex = re.compile(f"^{domain}$")484 # example.com should match "example.com" but not "www.example.com"485 domain = re.escape(url.host)486 self.host_regex = re.compile(f"^{domain}$")487488 def matches(self, other: "URL") -> bool:489 if self.scheme and self.scheme != other.scheme:490 return False
32 unmodified lines