3
QfX                 @   st   yd dl mZ W n^ ek
rn   d dlmZmZ d dlZd dlm	Z	mZ ej
dZdd Zdd	 Zd
d ZY nX dS )    )open)lookupBOM_UTF8N)TextIOWrapperr   zcoding[:=]\s*([-\w.]+)c             C   sH   | dd j  jdd}|dks*|jdr.dS |dks@|jdrDdS | S )z(Imitates get_normal_name in tokenizer.c.N   _-zutf-8zutf-8-latin-1
iso-8859-1iso-latin-1latin-1-iso-8859-1-iso-latin-1-)r	   r
   r   )r   r   r   )lowerreplace
startswith)orig_encenc r   ]/home/psgendb/BIRCHDEV/pkg/SPAdes-3.15.4/linux-x86_64/share/spades/joblib3/_memory_helpers.py_get_normal_name   s    
r   c                s   d d}d}fdd} fdd}| }|j trHd |d	d }d
}|sT|g fS ||}|rj||gfS | }|s~||gfS ||}|r|||gfS |||gfS )aF  
        The detect_encoding() function is used to detect the encoding that
        should be used to decode a Python source file.  It requires one
        argment, readline, in the same way as the tokenize() generator.

        It will call readline a maximum of twice, and return the encoding used
        (as a string) and a list of any lines (left as bytes) it has read in.

        It detects the encoding from the presence of a utf-8 bom or an encoding
        cookie as specified in pep-0263.  If both a bom and a cookie are
        present, but disagree, a SyntaxError will be raised.  If the encoding
        cookie is an invalid charset, raise a SyntaxError.  Note that if a
        utf-8 bom is found, 'utf-8-sig' is returned.

        If no encoding is specified, then the default of 'utf-8' will be
        returned.
        FNzutf-8c                  s    y  S  t k
r   dS X d S )N    )StopIterationr   )readliner   r   read_or_stop-   s    z&_detect_encoding.<locals>.read_or_stopc                s   y| j d}W n tk
r"   d S X tj|}|s6d S t|d }yt|}W n  tk
rn   td| Y nX  r|jdkrtd|d7 }|S )Nasciir   zunknown encoding: zutf-8zencoding problem: utf-8z-sig)	decodeUnicodeDecodeError	cookie_refindallr   r   LookupErrorSyntaxErrorname)lineline_stringmatchesencodingcodec)	bom_foundr   r   find_cookie3   s"    

z%_detect_encoding.<locals>.find_cookieT   z	utf-8-sig)r   r   )r   r&   defaultr   r)   firstsecondr   )r(   r   r   _detect_encoding   s,    


r.   c             C   s:   t | d}t|j\}}|jd t||dd}d|_|S )z`Open a file in read only mode using the encoding detected by
        detect_encoding().
        rbr   T)line_bufferingr)r   r.   r   seekr   mode)filenamebufferr&   linestextr   r   r   open_py_source`   s    

r8   )tokenizer   r8   ImportErrorcodecsr   r   reior   compiler   r   r.   r   r   r   r   <module>   s   
I