pyeudiw.tools package

Submodules

pyeudiw.tools.base_endpoint module

class pyeudiw.tools.base_endpoint.BaseEndpoint(config: dict, internal_attributes: dict[str, dict[str, str | list[str]]], base_url: str, name: str, auth_callback: Callable[[Context, Any], Response] | None = None, converter: AttributeMapper | None = None)[source]

Bases: BaseHTTPResponseHandler, BaseLogger

endpoint(context: Context) Redirect | Response[source]

Handle the incoming request and return either a Redirect or Response.

This method must be implemented by subclasses to process the given context and return an appropriate HTTP response, such as a redirect to another URL or a standard HTTP response.

Args:

context (Context): The SATOSA context object containing the request and environment information.

Returns:

Redirect | Response: A Redirect or Response object depending on the logic implemented.

Raises:

NotImplementedError: If the method is not overridden by a subclass.

pyeudiw.tools.base_logger module

class pyeudiw.tools.base_logger.BaseLogger[source]

Bases: object

property effective_log_level: int

Returns the effective log level.

Returns:

the effective log level

Return type:

int

pyeudiw.tools.content_type module

pyeudiw.tools.content_type.get_accept_header(headers: list[tuple[str, str]]) str | None[source]

Retrieve the Accept header value from a list of HTTP headers.

Args:

headers (list[tuple[str, str]]): A list of header key-value pairs.

Returns:

str | None: The value of the Accept header if present, None otherwise.

pyeudiw.tools.content_type.get_content_type_header(headers: list[tuple[str, str]]) str | None[source]

Retrieve the Content-Type header value from a list of HTTP headers.

Args:

headers (list[tuple[str, str]]): A list of header key-value pairs.

Returns:

str | None: The value of the Content-Type header if present, None otherwise.

pyeudiw.tools.content_type.is_application_json(content_type: str) bool[source]

Check if the provided Content-Type header indicates JSON content.

Args:

content_type (str): The value of the Content-Type header.

Returns:

bool: True if the content type includes “application/json”, False otherwise.

pyeudiw.tools.content_type.is_form_urlencoded(content_type: str) bool[source]

Check if the provided Content-Type header indicates form-urlencoded content.

Args:

content_type (str): The value of the Content-Type header.

Returns:

bool: True if the content type includes “application/x-www-form-urlencoded”, False otherwise.

pyeudiw.tools.date module

pyeudiw.tools.date.is_valid_unix_timestamp(ts: Any, range: int | None = 60) bool[source]

Checks if the given value is a valid UNIX timestamp (in seconds).

Args:

ts (int): Timestamp to validate.

Returns:

bool: True if valid UNIX timestamp, False otherwise.

pyeudiw.tools.endpoints_loader module

class pyeudiw.tools.endpoints_loader.EndpointsLoader(config: dict[str, Any], internal_attributes: dict[str, dict[str, str | list[str]]], base_url: str, name: str, auth_callback_func: Callable[[Context, InternalData], Response] | None = None, converter: AttributeMapper | None = None, trust_evaluator: CombinedTrustEvaluator | None = None)[source]

Bases: object

A dynamic backend/frontend module.

pyeudiw.tools.exceptions module

exception pyeudiw.tools.exceptions.HttpError[source]

Bases: Exception

pyeudiw.tools.http module

async pyeudiw.tools.http.fetch(session: ClientSession, url: str, httpc_params: dict = {'connection': {'ssl': True}, 'session': {'timeout': 4}}) ClientResponse[source]

Fetches the content of a URL.

Parameters:
  • session (dict) – a dict representing the current session

  • url (str) – the url where fetch the content

  • httpc_params (dict) – parameters to perform http requests.

Returns:

the client response

Return type:

aiohttp.ClientResponse

async pyeudiw.tools.http.fetch_all(session: ClientSession, urls: list[str], httpc_params: dict = {'connection': {'ssl': True}, 'session': {'timeout': 4}}) list[Response][source]

Fetches the content of a list of URL.

Parameters:
  • session (dict) – a dict representing the current session

  • urls (list[str]) – the url list where fetch the content

  • httpc_params (dict) – parameters to perform http requests.

Raises:

HttpError – if the response status code is not 200 or a connection error occurs

Returns:

the list of responses in string format

Return type:

list[str]

async pyeudiw.tools.http.http_get_async(urls, httpc_params: dict = {'connection': {'ssl': True}, 'session': {'timeout': 4}}) list[Response][source]

Perform a GET http call async.

Parameters:
  • session (dict) – a dict representing the current session

  • urls (list[str]) – the url list where fetch the content

  • httpc_params (dict) – parameters to perform http requests.

Raises:

HttpError – if the response status code is not 200 or a connection error occurs

Returns:

the list of responses

Return type:

list[requests.Response]

pyeudiw.tools.http.http_get_sync(urls: list[str], httpc_params: dict = {'connection': {'ssl': True}, 'session': {'timeout': 4}}) list[Response][source]

Perform a GET http call sync.

Parameters:
  • urls (list[str]) – the url list where fetch the content

  • httpc_params (dict) – parameters to perform http requests.

Raises:

HttpError – if the response status code is not 200 or a connection error occurs

Returns:

the list of responses

Return type:

list[requests.Response]

pyeudiw.tools.mobile module

pyeudiw.tools.mobile.is_smartphone(useragent: str) bool[source]

Check if the useragent is a smartphone

Parameters:

useragent (str) – The useragent to check

Returns:

True if the useragent is a smartphone else False

Return type:

bool

pyeudiw.tools.mso_mdoc module

pyeudiw.tools.mso_mdoc.from_jwk_to_mso_mdoc_private_key(jwk_key: dict) dict[source]

Converts a JWK (JSON Web Key) EC private key to a format compatible with MSO/mDoc structures.

This function transforms a JWK-style elliptic curve private key into a dictionary suitable for Mobile Security Object (MSO) or mdoc (mobile document) signing usage. It handles key type mapping, curve renaming, and base64url decoding of the private key value.

pyeudiw.tools.mso_mdoc.render_mso_mdoc_template(template_str: str, data: dict, transform_config: dict = None) dict[source]

Render an mso_mdoc YAML template using the provided data. Handles base64 for images and CBOR tag 1004 for dates.

Parameters:
  • template_str – The YAML template as a string (with Jinja2 placeholders).

  • data – A dictionary of values to populate the template.

Returns:

A Python dictionary with the rendered and properly typed content.

pyeudiw.tools.schema_utils module

pyeudiw.tools.schema_utils.check_algorithm(alg: str, info: ValidationInfo) None[source]

Check if the algorithm is supported by the relaying party.

Parameters:
  • alg (str) – The algorithm to check

  • info (ValidationInfo) – The field validation info

Raises:

ValueError – If the algorithm is not supported

pyeudiw.tools.utils module

pyeudiw.tools.utils.cacheable_get_http_url(cache_ttl: int, url: str, httpc_params: dict, http_async: bool = True) Response[source]

Cached HTTP GET with TTL (seconds) implemented via lru_cache. The TTL is enforced by rounding a timestamp argument; entries expire after up to cache_ttl seconds. Minimum TTL is 1 second. Only httpc_params.connection.ssl (bool) and httpc_params.session.timeout (int) are supported and required. Non-200 responses will cause the cache to be cleared.

pyeudiw.tools.utils.datetime_from_timestamp(timestamp: int | float) datetime[source]

Get a datetime from a timestamp.

Parameters:

value (int | float) – The timestamp

Returns:

The datetime

Return type:

datetime.datetime

pyeudiw.tools.utils.dynamic_class_loader(module_name: str, class_name: str, init_params: dict = {}) object[source]

Load a class dynamically.

Parameters:
  • module_name (str) – The name of the module

  • class_name (str) – The name of the class

  • init_params (dict) – The parameters to pass to the class constructor

Returns:

The class instance

Return type:

object

pyeudiw.tools.utils.exp_from_now(minutes: int = 33) int[source]

Get the expiration timestamp in seconds for the given minutes from now.

Parameters:

minutes (int) – The minutes from now

Returns:

The timestamp in seconds for the given minutes from now

Return type:

int

pyeudiw.tools.utils.get_dynamic_class(module_name: str, class_name: str) Type[source]

Get a class type dynamically.

Parameters:
  • module_name (str) – The name of the module

  • class_name (str) – The name of the class

Returns:

The class type

Return type:

Type

pyeudiw.tools.utils.get_http_url(urls: list[str] | str, httpc_params: dict, http_async: bool = True) list[Response][source]

Perform an HTTP Request returning the payload of the call.

Parameters:
  • urls (list[str] | str) – The url or a list of url where perform the GET HTTP calls

  • httpc_params (dict) – parameters to perform http requests.

  • http_async (bool) – if is set to True the operation will be performed in async (deafault True)

Returns:

A list of responses.

Return type:

list[dict]

pyeudiw.tools.utils.iat_now() int[source]

Get the current timestamp in seconds.

Returns:

The current timestamp in seconds

Return type:

int

pyeudiw.tools.utils.make_timezone_aware(dt: datetime, tz: timezone | tzinfo = datetime.timezone.utc) datetime[source]

Make a datetime timezone aware.

Parameters:
  • dt (datetime.datetime) – The datetime to make timezone aware

  • tz (datetime.timezone | datetime.tzinfo) – The timezone to use

Returns:

The timezone aware datetime

Return type:

datetime.datetime

pyeudiw.tools.utils.random_token(n=254) str[source]

Generate a random token.

Parameters:

n (int) – The length of the token

Returns:

The random token

Return type:

str

pyeudiw.tools.utils.timestamp_from_datetime(dt: datetime) int[source]

Get a timestamp from a datetime.

Parameters:

dt (datetime.datetime) – The datetime

Returns:

The timestamp

Return type:

int

Module contents