File: //usr/lib/python3.9/site-packages/babel/__pycache__/util.cpython-39.pyc
a
�`� � @ 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-2021 by the Babel Team.
:license: BSD, see LICENSE for more details.
� N)� timedelta�tzinfo)�izip�imap)� localtimec c s0 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.9/site-packages/babel/util.py�distinct s
r s( [ \t\f]* \# .* coding[=:][ \t]*([-\w.]+)c
C s" | � � }| �d� � z�| �� }|�tj�}|r@|ttj�d� }t�|�}|s�zddl }|�
|�d�� W n tt
tfy� Y n0 | �� }t�|�}|r�|r�|�d��d�}|dkr�t
d�|���W | �|� dS |r�|�d��d�W | �|� S W | �|� dS W | �|� n| �|� 0 dS )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�ast�parse�decode�ImportError�SyntaxError�UnicodeEncodeError�group�format)�fp�posZline1Zhas_bom�mr Zline2Zmagic_comment_encodingr
r
r �parse_encoding1 sH
��
�
�
�r&