csb43.utils

Note

license: GNU Lesser General Public License v3.0 (see LICENSE)

exception csb43.utils.Csb43Exception(message)
exception csb43.utils.Csb43Warning(message)
class csb43.utils.CurrencyLite(alpha_3, numeric)
class csb43.utils.Message(message)
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

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

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)
(12345, '1')
>>> currency2raw(123.45)
(12345, '2')
csb43.utils.currencyISO(numeric)
Parameters

code (str) – a ISO 4217 numeric code

Return type

pycountry.db.Currency object from its numeric code

csb43.utils.currencyISOByLetter(alpha_3)
Parameters

code (str) – a ISO 4217 numeric code

Return type

pycountry.db.Currency object from its numeric code

csb43.utils.date2raw(value, yearFirst=True)

Convert a datetime.date / datetime.datetime object to a CSB formatted date

Args:

value (datetime.datetime, datetime.date) – 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.export_currency_code(value)
csb43.utils.export_date(value)
csb43.utils.export_decimal(value, fallback=None)
csb43.utils.isCurrency(obj)
csb43.utils.nullable(f)
csb43.utils.raiseCsb43Exception(value='', strict=False, silent=False, line=None, **kwargs)

raise a Csb43Exception or print the exception’s message to standard error

Parameters
  • value – message of the exception

  • strict – print to standard error instead of raising an exception if not strict

Raises

Csb43Exception

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')
Decimal('1234.56')
>>> raw2currency('12345',debit='1')
Decimal('-123.45')
csb43.utils.raw2date(value, yearFirst=True)

Convert the CSB date format to a datetime.date object

Args:

value (str) – date using the CSB format yearFirst (bool) – if False, consider the CSB format is DDMMYY instead of YYMMDD

Return:

(datetime.date) the date object

Examples:

>>> raw2date('020301')
datetime.date(2002, 3, 1)