csb43.utils
¶
Note
license: GNU Lesser General Public License v3.0 (see LICENSE)
-
exception
csb43.utils.
Csb43Exception
(value)¶
-
class
csb43.utils.
CurrencyLite
(alpha_3, numeric)¶
-
csb43.utils.
b_left_pad
(bvalue, n, fill=b' ')¶
-
csb43.utils.
b_right_pad
(bvalue, n, fill=b' ')¶
-
csb43.utils.
check_strict
(pattern)¶ Note
decorator
Parameters: - pattern (
basestring
) – pattern description using regular expressions - field – variable to be checked
- strict (
bool
) – treat exceptions as warnings if False
Raises: Csb43Exception
if field doesn’t match pattern and strict is True- pattern (
-
csb43.utils.
check_string
(pattern='', field='', strict=True, **csbexc)¶ Parameters: - pattern (
basestring
) – pattern description using regular expressions - field – variable to be checked
- strict (
bool
) – treat exceptions as warnings if False
Raises: Csb43Exception
if field doesn’t match pattern and strict is True- pattern (
-
csb43.utils.
currency2raw
(value, decimal=2)¶ Convert a real to the CSB amount format
- Args:
- value (float) – quantity as a real number decimal (int) – number of digits reserved for decimal numbers
- Return:
- tuple of absolute amount and debit flag
Examples:
>>> currency2raw(-123.456) (12345L, '1') >>> currency2raw(123.45) (12345L, '2')
-
csb43.utils.
currencyISO
(numeric)¶ Parameters: code ( str
) – a ISO 4217 numeric codeReturn type: pycountry.db.Currency
object from its numeric code
-
csb43.utils.
currencyISOByLetter
(alpha_3)¶ Parameters: code ( str
) – a ISO 4217 numeric codeReturn type: pycountry.db.Currency
object from its numeric code
-
csb43.utils.
date2raw
(value, yearFirst=True)¶ Convert a datetime object to a CSB formatted date
- Args:
- value (datetime.datetime) – datetime object yearFirst (bool) – if False, consider the CSB format is DDMMYY instead of YYMMDD
- Return:
- (str) the CSB date
Examples:
>>> a = raw2date('020301') >>> date2raw(a) '020301'
-
csb43.utils.
isCurrency
(obj)¶
-
csb43.utils.
raiseCsb43Exception
(value='', strict=False, silent=False, **kwargs)¶ raise a
Csb43Exception
or print the exception’s message to standard errorParameters: - value – message of the exception
- strict – print to standard error instead of raising an exception if not strict
Raises:
-
csb43.utils.
raw2currency
(value, decimal=2, debit='2')¶ Format the CSB composite type for amounts as a real number
- Args:
- value (long or str) – absolute amount without decimal separator decimal (int) – number of digits reserved for decimal numbers debit (‘1’,‘2’) – ‘1’ debit, ‘2’ credit
- Return:
- (float) the amount as a real number
Examples:
>>> raw2currency('123456') 1234.56 >>> raw2currency('12345',debit='1') -123.45
-
csb43.utils.
raw2date
(value, yearFirst=True)¶ Convert the CSB date format to a datetime.datetime object
- Args:
- value (str) – date using the CSB format yearFirst (bool) – if False, consider the CSB format is DDMMYY instead of YYMMDD
- Return:
- (datetime.datetime) the date object
Examples:
>>> raw2date('020301') datetime.datetime(2002, 3, 1, 0, 0)