³ò
Ñ‘RMc           @   sD  d  d k  Z  d  d k Z d  d k l Z d  d k l Z d  d k l Z e  i d ƒ Z	 e
 Z d e f d „  ƒ  YZ h  Z h  Z d „  Z d	 „  Z d
 „  Z d e _ d „  Z d e _ d  d k l Z d e
 d „ Z y e Wn e j
 o e Z n Xe
 Z d d „ Z d d d d „ Z d e _ d d d d „ Z d e _ d S(   iÿÿÿÿN(   t   we_are_translated(   t   jit(   t   EINTRt
   PYPY_DEBUGt   OperationErrorc           B   s¼   e  Z d  Z d Z d Z d d „ Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z e d „ Z d „  Z d d	 „ Z d
 „  Z d d d „ Z e i d „  ƒ Z d d „ Z d „  Z d „  Z RS(   sƒ  Interpreter-level exception that signals an exception that should be
    sent to the application level.

    OperationError instances have three public attributes (and no .args),
    w_type, w_value and application_traceback, which contain the wrapped
    type and value describing the exception, and a chained list of
    PyTraceback objects making the application-level traceback.
    c         C   s[   t  ƒ  o- | d  j o  d d k l } | | ƒ ‚ n |  i | ƒ | |  _ | |  _ d  S(   Niÿÿÿÿ(   t   FlowingError(   R    t   Nonet   pypy.tool.errorR   t   setupt   _w_valuet   application_traceback(   t   selft   w_typet   w_valuet   tbR   (    (    s*   /64/home/arigo/u/pypy/interpreter/error.pyt   __init__   s    	c         C   s$   | |  _  t ƒ  p g  |  _ n d  S(   N(   R   R    t
   debug_excs(   R   R   (    (    s*   /64/home/arigo/u/pypy/interpreter/error.pyR      s    	
c         C   s:   | i  |  _ | i  |  _ d  |  _ t ƒ  p |  i 2n d  S(   N(   t   w_NoneR   R	   R   R
   R    R   (   R   t   space(    (    s*   /64/home/arigo/u/pypy/interpreter/error.pyt   clear$   s
    	
c         C   s   | i  |  i | ƒ S(   sB   Check if this application-level exception matches 'w_check_class'.(   t   exception_matchR   (   R   R   t   w_check_class(    (    s*   /64/home/arigo/u/pypy/interpreter/error.pyt   match,   s    c         C   s)   |  i  | | i ƒ p |  i  | | i ƒ S(   s?   Check if this is an exception that should better not be caught.(   R   t   w_SystemExitt   w_KeyboardInterrupt(   R   R   (    (    s*   /64/home/arigo/u/pypy/interpreter/error.pyt   async0   s    c         C   sG   |  i  } |  i t j	 o | d j o |  i ƒ  } n d |  i | f S(   s(   NOT_RPYTHON: Convenience for tracebacks.s   [%s: %s]N(   R	   t	   __class__R   R   t   _compute_valueR   (   R   t   s(    (    s*   /64/home/arigo/u/pypy/interpreter/error.pyt   __str__5   s    	c         C   s<  |  i  | ƒ } | d j o t |  i ƒ } t | ƒ } ná | i } | i | i |  i ƒ | i ƒ o | i |  i ƒ } n% | i | i	 |  i | d ƒ ƒ ƒ } | i | | i
 ƒ o
 d } n\ y? | o | i | i | ƒ ƒ } n | i | i | ƒ ƒ } Wn t j
 o d } n X| p | Sn d | | f Sd S(   s+   The exception class and value, as a string.t   __name__t    s/   <oups, exception object itself cannot be str'd>s   %s: %sN(   t   get_w_valueR   t   strR   t   wrapt   is_wt   typet   w_strt   str_wt   getattrR   t   reprR   (   R   R   t   use_reprR   t   exc_typenamet	   exc_valuet   w(    (    s*   /64/home/arigo/u/pypy/interpreter/error.pyt   errorstr<   s(    	"
c         C   s3   t  ƒ  p% t o |  i i t i ƒ  ƒ q/ n d S(   s’   Records the current traceback inside the interpreter.
        This traceback is only useful to debug the interpreter, not the
        application.N(   R    t   RECORD_INTERPLEVEL_TRACEBACKR   t   appendt   syst   exc_info(   R   (    (    s*   /64/home/arigo/u/pypy/interpreter/error.pyt   record_interpreter_tracebackZ   s    
c         C   s>   | d j o t i } n |  i | ƒ | |  i | ƒ IJd S(   s9   NOT_RPYTHON: Dump a standard application-level traceback.N(   R   R0   t   stderrt   print_app_tb_onlyR-   (   R   R   t   file(    (    s*   /64/home/arigo/u/pypy/interpreter/error.pyt   print_application_tracebackb   s     c   	      C   sL  |  i  } | o8d d k } | d IJx| d j	 o| i i } | i ƒ  } | i } | i d ƒ oM | i d ƒ } | d i	 ƒ  } y | | } WqÆ t
 j
 o d } qÆ Xn | i | | ƒ } | d | I| d	 I| Id
 I| i IJ| o< | i d ƒ o | d  } n d | i ƒ  } | | IJn | i } q) Wn d S(   t   NOT_RPYTHONiÿÿÿÿNs   Traceback (application-level):s	   <inline>
s   
i    R   s     File "%s",t   linet   ins       (   R
   t	   linecacheR   t   framet   pycodet
   get_linenot   co_filenamet
   startswitht   splitt   stript
   IndexErrort   getlinet   co_namet   endswitht   lstript   next(	   R   R5   R   R:   t   cot   linenot   fnamet   linest   l(    (    s*   /64/home/arigo/u/pypy/interpreter/error.pyR4   h   s2    	
 	c         C   sX  d d k  } d d k } | d j o t i } n | i ƒ  } xO t t |  i ƒ d d d ƒ D]. } | d IJ| i	 |  i | d d | ƒq^ W| i
 d ƒ t d i g  } | i ƒ  D] } | d	 | q· ~ ƒ | ƒ |  i o( d d
 k l }	 |	 i |  i d ƒ n |  i | ƒ | d I|  i | ƒ IJt o d d k }
 |
 i |  ƒ n d S(   sx   NOT_RPYTHON: Dump a nice detailed interpreter- and
        application-level traceback, useful to debug the interpreter.iÿÿÿÿNi   s   Traceback (interpreter-level):i   R5   i    R   s   || (   t	   tb_servers   (application-level)(   t	   tracebackt	   cStringIOR   R0   R3   t   StringIOt   ranget   lenR   t   print_tbt   seekt   debug_printt   joint	   readlinest	   pypy.toolRM   t   publish_excR4   R-   t
   AUTO_DEBUGt   debugt   fire(   R   R   R5   RN   RO   t   ft   it   _[1]R8   RM   R[   (    (    s*   /64/home/arigo/u/pypy/interpreter/error.pyt   print_detailed_traceback„   s$       
";
c   	      C   sê  |  i  } |  i | ƒ } | i oF xC | i | i | | i ƒ ƒ o | i | | i d ƒ ƒ } q% Wn | i | ƒ oÈ | i	 | | i
 ƒ o" | i | ƒ } | i | ƒ } qÔ| i | ƒ } | i | | ƒ o
 | } qÔ| i o5 | i | i | | i ƒ ƒ o | i | | ƒ } n | i | | ƒ } | i | ƒ } n• | } | i | ƒ } | i | ƒ p. | i | ƒ } d } t | i | | ƒ ‚ n | i	 | | i
 ƒ p t | i | i d ƒ ƒ ‚ n | } | } | |  _  | |  _ d S(   s—   Normalize the OperationError.  In other words, fix w_type and/or
        w_value to make sure that the __class__ of w_value is exactly w_type.
        i    sJ   exceptions must be old-style classes or derived from BaseException, not %ss0   instance exception may not have a separate valueN(   R   R    t   full_exceptionst   is_truet
   isinstancet   w_tuplet   getitemR"   t!   exception_is_valid_obj_as_class_wR#   R   t   call_functiont   exception_getclasst   exception_issubclass_wt   callt   exception_is_valid_class_wt   getnamet   operationerrfmtt   w_TypeErrorR   R	   (	   R   R   R   R   t   w_valuetypet   w_instt   w_instclasst   instclassnamet   msg(    (    s*   /64/home/arigo/u/pypy/interpreter/error.pyt   normalize_exception˜   s>    	
 $
		c         C   s·   | d  j o
 d } n9 y | i | i | ƒ ƒ } Wn t j
 o d } n Xd |  i | d t ƒ| | f } y, | i | i i d ƒ d | i	 | ƒ ƒ Wn t j
 o n Xd  S(   NR   t   ?s   Exception %s in %s%s ignored
R)   R3   t   write(
   R   R&   R(   R   R-   t   Truet   call_methodR0   t   getR"   (   R   R   t   wheret   w_objectt   objreprRs   (    (    s*   /64/home/arigo/u/pypy/interpreter/error.pyt   write_unraisableå   s    
,c         C   s@   |  i  } | d  j o& |  i ƒ  } | i | ƒ |  _  } n | S(   N(   R	   R   R   R"   (   R   R   R   t   value(    (    s*   /64/home/arigo/u/pypy/interpreter/error.pyR    ô   s
    	c         C   s
   t  ‚ d  S(   N(   t   NotImplementedError(   R   (    (    s*   /64/home/arigo/u/pypy/interpreter/error.pyR   û   s    N(   R   t
   __module__t   __doc__R   R	   R
   R   R   R   R   R   R   t   FalseR-   R2   R6   R4   R`   R   t   unroll_safeRt   R}   R    R   (    (    (    s*   /64/home/arigo/u/pypy/interpreter/error.pyR   
   s$   							M	c         C   s  g  } |  i  d ƒ } d } xÄ | t | ƒ j  o° | | i d ƒ p | | i d ƒ o5 | i | | d ƒ | | d | | <| d 7} q | | d j o2 | | d c d | | d 7<| | | d 5q t d ƒ ‚ q Wt | ƒ d j p
 t d	 ‚ t | ƒ t | ƒ f S(
   s^   Returns a tuple of string parts extracted from valuefmt,
    and a tuple of format characters.t   %i   R   t   di    R   i   s/   invalid format string (only %s or %d supported)s   unsupported: no % command found(   R@   RR   R?   R/   t
   ValueErrort   AssertionErrort   tuple(   t   valuefmtt   formatst   partsR^   (    (    s*   /64/home/arigo/u/pypy/interpreter/error.pyt   decompose_valuefmt  s     ( c            sà   t  |  ƒ \ } ‰  t | ƒ t ˆ  ƒ d j p t ‚ y t ˆ  } Wn t j
 oƒ d d k l } g  } t t ˆ  ƒ ƒ D] } | d | q| ~ } | t | ƒ ƒ ‰ d t	 f ‡ ‡  f d †  ƒ  Y} | t ˆ  <n X| | f S(   Ni   iÿÿÿÿ(   t   unrolling_iterables   x%dt   OpErrFmtc              s)   e  Z ‡  f d  †  Z ‡  ‡ f d †  Z RS(   c            s§   |  i  | ƒ t | ƒ t | ƒ d j p t ‚ | |  _ x( ˆ  D]  \ } } t |  | | | ƒ qA Wt ƒ  o3 | d  j o& d d k l } | |  i	 ƒ  ƒ ‚ n d  S(   Ni   iÿÿÿÿ(   R   (
   R   RR   R‡   t   xstringst   setattrR    R   R   R   R   (   R   R   t   stringst   argsR^   t   attrR   (   t   entries(    s*   /64/home/arigo/u/pypy/interpreter/error.pyR   $  s    $	 c            s˜   d  g t ˆ ƒ t ˆ ƒ d } xV ˆ  D]N \ } } |  i | } t |  | ƒ } | | | | <t | ƒ | | | d <q( W|  i d | d <d i | ƒ S(   Ni   iÿÿÿÿR   (   R   RR   R   R'   R!   RV   (   R   t   lstR^   R“   t   stringR~   (   R”   RŠ   (    s*   /64/home/arigo/u/pypy/interpreter/error.pyR   -  s    ! (   R   R€   R   R   (    (   R”   RŠ   (    s*   /64/home/arigo/u/pypy/interpreter/error.pyRŽ   #  s   	(
   RŒ   RR   R‡   t
   _fmtcache2t   KeyErrort   pypy.rlib.unrollR   RQ   t	   enumerateR   (   R‰   R‘   RŽ   R   R_   R^   t   attrs(    (   RŠ   R”   s*   /64/home/arigo/u/pypy/interpreter/error.pyt   get_operrcls2  s    $1c         C   s<   y t  |  } Wn' t j
 o t |  ƒ } t  |  <n X| S(   N(   t	   _fmtcacheR˜   Rœ   (   R‰   t   result(    (    s*   /64/home/arigo/u/pypy/interpreter/error.pyt   get_operationerr_class:  s
    s   specialize:memoc         G   s"   t  | ƒ \ } } | |  | | Œ S(   s–   Equivalent to OperationError(w_type, space.wrap(valuefmt % args)).
    More efficient in the (common) case where the value is not actually
    needed.(   RŸ   (   R   R‰   R’   RŽ   R‘   (    (    s*   /64/home/arigo/u/pypy/interpreter/error.pyRm   B  s    s   specialize:arg(1)(   t
   ansi_printc         C   s    t  |  d d d | d | ƒd  S(   Nt   esct   31R5   t   newline(   R    (   t   textR5   R£   (    (    s*   /64/home/arigo/u/pypy/interpreter/error.pyRU   O  s    c      	   C   sÄ   d d k  l } | i } y | i | ƒ } Wn t j
 o d | } n X|  i } | d  j	 o. |  i | |  i | ƒ |  i | ƒ | ƒ } n( |  i | |  i | ƒ |  i | ƒ ƒ } t	 | | ƒ S(   Niÿÿÿÿ(   t   rwin32s   Windows Error %d(
   t	   pypy.rlibR¥   t   winerrort   FormatErrorR†   t   w_WindowsErrorR   Rg   R"   R   (   R   t   et
   w_filenameR¥   R§   Rs   t   exct   w_error(    (    s*   /64/home/arigo/u/pypy/interpreter/error.pyt   wrap_windowserrorZ  s    		t	   w_OSErrorc   	      C   s4  t  | t ƒ p t ‚ t o$ t  | t ƒ o t |  | | ƒ Sn | i } | t j o |  i ƒ  i	 ƒ  n y t
 i | ƒ } Wn t j
 o d | } n X| d  j o t |  | ƒ } n | } | d  j	 o. |  i | |  i | ƒ |  i | ƒ | ƒ } n( |  i | |  i | ƒ |  i | ƒ ƒ } t | | ƒ S(   Ns   error %d(   Rc   t   OSErrorR‡   t   _WINDOWSt   WindowsErrorR®   t   errnoR   t   getexecutioncontextt   checksignalst   ost   strerrorR†   R   R'   Rg   R"   R   (	   R   Rª   R«   t   exception_namet   w_exception_classR³   Rs   R¬   R­   (    (    s*   /64/home/arigo/u/pypy/interpreter/error.pyt   wrap_oserror2k  s&    	s   specialize:arg(3)c         C   sV   | d  j	 o) t |  | |  i | ƒ d | d | ƒSn t |  | d  d | d | ƒSd  S(   NR¸   R¹   (   R   Rº   R"   (   R   Rª   t   filenameR¸   R¹   (    (    s*   /64/home/arigo/u/pypy/interpreter/error.pyt   wrap_oserrorˆ  s    (    R¶   R0   t   pypy.rlib.objectmodelR    R¦   R   R³   R   t   getenvRZ   Rw   R.   t	   ExceptionR   R   R—   RŒ   Rœ   RŸ   t   _annspecialcase_Rm   t   pypy.tool.ansi_printR    R   RU   R²   t	   NameErrorR‚   R±   R®   Rº   R¼   (    (    (    s*   /64/home/arigo/u/pypy/interpreter/error.pys   <module>   s8   ù		!						
