Url
- class Url
URLas described using the Uniform Resource Identifier (URI) specification (RFC3986).Raises
RuntimeErroron invalid URLs, including those with unicode characters. Unicode characters must be percent escaped by encoding them as hex with%escape. Url components are accessible both as encoded and decoded strings.Encoded strings use
.encodedproperties and returns strings exactly as they appear in the URL. Setting components to escaped strings via.set_encodedmethods preserve the escapes while still percent-escaping reserved characters in the result.Otherwise properties and methods operate on decoded strings. Retrieving a decoded string unescapes percent-encoded octects with the corresponding characters. Setting component values to unescaped strings will percent-escape any reserved characters in the result.
Note that an empty component is distinct from no component, however getters will return empty strings for missing components.
Documentation is based on Boost.URL.
Normalization
URL can be normalized using any of the
.normalizemethods:schemeis normalized to lowercaseother components have percent-encoding triplets normalized to uppercase. Percent-encoded octects that correspond to unreserved characters are decoded.
See Specification for more details.
Members defined in
Url(94 members)
RReturn the authority
RReturn the authority.
RReturn the fragment
RReturn the host
RReturn the host
RReturn the host and port
RReturn the host name
RReturn the origin
RReturn the query as a sequence of parameters
RReturn the password
RReturn the path
RReturn the query
RReturn the resource
RReturn the target
RReturn the user
RReturn the userinfo
RReturn the IPv6 Zone ID
RReturn the fragment
RReturn true if an authority is present
RReturn true if a fragment is present
RReturn true if a password is present
RReturn true if a port is present
RReturn true if a query is present
RReturns true if a scheme is present
RReturn true if a userinfo is present
RReturn the host
RReturn the host
RReturn the host IPv4 address
RReturn the host IPv6 address
RReturn the host IPvFuture address
RReturn the host name
RReturn the host type
RReturn true if the path is absolute
RReturn the password
RReturn the path
RReturn the port
RReturn the port
RReturn the query
RReturns the scheme
RReturn the scheme
RReturn the user
RReturn the userinfo
RReturn the IPv6 Zone ID
Returns true if the url is not empty
Returns the number of characters in the url
Clear the contents while preserving the capacity
Normalize all URL components
Normalize the URL authority
Normalize the URL fragment
Normalize the URL path
Normalize the URL query
Normalize the URL scheme to lowercase
Return the query as a sequence of parameters
Remove the authority
Remove the fragment
Removes the origin (scheme and authority)
Remove the password
Remove the port without affecting the rest of the authority
Remove the query
Remove the scheme
Remove the userinfo if present, without removing any authority.
Adjust the capacity without changing the size
Set the authority
Set the fragment.
Set the host
Set the host to an address
Set the host to a name
Set the password.
Set the path.
Set the query
Set the user
Set the userinfo.
Set the fragment.
Set the host
Set the host to an address
Set the host to an address
Set the host to an address
Set the host to an address
Set the host to a name
Set the password.
Set the path.
Set the port
Set the port
Set the query
Set the scheme
Set the scheme
Set the user
Set the userinfo
Attributes
- property authority: str
Return the authority
- property encoded_authority: str
Return the authority.
- property encoded_fragment: str
Return the fragment
- property encoded_host: str
Return the host
- property encoded_host_address: str
Return the host
- property encoded_host_and_port: str
Return the host and port
If an authority is present, this returns the host and optional port as a string, which may be empty. Otherwise it returns an empty string.
- property encoded_host_name: str
Return the host name
If the host type is
Name, this returns the name as a string. Otherwise, returns an empty string.
- property encoded_origin: str
Return the origin
If an authority is present, this returns the scheme and authority portion of the url. Otherwise, an empty string is returned.
- property encoded_params: list[tuple[str, str | None]]
Return the query as a sequence of parameters
This returns a bidirectional sequence of key/value pairs over the query. Strings returned when iterating the range may contain percent escapes. Changes to the container are not reflected in the underlying URL.
- property encoded_password: str
Return the password
This returns the password portion of the userinfo as a percent-encoded string.
- property encoded_path: str
Return the path
- property encoded_query: str
Return the query
- property encoded_resource: str
Return the resource
This returns the resource, which is the portion of the url that includes only the path, query, and fragment.
- property encoded_target: str
Return the target
This returns the target, which is the portion of the url that includes only the path and query.
- property encoded_user: str
Return the user
- property encoded_userinfo: str
Return the userinfo
- property encoded_zone_id: str
Return the IPv6 Zone ID
If the host type is
IPv6, this returns the Zone ID as a string. Otherwise an empty string is returned.
- property fragment: str
Return the fragment
This calculates the fragment of the url, with percent escapes decoded and without the leading pound sign (‘#’) whose presence indicates that the url contains a fragment.
- property has_authority: bool
Return true if an authority is present
This returns true if the url contains an authority. The presence of an authority is denoted by a double slash (“//”) at the beginning or after the scheme.
- property has_fragment: bool
Return true if a fragment is present
- property has_password: bool
Return true if a password is present
This returns true if the userinfo is present and contains a password.
- property has_port: bool
Return true if a port is present
This returns true if an authority is present and contains a port.
- property has_query: bool
Return true if a query is present
This returns true if this contains a query.
- property has_scheme: bool
Returns true if a scheme is present
- property has_userinfo: bool
Return true if a userinfo is present
- property host: str
Return the host
- property host_address: str
Return the host
- property host_ipv4_address: syside.IPv4Address
Return the host IPv4 address
If the host type is
IPv4, this returns the address. Otherwise, returns a default-constructed value which is equal to the unspecified address “0.0.0.0”.
- property host_ipv6_address: syside.IPv6Address
Return the host IPv6 address
If the host type is
IPv6, this returns the address. Otherwise, returns a default-constructed value which is equal to the unspecified address “0:0:0:0:0:0:0:0”.
- property host_ipvfuture: str
Return the host IPvFuture address
If the host type is
IPvFuture, this returns the address as a string. Otherwise, returns an empty string.
- property host_name: str
Return the host name
If the host type is
Name, this returns the name as a string. Otherwise, returns an empty string.
- property host_type: syside.HostType
Return the host type
This returns one of the following constants representing the type of host present.
HostType.IPv4HostType.IPv6HostType.IPvFutureHostType.NameHostType.none
When
has_authorityis false, the host type isHostType.none.
- property is_path_absolute: bool
Return true if the path is absolute
This returns true if the path begins with a forward slash (‘/’)
- property password: str
Return the password
- property path: str
Return the path
- property port: str
Return the port
- property port_number: int
Return the port
If a port is present and the numerical value is representable, it is returned as an unsigned integer. Otherwise, the number zero is returned.
- property query: str
Return the query
When plus signs appear in the query portion of the url, they are converted to spaces automatically upon decoding.
- property scheme: str
Returns the scheme
- property scheme_id: syside.Scheme
Return the scheme
This returns a value which depends on the scheme in the url:
If the scheme is a well-known scheme, corresponding value from the enumeration
Schemeis returned.If a scheme is present but is not a well-known scheme, the value returned is
Scheme.Unknown.Otherwise, the value returned is
Scheme.none.
- property user: str
Return the user
- property userinfo: str
Return the userinfo
- property zone_id: str
Return the IPv6 Zone ID
If the host type is
IPv6, this returns the Zone ID as a string. Otherwise an empty string is returned.
Methods
- __bool__() bool
Returns true if the url is not empty
- __copy__() syside.Url
- __deepcopy__() syside.Url
- __hash__() int
- __init__() None
- __init__(arg: str, /) None
- __len__() int
Returns the number of characters in the url
- __repr__() str
- __str__() str
- clear() None
Clear the contents while preserving the capacity
- normalize() syside.Url
Normalize all URL components
- normalize_authority() syside.Url
Normalize the URL authority
- normalize_fragment() syside.Url
Normalize the URL fragment
- normalize_path() syside.Url
Normalize the URL path
- normalize_query() syside.Url
Normalize the URL query
- normalize_scheme() syside.Url
Normalize the URL scheme to lowercase
- params(options: syside.EncodingOpts = ...) list[tuple[str, str | None]]
Return the query as a sequence of parameters
This function returns a bidirectional sequence of key/value pairs over the query. Any percent-escapes in strings returned when iterating the view are decoded first. Changes to the container are not reflected in the underlying URL.
- remove_authority() syside.Url
Remove the authority
This function removes the authority, which includes the userinfo, host, and a port if present.
- remove_fragment() syside.Url
Remove the fragment
- remove_origin() syside.Url
Removes the origin (scheme and authority)
- remove_password() syside.Url
Remove the password
This function removes the password from the userinfo if a password exists. If there is no userinfo or no authority, the call has no effect.
Note
The interpretation of the userinfo as individual user and password components is scheme-dependent. Transmitting passwords in URLs is deprecated.
- remove_port() syside.Url
Remove the port without affecting the rest of the authority
- remove_query() syside.Url
Remove the query
- remove_scheme() syside.Url
Remove the scheme
- remove_userinfo() syside.Url
Remove the userinfo if present, without removing any authority.
- reserve(arg: int, /) None
Adjust the capacity without changing the size
- set_encoded_authority(arg: str, /) syside.Url
Set the authority
- set_encoded_fragment(arg: str, /) syside.Url
Set the fragment.
- set_encoded_host(arg: str, /) syside.Url
Set the host
Depending on the contents of the passed string, this function sets the host:
If the string is a valid IPv4 address, then the host is set to the address.
If the string is a valid IPv6 address enclosed in square brackets, then the host is set to that address.
If the string is a valid IPvFuture address enclosed in square brackets, then the host is set to that address.
Otherwise, the host name is set to the string.
In all cases, when this function returns, the URL contains an authority.
- set_encoded_host_address(arg: str, /) syside.Url
Set the host to an address
Depending on the contents of the passed string, this function sets the host:
If the string is a valid IPv4 address, then the host is set to the address.
If the string is a valid IPv6 address, then the host is set to that address.
If the string is a valid IPvFuture, then the host is set to that address.
Otherwise, the host name is set to the string.
In all cases, when this function returns, the URL contains an authority.
- set_encoded_host_name(arg: str, /) syside.Url
Set the host to a name
- set_encoded_password(arg: str, /) syside.Url
Set the password.
Note
The interpretation of the userinfo as individual user and password components is scheme-dependent. Transmitting passwords in URLs is deprecated.
- set_encoded_path(arg: str, /) syside.Url
Set the path.
- set_encoded_query(arg: str, /) syside.Url
Set the query
- set_encoded_user(arg: str, /) syside.Url
Set the user
- set_encoded_userinfo(arg: str, /) syside.Url
Set the userinfo.
The effects on the user and password depend on the presence of a colon (‘:’) in the string:
If an unescaped colon exists, the characters up to the colon become the user and the rest of the characters after the colon become the password. In this case
has_passwordreturns true. Otherwise,If there is no colon, the user is set to the string.
has_passwordreturns false.
Note
The interpretation of the userinfo as individual user and password components is scheme-dependent. Transmitting passwords in URLs is deprecated.
- set_fragment(arg: str, /) syside.Url
Set the fragment.
- set_host(arg: str, /) syside.Url
Set the host
Depending on the contents of the passed string, this function sets the host:
If the string is a valid IPv4 address, then the host is set to the address.
If the string is a valid IPv6 address enclosed in square brackets, then the host is set to that address.
If the string is a valid IPvFuture address enclosed in square brackets, then the host is set to that address.
Otherwise, the host name is set to the string, which may be empty.
In all cases, when this function returns, the URL contains an authority.
- set_host_address(arg: str, /) syside.Url
Set the host to an address
Depending on the contents of the passed string, this function sets the host:
If the string is a valid IPv4 address, then the host is set to the address.
If the string is a valid IPv6 address, then the host is set to that address.
If the string is a valid IPvFuture, then the host is set to that address.
Otherwise, the host name is set to the string.
In all cases, when this function returns, the URL contains an authority.
- set_host_ipv4(arg: syside.IPv4Address, /) syside.Url
Set the host to an address
The host is set to the specified IPv4 address.
- set_host_ipv6(arg: syside.IPv6Address, /) syside.Url
Set the host to an address
The host is set to the specified IPv6 address.
- set_host_ipvfuture(arg: str, /) syside.Url
Set the host to an address
The host is set to the specified IPvFuture string.
- set_host_name(arg: str, /) syside.Url
Set the host to a name
- set_password(arg: str, /) syside.Url
Set the password.
Note
The interpretation of the userinfo as individual user and password components is scheme-dependent. Transmitting passwords in URLs is deprecated.
- set_path(arg: str, /) syside.Url
Set the path.
Note
The library may adjust the final result to ensure that no other parts of the url are semantically affected.
Note
This function does not encode ‘/’ chars, which are unreserved for paths but reserved for path segments. If a path segment should include encoded ‘/’s to differentiate it from path separators, the function
set_encoded_pathshould be used instead.
- set_port(arg: str, /) syside.Url
Set the port
This port is set to the string, which must contain only digits or be empty.
- set_port_number(arg: int, /) syside.Url
Set the port
The port is set to the specified integer.
- set_query(arg: str, /) syside.Url
Set the query
- set_scheme(arg: str, /) syside.Url
Set the scheme
The scheme is set to the specified string, which must contain a valid scheme without any trailing colon (‘:’). Note that schemes are case-insensitive, and the canonical form is lowercased.
- set_scheme_id(arg: syside.Scheme, /) syside.Url
Set the scheme
This function sets the scheme to the specified known scheme id, which may not be
Unknownor else an error is raide. If the id isnone, this function behaves as ifremove_schemewere called.
- set_user(arg: str, /) syside.Url
Set the user
- set_userinfo(arg: str, /) syside.Url
Set the userinfo
The effects on the user and password depend on the presence of a colon (‘:’) in the string:
If an unescaped colon exists, the characters up to the colon become the user and the rest of the characters after the colon become the password. In this case
has_passwordreturns true. Otherwise,If there is no colon, the user is set to the string.
has_passwordreturns false.
Note
The interpretation of the userinfo as individual user and password components is scheme-dependent. Transmitting passwords in URLs is deprecated.