B
    |b                 @   s  d Z ddlZyddlZW n ek
r,   Y nX ddlZddlZddlZddlZdZej	dkZ
e
rfejneZe
rreneZe
r~eneZe
reneZdddZddd	Ze
rd
d Zndd Ze
reneZe
rejn
ejejfZdd Zy
ejZW n$ ek
r   ejdd ZY nX dS )z:mod:`wand.compat` --- Compatibility layer
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This module provides several subtle things to support
multiple Python versions (2.7, 3.3+) and VM implementations
(CPython, PyPy).

    N)PY3abcbinarybinary_typeencode_filename
file_typesnestedstring_typetext	text_typeto_bytesxrange)   c             C   sH   t | tr|  S t | tr | S |r4td|| tdt|  dS )aJ  Makes ``string`` to :class:`str` in Python 2.
    Makes ``string`` to :class:`bytes` in Python 3.

    :param string: a string to cast it to :data:`binary_type`
    :type string: :class:`bytes`, :class:`str`, :class:`unicode`
    :param var: an optional variable name to be used for error message
    :type var: :class:`str`

    z{0} must be a string, not {1!r}zexpected a string, not N)
isinstancer   encoder   	TypeErrorformatrepr)stringvar r   N/home/ankuromar296_gmail_com/.local/lib/python3.7/site-packages/wand/compat.pyr   ,   s    


r   {0}c             C   s   | |  S )ax  Short-cut method to allow mixed value types to be converted to bytes.

    :param value: Value to be cast to bytes
    :type value: :class:`basestring`, :class:`int`, :class:`float`
    :param string_pattern: String format to allow printf style control of
                           bytes output.
    :type string_pattern: :class:`basestring`

    .. versionadded:: 0.6.4
    )r   r   )valueZstring_patternr   r   r   r   ?   s    r   c             C   s   t | tr| dS | S )Nzutf-8)r   bytesdecode)r   r   r   r   r
   N   s    

r
   c             C   s   | S )zMakes ``string`` to :class:`str` in Python 3.
        Does nothing in Python 2.

        :param string: a string to cast it to :data:`text_type`
        :type string: :class:`bytes`, :class:`str`, :class:`unicode`

        r   )r   r   r   r   r
   S   s    c             C   s.   t | dr|  } t| tr*| t S | S )zIf ``filename`` is a :data:`text_type`, encode it to
    :data:`binary_type` according to filesystem's default encoding.

    .. versionchanged:: 0.5.3
       Added support for PEP-519 https://github.com/emcconville/wand/pull/339
    
__fspath__)hasattrr   r   r   r   sysgetfilesystemencoding)filenamer   r   r   r   g   s
    

r   c              g   s   g }g }d}zTy:x.| D ]&}|j }|j}||  || qW |V  W n   t }Y nX W d x6|r| }y|| r~d}W qd   t }Y qdX qdW |dkr|d |d }|d |_|X d S )N)NNNr         )__exit__	__enter__appendr   exc_infopop__traceback__)ZmanagersZexitsvarsexcZmgrexitZenterer   r   r   r   y   s.    


r   )N)r   )__doc__collectionscollections.abcImportError
contextlibior   types__all__version_infor   r   r   strr   
basestringr	   unicoder   r   r   r
   ranger   	RawIOBaseFileTyper   r   r   AttributeErrorcontextmanagerr   r   r   r   <module>   s6   




