MCPcopy
hub / github.com/encode/httpx / __init__

Method __init__

httpx/_utils.py:162–190  ·  httpx/_utils.py::URLPattern.__init__
(self, pattern: str)

Source from the content-addressed store, hash-verified

160 class="st">"""
161
162 def __init__(self, pattern: str) -> None:
163 from ._urls import URL
164
165 if pattern and class="st">":" not in pattern:
166 raise ValueError(
167 fclass="st">"Proxy keys should use proper URL forms rather "
168 fclass="st">"than plain scheme strings. "
169 f&class="cm">#x27;Instead of class="st">"{pattern}", use class="st">"{pattern}://"'
170 )
171
172 url = URL(pattern)
173 self.pattern = pattern
174 self.scheme = class="st">"" if url.scheme == class="st">"all" else url.scheme
175 self.host = class="st">"" if url.host == class="st">"*" else url.host
176 self.port = url.port
177 if not url.host or url.host == class="st">"*":
178 self.host_regex: typing.Pattern[str] | None = None
179 elif url.host.startswith(class="st">"*."):
180 class="cm"># *.example.com should match class="st">"www.example.com", but not class="st">"example.com"
181 domain = re.escape(url.host[2:])
182 self.host_regex = re.compile(fclass="st">"^.+\\.{domain}$")
183 elif url.host.startswith(class="st">"*"):
184 class="cm"># *example.com should match class="st">"www.example.com" and class="st">"example.com"
185 domain = re.escape(url.host[1:])
186 self.host_regex = re.compile(fclass="st">"^(.+\\.)?{domain}$")
187 else:
188 class="cm"># example.com should match class="st">"example.com" but not class="st">"www.example.com"
189 domain = re.escape(url.host)
190 self.host_regex = re.compile(fclass="st">"^{domain}$")
191
192 def matches(self, other: URL) -> bool:
193 if self.scheme and self.scheme != other.scheme:

Callers

nothing calls this directly

Calls 1

URLClass · 0.85

Tested by

no test coverage detected