/usr/lib/python2.6/site-packages/babel
Edit: /usr/lib/python2.6/site-packages/babel/units.pyc (9216B)
Ñò
6
Wc
@ s¤ d d k l Z d d k l Z d d k l Z l Z d e f d „ ƒ YZ d e d „ Z e d „ Z
d d
e d „ Z e d
„ Z
d
d d
d d
e d „ Z d
S( iÿÿÿÿ( t string_types( t Locale( t format_decimalt
LC_NUMERICt UnknownUnitErrorc B s e Z d „ Z RS( c C s t i | d | | f ƒ d S( Ns %s is not a known unit in %s( t
ValueErrort __init__( t selft unitt locale( ( s* /tmp/pip-build-wCUybK/Babel/babel/units.pyR s ( t __name__t
__module__R ( ( ( s* /tmp/pip-build-wCUybK/Babel/babel/units.pyR s t longc C s] t i | ƒ } t | d | ƒ} | p t d | d | ƒ ‚ n | i i | h ƒ i | ƒ S( sç
Get the display name for a measurement unit in the given locale.
>>> get_unit_name("radian", locale="en")
'radians'
Unknown units will raise exceptions:
>>> get_unit_name("battery", locale="fi")
Traceback (most recent call last):
...
UnknownUnitError: battery/long is not a known unit/length in fi
:param measurement_unit: the code of a measurement unit.
Known units can be found in the CLDR Unit Validity XML file:
http://unicode.org/repos/cldr/tags/latest/common/validity/unit.xml
:param length: "short", "long" or "narrow"
:param locale: the `Locale` object or locale identifier
:return: The unit display name, or None.
R R ( R t parset _find_unit_patternR t unit_display_namest get( t measurement_unitt lengthR R ( ( s* /tmp/pip-build-wCUybK/Babel/babel/units.pyt
get_unit_name
s
c C sd t i | ƒ } | i d } | | j o | Sx/ t | d t ƒD] } | i | ƒ o | SqA Wd S( sÇ
Expand an unit into a qualified form.
Known units can be found in the CLDR Unit Validity XML file:
http://unicode.org/repos/cldr/tags/latest/common/validity/unit.xml
>>> _find_unit_pattern("radian", locale="en")
'angle-radian'
Unknown values will return None.
>>> _find_unit_pattern("horse", locale="en")
:param unit_id: the code of a measurement unit.
:return: A key to the `unit_patterns` mapping, or None.
t
unit_patternst keyN( R R
t _datat sortedt lent endswith( t unit_idR R t unit_pattern( ( s* /tmp/pip-build-wCUybK/Babel/babel/units.pyR * s
c C så t i | ƒ } t | d | ƒ} | p t d | d | ƒ ‚ n | i d | i | h ƒ } t | t ƒ o | } d } n" t | | | ƒ } | i | ƒ } | | j o | | i
| ƒ Sd | t | d | d | ƒp | f S( s— Format a value of a given unit.
Values are formatted according to the locale's usual pluralization rules
and number formats.
>>> format_unit(12, 'length-meter', locale='ro_RO')
u'12 metri'
>>> format_unit(15.5, 'length-mile', locale='fi_FI')
u'15,5 mailia'
>>> format_unit(1200, 'pressure-inch-hg', locale='nb')
u'1\xa0200 tommer kvikks\xf8lv'
Number formats may be overridden with the ``format`` parameter.
>>> from babel._compat import Decimal
>>> format_unit(Decimal("-42.774"), 'temperature-celsius', 'short', format='#.0', locale='fr')
u'-42,8 \xb0C'
The locale's usual pluralization rules are respected.
>>> format_unit(1, 'length-meter', locale='ro_RO')
u'1 metru'
>>> format_unit(0, 'length-picometer', locale='cy')
u'0 picometr'
>>> format_unit(2, 'length-picometer', locale='cy')
u'2 bicometr'
>>> format_unit(3, 'length-picometer', locale='cy')
u'3 phicometr'
>>> format_unit(15, 'length-horse', locale='fi')
Traceback (most recent call last):
...
UnknownUnitError: length-horse is not a known unit in fi
.. versionadded:: 2.2.0
:param value: the value to format. If this is a string, no number formatting will be attempted.
:param measurement_unit: the code of a measurement unit.
Known units can be found in the CLDR Unit Validity XML file:
http://unicode.org/repos/cldr/tags/latest/common/validity/unit.xml
:param length: "short", "long" or "narrow"
:param format: An optional format, as accepted by `format_decimal`.
:param locale: the `Locale` object or locale identifier
R R R t ones %s %sR ( R R
R R R R t
isinstanceR R t plural_formt formatR ( t valueR R R R t q_unitR t formatted_valueR ( ( s* /tmp/pip-build-wCUybK/Babel/babel/units.pyt format_unitD s -
c C sŒ t i | ƒ } t | d | ƒ} t | d | ƒ} | o | p d S| i d d ƒ d } | i d d ƒ d } t d | | f d | ƒS( sæ
Find a predefined compound unit pattern.
Used internally by format_compound_unit.
>>> _find_compound_unit("kilometer", "hour", locale="en")
'speed-kilometer-per-hour'
>>> _find_compound_unit("mile", "gallon", locale="en")
'consumption-mile-per-gallon'
If no predefined compound pattern can be found, `None` is returned.
>>> _find_compound_unit("gallon", "mile", locale="en")
>>> _find_compound_unit("horse", "purple", locale="en")
:param numerator_unit: The numerator unit's identifier
:param denominator_unit: The denominator unit's identifier
:param locale: the `Locale` object or locale identifier
:return: A key to the `unit_patterns` mapping, or None.
:rtype: str|None
R t -i iÿÿÿÿs %s-per-%sN( R R
R t Nonet split( t numerator_unitt denominator_unitR t bare_numerator_unitt bare_denominator_unit( ( s* /tmp/pip-build-wCUybK/Babel/babel/units.pyt _find_compound_unitŠ s i c C sÍ t i | ƒ } | oT | oM | d j o@ t | | d | ƒ} | o t | | d | d | d | ƒSn t | t ƒ o
| } nE | o% t | | d | d | d | ƒ} n t | d | d | ƒ} t | t ƒ o
| } n· | o— | d j o_ t | d | ƒ} | i d i | h ƒ i | h ƒ i d ƒ }
|
o |
i
| ƒ Sd } n t | | d | d | d | ƒi ƒ } n t | d | d | ƒ} | i d i d h ƒ i | d ƒ }
|
i
| | ƒ S(
sÆ
Format a compound number value, i.e. "kilometers per hour" or similar.
Both unit specifiers are optional to allow for formatting of arbitrary values still according
to the locale's general "per" formatting specifier.
>>> format_compound_unit(7, denominator_value=11, length="short", locale="pt")
'7/11'
>>> format_compound_unit(150, "kilometer", denominator_unit="hour", locale="sv")
'150 kilometer per timme'
>>> format_compound_unit(150, "kilowatt", denominator_unit="year", locale="fi")
'150 kilowattia vuodessa'
>>> format_compound_unit(32.5, "ton", 15, denominator_unit="hour", locale="en")
'32.5 tons per 15 hours'
>>> format_compound_unit(160, denominator_unit="square-meter", locale="fr")
'160 par m\xe8tre carr\xe9'
>>> format_compound_unit(4, "meter", "ratakisko", length="short", locale="fi")
'4 m/ratakisko'
>>> format_compound_unit(35, "minute", denominator_unit="fathom", locale="sv")
'35 minuter per famn'
>>> from babel.numbers import format_currency
>>> format_compound_unit(format_currency(35, "JPY", locale="de"), denominator_unit="liter", locale="de")
'35\xa0\xa5 pro Liter'
See http://www.unicode.org/reports/tr35/tr35-general.html#perUnitPatterns
:param numerator_value: The numerator value. This may be a string,
in which case it is considered preformatted and the unit is ignored.
:param numerator_unit: The numerator unit. See `format_unit`.
:param denominator_value: The denominator value. This may be a string,
in which case it is considered preformatted and the unit is ignored.
:param denominator_unit: The denominator unit. See `format_unit`.
:param length: The formatting length. "short", "long" or "narrow"
:param format: An optional format, as accepted by `format_decimal`.
:param locale: the `Locale` object or locale identifier
:return: A formatted compound value.
i R R R R t pert t compound_unit_patternss {0}/{1}( R R
R+ R# R R R R R R R t strip( t numerator_valueR' t denominator_valueR( R R R t
compound_unitt formatted_numeratort formatted_denominatort per_pattern( ( s* /tmp/pip-build-wCUybK/Babel/babel/units.pyt format_compound_unitº s2 1$
"
.
(%N( t
babel._compatR t
babel.coreR t
babel.numbersR R R R R R R% R# R+ R6 ( ( ( s* /tmp/pip-build-wCUybK/Babel/babel/units.pyt
s F1