ó
î–+[c           @   s4  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 d d l
 Z
 y e j Z Wn e k
 r§ e j Z n Xe j d d k Z d Z d „  Z e d „ Z d	 „  Z d
 „  Z d d d „ Z d d „ Z d „  Z d d d „ Z d d d e d „ Z d S(   s"  
Represent an exception with a lot of information.

Provides 2 useful functions:

format_exc: format an exception into a complete traceback, with full
            debugging instruction.

format_outer_frames: format the current position in the stack call.

Adapted from IPython's VerboseTB.
iÿÿÿÿNi    t   3t    i   c         C   sÊ   y t  j j |  ƒ SWn¯ t k
 r* ‚  nœ y t |  ƒ SWqÆ t k
 rQ ‚  qÆ yL t |  d d ƒ } | ry t | ƒ St |  d d ƒ } | rŸ d t | ƒ SWqÂ t k
 r¶ ‚  qÂ d SXqÆ Xn Xd S(   s(   Hopefully pretty robust repr equivalent.t   __name__t	   __class__s   %s instances   UNRECOVERABLE REPR FAILUREN(   t   pydoct   textt   reprt   KeyboardInterruptt   getattrt   Nonet	   safe_repr(   t   valuet   namet   klass(    (    s[   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/format_stack.pyR
   +   s*    
c         C   s   d | |  ƒ S(   Ns   =%s(    (   R   R   (    (    s[   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/format_stack.pyt   eq_reprH   s    c         C   sM   g  } t  ƒ  } x7 |  D]/ } | | k r | j | ƒ | j | ƒ q q W| S(   s™  uniq_stable(elems) -> list

    Return from an iterable, a list of all the unique elements in the input,
    but maintaining the order in which they first appear.

    A naive solution to this problem which just makes a dictionary with the
    elements as keys fails to respect the stability condition, since
    dictionaries are unsorted by nature.

    Note: All elements in the input must be hashable.
    (   t   sett   appendt   add(   t   elemst   uniquet
   unique_sett   nn(    (    s[   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/format_stack.pyt   uniq_stableM   s    	c   	      C   sy   g  } xl |  D]d \ } } } } } } | j  j d d ƒ } t | t ƒ rR | } n  | j | | | | | | f ƒ q W| S(   sè   Try to fix the filenames in each record from inspect.getinnerframes().

    Particularly, modules loaded from within zip files have useless filenames
    attached to their code object, and inspect.getinnerframes() just uses it.
    t   __file__N(   t	   f_globalst   getR	   t
   isinstancet   strR   (	   t   recordst   fixed_recordst   framet   filenamet   line_not	   func_namet   linest   indext	   better_fn(    (    s[   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/format_stack.pyt   fix_frame_records_filenamesc   s    	i   c         C   s¬  d	 \ } } } t  t j |  | ƒ ƒ } | | } y1 | d d } | d k s] | j d ƒ ra | SWn t k
 ru n Xt j |  ƒ }	 t | ƒ t |	 ƒ k s£ t ‚ xþ t	 |	 ƒ D]ð \ }
 \ } } } } | d | d } t
 | d ƒ } | | } t j | ƒ | | !} | d k  r*d g | | } n  t | ƒ | k  rZ| d g | t | ƒ 7} n  t | |
 ƒ } | | | <| d | | | <| | | <t | ƒ | |
 <q° W| | S(
   Ni   i   i   i    i   s   <ipython console>s   <string>s   
(   i   i   i   (   R%   t   inspectt   getinnerframest   endswitht
   IndexErrort	   tracebackt
   extract_tbt   lent   AssertionErrort	   enumeratet   maxt	   linecachet   getlinest   listt   tuple(   t   etbt   contextt	   tb_offsett   LNUM_POSt	   LINES_POSt	   INDEX_POSR   t	   rec_checkt   rnamet   auxt   it   filet   lnumt   _t
   maybeStartt   startt   endR"   t   buf(    (    s[   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/format_stack.pyt   _fixed_getframesx   s4    
%


c         C   s  d } g  } |  | } xñ | D]é } | |  k r© | t  t | ƒ ƒ } | d k rf d | d d }	 n0 | d k r{ d }	 n | d k r d }	 n d	 }	 |	 t | ƒ }
 n d
 | | f }
 d |
 | f } | j | ƒ | rü | |  k rü | j | d ƒ n  | d } q W| S(   Ni   i   t   -s   -> i   s   > i   t   >t    s   %*ss   %s %ss   
(   R,   R   R   (   R?   R#   R"   t   lvalst   numbers_widtht   resR=   t   linet   padt   markert   num(    (    s[   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/format_stack.pyt   _format_traceback_linesœ   s*    
		c            sÚ  g  } t  j j } xÁ|  D]¹\ } } } } } } y | rF | | ƒ pI d } Wn t k
 r` n X| }	 y t j | ƒ \ }
 } } } Wn d GHn X| d k rª d } nO y, d | t j |
 | | | d t ƒf } Wn  t k
 rø d GHd | } n Xg  ‰  ‡  ‡ f d †  ‰ t	 ˆ _
 | | g t j d „ } y% x t | ƒ D] } ˆ | Œ  qBWWn; t t f k
 rpn% t j k
 r”} d	 | } | GHn Xt ˆ  ƒ } g  } xš | D]’ } | j d
 d ƒ d } | | j j k r®| | j ƒ  k ry t t | | ƒ ƒ } Wq d } q Xn d } | } | j d | | f ƒ q®q®W| rjd t d t j | ƒ f } n d } d d d
 |	 | f } | d  k r£| j | ƒ q | j d | d j t | | | | ƒ ƒ f ƒ q W| S(   Nt   ?s+   
Joblib's exception reporting continues...
RH   s   in %s%st   formatvalues'   in %s(***failed resolving arguments***)c            s³   | d k rD y! ˆ  d c d 7<t  ˆ _ d SWqD t k
 r@ qD Xn  |  t j k r— | t j k r— ˆ j r‡ ˆ  d c | 7<t ˆ _ q¯ ˆ  j | ƒ n |  t j	 k r¯ t ‚ n  d S(   s”  Stateful tokeneater which builds dotted names.

            The list of names it appends to (from the enclosing scope) can
            contain repeated composite names.  This is unavoidable, since
            there is no way to disambguate partial dotted structures until
            the full list is known.  The caller is responsible for pruning
            the final list of duplicates before using it.t   .iÿÿÿÿN(
   t   Truet	   name_contR)   t   tokenizet   NAMEt   keywordt   kwlistt   FalseR   t   NEWLINE(   t
   token_typet   tokenRB   RC   RL   (   t   namest
   tokeneater(    s[   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/format_stack.pyR_   æ   s    
		c         S   s'   | |  | d ƒ } | d c d 7<| S(   Ni    i   (    (   R>   R?   t   getlineRL   (    (    s[   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/format_stack.pyt
   linereader  s    s   An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: %s
RS   i   i    t	   undefineds   %s = %ss   %s%ss   
%ss	   %s
%s %s
iK   (   t   ost   patht   abspatht   OSErrorR&   t   getargvaluest   formatargvaluesR   t   KeyErrorRZ   RU   R0   R`   t   generate_tokensR)   t   UnicodeDecodeErrorRV   t
   TokenErrorR   t   splitt   f_codet   co_varnamest   keysR   t   evalR   t   INDENTt   joinR	   RP   (   R   t   framesRe   R   R>   R?   t   funcR"   R#   t   linkt   argst   varargst   varkwt   localst   callRa   R]   t   msgt   _mt   unique_namesRI   t	   name_fullt	   name_baseR   R   t   level(    (   R^   R_   s[   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/format_stack.pyt   format_records¹   sp    		#		 !i   c      
   C   s|  y |  j  }  Wn t k
 r  n Xd t j j ƒ  d d t j } t j t j ƒ  ƒ } d t j	 ƒ  } d |  d d t
 t |  ƒ ƒ t
 | ƒ | | d d t
 t | ƒ ƒ t
 | ƒ | f } t j ƒ  y t | | | ƒ }	 Wn ‚  d d	 GHd
 SXy t t |  | f ƒ \ }
 } Wn9 t t j ƒ  d  }  } t t |  | f ƒ \ }
 } n Xd |
 | f g } t rIt | ƒ t j k rIy2 g  t | ƒ D] } t | t ƒ r‘| ^ q‘} WnP | j d ƒ t t t j ƒ  d  ƒ \ }
 } | j d |
 | f ƒ g  } n Xx@ | D]5 } t t | | ƒ ƒ } | j d t | | f ƒ qWn  t |	 ƒ } d | d j | ƒ d
 j | d ƒ f S(   s   Return a nice text document describing the traceback.

        Parameters
        -----------
        etype, evalue, etb: as returned by sys.exc_info
        context: number of lines of the source file to plot
        tb_offset: the number of stack frame not to use (0 = use all)

    s   Python i    s   : s   PID: %is   %s%s%s
%s%s%sR   iK   s3   
Unfortunately, your original traceback can not be s   constructed.
RH   i   s   %s: %ss5   Exception reporting error (object with broken dir()):s
   
%s%s = %ss   %s
%s
%ss   
(   R   t   AttributeErrort   syst   versionRm   t
   executablet   timet   ctimeRc   t   getpidR,   R   R0   t
   checkcacheRE   t   mapt   exc_infot   PY3t   typet   typest   InstanceTypet   dirR   t
   basestringR   R
   R   Rr   R‚   Rs   (   t   etypet   evalueR4   R5   R6   t   pyvert   datet   pidt   headR   t	   etype_strt
   evalue_strt	   exceptiont   wR^   R   R   Rt   (    (    s[   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/format_stack.pyt
   format_excL  sL    "''

2
!c         C   sÕ  d \ } } } t  j t  j ƒ  ƒ } t ƒ  } x…t | ƒ D]w\ }	 \ }
 } } } } } |
 j j d d  ƒ } t | t	 ƒ r¥ | } | j
 d ƒ r¥ | d  d } q¥ n  | rÖ t j j | ƒ d k rÖ | d k rÖ PqÖ n  | d |  d } t | d ƒ } | |  } t j | ƒ | | !} | d k  r8d g | | } n  t | ƒ |  k  rh| d g |  t | ƒ 7} n  t | |	 ƒ } | | | <| d | | | <| | | <| j t | ƒ ƒ q: Wd j t | | | d … ƒ ƒ S(   Ni   i   i   R   s   .pyciüÿÿÿs   .pys   iplib.pyt   safe_execfilet   runcodei   i    s   
iÿÿÿÿ(   i   i   i   (   Rž   RŸ   (   R&   t   getouterframest   currentframeR2   R.   R   R   R	   R   R   R(   Rc   Rd   t   basenameR/   R0   R1   R,   R   R3   Rs   R‚   (   R5   t   stack_startt	   stack_endt   ignore_ipythonR7   R8   R9   R   t   outputR=   R   R   R    R!   R"   R#   R$   RA   RB   RC   RD   (    (    s[   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/format_stack.pyt   format_outer_frames  s8    	(


s           (   t   __doc__R&   RX   R0   Rc   R   R„   R‡   RV   R*   R   Rj   Rƒ   R…   R   Rr   R
   R   R   R%   RE   R	   RP   R‚   R   RT   R§   (    (    (    s[   /home/psgendb/BIRCHDEV/install/quast-5.2.0/quast_libs/site_packages/joblib2/format_stack.pyt   <module>   s4   
			$	“D	