MambuPy.mambuutil
Mambu utilites module.
Exceptions, some API return codes, utility functions, a lot of urlfuncs (see MambuStruct.__init__ and .connect pydocs for more info on this)
Warning
Secutiry WARNING: Imports the configurations from mambuconfig. It surely is a bad idea. Got to improve this!
Todo
status API V2: fullDetails are not compatible
Todo
status API V2: pagination managements needs review
Todo
status API V2: almost al GET operations seems compatible. PATCH/POST/DELETE operations needs review
Todo
status API V2: testing of EVERYTHING is required
Module Attributes
Deprecated since version 0.8. |
|
Current maximum number of response elements Mambu returns |
|
paginationDetails options |
|
detailsLevel options |
|
upload files maximum size |
|
invalid characters for an uploaded filename |
|
allowed file types for uploads |
|
search operators |
|
Default logger for mambupy module |
Functions
|
Backup Mambu Database via REST API. |
|
Converts a datetime field to a datetime using some specified format. |
|
Encode every value of a dict to UTF-8. |
|
Change an IRI (internationalized R) to an URI. |
|
Get a logger configured with a yaml file. |
Strip characters in a string which are consecutively repeated. |
|
|
Stripts HTML tags from text. |
Exceptions
Thrown when communication issues with Mambu arise |
|
Default exception from Mambu |
|
Default exception |
- MambuPy.mambuutil.ALLOWED_UPLOAD_MIMETYPES = ['JPEG', 'PNG', 'GIF', 'BMP', 'TIFF', 'PDF', 'XML', 'DOC', 'DOCX', 'DOCM', 'DOT', 'DOTX', 'DOTM', 'XLS', 'XLSX', 'XLSB', 'PPT', 'PPTX', 'ODT', 'OTT', 'FODT', 'PDF', 'XML', 'TXT', 'CSV', 'PROPERTIES', 'MSG', 'TIF', 'ZIP', 'RTF', 'XLSM', 'ODS', 'ODP', 'EML', 'EMLX', 'HTML', 'MHT', 'MHTML', 'XPS', 'NUMBERS', 'KEY', 'PAGES', 'YAML', 'JSON', 'JASPER', 'JRXML']
allowed file types for uploads
- MambuPy.mambuutil.API_RETURN_CODES = {'EXCESS_REPAYMENT_ERROR': 110, 'INCONSISTENT_SCHEDULE_PRINCIPAL_DUE_WITH_LOAN_AMOUNT': 132, 'INVALID_ACCOUNT_STATE': 105, 'INVALID_ACCOUNT_STATE_FOR_REPAYMENTS': 128, 'INVALID_LOAN_ACCOUNT_ID': 100, 'INVALID_PARAMETERS': 4, 'INVALID_REPAYMENT_DATE_ERROR': 111, 'INVALID_STATE_TRANSITION': 116, 'SUCCESS': 0}
Deprecated since version 0.8.
It’s probably not useful. Besides,
mambustruct.MambuStruct.connect()method returns the code when an error occurs by default.
- MambuPy.mambuutil.DETAILSLEVEL = ['BASIC', 'FULL']
detailsLevel options
- MambuPy.mambuutil.MAX_UPLOAD_SIZE = 52428800
upload files maximum size
- exception MambuPy.mambuutil.MambuCommError[source]
Bases:
MambuErrorThrown when communication issues with Mambu arise
- __module__ = 'MambuPy.mambuutil'
- exception MambuPy.mambuutil.MambuError[source]
Bases:
MambuPyErrorDefault exception from Mambu
- __module__ = 'MambuPy.mambuutil'
- exception MambuPy.mambuutil.MambuPyError[source]
Bases:
ExceptionDefault exception
- __module__ = 'MambuPy.mambuutil'
- __weakref__
list of weak references to the object (if defined)
- MambuPy.mambuutil.OUT_OF_BOUNDS_PAGINATION_LIMIT_VALUE = 50
Current maximum number of response elements Mambu returns
- MambuPy.mambuutil.PAGINATIONDETAILS = ['ON', 'OFF']
paginationDetails options
- MambuPy.mambuutil.SEARCH_OPERATORS = ['EQUALS', 'EQUALS_CASE_SENSITIVE', 'DIFFERENT_THAN', 'MORE_THAN', 'LESS_THAN', 'BETWEEN', 'ON', 'AFTER', 'BEFORE', 'BEFORE_INCLUSIVE', 'STARTS_WITH', 'STARTS_WITH_CASE_SENSITIVE', 'IN', 'TODAY', 'THIS_WEEK', 'THIS_MONTH', 'THIS_YEAR', 'LAST_DAYS', 'EMTPY', 'NOT_EMPTY']
search operators
- MambuPy.mambuutil.UPLOAD_FILENAME_INVALID_CHARS = '/><|:&?*[]#\\*`'
invalid characters for an uploaded filename
- MambuPy.mambuutil._backup_db_timeout_mechanism(justbackup, retries, bool_func, force_download_latest, logger=None)[source]
- MambuPy.mambuutil.backup_db(callback, bool_func, output_fname, *args, **kwargs)[source]
Backup Mambu Database via REST API.
Makes two calls to Mambu API:
a POST to request a backup to be made
a GET, once the backup is ready, to download the latest backup
callback is a string to a callback URL Mambu will internally call when the backup is ready to download. You should have a webservice there to warn you when the backup is ready.
bool_func is a function you use against your own code to test if the said backup is ready. This function backup_db manages both the logic of the request of a backup and the downloading of it too, so bool_func allows you to have some way on your side to know when this function will download the backup.
The thing is you have to build a webservice (for the callback) making some kind of flag turn that your bool_func will read and know when to say True, telling backup_db to begin the download of the backup.
output_fname the name of the file that will hold the downloaded backup. PLEASE MIND that Mambu sends a ZIP file here.
user, pwd and url allow you to change the Mambu permissions for the getmambuurl internally called here.
retries number of retries for bool_func or -1 for keep waiting.
just_backup bool if True, skip asking for backup, just download LATEST
force_download_latest boolean, True to force download even if no callback is called. False to throw error if callback isn’t received after retries.
- returns a dictionary with info about the download
- -latest
boolean flag, if the db downloaded was the latest or not
Todo
status API V2: compatible
- MambuPy.mambuutil.date_format(field, formato=None, as_utc=False)[source]
Converts a datetime field to a datetime using some specified format.
What this really means is that, if specified format includes only for instance just year and month, day and further info gets ignored and the objects get a datetime with year and month, and day 1, hour 0, minute 0, etc.
A useful format may be %Y%m%d, then the datetime objects effectively translates into date objects alone, with no relevant time information.
When as_utc is True, the datetime object is converted to UTC timezone.
PLEASE BE AWARE, that this may lose useful information for your datetimes from Mambu. Read this for why this may be a BAD idea: https://julien.danjou.info/blog/2015/python-and-timezones
- MambuPy.mambuutil.encoded_dict(in_dict)[source]
Encode every value of a dict to UTF-8.
Useful for POSTing requests on the ‘data’ parameter of urlencode.
- MambuPy.mambuutil.iri_to_uri(iri)[source]
Change an IRI (internationalized R) to an URI.
Used at MambuStruct.connect() method for any requests done to Mambu.
Perfect example of unicode getting in the way.
Illustrative (I hope) example: I have Mambu usernames with special chars in them. When retrieving them and then trying to build a MambuUser object with them, I get a BIG problem because of the unicode chars there. Using this I solved the problem.
- MambuPy.mambuutil.logger = <Logger mambupy (INFO)>
Default logger for mambupy module
- MambuPy.mambuutil.setup_logging(loggername, default_level=20) Logger[source]
Get a logger configured with a yaml file.
- MambuPy.mambuutil.strip_consecutive_repeated_char(s, ch)[source]
Strip characters in a string which are consecutively repeated.
Useful when in notes or some other free text fields on Mambu, users capture anything and a lot of capture errors not always detected by Mambu get through. You want some cleaning? this may be useful.
This is a string processing function.