B
    \                 @   s
  d Z ddlZddlZddlmZmZmZ edZer:dZ	ndZ	erPddl
mZ ndd Zerfe Zned	 Zerd
d Zndd Zerdd ZndZerddlmZ nddlmZ erG dd deZnG dd deZerddlmZ n
dddZefddZdS )z
    sphinx.util.pycompat
    ~~~~~~~~~~~~~~~~~~~~

    Stuff for Python version compatibility.

    :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
    N)PY3	text_typeexec_ u)TextIOWrapperc             C   s   t |p
dd | S )Nascii   )codecslookup)streamencoding r   3lib/python3.7/site-packages/sphinx/util/pycompat.pyr   &   s    r   Zlocalec             C   s   |  dddS )Nr   backslashreplace)encodedecode)sr   r   r   terminal_safe5   s    r   c             C   s   |  ddS )Nr   r   )r   )r   r   r   r   r   9   s    c          
   C   s   ddl m}m} ddlm} |d}||}|| d }y||d}W nF |k
r } z(|jd \}	}
t|j	| |	|
|j
fW d d }~X Y nX t|S )Nr   )RefactoringToolget_fixers_from_package)
ParseErrorzlib2to3.fixeszconf.py   )Zlib2to3.refactorr   r   Zlib2to3.pgen2.parser   Z_read_python_sourceZrefactor_stringcontextSyntaxErrormsgvaluer   )filepathr   r   r   ZfixersZrefactoring_toolsourceZtreeerrlinenooffsetr   r   r   convert_with_2to3A   s    (r"   )escapec               @   s   e Zd ZdZdd ZdS )UnicodeMixinz_Mixin class to handle defining the proper __str__/__unicode__
        methods in Python 2 or 3.c             C   s   |   S )N)__unicode__)selfr   r   r   __str__b   s    zUnicodeMixin.__str__N)__name__
__module____qualname____doc__r'   r   r   r   r   r$   ^   s   r$   c               @   s   e Zd ZdZdd ZdS )r$   z_Mixin class to handle defining the proper __str__/__unicode__
        methods in Python 2 or 3.c             C   s   |   dS )Nutf8)r%   r   )r&   r   r   r   r'   i   s    zUnicodeMixin.__str__N)r(   r)   r*   r+   r'   r   r   r   r   r$   e   s   )indentc                s,    d krdd   fdd}d | S )Nc             S   s   |   S )N)strip)liner   r   r   	predicatev   s    zindent.<locals>.predicatec              3   s.   x( dD ]}  | r |  n| V  qW d S )NT)
splitlines)r/   )r0   prefixtextr   r   prefixed_linesz   s    zindent.<locals>.prefixed_linesr   )join)r3   r2   r0   r4   r   )r0   r2   r3   r   r-   s   s    r-   c       	   	   C   s   ddl m} trdnd}|| |}| }W d Q R X | |}yt||d}W n0 tk
r   trzt| }t||d}n Y nX t|| d S )Nr   )fs_encodingrbZrbUexec)	Zsphinx.util.osutilr6   r   readr   compiler   r"   r   )	r   Z_globalsopenr6   modefr   Zfilepath_enccoder   r   r   	execfile_   s    
r?   )N)r+   r
   sysZsixr   r   r   typeZNoneTyper   ior   getdefaultencodingZsys_encoding
__import__Zgetpreferredencodingr   r"   Zhtmlr#   Z
htmlescapeZcgiobjectr$   textwrapr-   r;   r?   r   r   r   r   <module>
   s:   




