Url

class Url

Description

URL as described using the Uniform Resource Identifier (URI) specification (RFC3986).

Raises RuntimeError on 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 .encoded properties and returns strings exactly as they appear in the URL.

Otherwise properties and methods operate on decoded strings. Retrieving a decoded string unescapes percent-encoded octets with the corresponding characters.

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.

Inheritance:

Members defined in Url (52 members)

authority

R

Return the authority

encoded_authority

R

Return the authority.

encoded_fragment

R

Return the fragment

encoded_host

R

Return the host

encoded_host_address

R

Return the host

encoded_host_and_port

R

Return the host and port

encoded_host_name

R

Return the host name

encoded_origin

R

Return the origin

encoded_params

R

Return the query as a sequence of parameters

encoded_password

R

Return the password

encoded_path

R

Return the path

encoded_query

R

Return the query

encoded_resource

R

Return the resource

encoded_target

R

Return the target

encoded_user

R

Return the user

encoded_userinfo

R

Return the userinfo

encoded_zone_id

R

Return the IPv6 Zone ID

fragment

R

Return the fragment

has_authority

R

Return true if an authority is present

has_fragment

R

Return true if a fragment is present

has_password

R

Return true if a password is present

has_port

R

Return true if a port is present

has_query

R

Return true if a query is present

has_scheme

R

Returns true if a scheme is present

has_userinfo

R

Return true if a userinfo is present

host

R

Return the host

host_address

R

Return the host

host_ipv4_address

R

Return the host IPv4 address

host_ipv6_address

R

Return the host IPv6 address

host_ipvfuture

R

Return the host IPvFuture address

host_name

R

Return the host name

host_type

R

Return the host type

is_path_absolute

R

Return true if the path is absolute

password

R

Return the password

path

R

Return the path

port

R

Return the port

port_number

R

Return the port

query

R

Return the query

scheme

R

Returns the scheme

scheme_id

R

Return the scheme

user

R

Return the user

userinfo

R

Return the userinfo

zone_id

R

Return the IPv6 Zone ID

__bool__

Returns true if the url is not empty

__copy__

__deepcopy__

__hash__

__init__

__len__

Returns the number of characters in the url

__repr__

__str__

params

Return the query as a sequence of parameters

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.IPv4

  • HostType.IPv6

  • HostType.IPvFuture

  • HostType.Name

  • HostType.none

When has_authority is false, the host type is HostType.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 Scheme is 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
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.

Used by