Skip to content
Myr

Remove 'URIReference' from public interfaces (#170)

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

authored by Tom Christie · committed by Seth Michael Larson · parent fb17459 · Browse files · 1 file+25 added−27 removed
This commit

State

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

Diff stats

1 file+25 added−27 removed

  • other:+25 added−27 removed

1 file+25 added−27 removed

modified:httpx/models.py+25 added-27 removed
83 unmodified lines
84 url: URLTypes,85 allow_relative: bool = False,86 params: QueryParamTypes = None,87 ) -> None:88 if isinstance(url, rfc3986.uri.URIReference):89 self.components = url90 elif isinstance(url, str):91 self.components = rfc3986.api.uri_reference(url)88 if isinstance(url, str):89 self._uri_reference = rfc3986.api.uri_reference(url)90 else:93 self.components = url.components91 self._uri_reference = url._uri_reference9293 # Handle IDNA domain names.96 if self.components.authority:97 idna_authority = self.components.authority.encode("idna").decode("ascii")98 if idna_authority != self.components.authority:99 self.components = self.components.copy_with(authority=idna_authority)94 if self._uri_reference.authority:95 idna_authority = self._uri_reference.authority.encode("idna").decode("ascii")96 if idna_authority != self._uri_reference.authority:97 self._uri_reference = self._uri_reference.copy_with(authority=idna_authority)9899 # Normalize scheme and domain name.100 if self.is_absolute_url:103 self.components = self.components.normalize()101 self._uri_reference = self._uri_reference.normalize()102103 # Add any query parameters.104 if params:105 query_string = str(QueryParams(params))108 self.components = self.components.copy_with(query=query_string)106 self._uri_reference = self._uri_reference.copy_with(query=query_string)107108 # Enforce absolute URLs by default.109 if not allow_relative:110 if not self.scheme:
6 unmodified lines
117 self.scheme == "http"118 and self.host119 and hstspreload.in_hsts_preload(self.host)120 ):123 self.components = self.components.copy_with(scheme="https")121 self._uri_reference = self._uri_reference.copy_with(scheme="https")122123 @property124 def scheme(self) -> str:127 return self.components.scheme or ""125 return self._uri_reference.scheme or ""126127 @property128 def authority(self) -> str:131 return self.components.authority or ""129 return self._uri_reference.authority or ""130131 @property132 def username(self) -> str:135 userinfo = self.components.userinfo or ""133 userinfo = self._uri_reference.userinfo or ""134 return userinfo.partition(":")[0]135136 @property137 def password(self) -> str:140 userinfo = self.components.userinfo or ""138 userinfo = self._uri_reference.userinfo or ""139 return userinfo.partition(":")[2]140141 @property142 def host(self) -> str:145 return self.components.host or ""143 return self._uri_reference.host or ""144145 @property146 def port(self) -> int:149 port = self.components.port147 port = self._uri_reference.port148 if port is None:149 return {"https": 443, "http": 80}[self.scheme]150 return int(port)151152 @property153 def path(self) -> str:156 return self.components.path or "/"154 return self._uri_reference.path or "/"155156 @property157 def query(self) -> str:160 return self.components.query or ""158 return self._uri_reference.query or ""159160 @property161 def full_path(self) -> str:162 path = self.path
2 unmodified lines
165 return path166167 @property168 def fragment(self) -> str:171 return self.components.fragment or ""169 return self._uri_reference.fragment or ""170171 @property172 def is_ssl(self) -> bool:175 return self.components.scheme == "https"173 return self.scheme == "https"174175 @property176 def is_absolute_url(self) -> bool:177 """
3 unmodified lines
181 # We don't use `.is_absolute` from `rfc3986` because it treats182 # URLs with a fragment portion as not absolute.183 # What we actually care about is if the URL provides184 # a scheme and hostname to which connections should be made.187 return self.components.scheme and self.components.host185 return self.scheme and self.host186187 @property188 def is_relative_url(self) -> bool:189 return not self.is_absolute_url
2 unmodified lines
192 def origin(self) -> "Origin":193 return Origin(self)194195 def copy_with(self, **kwargs: typing.Any) -> "URL":198 return URL(self.components.copy_with(**kwargs))196 return URL(self._uri_reference.copy_with(**kwargs).unsplit())197198 def join(self, relative_url: URLTypes) -> "URL":199 """200 Return an absolute URL, using given this URL as the base.
2 unmodified lines
203 return URL(relative_url)204205 # We drop any fragment portion, because RFC 3986 strictly206 # treats URLs with a fragment portion as not being absolute URLs.209 base_components = self.components.copy_with(fragment=None)207 base_uri = self._uri_reference.copy_with(fragment=None)208 relative_url = URL(relative_url, allow_relative=True)211 return URL(relative_url.components.resolve_with(base_components))209 return URL(relative_url._uri_reference.resolve_with(base_uri).unsplit())210211 def __hash__(self) -> int:212 return hash(str(self))213214 def __eq__(self, other: typing.Any) -> bool:215 return isinstance(other, (URL, str)) and str(self) == str(other)216217 def __str__(self) -> str:220 return self.components.unsplit()218 return self._uri_reference.unsplit()219220 def __repr__(self) -> str:221 class_name = self.__class__.__name__222 url_str = str(self)
960 unmodified lines