ó
-òPPc           @`  sX  d  Z  d d l m Z m Z d d l Z d d l Z d d l Z d d l Z d d l m Z d d l	 m
 Z
 m Z d d l m Z d a d Z d e f d	 „  ƒ  YZ d
 d „ Z d Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d f  d „  ƒ  YZ d „  Z e Z e e e e  e j! d „ Z" d „  Z# d S(   s9   
Asynchronous-friendly error mechanism.

See L{Failure}.
i    (   t   divisiont   absolute_importN(   t   getmro(   t   _PY3t   NativeStringIO(   t   _reflectpy3i   t   DefaultExceptionc           B`  s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyR      s   t   defaultc         C`  sä  | d k r" t  d | f ƒ ‚ n  | } | d k rn x©|  D], \ } } } } } | d | | | f ƒ q; Wnr| d k rÔ xc|  D]L \ } } } } } | d | | | f ƒ | d t j | | ƒ j ƒ  ƒ q Wn| d k r$x4 |  D], \ } } } } } | d	 | | | f ƒ qç W| d
 ƒ n¼ | d k ràx­ |  D]¢ \ } } } } } | d	 | | | f ƒ | d ƒ x. | D]& \ }	 }
 | d |	 t |
 ƒ f ƒ qtW| d ƒ x. | D]& \ }	 }
 | d |	 t |
 ƒ f ƒ q¯Wq7Wn  d S(   s“  Format and write frames.

    @param frames: is a list of frames as used by Failure.frames, with
        each frame being a list of
        (funcName, fileName, lineNumber, locals.items(), globals.items())
    @type frames: list
    @param write: this will be called with formatted strings.
    @type write: callable
    @param detail: Four detail levels are available:
        default, brief, verbose, and verbose-vars-not-captured.
        C{Failure.printDetailedTraceback} uses the latter when the caller asks
        for verbose, but no vars were captured, so that an explicit warning
        about the missing data is shown.
    @type detail: string
    R	   t   brieft   verboses   verbose-vars-not-capturedsN   Detail must be default, brief, verbose, or verbose-vars-not-captured. (not %r)s	   %s:%s:%s
s     File "%s", line %s, in %s
s       %s
s   %s:%d: %s(...)
sA    [Capture of Locals and Globals disabled (use captureVars=True)]
s    [ Locals ]
s
     %s : %s
s    ( Globals )
N(   s   defaultR
   s   verboses   verbose-vars-not-captured(   t
   ValueErrort	   linecachet   getlinet   stript   repr(   t   framest   writet   detailt   wt   methodt   filenamet   linenot	   localVarst
   globalVarst   namet   val(    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyt   format_frames    s4    	'

s   --- <exception caught here> ---t   NoCurrentExceptionErrorc           B`  s   e  Z d  Z RS(   sŠ   
    Raised when trying to create a Failure from the current interpreter
    exception state and there is no current exception state.
    (   R   R   t   __doc__(    (    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyR   R   s   t
   _Tracebackc           B`  s   e  Z d  Z d „  Z RS(   sq   
    Fake traceback object which can be passed to functions in the standard
    library L{traceback} module.
    c         C`  s”   t  | ƒ d k s t d ƒ ‚ | d | d } } | \ } } } } } t | | ƒ |  _ | |  _ t  | ƒ d k r d |  _ n t | ƒ |  _ d S(   s]  
        Construct a fake traceback object using a list of frames. Note that
        although frames generally include locals and globals, this information
        is not kept by this object, since locals and globals are not used in
        standard tracebacks.

        @param frames: [(methodname, filename, lineno, locals, globals), ...]
        i    s   Must pass some framesi   N(   t   lent   AssertionErrort   _Framet   tb_framet	   tb_linenot   Nonet   tb_nextR   (   t   selfR   t   headR   R   R   t   localzt   globalz(    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyt   __init___   s    		(   R   R   R   R+   (    (    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyR   Y   s   R"   c           B`  s   e  Z d  Z d „  Z RS(   sè   
    A fake frame object, used by L{_Traceback}.

    @ivar f_code: fake L{code<types.CodeType>} object
    @ivar f_globals: fake f_globals dictionary (usually empty)
    @ivar f_locals: fake f_locals dictionary (usually empty)
    c         C`  s(   t  | | ƒ |  _ i  |  _ i  |  _ d S(   s«   
        @param name: method/function name for this frame.
        @type name: C{str}
        @param filename: filename for this frame.
        @type name: C{str}
        N(   t   _Codet   f_codet	   f_globalst   f_locals(   R'   R   R   (    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyR+   |   s    	(   R   R   R   R+   (    (    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyR"   s   s   R,   c           B`  s   e  Z d  Z d „  Z RS(   sB   
    A fake code object, used by L{_Traceback} via L{_Frame}.
    c         C`  s   | |  _  | |  _ d  S(   N(   t   co_namet   co_filename(   R'   R   R   (    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyR+   Œ   s    	(   R   R   R   R+   (    (    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyR,   ˆ   s   t   Failurec           B`  s  e  Z d  Z d Z d Z e e j d ƒ Z	 d d d e
 d „ Z d „  Z d „  Z e rd d „  Z n d d Ud	 e _ d
 „  Z d „  Z e e ƒ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d d „ Z d e
 d d „ Z d d d „ Z d d d „ Z RS(   sì  
    A basic abstraction for an error that has occurred.

    This is necessary because Python's built-in error mechanisms are
    inconvenient for asynchronous communication.

    The C{stack} and C{frame} attributes contain frames.  Each frame is a tuple
    of (funcName, fileName, lineNumber, localsItems, globalsItems), where
    localsItems and globalsItems are the contents of
    C{locals().items()}/C{globals().items()} for that frame, or an empty tuple
    if those details were not captured.

    @ivar value: The exception instance responsible for this failure.
    @ivar type: The exception's class.
    @ivar stack: list of frames, innermost last, excluding C{Failure.__init__}.
    @ivar frames: list of frames, innermost first.
    i    t   YIELD_VALUEc      	   C`  s  t  d a  t  |  _  d |  _ |  _ } | |  _ t | t ƒ rZ | d k rZ t d ƒ ‚ n  d } | d k r{ |  j ƒ  } n  | d k rÆ t	 j
 ƒ  \ |  _ |  _ } |  j d k r½ t ƒ  ‚ n  d } nW | d k rt | t ƒ rð | j |  _ n t | ƒ |  _ | |  _ n | |  _ | |  _ t |  j t ƒ rB|  j j |  _ d S| d k ru| r]| } qut ru|  j j } qun  g  } |  _ g  } |  _ | |  _ | rª| j }	 n t |  j t ƒ sÉd }	 } n  x# | rî|	 rî|	 j }	 | d 8} qÌWxÒ |	 rÃ| r|	 j j ƒ  }
 |	 j |	 j k r(i  } n |	 j j ƒ  } x* | |
 f D] } d | k rD| d =qDqDW|
 j ƒ  }
 | j ƒ  } n
 d }
 } | j d |	 j j |	 j j |	 j |
 | f ƒ |	 j }	 qòWxê | d k	 r°| j }	 | ro|	 j j ƒ  }
 |	 j |	 j k ri  } n |	 j j ƒ  } x* | |
 f D] } d | k r(| d =q(q(Wt  |
 j ƒ  ƒ }
 t  | j ƒ  ƒ } n
 d }
 } | j! |	 j j |	 j j | j" |
 | f ƒ | j# } qÇWt$ j% |  j ƒ rt& |  j t ƒ rt' |  j ƒ } t  t( t) j* | ƒ ƒ |  _+ n |  j g |  _+ d S(   s-  
        Initialize me with an explanation of the error.

        By default, this will use the current C{exception}
        (L{sys.exc_info}()).  However, if you want to specify a
        particular kind of failure, you can pass an exception as an
        argument.

        If no C{exc_value} is passed, then an "original" C{Failure} will
        be searched for. If the current exception handler that this
        C{Failure} is being constructed in is handling an exception
        raised by L{raiseException}, then this C{Failure} will act like
        the original C{Failure}.

        For C{exc_tb} only L{traceback} instances or C{None} are allowed.
        If C{None} is supplied for C{exc_value}, the value of C{exc_tb} is
        ignored, otherwise if C{exc_tb} is C{None}, it will be found from
        execution context (ie, L{sys.exc_info}).

        @param captureVars: if set, capture locals and globals of stack
            frames.  This is pretty slow, and makes no difference unless you
            are going to use L{printDetailedTraceback}.
        i   s$   Strings are not supported by Failurei    Nt   __builtins__(    (    (,   t   countR%   t   typet   valuet   captureVarst
   isinstancet   strt	   TypeErrort   _findFailuret   syst   exc_infoR   t	   Exceptiont	   __class__R2   t   __dict__R   t   __traceback__R   t   stackt   tbR#   t   f_backR/   t   copyR.   t   itemst   insertR-   R0   R1   t   f_linenot   listt   appendR$   R&   t   inspectt   isclasst
   issubclassR   t   mapt   reflectt   qualt   parents(   R'   t	   exc_valuet   exc_typet   exc_tbR8   RD   t   stackOffsetR   RC   t   fR)   R*   t   dt   parentCs(    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyR+   ¬   s¤    
								
		
			
		
		
$c         G`  s5   |  j  | Œ  } | s1 t r( |  j ƒ  q1 |  ‚ n  | S(   st  Trap this failure if its type is in a predetermined list.

        This allows you to trap a Failure in an error callback.  It will be
        automatically re-raised if it is not a type that you expect.

        The reason for having this particular API is because it's very useful
        in Deferred errback chains::

            def _ebFoo(self, failure):
                r = failure.trap(Spam, Eggs)
                print 'The Failure is due to either Spam or Eggs!'
                if r == Spam:
                    print 'Spam did it!'
                elif r == Eggs:
                    print 'Eggs did it!'

        If the failure is not a Spam or an Eggs, then the Failure will be
        'passed on' to the next errback. In Python 2 the Failure will be
        raised; in Python 3 the underlying exception will be re-raised.

        @type errorTypes: L{Exception}
        (   t   checkR   t   raiseException(   R'   t
   errorTypest   error(    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyt   trap<  s    	c         G`  s^   xW | D]O } | } t  j | ƒ rC t | t ƒ rC t j | ƒ } n  | |  j k r | Sq Wd S(   sú   Check if this failure's type is in a predetermined list.

        @type errorTypes: list of L{Exception} classes or
                          fully-qualified class names.
        @returns: the matching L{Exception} type, or None if no match.
        N(   RL   RM   RN   R?   RP   RQ   RR   R%   (   R'   R\   R]   t   err(    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyRZ   [  s    c         C`  s   |  j  j |  j ƒ ‚ d  S(   N(   R7   t   with_tracebackRD   (   R'   (    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyR[   o  s    sB   def raiseException(self):
    raise self.type, self.value, self.tbNsf   
        raise the original exception, preserving traceback
        information if available.
        c         C`  s   | j  |  j |  j |  j ƒ S(   sJ  
        Throw the original exception into the given generator,
        preserving traceback information if available.

        @return: The next value yielded from the generator.
        @raise StopIteration: If there are no more values in the generator.
        @raise anything else: Anything that the generator raises.
        (   t   throwR6   R7   RD   (   R'   t   g(    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyt   throwExceptionIntoGenerator|  s    	c         C`  s  t  j ƒ  d } | s d Sd } | } x | j rD | } | j } q) W| j } | j |  j j k rs | j j	 d ƒ S| j j
 sœ | j j
 | j |  j k r  d S| r× | j } | j |  j j k r× | j j	 d ƒ Sn  | j j } | r| j |  j j k r| j j	 d ƒ Sd S(   sV   
        Find the failure that represents the exception currently in context.
        iÿÿÿÿNR'   (   R=   R>   R%   R&   R#   R-   R[   t   __code__R/   t   gett   co_codet   tb_lastit   _yieldOpcodeRc   RE   (   t   clsRD   t   secondLastTbt   lastTbt	   lastFramet   frame(    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyR<   ˆ  s*    			c         C`  s   d |  j  |  j f S(   Ns   <%s %s>(   R@   R6   (   R'   (    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyt   __repr__Â  s    c         C`  s   d |  j  ƒ  S(   Ns   [Failure instance: %s](   t   getBriefTraceback(   R'   (    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyt   __str__Å  s    c      	   C`  sç   |  j  r |  j S|  j j ƒ  } g  |  j D]; } | d | d | d t | d ƒ t | d ƒ g ^ q) | d <d
 | d <|  j d
 k	 rÙ g  |  j D]; } | d | d | d t | d ƒ t | d ƒ g ^ q‘ | d <n  d | d	 <| S(   s1   Avoid pickling objects in the traceback.
        i    i   i   i   i   R   RD   RC   t   pickledN(   Rq   RA   RF   R   t   _safeReprVarsR%   RC   (   R'   t   ct   v(    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyt   __getstate__È  s    	L
O
c         C`  s(   |  j  ƒ  |  _ t r$ d |  j _ n  d S(   sÈ   
        Remove references to other objects, replacing them with strings.

        On Python 3, this will also set the C{__traceback__} attribute of the
        exception instance to C{None}.
        N(   Ru   RA   R   R%   R7   RB   (   R'   (    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyt   cleanFailureé  s    c         C`  s@   |  j  d k	 r |  j  St |  j ƒ d k r8 t |  j ƒ Sd Sd S(   s‘  
        Get an object that represents this Failure's stack that can be passed
        to traceback.extract_tb.

        If the original traceback object is still present, return that. If this
        traceback object has been lost but we still have the information,
        return a fake traceback object (see L{_Traceback}). If there is no
        traceback information at all, return None.
        i    N(   RD   R%   R    R   R   (   R'   (    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyt   getTracebackObjectõ  s
    
c         C`  s/   t  |  j t ƒ r |  j j ƒ  St j |  j ƒ S(   s8   Get a string of the exception which caused this Failure.(   R9   R7   R2   t   getErrorMessageRP   t   safe_str(   R'   (    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyRx     s    c         C`  s#   t  ƒ  } |  j d | ƒ | j ƒ  S(   Nt   file(   t   StringIOt   printBriefTracebackt   getvalue(   R'   t   io(    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyRo     s    	R	   c         C`  s/   t  ƒ  } |  j d | d | d | ƒ | j ƒ  S(   NRz   t   elideFrameworkCodeR   (   R{   t   printTracebackR}   (   R'   R   R   R~   (    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyt   getTraceback  s    	c         C`  sì  | d k r( d d l m } | j } n  | j } | d k rP |  j rP d } n | } | d k r‹ | d |  j |  j r} d p€ d f ƒ n` | d k rá |  j r© d	 } n d
 } | d | t	 j
 |  j ƒ t	 j
 |  j ƒ f ƒ n
 | d ƒ |  j r<| s&t |  j t | | ƒ | d t f ƒ n  t |  j | | ƒ n | d k sU| d ƒ n  | d k s| d t	 j |  j ƒ t	 j
 |  j ƒ f ƒ n  t |  j t ƒ rÈ| j d ƒ |  j j | | | ƒ n  | d k rè| d |  j ƒ n  d S(   s  
        Emulate Python's standard error reporting mechanism.

        @param file: If specified, a file-like object to which to write the
            traceback.

        @param elideFrameworkCode: A flag indicating whether to attempt to
            remove uninteresting frames from within Twisted itself from the
            output.

        @param detail: A string indicating how much information to include
            in the traceback.  Must be one of C{'brief'}, C{'default'}, or
            C{'verbose'}.
        i    (   t   logR   s   verbose-vars-not-captureds   *--- Failure #%d%s---
s    (pickled) t    R
   t	   Tracebacks"   Traceback (failure with no frames)s   %s: %s: %s
s#   Traceback (most recent call last):
s   %s
s	   Failure: s   %s: %s
s    (chained Failure)
s   *--- End of Failure #%d ---
N(   R%   t   twisted.pythonR‚   t   logerrR   R8   R5   Rq   R   RP   Ry   R6   R7   R   RC   t   traceupLengtht   EXCEPTION_CAUGHT_HERERQ   R9   R2   R€   (   R'   Rz   R   R   R‚   R   t   formatDetailt	   hasFrames(    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyR€     sF    				
	c         C`  s   |  j  | | d d ƒd S(   s2   Print a traceback as densely as possible.
        R   R
   N(   R€   (   R'   Rz   R   (    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyR|   \  s    c         C`  s   |  j  | | d d ƒd S(   sH   Print a traceback with detailed locals and globals information.
        R   R   N(   R€   (   R'   Rz   R   (    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyt   printDetailedTracebacka  s    (   R   R   R   Rq   R%   RC   t   chrt   opcodet   opmapRh   t   FalseR+   R^   RZ   R   R[   Rc   R<   t   classmethodRn   Rp   Ru   Rv   Rw   Rx   Ro   R   R€   R|   R‹   (    (    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyR2   ‘   s4   						8			!				Ec         C`  s,   g  |  D]! \ } } | t  j | ƒ f ^ q S(   sq  
    Convert a list of (name, object) pairs into (name, repr) pairs.

    L{twisted.python.reflect.safe_repr} is used to generate the repr, so no
    exceptions will be raised by faulty C{__repr__} methods.

    @param varsDictItems: a sequence of (name, value) pairs as returned by e.g.
        C{locals().items()}.
    @returns: a sequence of (name, repr) pairs.
    (   RP   t	   safe_repr(   t   varsDictItemsR   t   obj(    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyRr   g  s    c   	      C`  s¨   | | | f d k rŽ t j ƒ  } | d |  j k rŽ t rŽ y t | d ƒ } Wn d } n Xd | f GHd d l } | j | d ƒ qŽ n  | |  | | | | ƒ d S(   s;   
    Initialize failure object, possibly spawning pdb.
    i    i   s
   broken strs8   Jumping into debugger for post-mortem of exception '%s':Ni   (   NNN(   R%   R=   R>   R@   t   DO_POST_MORTEMR:   t   pdbt   post_mortem(	   R'   RS   RT   RU   R8   t   Failure__init__t   exct   strreprR•   (    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyt
   _debuginity  s    
c           C`  s   t  t _ d S(   s    Enable debug hooks for Failures.N(   Rš   R2   R+   (    (    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyt   startDebugModeŒ  s    ($   R   t
   __future__R    R   R=   R   RL   R   R   t   twisted.python.compatR   R   R{   R…   R   RP   R5   R‡   R?   R   R   Rˆ   R   t   objectR   R"   R,   R2   Rr   t   TrueR”   R%   R   R+   Rš   R›   (    (    (    sH   /var/www/html/hlstest/hls-proxy/Twisted-13.2.0/twisted/python/failure.pyt   <module>   s2   .	ÿ ×		