linotp.lib.util module

contains utility functions

linotp.lib.util.check_selfservice_session(cookies=None, params=None, url=None)[source]

This function checks the session cookie for the selfservice / userservice session

linotp.lib.util.check_session(request)[source]

This function checks the session cookie for management API and compares it to the session parameter

linotp.lib.util.checksum(msg)[source]
linotp.lib.util.dict_copy(dict_)[source]

recursively copies a dict

linotp.lib.util.generate_otpkey(key_size=20)[source]

generates the HMAC key of keysize. Should be 20 or 32 THe key is returned as a hexlified string

linotp.lib.util.generate_password(size=6, characters=None)[source]
linotp.lib.util.getLowerParams(param)[source]
linotp.lib.util.getParam()[source]
input:
  • param (hash set): the set, which contains all parameters

  • which (lteral): the entry lookup

  • optional (boolean): defines if this parameter is optional or not
    • an exception is thrown if the parameter is required
    • otherwise: nothing done!
return:
  • the value (literal) of the parameter if exists or nothing in case the parameter is optional, otherwise throw an exception
linotp.lib.util.get_api_version()[source]

return the api version number

linotp.lib.util.get_client(request)[source]

This function returns the client.

It first tries to get the client as it is passed as the HTTP Client via REMOTE_ADDR.

If this client Address is in a list, that is allowed to overwrite its client address (like e.g. a FreeRADIUS server, which will always pass the FreeRADIUS address but not the address of the RADIUS client) it checks for the existance of the client parameter.

This returns the copyright information displayed in the WebUI and selfservice portal.

linotp.lib.util.get_version()[source]

This returns the version, that is displayed in the WebUI and self service portal.

linotp.lib.util.get_version_number()[source]

returns the linotp version

linotp.lib.util.is_valid_fqdn(hostname, split_port=False)[source]

Checks if the hostname is a valid FQDN

linotp.lib.util.modhex_decode(m)[source]
linotp.lib.util.modhex_encode(s)[source]
linotp.lib.util.normalize_activation_code(activationcode, upper=True, convert_o=True, convert_0=True)[source]

This normalizes the activation code. 1. lower letters are capitaliezed 2. Oh’s in the last two characters are turned to zeros 3. zeros before the last 2 characters are turned to Ohs

linotp.lib.util.parse_duration(duration_str)[source]

transform a duration string into a time delta object

from:
http://stackoverflow.com/questions/35626812/how-to-parse-timedelta-from-strings
Parameters:duration_str – duration string like ‘1h’ ‘3h 20m 10s’ ‘10s’
Returns:timedelta
linotp.lib.util.remove_empty_lines(doc)[source]

remove empty lines from the input document

Parameters:doc (string) – documemt containing long multiline text
Returns:data without empty lines
Return type:string
linotp.lib.util.remove_session_from_param(param)[source]

Some low level functions like the userlisting do not like to have a session parameter in the param dictionary. So we remove the session from the params.

linotp.lib.util.str2unicode(input_str)[source]

convert as binary string into a unicode string by trying various encodings :param input_str: input binary string :return: unicode output

linotp.lib.util.unicode_compare(x, y)[source]

locale and unicode aware comparison operator - for usage in sorted()

Parameters:
  • x – left value
  • y – right value
Returns:

the locale aware comparison result

linotp.lib.util.uniquify(doubleList)[source]