module documentation

This module provides various non-oneM2M related utility functions.

Function buildBasicAuthUrl Build a URL with basic auth credentials.
Function getBasicAuthFromUrl Get the basic auth credentials from a URL.
Function getThreadName Get the name of a thread.
Function hashString Hash a string using SHA256.
Function isAcmeUrl Test whether a URL is a valid URL and an internal ACME event URL.
Function isCoAPUrl Test whether a URL is a valid URL, and indicates a coap or coaps scheme.
Function isHttpUrl Test whether a URL is a valid URL, and indicates an http or https scheme.
Function isMQTTUrl Test whether a URL is a valid URL, and indicates an mqtt URL.
Function isURL Check whether a given string is a URL.
Function isWSUrl Test whether a URL is a valid URL, and indicates a WebSocket URL.
Function normalizeURL Remove trailing / from a url.
Function openFileWithDefaultApplication Open a file with the default application.
Function renameThread Rename a thread.
Function reverseEnumerate Reverse enumerate a list.
Function runsInIPython Check whether the current runtime environment is IPython or not.
Function strToBool Convert a string value to a boolean.
Variable _urlregex Regular expression to test for a valid URL.
def buildBasicAuthUrl(url: str, username: str, password: str) -> str:

Build a URL with basic auth credentials.

Parameters
url:strURL to add the basic auth credentials to.
username:strUsername for the basic auth.
password:strPassword for the basic auth.
Returns
strURL with the basic auth credentials.
def getBasicAuthFromUrl(url: str) -> tuple[str, str, str]:

Get the basic auth credentials from a URL.

Parameters
url:strURL to extract the basic auth credentials from.
Returns
tuple[str, str, str]A tuple with the URL without the basic auth credentials, the username and the password.
def getThreadName(thread: threading.Thread | None = None) -> str:

Get the name of a thread.

Parameters
thread:threading.Thread | NoneThe Thread to get the name from. If none is provided then the current thread is used.
Returns
strThe name of the thread.
def hashString(s: str, salt: str = '') -> str:

Hash a string using SHA256.

Parameters
s:strString to hash.
salt:strSalt to add to the string before hashing.
Returns
strThe SHA256 hash of the string as hex.
def isAcmeUrl(url: str) -> bool:

Test whether a URL is a valid URL and an internal ACME event URL.

Parameters
url:strURL to check.
Returns
boolTrue if the argument is a URL, and is an internal ACME scheme.
def isCoAPUrl(url: str) -> bool:

Test whether a URL is a valid URL, and indicates a coap or coaps scheme.

Parameters
url:strString to check.
Returns
boolTrue if the argument is a URL, and is an coap or coaps scheme.
def isHttpUrl(url: str) -> bool:

Test whether a URL is a valid URL, and indicates an http or https scheme.

Parameters
url:strString to check.
Returns
boolTrue if the argument is a URL, and is an http or https scheme.
def isMQTTUrl(url: str) -> bool:

Test whether a URL is a valid URL, and indicates an mqtt URL.

Parameters
url:strString to check.
Returns
boolTrue if the argument is a URL, and is an mqtt or mqtts scheme.
def isURL(url: str) -> bool:

Check whether a given string is a URL.

Parameters
url:strString to check for URL-ness.
Returns
boolBoolean indicating whether the argument is a valid URL.
def isWSUrl(url: str) -> bool:

Test whether a URL is a valid URL, and indicates a WebSocket URL.

Parameters
url:strString to check.
Returns
boolTrue if the argument is a URL, and is a ws or wss scheme.
def normalizeURL(url: str) -> str:

Remove trailing / from a url.

Parameters
url:strURL to remove trailing /'s from.
Returns
strURL without trailing /'s.
def openFileWithDefaultApplication(filename: str):

Open a file with the default application.

Parameters
filename:strName of the file to open.
def renameThread(prefix: str | None = None, name: str | None = None, thread: threading.Thread | None = None) -> bool:

Rename a thread.

If name is provided then the thread is renamed to that name. If name is not provided, but prefix is, then the thread is renamed to the prefix + the last 5 digits of its thread ID. If neither name nor prefix is provided, then the thread is renamed to its own ID.

Parameters
prefix:str | NoneUsed for "prefix + ID" procedure explained above.
name:str | NoneNew name for a thread.
thread:threading.Thread | NoneThe Thread to rename. If none is provided then the current thread is renamed.
Returns
boolAlways True.
def reverseEnumerate(data: list) -> Generator[tuple[int, Any], None, None]:

Reverse enumerate a list.

Parameters
data:listList to enumerate.
Returns
Generator[tuple[int, Any], None, None]Generator that yields a tuple with the index and the value of the list.
def runsInIPython() -> bool:

Check whether the current runtime environment is IPython or not.

This is a hack!

Returns
boolTrue if run in IPython, otherwise False.
def strToBool(value: str) -> bool:

Convert a string value to a boolean.

Parameters
value:strAny string value that looks like a boolean true or false.
Returns
boolThe boolean value.
Raises
ValueError if the string does not look like a boolean.
_urlregex =

Regular expression to test for a valid URL.