File: //opt/alt/python37/lib/python3.7/site-packages/babel/__pycache__/util.cpython-37.opt-1.pyc
B
�`� � @ 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 s4 t � }x(t| �D ]}||kr|V |�|� qW dS )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
�;/opt/alt/python37/lib/python3.7/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�yddl }|�
|�d�� W n tt
tfk
r� Y nX | �� }t�|�}|r�|r�|�d��d�}|dkr�t
d�|���dS |r�|�d��d�S dS W d| �|� X 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 Nzlatin-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 s8
r% z'from\s+__future__\s+import\s+\(*(.+)\)*�latin-1c
C s� ddl }| �� }| �d� d}z�| �� �|�}t�dd|�}t�dd|�}t�dd|�}xTt�|�D ]F}d d
� |� d��
d�D �}x&|D ]}t||d�} | r�|| jO }q�W qdW W d| �|� X |S )
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�getattrZ
compiler_flag)
r"