???<!-- GIF89;a -->
123123123123
.....................................................................................................................................???<!-- GIF89;a -->
123123123123
.....................................................................................................................................ó
¿öYc           @`  sý   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 Z d d l	 m
 Z
 d d l m Z e j d ƒ Z d d d „ Z d d „ Z d	 „  Z d
 „  Z d d „ Z e
 d d „ Z d d „ Z d d „ Z e
 e d d „ Z d S(   s©   
raven.utils.stacks
~~~~~~~~~~~~~~~~~~~~~~~~~~

:copyright: (c) 2010-2012 by the Sentry Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
i    (   t   absolute_importt   divisionN(   t	   transform(   t	   iteritemss   coding[:=]\s*([-\w.]+)c         C`  sŠ  d } | d k	 rr t | d ƒ rr y | j | ƒ } Wn t t f k
 rS d } n X| d k	 rr | j ƒ  } qr n  | d k r¯ y t j |  ƒ } Wq¯ t t f k
 r« d SXn  | s¹ d St	 d | | ƒ } t
 | d | t | ƒ ƒ } ym g  | | | !D] } | j d ƒ ^ qú }	 | | j d ƒ }
 g  | | d | !D] } | j d ƒ ^ q:} Wn t k
 rjd SXt |	 ƒ t |
 ƒ t | ƒ f S(	   s   
    Returns context_lines before and after lineno from file.
    Returns (pre_context_lineno, pre_context, context_line, post_context).
    t
   get_sourcei    i   s   
N(   NNN(   NNN(   NNN(   t   Nonet   hasattrR   t   ImportErrort   IOErrort
   splitlinest	   linecachet   getlinest   OSErrort   maxt   mint   lent   stript
   IndexErrort   slim_string(   t   filenamet   linenot   context_linest   loadert   module_namet   sourcet   lower_boundt   upper_boundt   linet   pre_contextt   context_linet   post_context(    (    sC   /opt/alt/python27/lib/python2.7/site-packages/raven/utils/stacks.pyt   get_lines_from_file   s8    
&.		c         C`  s%   y |  | SWn t  k
 r  | SXd S(   s‹   
    f_locals is not guaranteed to have .get(), but it will always
    support __getitem__. Even if it doesn't, we return ``default``.
    N(   t	   Exception(   t   f_localst   keyt   default(    (    sC   /opt/alt/python27/lib/python2.7/site-packages/raven/utils/stacks.pyt   _getitem_from_frameU   s    c         `  s_   t  ˆ  d ƒ r ˆ  j } n' t  ˆ  d ƒ r6 ˆ  j } n t ˆ  ƒ ‚ t ‡  f d †  | ƒ  Dƒ ƒ S(   su   
    Given something that closely resembles a dictionary, we attempt
    to coerce it into a propery dictionary.
    t   iterkeyst   keysc         3`  s   |  ] } | ˆ  | f Vq d  S(   N(    (   t   .0t   k(   t   dictish(    sC   /opt/alt/python27/lib/python2.7/site-packages/raven/utils/stacks.pys	   <genexpr>l   s    (   R   R%   R&   t
   ValueErrort   dict(   R)   t   m(    (   R)   sC   /opt/alt/python27/lib/python2.7/site-packages/raven/utils/stacks.pyt   to_dict`   s    c         c`  sj   xc |  re t  |  d ƒ re t |  j d i  ƒ } t | d ƒ sY |  j t |  d d ƒ f Vn  |  j }  q Wd S(   sŠ   
    Given a traceback object, it will iterate over all
    frames that do not contain the ``__traceback_hide__``
    local variable.
    t   tb_frameR!   t   __traceback_hide__t	   tb_linenoN(   R   t   getattrR.   R$   R   t   tb_next(   t   tbR!   (    (    sC   /opt/alt/python27/lib/python2.7/site-packages/raven/utils/stacks.pyt   iter_traceback_frameso   s
    c         c`  sp   |  s t  j ƒ  d }  n  xP d „  |  Dƒ D]> \ } } t | d i  ƒ } t | d ƒ r] q* n  | | f Vq* Wd S(   s§   
    Given an optional list of frames (defaults to current stack),
    iterates over all frames that do not contain the ``__traceback_hide__``
    local variable.
    i   c         s`  s#   |  ] } | d  | d f Vq d S(   i    i   N(    (   R'   t   f(    (    sC   /opt/alt/python27/lib/python2.7/site-packages/raven/utils/stacks.pys	   <genexpr>‰   s    R!   R/   N(   t   inspectt   stackR1   R$   (   t   framest   frameR   R!   (    (    sC   /opt/alt/python27/lib/python2.7/site-packages/raven/utils/stacks.pyt   iter_stack_frames€   s    i   c   	      C`  sÅ   t  |  d d  ƒ } | s d  St | t ƒ sS y t | ƒ } WqS t k
 rO d  SXn  i  } d } x_ t | ƒ D]Q \ } } | | ƒ } t t | ƒ ƒ } | | | k  rl | | | <| | 7} ql ql W| S(   NR!   i    (	   R1   R   t
   isinstanceR+   R-   R    R   R   t   repr(	   R9   t   transformert   max_var_sizeR!   t   f_varst   f_sizeR(   t   vt   v_size(    (    sC   /opt/alt/python27/lib/python2.7/site-packages/raven/utils/stacks.pyt   get_frame_locals   s"    
i   c         C`  sº  d } g  } g  } xD |  D]< } | d 7} | j  d ƒ rH | j | ƒ q | j | ƒ q W| | k ri |  S| | } t | ƒ } t | | d ƒ } | rþ t | d ƒ }	 xž | |	 |	 !D]@ } | j d d ƒ | j d d ƒ | j d d ƒ | d 8} q· WnK xH | D]@ } | j d d ƒ | j d d ƒ | j d d ƒ | d 8} qW| sS|  S| | }
 t |
 d ƒ }	 xF | |	 |	 !D]6 } | j d d ƒ | j d d ƒ | j d d ƒ q|W|  S(	   s~   
    Removes various excess metadata from middle frames which go beyond
    ``frame_allowance``.

    Returns ``frames``.
    i    i   t   in_appi   t   varsR   R   N(   t   gett   appendR   R   t   intt   popR   (   R8   t   frame_allowancet
   frames_lent
   app_framest   system_framesR9   t	   remainingt	   app_countt   system_allowancet   half_maxt   app_allowance(    (    sC   /opt/alt/python27/lib/python2.7/site-packages/raven/utils/stacks.pyt   slim_frame_data¨   sD    


i   c         C`  s4   |  s
 |  St  |  ƒ | k r, |  | d  d S|  |  S(   Ni   s   ...(   R   (   t   valuet   length(    (    sC   /opt/alt/python27/lib/python2.7/site-packages/raven/utils/stacks.pyR   Ü   s
    c         C`  s‚  t  } g  } xV|  D]N} t | t t f ƒ r= | \ } } n | } | j } t | d i  ƒ }	 t |	 d ƒ rs q n  t | d i  ƒ }
 t | d d ƒ } | r¸ | j j	 } | j j
 } n d } d } t |
 d ƒ } t |
 d ƒ } | rõ | d 8} n  | d k	 r+| r+t | | d | | ƒ \ } } } n d \ } } } yY t j | j d	 d ƒ d
 j } | j | j t j d ƒ d
 d ƒ d j t j ƒ } Wn t k
 r¬| } n X| s¼| } n  i | d 6| d 6| pÖd d 6| pãd d 6| d d 6} | r#t | d | ƒ} | r#| | d <q#n  | d k	 rT| j i | d 6| d 6| d 6ƒ n  | j | ƒ q Wi t | d | ƒd 6} | S(   s  
    Given a list of frames, returns a list of stack information
    dictionary objects that are JSON-ready.

    We have to be careful here as certain implementations of the
    _Frame class do not contain the necessary data to lookup all
    of the information we want.
    R!   R/   t	   f_globalst   f_codet
   __loader__t   __name__i   i   t   .i    i   iÿÿÿÿt   abs_pathR   t   modules	   <unknown>t   functionR   R=   RE   R   R   R   RJ   R8   N(   NNN(   t   TrueR;   t   listt   tuplet   f_linenoR1   R$   R   RW   t   co_filenamet   co_nameR   t   syst   modulest   splitt   __file__t   rsplitt   ost   sept   lstripR    RC   t   updateRG   RS   (   R8   R=   t   capture_localsRJ   R/   t   resultt
   frame_infoR9   R   R!   RV   RW   R[   R]   R   R   R   R   R   t   base_filenameR   t   frame_resultR?   t	   stackinfo(    (    sC   /opt/alt/python27/lib/python2.7/site-packages/raven/utils/stacks.pyt   get_stack_infoä   sf    
	$ 3
		(   t   __doc__t
   __future__R    R   R6   R
   t   reRi   Rd   t   raven.utils.serializerR   t   raven.utils.compatR   t   compilet
   _coding_reR   R   R$   R-   R4   R:   RC   RS   R   R^   Rs   (    (    (    sC   /opt/alt/python27/lib/python2.7/site-packages/raven/utils/stacks.pyt   <module>   s&   =		4