Package pytils :: Module numeral
[hide private]

Module numeral

source code

Plural forms and in-word representation for numerals.

Functions [hide private]
str
_get_float_remainder(fvalue, signs=9)
Get remainder of float, i.e.
source code
unicode
choose_plural(amount, variants)
Choose proper case depending on amount
source code
unicode
get_plural(amount, variants, absence=None)
Get proper case with value
source code
unicode
_get_plural_legacy(amount, extra_variants)
Get proper case with value (legacy variant, without absence)
source code
unicode
rubles(amount, zero_for_kopeck=False)
Get string for money
source code
unicode
in_words_int(amount, gender=1)
Integer in words
source code
unicode
in_words_float(amount, _gender=2)
Float in words
source code

unicode

raise TypeError: when amount not int or float raise ValueError: when amount is negative raise TypeError: when gender is not int (and not None) raise ValueError: if gender isn't in (MALE, FEMALE, NEUTER)
in_words(amount, gender=None)
Numeral in words
source code
unicode
sum_string(amount, gender, items=None)
Get sum in words
source code
tuple
_sum_string_fn(into, tmp_val, gender, items=None)
Make in-words representation of single order
source code
Variables [hide private]
  __revision__ = '$Id: numeral.py 102 2007-07-12 12:33:36Z the.p...
  __id__ = '$Id: numeral.py 102 2007-07-12 12:33:36Z the.pythy $'
  __url__ = '$URL: https://pythy.googlecode.com/svn/tags/pytils/...
  FRACTIONS = ((u'\u0434\u0435\u0441\u044f\u0442\u0430\u044f', u...
Forms (1, 2, 5) for fractions
  ONES = {0: (u'', u'', u''), 1: (u'\u043e\u0434\u0438\u043d', u...
Forms (MALE, FEMALE, NEUTER) for ones
  TENS = {0: u'', 2: u'\u0434\u0432\u0430\u0434\u0446\u0430\u044...
Tens
  HUNDREDS = {0: u'', 1: u'\u0441\u0442\u043e', 2: u'\u0434\u043...
Hundreds
  MALE = 1
sex - male
  FEMALE = 2
sex - female
  NEUTER = 3
sex - neuter

Imports: utils


Function Details [hide private]

_get_float_remainder(fvalue, signs=9)

source code 
Get remainder of float, i.e. 2.05 -> '05'
Parameters:
  • fvalue (int, long or float) - input value
  • signs (int or long) - maximum number of signs
Returns: str
remainder
Raises:
  • TypeError - fvalue neither int, no float
  • ValueError - fvalue is negative
  • ValueError - signs overflow

choose_plural(amount, variants)

source code 
Choose proper case depending on amount
Parameters:
  • amount (int or long) - amount of objects
  • variants (3-element sequence of unicode or unicode (three variants with delimeter ',')) - variants (forms) of object in such form: (1 object, 2 objects, 5 objects).
Returns: unicode
proper variant
Raises:
  • TypeError - amount isn't int, variants isn't sequence
  • ValueError - amount is negative
  • ValueError - variants' length lesser than 3

get_plural(amount, variants, absence=None)

source code 
Get proper case with value
Parameters:
  • amount (int or long) - amount of objects
  • variants (3-element sequence of unicode or unicode (three variants with delimeter ',')) - variants (forms) of object in such form: (1 object, 2 objects, 5 objects).
  • absence (unicode) - if amount is zero will return it
Returns: unicode
amount with proper variant

_get_plural_legacy(amount, extra_variants)

source code 
Get proper case with value (legacy variant, without absence)
Parameters:
  • amount (int or long) - amount of objects
  • variants (3-element sequence of unicode or unicode (three variants with delimeter ',')) - variants (forms) of object in such form: (1 object, 2 objects, 5 objects, 0-object variant). 0-object variant is similar to absence in get_plural
Returns: unicode
amount with proper variant

rubles(amount, zero_for_kopeck=False)

source code 
Get string for money
Parameters:
  • amount (int, long or float) - amount of money
  • zero_for_kopeck (bool) - If false, then zero kopecks ignored
Returns: unicode
in-words representation of money's amount
Raises:
  • TypeError - amount neither int, no float
  • ValueError - amount is negative

in_words_int(amount, gender=1)

source code 
Integer in words
Parameters:
  • amount (int or long) - numeral
  • gender (int) - gender (MALE, FEMALE or NEUTER)
Returns: unicode
in-words reprsentation of numeral
Raises:
  • TypeError - when amount is not int
  • ValueError - amount is negative

in_words_float(amount, _gender=2)

source code 
Float in words
Parameters:
  • amount (float) - float numeral
Returns: unicode
in-words reprsentation of float numeral
Raises:
  • TypeError - when amount is not float
  • ValueError - when ammount is negative

in_words(amount, gender=None)

source code 
Numeral in words
Parameters:
  • amount (int, long or float) - numeral
  • gender (int) - gender (MALE, FEMALE or NEUTER)
Returns:

unicode

raise TypeError: when amount not int or float raise ValueError: when amount is negative raise TypeError: when gender is not int (and not None) raise ValueError: if gender isn't in (MALE, FEMALE, NEUTER)
in-words reprsentation of numeral

sum_string(amount, gender, items=None)

source code 
Get sum in words
Parameters:
  • amount (int or long) - amount of objects
  • gender (int) - gender of object (MALE, FEMALE or NEUTER)
  • items (3-element sequence of unicode or just unicode (three variants with delimeter ',')) - variants of object in three forms: for one object, for two objects and for five objects
Returns: unicode
in-words representation objects' amount
Raises:
  • TypeError - input parameters' check failed
  • ValueError - items isn't 3-element sequence or unicode
  • ValueError - amount bigger than 10**11
  • ValueError - amount is negative

_sum_string_fn(into, tmp_val, gender, items=None)

source code 
Make in-words representation of single order
Parameters:
  • into (unicode) - in-words representation of lower orders
  • tmp_val (int or long) - temporary value without lower orders
  • gender (int) - gender (MALE, FEMALE or NEUTER)
  • items (3-element sequence of unicode) - variants of objects
Returns: tuple
new into and tmp_val
Raises:
  • TypeError - input parameters' check failed
  • ValueError - tmp_val is negative

Variables Details [hide private]

__revision__

Value:
'$Id: numeral.py 102 2007-07-12 12:33:36Z the.pythy $'

__url__

Value:
'$URL: https://pythy.googlecode.com/svn/tags/pytils/0_2_2/pytils/numer\
al.py $'

FRACTIONS

Forms (1, 2, 5) for fractions
Value:
((u'\u0434\u0435\u0441\u044f\u0442\u0430\u044f',
  u'\u0434\u0435\u0441\u044f\u0442\u044b\u0445',
  u'\u0434\u0435\u0441\u044f\u0442\u044b\u0445'),
 (u'\u0441\u043e\u0442\u0430\u044f',
  u'\u0441\u043e\u0442\u044b\u0445',
  u'\u0441\u043e\u0442\u044b\u0445'),
 (u'\u0442\u044b\u0441\u044f\u0447\u043d\u0430\u044f',
  u'\u0442\u044b\u0441\u044f\u0447\u043d\u044b\u0445',
...

ONES

Forms (MALE, FEMALE, NEUTER) for ones
Value:
{0: (u'', u'', u''),
 1: (u'\u043e\u0434\u0438\u043d',
     u'\u043e\u0434\u043d\u0430',
     u'\u043e\u0434\u043d\u043e'),
 2: (u'\u0434\u0432\u0430',
     u'\u0434\u0432\u0435',
     u'\u0434\u0432\u0430'),
 3: (u'\u0442\u0440\u0438', u'\u0442\u0440\u0438', u'\u0442\u0440\u043\
...

TENS

Tens
Value:
{0: u'',
 2: u'\u0434\u0432\u0430\u0434\u0446\u0430\u0442\u044c',
 3: u'\u0442\u0440\u0438\u0434\u0446\u0430\u0442\u044c',
 4: u'\u0441\u043e\u0440\u043e\u043a',
 5: u'\u043f\u044f\u0442\u044c\u0434\u0435\u0441\u044f\u0442',
 6: u'\u0448\u0435\u0441\u0442\u044c\u0434\u0435\u0441\u044f\u0442',
 7: u'\u0441\u0435\u043c\u044c\u0434\u0435\u0441\u044f\u0442',
 8: u'\u0432\u043e\u0441\u0435\u043c\u044c\u0434\u0435\u0441\u044f\u04\
...

HUNDREDS

Hundreds
Value:
{0: u'',
 1: u'\u0441\u0442\u043e',
 2: u'\u0434\u0432\u0435\u0441\u0442\u0438',
 3: u'\u0442\u0440\u0438\u0441\u0442\u0430',
 4: u'\u0447\u0435\u0442\u044b\u0440\u0435\u0441\u0442\u0430',
 5: u'\u043f\u044f\u0442\u044c\u0441\u043e\u0442',
 6: u'\u0448\u0435\u0441\u0442\u044c\u0441\u043e\u0442',
 7: u'\u0441\u0435\u043c\u044c\u0441\u043e\u0442',
...