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

Class URLPattern

httpx/_utils.py:120–226  ·  view source on GitHub ↗

A utility class currently used for making lookups against proxy keys... # Wildcard matching... >>> pattern = URLPattern("all://") >>> pattern.matches(httpx.URL("http://example.com")) True # Witch scheme matching... >>> pattern = URLPattern("https://") >>> pattern.m

Source from the content-addressed store, hash-verified

118
119
120class URLPattern:
121 """
122 A utility class currently used for making lookups against proxy keys...
123
124 # Wildcard matching...
125 >>> pattern = URLPattern("all://")
126 >>> pattern.matches(httpx.URL("http://example.com"))
127 True
128
129 # Witch scheme matching...
130 >>> pattern = URLPattern("https://")
131 >>> pattern.matches(httpx.URL("https://example.com"))
132 True
133 >>> pattern.matches(httpx.URL("http://example.com"))
134 False
135
136 # With domain matching...
137 >>> pattern = URLPattern("https://example.com")
138 >>> pattern.matches(httpx.URL("https://example.com"))
139 True
140 >>> pattern.matches(httpx.URL("http://example.com"))
141 False
142 >>> pattern.matches(httpx.URL("https://other.com"))
143 False
144
145 # Wildcard scheme, with domain matching...
146 >>> pattern = URLPattern("all://example.com")
147 >>> pattern.matches(httpx.URL("https://example.com"))
148 True
149 >>> pattern.matches(httpx.URL("http://example.com"))
150 True
151 >>> pattern.matches(httpx.URL("https://other.com"))
152 False
153
154 # With port matching...
155 >>> pattern = URLPattern("https://example.com:1234")
156 >>> pattern.matches(httpx.URL("https://example.com:1234"))
157 True
158 >>> pattern.matches(httpx.URL("https://example.com"))
159 False
160 """
161
162 def __init__(self, pattern: str) -> None:
163 from ._urls import URL
164
165 if pattern and ":" not in pattern:
166 raise ValueError(
167 f"Proxy keys should use proper URL forms rather "
168 f"than plain scheme strings. "
169 f'Instead of "{pattern}", use "{pattern}://"'
170 )
171
172 url = URL(pattern)
173 self.pattern = pattern
174 self.scheme = "" if url.scheme == "all" else url.scheme
175 self.host = "" if url.host == "*" else url.host
176 self.port = url.port
177 if not url.host or url.host == "*":

Callers 4

test_url_matchesFunction · 0.90
test_pattern_priorityFunction · 0.90
__init__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by 2

test_url_matchesFunction · 0.72
test_pattern_priorityFunction · 0.72