ó
jÜxec           @   s_   d  d l  m Z d  d l m Z d e f d     YZ d d
 d     YZ d   Z d   Z d	 S(   i˙˙˙˙(   t   division(   t   wrapst   LogomakerErrorc           B   s    e  Z d  Z d   Z d   Z RS(   s  
    Class used by Logomaker to handle errors.

    parameters
    ----------

    message: (str)
        The message passed to check(). This only gets passed to the
        LogomakerError constructor when the condition passed to check() is
        False.
    c         C   s   | |  _  d  S(   N(   t   message(   t   selfR   (    (    su   /oak/stanford/groups/akundaje/marinovg/programs/Anaconda2/lib/python2.7/site-packages/logomaker/src/error_handling.pyt   __init__   s    c         C   s   |  j  S(   N(   R   (   R   (    (    su   /oak/stanford/groups/akundaje/marinovg/programs/Anaconda2/lib/python2.7/site-packages/logomaker/src/error_handling.pyt   __str__   s    (   t   __name__t
   __module__t   __doc__R   R   (    (    (    su   /oak/stanford/groups/akundaje/marinovg/programs/Anaconda2/lib/python2.7/site-packages/logomaker/src/error_handling.pyR      s   	t   DebugResultc           B   s   e  Z d  Z d   Z RS(   s0   
    Container class for debugging results.
    c         C   s   | |  _  | |  _ d  S(   N(   t   resultt   mistake(   R   R   R   (    (    su   /oak/stanford/groups/akundaje/marinovg/programs/Anaconda2/lib/python2.7/site-packages/logomaker/src/error_handling.pyR      s    	(   R   R   R	   R   (    (    (    su   /oak/stanford/groups/akundaje/marinovg/programs/Anaconda2/lib/python2.7/site-packages/logomaker/src/error_handling.pyR
      s   c         C   s   |  s t  |   n  d S(   sp  
    Checks a condition; raises a LogomakerError with message if condition
    evaluates to False

    parameters
    ----------

    condition: (bool)
        A condition that, if false, halts Logomaker execution and raises a
        clean error to user

    message: (str)
        The string to show user if condition is False.

    returns
    -------
    None
    N(   R   (   t	   conditionR   (    (    su   /oak/stanford/groups/akundaje/marinovg/programs/Anaconda2/lib/python2.7/site-packages/logomaker/src/error_handling.pyt   check"   s    c            s   t       f d    } | S(   să  
    Decorator function to handle Logomaker errors.

    This decorator allows the user to pass the keyword argument
    'should_fail' to any wrapped function.

    If should_fail is None (or is not set by user), the function executes
    normally, and can be called as

        result = func(*args, **kwargs)

    In particular, Python execution will halt if any errors are raised.

    However, if the user specifies should_fail=True or should_fail=False, then
    Python will not halt even in the presence of an error. Moreover, the
    function will return a tuple, e.g.,

        result, mistake = func(*args, should_fail=True, **kwargs)

    with mistake flagging whether or not the function failed or succeeded
    as expected.
    c             s.  | j  d d   } t | t t d  f k d |  d  } d  } yG   |  |   } | t k rj d GHt } n | t k r d GHt } n  Wne t k
 rě } | t k r˝ d | j   f GHt } qí | t k ră d | j   f GHt } qí |  n X| d  k rý | S  j d k r| |  d _ d  St	 | |  Sd  S(	   Nt   should_fails+   FATAL: should_fail = %s is not bool or Nones   UNEXPECTED SUCCESS.s   Expected success.s   Expected error:s   UNEXPECTED ERROR:R   i    (
   t   popt   NoneR   t   Truet   FalseR   R   R   R   R
   (   t   argst   kwargsR   R   R   t   e(   t   func(    su   /oak/stanford/groups/akundaje/marinovg/programs/Anaconda2/lib/python2.7/site-packages/logomaker/src/error_handling.pyt   wrapped_funcS   s<    				
(   R   (   R   R   (    (   R   su   /oak/stanford/groups/akundaje/marinovg/programs/Anaconda2/lib/python2.7/site-packages/logomaker/src/error_handling.pyt   handle_errors;   s    KN(    (	   t
   __future__R    t	   functoolsR   t	   ExceptionR   R
   R   R   (    (    (    su   /oak/stanford/groups/akundaje/marinovg/programs/Anaconda2/lib/python2.7/site-packages/logomaker/src/error_handling.pyt   <module>   s
   		