Utils¶
pymco.utils
¶
python-mcollective utils that don’t fit elsewhere.
-
pymco.utils.
import_class
(import_path)[source]¶ Import a class based on given dotted import path string.
It just splits the import path in order to geth the module and class names, then it just calls to
__import__()
with the module name andgetattr()
with the module and the class name.Parameters: import_path – dotted import path string. Returns: the class once imported. Raise: ImportError
if the class can’t be imported.
-
pymco.utils.
import_object
(import_path, *args, **kwargs)[source]¶ Import a class and instantiate it.
Uses
import_class()
in order to import the given class by its import path and instantiate it using given positional and keyword arguments.Parameters: - import_path – Same argument as
import_class()
. - *args – extra pPositional arguments for object instantiation.
- **kwargs – extra Keyword arguments for object instantiation.
Returns: an object the imported class initialized with given arguments.
- import_path – Same argument as
-
pymco.utils.
load_rsa_key
(filename)[source]¶ Read filename and try to load its contents as an RSA key.
Wrapper over
Crypto.PublicKey.RSA.importKey()
, just getting the file content first and then just loading the key from it.Parameters: filename – RSA key file name. Returns: loaded RSA key.
-
pymco.utils.
pem_to_der
(pem)[source]¶ Convert an ascii-armored PEM certificate to a DER encoded certificate
See http://stackoverflow.com/a/12921889 for details. Python
ssl
module has it own method for this, but it shouldn’t work properly and this method is required.Parameters: pem (str) – The PEM certificate as string.