Files
intellecton/venv/lib/python3.12/site-packages/babel/__pycache__/units.cpython-312.pyc
T

189 lines
12 KiB
Plaintext
Raw Normal View History

Ë
jž6ãóddlmZddlZddlmZddlmZddlmZm Z Gdde
«Z d ddZ ddd „Z
dd
d œ dd Z d dd
Z dd
d œ ddZy)é)Ú annotationsN)ÚLiteral)ÚLocale)Ú
LC_NUMERICÚformat_decimalcóeZdZddZy)ÚUnknownUnitErrorcó:tj||d|«y)Nz is not a known unit in )Ú
ValueErrorÚ__init__)ÚselfÚunitÚlocales úN/home/antigravity/intellecton/venv/lib/python3.12/site-packages/babel/units.pyr zUnknownUnitError.__init__ sÜ×јD T FÐ*BÀ6À(Ð"KÕN)rÚstrrrÚreturnÚNone)Ú__name__Ú
__module__Ú __qualname__r ©rrr r
sôMrr cóÊtj|xst«}t||¬«}|s
t ||¬«|j
j
|i«j
|«S)a
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:
https://unicode.org/repos/cldr/tags/latest/common/validity/unit.xml
:param length: "short", "long" or "narrow"
:param locale: the `Locale` object or locale identifier. Defaults to the system numeric locale.
:return: The unit display name, or None.
©r©rr)rÚparserÚ_find_unit_patternr Úunit_display_namesÚget)Úmeasurement_unitÚlengthrrs rÚ
get_unit_namer"sYô4\‰\˜.¤JÓ
/€FÜ Ð.°vÔ >€DÙ ÜÐ$4¸ × ¨rÓ 2× 6°vÓ >rcó¾tj|xst«}|jd}||vr|St |t
¬«D]}|j
|«sŒ|cSy)
Expand a unit into a qualified form.
Known units can be found in the CLDR Unit Validity XML file:
https://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.
Ú
unit_patterns)ÚkeyN)rrrÚ_dataÚsortedÚlenÚendswith)Úunit_idrr$Ú unit_patterns rrr0saô"\‰\˜.¤JÓ
/€FØ$*§L¡L°Ñ$A€MØØˆÜ˜}´#Ô ˆ Ø × Ñ  Õ Ò ð ð rÚlatn©Únumbering_systemcó„tj|xst«}t||¬«}|s
t ||¬«|j
d|j
|i«}t|t«r|}d} n t||||¬«}|j|«} | |vr|| j|«St|||¬«}
|d|
xs|S)u•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')
'12 metri'
>>> format_unit(15.5, 'length-mile', locale='fi_FI')
'15,5 mailia'
>>> format_unit(1200, 'pressure-millimeter-ofhg', locale='nb')
'1\xa0200 millimeter kvikks\xf8lv'
>>> format_unit(270, 'ton', locale='en')
'270 tons'
>>> format_unit(1234.5, 'kilogram', locale='ar_EG', numbering_system='default')
'1٬234٫5 كيلوغرام'
Number formats may be overridden with the ``format`` parameter.
>>> import decimal
>>> format_unit(decimal.Decimal("-42.774"), 'temperature-celsius', 'short', format='#.0', locale='fr')
'-42,8\u202f\xb0C'
The locale's usual pluralization rules are respected.
>>> format_unit(1, 'length-meter', locale='ro_RO')
'1 metru'
>>> format_unit(0, 'length-mile', locale='cy')
'0 mi'
>>> format_unit(1, 'length-mile', locale='cy')
'1 filltir'
>>> format_unit(3, 'length-mile', locale='cy')
'3 milltir'
>>> 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:
https://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. Defaults to the system numeric locale.
:param numbering_system: The numbering system used for formatting number symbols. Defaults to "latn".
The special value "default" will use the default numbering system of the locale.
:raise `UnsupportedNumberingSystemError`: If the numbering system is not supported by the locale.
rrr$Úoner-)r!rú )
rrrrr r&rÚ
isinstancerrÚ plural_formÚformatr") Úvaluer r!r4rr.Úq_unitr$Úformatted_valuer3Ú
fallback_names rÚ format_unitr9Kôx\‰\˜.¤JÓ
/€Fä
Ð 0¸Ô
@€FÙ ÜÐ$4¸VÔ—LL Ñ1°&Ñ9×=¸fÀbÓI€MäÔØˆØ ä Ø Ø Ø
ˆð ×Ó à˜[ÑÓØØô€Mð
Ð
˜a 
Ò AÐ1AÐ Crcóòtj|xst«}t||¬«}t||¬«}|r|sy|j dd«d}|j dd«d}t|d||¬«S)a
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. Defaults to the system numeric locale.
:return: A key to the `unit_patterns` mapping, or None.
:rtype: str|None
réÿÿÿÿz-per-)rrrrÚsplit)Únumerator_unitÚdenominator_unitrÚresolved_numerator_unitÚresolved_denominator_unitÚbare_numerator_unitÚbare_denominator_units rÚ_find_compound_unitrE§s”ô8\‰\˜.¤JÓ
/€Fô ÈÔÜ 2Ð3CÈFÔ SÐñ
$Ñ(AØð
¸QÓÑØ;¸CÀÓCÀBÑô Ø Ð
˜uÐ%:Ð$;Ðô ðrcóøtj|xst«}|r(|r&|dk(r!t|||¬«}|rt ||||||¬«St |t «r|} n#|rt ||||||¬«} nt||||¬«} t |t «r|}
nš|r‰|dk(r`t||¬«}|jdj|i«j|i«jd«} | r| j| «Sd}t ||xsd||||¬«j«}
nt||||¬«}
|jd jdi«j|i«jd
d «} | j| |
«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 / vuosi'
>>> format_compound_unit(32.5, "ton", 15, denominator_unit="hour", locale="en")
'32.5 tons per 15 hours'
>>> format_compound_unit(1234.5, "ton", 15, denominator_unit="hour", locale="ar_EG", numbering_system="arab")
'1٬234٫5 طن لكل 15 ساعة'
>>> 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="nautical-mile", locale="sv")
'35 minuter per nautisk mil'
>>> 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 https://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.