3
qDY\" @ s d Z ddlZddlmZmZ ddlZddlZddlZddlm Z m
Z
ddlZddl
mZ e Zdd ZejdejZd d
ZejdZdd
dZdd ZG dd dejZdddZG dd deZG dd deZejZej Z ej!Z!ej"Z"ej#Z#ej$Z$ej%Z%dS )z
babel.util
~~~~~~~~~~
Various utility classes and functions.
:copyright: (c) 2013 by the Babel Team.
:license: BSD, see LICENSE for more details.
N) timedeltatzinfo)izipimap) localtimec c s4 t }x(t| D ]}||kr|V |j| 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)setiteradd)iterableseenitem r
/usr/lib/python3.6/util.pydistinct s
r s( [ \t\f]* \# .* coding[=:][ \t]*([-\w.]+)c C s | j }| jd z| j }|jtj}|r>|ttjd }tj|}|syddl }|j
|jd W n tt
tfk
r Y nX | j }tj|}|r|r|jdjd}|dkrt
dj|dS |r|jdjdS dS W d| j| 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)tellseekreadline
startswithcodecsBOM_UTF8lenPYTHON_MAGIC_COMMENT_rematchparserZsuitedecodeImportErrorSyntaxErrorUnicodeEncodeErrorgroupformat)fpposZline1Zhas_bommr Zline2Zmagic_comment_encodingr
r
r parse_encoding0 s8
r$ z'from\s+__future__\s+import\s+\(*(.+)\)*latin-1c
C s ddl }| j }| jd d}z| j j|}tjdd|}tjdd|}tjdd|}xTtj|D ]F}d d
|j dj
dD }x&|D ]}t||d} | r|| jO }qW qdW W d| j| 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 | ]}|j j d qS )z())strip).0xr
r
r