File: //home/arjun/projects/env/lib/python3.10/site-packages/babel/__pycache__/util.cpython-310.pyc
o
!we � @ s2 d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl m
Z
mZ ddlm
Z
mZmZ ddlmZmZ e� Zed�Zd2dd
�Ze�dej�Zd3dd�Ze�d�Zd4d5dd�Zd6dd�ZG d d!� d!ej�Zd7d8d)d*�Zej Z!G d+d,� d,ej"�Z#ej$Z$ej%Z%ej&Z&ej'Z'ej(Z(ej)Z)ej*Z*d9d0d1�Z+dS ):z�
babel.util
~~~~~~~~~~
Various utility classes and functions.
:copyright: (c) 2013-2023 by the Babel Team.
:license: BSD, see LICENSE for more details.
� )�annotationsN)� Generator�Iterable)�IO�Any�TypeVar)�dates� localtime�_T�iterable�Iterable[_T]�return�Generator[_T, None, None]c c s2 � t � }t| �D ]}||vr|V |�|� qdS )a� Yield all items in an iterable collection that are distinct.
Unlike when using sets for a similar effect, the original ordering of the
items in the collection is preserved by this function.
>>> print(list(distinct([1, 2, 1, 3, 4, 4])))
[1, 2, 3, 4]
>>> print(list(distinct('foobar')))
['f', 'o', 'b', 'a', 'r']
:param iterable: the iterable collection providing the data
N)�set�iter�add)r �seen�item� r �C/home/arjun/projects/env/lib/python3.10/site-packages/babel/util.py�distinct s �
��r s( [ \t\f]* \# .* coding[=:][ \t]*([-\w.]+)�fp� IO[bytes]�
str | Nonec
C s | � � }| �d� zx| �� }|�tj�}|r|ttj�d� }t�|�}|sJzddl }|�
|�d�� W n tt
tfy@ Y n
w | �� }t�|�}|rj|rb|�d��d�}|dkrbt
d|� d���W | �|� dS |rz|�d��d�W | �|� S W | �|� dS | �|� w )a/ Deduce the encoding of a source file from magic comment.
It does this in the same way as the `Python interpreter`__
.. __: https://docs.python.org/3.4/reference/lexical_analysis.html#encoding-declarations
The ``fp`` argument should be a seekable file object.
(From Jeff Dairiki)
r N�latin-1� zutf-8zencoding problem: z with BOM)�tell�seek�readline�
startswith�codecs�BOM_UTF8�len�PYTHON_MAGIC_COMMENT_re�match�ast�parse�decode�ImportError�SyntaxError�UnicodeEncodeError�group)r �pos�line1�has_bom�mr% �line2�magic_comment_encodingr r r �parse_encoding5 s:
�
��r2 z'from\s+__future__\s+import\s+\(*(.+)\)*r �encoding�str�intc
C s� ddl }| �� }| �d� d}zK| �� �|�}t�dd|�}t�dd|�}t�dd|�}t�|�D ]!}d d
� |� d��
d�D �}|D ]}t||d�} | rQ|| jO }qBq1W | �|� |S | �|� w )
zRParse the compiler flags by :mod:`__future__` from the given Python
code.
r Nzimport\s*\([\r\n]+zimport (z,\s*[\r\n]+z, z\\\s*[\r\n]+� c S s g | ] }|� � � d ��qS )z())�strip)�.0�xr r r �
<listcomp> s z&parse_future_flags.<locals>.<listcomp>r �,)
�
__future__r r �readr'