D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
usr
/
lib
/
python2.7
/
site-packages
/
babel
/
Filename :
units.pyo
back
Copy
� rޖYc @ s� d d l m Z d d l m Z d d l m Z m 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 j | d | | f � d S( Ns %s is not a known unit in %s( t ValueErrort __init__( t selft unitt locale( ( s/ /usr/lib/python2.7/site-packages/babel/units.pyR s ( t __name__t __module__R ( ( ( s/ /usr/lib/python2.7/site-packages/babel/units.pyR s t longc C s[ t j | � } t | d | �} | s? t d | d | � � n | j j | i � j | � 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/ /usr/lib/python2.7/site-packages/babel/units.pyt get_unit_name s c C s` t j | � } | j d } | | k r, | Sx- t | d t �D] } | j | � r? | Sq? 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/ /usr/lib/python2.7/site-packages/babel/units.pyR * s c C s� t j | � } t | d | �} | s? t d | d | � � n | j d | j | i � } t | t � rz | } d } n! t | | | � } | j | � } | | k r� | | j | � 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.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/ /usr/lib/python2.7/site-packages/babel/units.pyt format_unitD s - c C s� t j | � } t | d | �} t | d | �} | o<