#qL d dl mZ d dlZd dlmZ d dlmZ d dlmZm Z erd dl mZ G d de Z d efd dZefd!dZd defd"dZefd#dZdddd defd$dZdS )% )annotationsN) TYPE_CHECKING)Locale) LC_NUMERICformat_decimal)Literalc e Zd Zd dZdS ) UnknownUnitErrorunitstrlocaler returnNonec F t | | d| d S )Nz is not a known unit in ) ValueError__init__)selfr r s k/builddir/build/BUILD/imunify360-venv-2.6.2/opt/imunify360/venv/lib/python3.11/site-packages/babel/units.pyr zUnknownUnitError.__init__ s, DT"K"K6"K"KLLLLL N)r r r r r r )__name__ __module____qualname__r r r r r s. M M M M M Mr r longmeasurement_unitr length"Literal['short', 'long', 'narrow']r Locale | str | Noner str | Nonec t j | }t | | }|st | | |j |i | 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 :return: The unit display name, or None. r r r )r parse_find_unit_patternr unit_display_namesget)r r r r s r get_unit_namer' sj 4 \& ! !F.v>>>D E$4VDDDD$((r2266v>>>r unit_idc t j | }|j d }| |v r| S t |t D ]}| | r|c S dS )a Expand an 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)r r# _datasortedlenendswith)r( r r* unit_patterns r r$ r$ 3 s| " \& ! !FL1M-}#666 )) r valuefloat | decimal.Decimalformatc t j | }t || }|st || |j d | |i }t | t r| }d}n&t | || }| | }||v r|| | S t ||| } | d| p| S )a 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-millimeter-ofhg', locale='nb') u'1\xa0200 millimeter kvikks\xf8lv' >>> format_unit(270, 'ton', locale='en') u'270 tons' Number formats may be overridden with the ``format`` parameter. >>> import decimal >>> format_unit(decimal.Decimal("-42.774"), 'temperature-celsius', 'short', format='#.0', locale='fr') u'-42,8\u202f\xb0C' The locale's usual pluralization rules are respected. >>> format_unit(1, 'length-meter', locale='ro_RO') u'1 metru' >>> format_unit(0, 'length-mile', locale='cy') u'0 mi' >>> format_unit(1, 'length-mile', locale='cy') u'1 filltir' >>> format_unit(3, 'length-mile', locale='cy') u'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 r! r" r* one)r r )r r# r$ r r, r&