File: //snap/core22/2111/lib/python3/dist-packages/babel/__pycache__/util.cpython-310.pyc
o
V��\� � @ s d Z ddlZddlZddlmZmZ ddlZddlZddlZddl m
Z
mZ ddlZ
ddlmZ e� Zdd� Ze�dej�Zd d
� Ze�d�Zdd
d�Zdd� ZG dd� dej�Zddd�ZejZG dd� de�Ze
jZ ej!Z!ej"Z"ej#Z#ej$Z$ej%Z%ej&Z&dS )z�
babel.util
~~~~~~~~~~
Various utility classes and functions.
:copyright: (c) 2013-2019 by the Babel Team.
:license: BSD, see LICENSE for more details.
� N)� timedelta�tzinfo)�izip�imap)� localtimec 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)�iterable�seen�item� r
�,/usr/lib/python3/dist-packages/babel/util.py�distinct s �
��r s( [ \t\f]* \# .* coding[=:][ \t]*([-\w.]+)c
C s | � � }| �d� zw| �� }|�tj�}|r|ttj�d� }t�|�}|sJzddl }|�
|�d�� W n tt
tfy@ Y n
w | �� }t�|�}|ri|ra|�d��d�}|dkrat
d�|���W | �|� dS |ry|�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: {0} with BOM)�tell�seek�readline�
startswith�codecs�BOM_UTF8�len�PYTHON_MAGIC_COMMENT_re�match�parser�suite�decode�ImportError�SyntaxError�UnicodeEncodeError�group�format)�fp�pos�line1�has_bom�mr �line2�magic_comment_encodingr
r
r �parse_encoding1 sB
�
����r* z'from\s+__future__\s+import\s+\(*(.+)\)*r c
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 �re�sub�PYTHON_FUTURE_IMPORT_re�finditerr! �split�getattr�
compiler_flag)
r# �encodingr1 r$ �flags�bodyr'