eta_nexus.util.utils module

eta_nexus.util.utils.url_parse(url: str | None, scheme: str = '') tuple[ParseResult, str | None, str | None][source]

Extend parsing of URL strings to find passwords and remove them from the original URL.

Parameters:

url – URL string to be parsed.

Returns:

Tuple of ParseResult object and two strings for username and password.

eta_nexus.util.utils.dict_get_any(dikt: dict[str, Any], *names: str, fail: bool = True, default: Any = None) Any[source]

Get any of the specified items from dictionary, if any are available.

The function will return the first value it finds, even if there are multiple matches.

Parameters:
  • dikt – Dictionary to get values from.

  • names – Item names to look for.

  • fail – Flag to determine, if the function should fail with a KeyError, if none of the items are found. If this is False, the function will return the value specified by ‘default’.

  • default – Value to return, if none of the items are found and ‘fail’ is False.

Returns:

Value from dictionary.

Raise:

KeyError, if none of the requested items are available and fail is True.

eta_nexus.util.utils.dict_pop_any(dikt: dict[str, Any], *names: str, fail: bool = True, default: Any = None) Any[source]

Pop any of the specified items from dictionary, if any are available.

The function will return the first value it finds, even if there are multiple matches. This function removes the found values from the dictionary!

Parameters:
  • dikt – Dictionary to pop values from.

  • names – Item names to look for.

  • fail – Flag to determine, if the function should fail with a KeyError, if none of the items are found. If this is False, the function will return the value specified by ‘default’.

  • default – Value to return, if none of the items are found and ‘fail’ is False.

Returns:

Value from dictionary.

Raise:

KeyError, if none of the requested items are available and fail is True.

Function to get key of _psr_types dictionary, given value.

Raise ValueError in case of value not specified in data.

Parameters:
  • val – value to search

  • data – dictionary to search for value

Returns:

key of the dictionary