| Server IP : 127.0.0.1 / Your IP : 216.73.216.109 Web Server : Apache/2.4.54 (Win64) OpenSSL/1.1.1q PHP/8.1.10 System : Windows NT DESKTOP-E5T4RUN 10.0 build 19045 (Windows 10) AMD64 User : SERVERWEB ( 0) PHP Version : 8.1.10 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/cygwin64/lib/python3.9/site-packages/babel/__pycache__/ |
Upload File : |
a
�4dh. �
@ s� d dl mZ d dlZd dlmZ d dlmZ d dlmZm Z erLd dl
mZ G dd� de�Z
d efd
ddd
d�dd�Zefd
dd
d�dd�Zd defdd
dd
dd
d�dd�Zefd
d
dd
d�dd�Zdddd defdd
dd
dd
dd
d�dd�ZdS )� )�annotationsN)�
TYPE_CHECKING)�Locale)�
LC_NUMERIC�format_decimal)�Literalc @ s e Zd Zdddd�dd�ZdS )�UnknownUnitError�strr �None)�unit�locale�returnc C s t �| |� d|� �� d S )Nz is not a known unit in )�
ValueError�__init__)�selfr r � r �//usr/lib/python3.9/site-packages/babel/units.pyr s zUnknownUnitError.__init__N)�__name__�
__module__�__qualname__r r r r r r
s r Zlongr z"Literal['short', 'long', 'narrow']zLocale | str | Nonez
str | None)�measurement_unit�lengthr r
c C s: t �|�}t| |d�}|s&t| |d��|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 Zunit_display_names�get)r r r r r r r �
get_unit_name s
r )�unit_idr r
c C sH t �|�}|jd }| |v r | S t|td�D ]}|�| �r,| S q,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 �_data�sorted�len�endswith)r r r Zunit_patternr r r r 3 s
r zfloat | decimal.Decimal)�valuer r �formatr r
c
C s� t �|�}t||d�}|s&t||d��|jd | �|i �}t| t�rP| }d}nt| ||�}|� | �}||v r||| �
|�S t|||d�} |� 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 Zone)r r � )r r r r r! r �
isinstancer r �plural_formr&