�
ƪb�+ � � � d dl mZ d dlmZmZ G d� de� � Zdefd�Zefd�Zddefd �Z efd
�Z
dddddefd�ZdS )
� )�Locale)�format_decimal�
LC_NUMERICc � � e Zd Zd� ZdS )�UnknownUnitErrorc �F � t � | |�d|��� � d S )Nz is not a known unit in )�
ValueError�__init__)�self�unit�locales �-/usr/lib/python3/dist-packages/babel/units.pyr
zUnknownUnitError.__init__ s) � ����D�D�D�D�&�&�"Q�R�R�R�R�R� N)�__name__�
__module__�__qualname__r
� r r r r s( � � � � � �S� S� S� S� Sr r �longc �� � 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_names�get)�measurement_unit�lengthr
r s r �
get_unit_namer
sj � �, �\�&�
!�
!�F��.�v�>�>�>�D�� E��$4�V�D�D�D�D��$�(�(��r�2�2�6�6�v�>�>�>r c � � 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 �_data�sorted�len�endswith)�unit_idr
r �unit_patterns r r r ' |