Utilities¶
-
class
flask_saml2.utils.cached_property(func, name=None, doc=None)¶ A decorator that converts a function into a lazy property. The function wrapped is called the first time to retrieve the result and then that calculated result is used the next time you access the value:
class Foo(object): @cached_property def foo(self): # calculate something important here return 42
The class has to have a
__dict__in order for this property to work.
-
flask_saml2.utils.import_string(path)¶ Import a dotted Python path to a class or other module attribute.
import_string('foo.bar.MyClass')will return the classMyClassfrom the packagefoo.bar.- Return type
-
flask_saml2.utils.get_random_id()¶ Generate a random ID string. The random ID will start with the ‘_’ character.
- Return type
-
flask_saml2.utils.utcnow()¶ Get the current time in UTC, as an aware
datetime.datetime.- Return type
-
flask_saml2.utils.certificate_to_string(certificate)¶ Take an x509 certificate and encode it to a string suitable for adding to XML responses.
- Parameters
certificate (
X509) – A certificate, perhaps loaded fromcertificate_from_file().- Return type
-
flask_saml2.utils.certificate_from_string(certificate, format=1)¶ Load an X509 certificate from a string. This just strips off the header and footer text.
- Parameters
str – A certificate string.
format – The format of the certificate, from crypto — Generic cryptographic module.
- Return type
X509
-
flask_saml2.utils.certificate_from_file(filename, format=1)¶ Load an X509 certificate from
filename.- Parameters
filename (
Union[str,Path]) – The path to the certificate on disk.format – The format of the certificate, from crypto — Generic cryptographic module.
- Return type
X509
-
flask_saml2.utils.private_key_from_string(private_key, format=1)¶ Load a private key from a string.
- Parameters
str – A private key string.
format – The format of the private key, from crypto — Generic cryptographic module.
- Return type
PKey
-
flask_saml2.utils.private_key_from_file(filename, format=1)¶ Load a private key from
filename.- Parameters
filename (
Union[str,Path]) – The path to the private key on disk.format – The format of the private key, from crypto — Generic cryptographic module.
- Return type
PKey