B
    ç|²bq  ã               @   sª   d Z ddlZyddlmZ W n  ek
r<   ddlmZ Y nX ddlmZ dd„ Zdd	„ Z	d
d„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZddlmZ dS )zÌ:mod:`wand.assertions` --- Input assertion helpers
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This module checks user input before calling MagickWands C-API methods.


.. versionadded:: 0.5.4
é    N)ÚSequenceé   )Ústring_typec              K   s@   x:|   ¡ D ].\}}t|tƒs
d}| |t|ƒ¡}t|ƒ‚q
W dS )zƒEnsure all given values are boolean.

    :raises TypeError: if value is not ``True`` or ``False.

    .. versionadded:: 0.5.4
    z{0} must be a bool, not {1}N)ÚitemsÚ
isinstanceÚboolÚformatÚreprÚ	TypeError)ÚkwargsÚlabelÚsubjectÚfmtÚmsg© r   úR/home/ankuromar296_gmail_com/.local/lib/python3.7/site-packages/wand/assertions.pyÚassert_bool   s
    
r   c              K   s@   x:|   ¡ D ].\}}t|tƒs
d}| |t|ƒ¡}t|ƒ‚q
W dS )zªEnsure all given values are instances of :class:`~wand.color.Color`.

    :raises TypeError: if value is not :class:`~wand.color.Color`.

    .. versionadded:: 0.5.4
    z:Expecting an instance of wand.color.Color for {0}, not {1}N)r   r   ÚColorr   r	   r
   )r   r   r   r   r   r   r   r   Úassert_color!   s
    
r   c              K   sD   t f | Ž x4|  ¡ D ](\}}|dk rd}| ||¡}t|ƒ‚qW dS )z·Ensure all given values are natural integer.

    :raises TypeError: if value is not an integer.
    :raises ValueError: if value is less than ``1``.

    .. versionadded:: 0.5.4
    r   z0{0}={1} must be an natural number greater than 0N)Úassert_integerr   r   Ú
ValueError)r   r   r   r   r   r   r   r   Úassert_counting_number/   s    
r   c              K   sB   x<|   ¡ D ]0\}}t|tjƒs
d}| |t|ƒ¡}t|ƒ‚q
W dS )z}Ensure all given values are an integer.

    :raises TypeError: if value is not an integer.

    .. versionadded:: 0.5.4
    z{0} must be an integer, not {1}N)r   r   ÚnumbersÚIntegralr   r	   r
   )r   r   r   r   r   r   r   r   r   ?   s
    r   c              K   sB   x<|   ¡ D ]0\}}t|tjƒs
d}| |t|ƒ¡}t|ƒ‚q
W dS )z‚Ensure all given values are real numbers.

    :raises TypeError: if value is not a real number.

    .. versionadded:: 0.5.4
    z"{0} must be a real number, not {1}N)r   r   r   ÚRealr   r	   r
   )r   r   r   r   r   r   r   r   Úassert_realM   s
    r   c              K   sD   t f | Ž x4|  ¡ D ](\}}|dk rd}| ||¡}t|ƒ‚qW dS )z¸Ensure all given values are positive integer.

    :raises TypeError: if value is not an integer.
    :raises ValueError: if value is less than ``0``.

    .. versionadded:: 0.5.4
    r   z"{0}={1} must be a positive integerN)r   r   r   r   )r   r   r   r   r   r   r   r   Úassert_unsigned_integer[   s    
r   c              K   sÎ   xÈ|   ¡ D ]¼\}}t|tƒs:d}| |t|ƒ¡}t|ƒ‚q
t|ƒdkrdd}| |t|ƒ¡}t|ƒ‚q
t|d tj	ƒs–d}| |t|d ƒ¡}t|ƒ‚q
t|d tj	ƒs
d}| |t|d ƒ¡}t|ƒ‚q
W dS )	z–Ensure all given values are a sequence of 2 real numbers.

    :raises TypeError: if value is not a pair of doubles.

    .. versionadded:: 0.6.0
    z-'{0}' must be a pair of real numbers, not {1}é   z/'{0}' must be a exactly 2 real numbers, not {1}r   z3first entry of '{0}' must be a real number, not {1}r   z4second entry of '{0}' must be a real number, not {1}N)
r   r   r   r   r	   r
   Úlenr   r   r   )r   r   r   r   r   r   r   r   Úassert_coordinatek   s"    



r   c              K   s@   x:|   ¡ D ].\}}t|tƒs
d}| |t|ƒ¡}t|ƒ‚q
W d S )Nz{0} must be a string, not {1})r   r   r   r   r	   r
   )r   r   r   r   r   r   r   r   Úassert_string…   s
    
r    c             K   s@   x:|  ¡ D ].\}}|| kr
d}| ||t|ƒ¡}t|ƒ‚q
W d S )Nz#{0} must be defined in {1}, not {2})r   r   r	   r   )Úoptionsr   r   Zsubject_labelr   r   r   r   r   r   Úin_list   s
    r"   c             K   s   t f |Ž t| |f|Ž d S )N)r    r"   )r!   r   r   r   r   r   Ústring_in_list•   s    
r#   )r   )Ú__doc__r   Úcollections.abcr   ÚImportErrorÚcollectionsÚcompatr   r   r   r   r   r   r   r   r    r"   r#   Úcolorr   r   r   r   r   Ú<module>   s"   