Utilities
This section shows general objects and helper functions that are used with this package.
- class balderhub.url.lib.utils.Url(url: str)
Bases:
objectBalderhub object to work with URLs. This object also supports schema parameters. You can define a schema parameter by using the following syntax:
<int:var_name>, while the first statement needs to be int for integer or str for strings. The second statement describes a variable name, that needs to start with an upper or lower case letter and can be followed by _ or any digits.- RE_PARAMETER_STATEMENT = '^<(int|str):([a-zA-Z_]+[a-zA-Z0-9_]+)>$'
regular expression schema parameter syntax
- as_string() str
- Returns:
returns the URL as a string
- compare(other: Url | str, allow_schemas: bool = False) bool
This method compares two
Urlinstances. If allow_schemas is True, it considers two urls as equal if the schema parameter description matches the schema parameter value of the other url.- Parameters:
other – the other url
allow_schemas – True if the method should match urls, in that one url holds a schema description and the other holds a matching value for it, otherwise False
- Returns:
true in case that both urls are equal
- extract_parameters(by_using_schema_url: Url) Dict[str, int | str]
This method extracts the schema parameter values of that URL for the schema parameters from the provided schema URL.
- Parameters:
by_using_schema_url – the url that holds all the schema parameters that should be extracted
- Returns:
a dictionary with the schema parameter name as key and the schema parameter value as value
- fill_parameters(**kwargs) Url
This method allows to fill internal defined schema parameters. For that, you need to provide the parameter name as parameter and its value as value. This method will validate the typing before inserting any values.
Note
Please note, this object will not be changed. The method returns a new
Urlinstance with the filled schema parameters.- Parameters:
kwargs – all schema parameters that should be filled
- Returns:
a new
Urlinstance with the filled parameters
- get_query_parameters() Dict[str, str]
This method returns all query parameter that are mentioned in the url. :return: a list of all query parameter as a dictionary
- get_unfilled_parameters() Dict[str, Type[int | str]]
This method returns a dictionary with schema parameter names as key and the defined Type[int] or Type[str] as value.
- Returns:
returns the unfilled parameters as a dictionary
- get_urlparse() ParseResult
- Returns:
returns the
urllib.parse.ParseResultof the url
- is_schema()
- Returns:
True in case this url is a schema (has internal unfilled parameters), otherwise False