ó ¿öYc@`sýdZddlmZmZddlZddlZddlZddlZddlZddl m Z ddl m Z ej dƒZddd„Zdd„Zd „Zd „Zdd „Ze d d „Zdd„Zdd„Ze edd„ZdS(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(tabsolute_importtdivisionN(t transform(t iteritemsscoding[:=]\s*([-\w.]+)c C`sŠd}|dk rrt|dƒrry|j|ƒ}Wnttfk rSd}nX|dk rr|jƒ}qrn|dkr¯ytj|ƒ}Wq¯ttfk r«dSXn|s¹dSt d||ƒ}t |d|t |ƒƒ}ymg|||!D]}|j dƒ^qú} ||j dƒ} g||d|!D]}|j dƒ^q:} Wnt k rjdSXt| ƒt| ƒt| ƒfS( s Returns context_lines before and after lineno from file. Returns (pre_context_lineno, pre_context, context_line, post_context). t get_sourceiis N(NNN(NNN(NNN(tNonethasattrRt ImportErrortIOErrort splitlinest linecachetgetlinestOSErrortmaxtmintlentstript IndexErrort slim_string( tfilenametlinenot context_linestloadert module_nametsourcet lower_boundt upper_boundtlinet pre_contextt context_linet post_context((sC/opt/alt/python27/lib/python2.7/site-packages/raven/utils/stacks.pytget_lines_from_files8   &.   cC`s%y ||SWntk r |SXdS(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(tf_localstkeytdefault((sC/opt/alt/python27/lib/python2.7/site-packages/raven/utils/stacks.pyt_getitem_from_frameUs  c`s_tˆdƒrˆj}n'tˆdƒr6ˆj}n tˆƒ‚t‡fd†|ƒDƒƒS(su Given something that closely resembles a dictionary, we attempt to coerce it into a propery dictionary. titerkeystkeysc3`s|]}|ˆ|fVqdS(N((t.0tk(tdictish(sC/opt/alt/python27/lib/python2.7/site-packages/raven/utils/stacks.pys ls(RR%R&t ValueErrortdict(R)tm((R)sC/opt/alt/python27/lib/python2.7/site-packages/raven/utils/stacks.pytto_dict`s    cc`sjxc|ret|dƒret|jdiƒ}t|dƒsY|jt|ddƒfVn|j}qWdS(sŠ Given a traceback object, it will iterate over all frames that do not contain the ``__traceback_hide__`` local variable. ttb_frameR!t__traceback_hide__t tb_linenoN(RtgetattrR.R$Rttb_next(ttbR!((sC/opt/alt/python27/lib/python2.7/site-packages/raven/utils/stacks.pytiter_traceback_framesos cc`sp|stjƒd}nxPd„|DƒD]>\}}t|diƒ}t|dƒr]q*n||fVq*WdS(s§ Given an optional list of frames (defaults to current stack), iterates over all frames that do not contain the ``__traceback_hide__`` local variable. ics`s#|]}|d|dfVqdS(iiN((R'tf((sC/opt/alt/python27/lib/python2.7/site-packages/raven/utils/stacks.pys ‰sR!R/N(tinspecttstackR1R$(tframestframeRR!((sC/opt/alt/python27/lib/python2.7/site-packages/raven/utils/stacks.pytiter_stack_frames€sic C`sÅt|ddƒ}|sdSt|tƒsSyt|ƒ}WqStk rOdSXni}d}x_t|ƒD]Q\}}||ƒ}tt|ƒƒ}|||krl|||<||7}qlqlW|S(NR!i( R1Rt isinstanceR+R-R RRtrepr( R9t transformert max_var_sizeR!tf_varstf_sizeR(tvtv_size((sC/opt/alt/python27/lib/python2.7/site-packages/raven/utils/stacks.pytget_frame_localss"   ic C`sºd}g}g}xD|D]<}|d7}|jdƒrH|j|ƒq|j|ƒqW||kri|S||}t|ƒ}t||dƒ}|rþt|dƒ} xž|| | !D]@}|jddƒ|jddƒ|jddƒ|d8}q·WnKxH|D]@}|jddƒ|jddƒ|jddƒ|d8}qW|sS|S||} t| dƒ} xF|| | !D]6}|jddƒ|jddƒ|jddƒq|W|S( s~ Removes various excess metadata from middle frames which go beyond ``frame_allowance``. Returns ``frames``. iitin_appitvarsRRN(tgettappendRR tinttpopR( R8tframe_allowancet frames_lent app_framest system_framesR9t remainingt app_counttsystem_allowancethalf_maxt app_allowance((sC/opt/alt/python27/lib/python2.7/site-packages/raven/utils/stacks.pytslim_frame_data¨sD       icC`s4|s |St|ƒ|kr,||d dS|| S(Nis...(R(tvaluetlength((sC/opt/alt/python27/lib/python2.7/site-packages/raven/utils/stacks.pyRÜs cC`s‚t}g}xV|D]N}t|ttfƒr=|\}}n|}|j}t|diƒ} t| dƒrsqnt|diƒ} t|ddƒ} | r¸|jj } |jj } n d} d} t| dƒ}t| dƒ}|rõ|d8}n|dk r+| r+t | |d||ƒ\}}}nd\}}}yYt j |jd dƒd j}| j|jtjd ƒd dƒd jtjƒ}Wntk r¬| }nX|s¼| }ni| d 6|d6|pÖdd6| pãdd6|dd6}|r#t|d|ƒ}|r#||dtfunctionRR=RERRRRJR8N(NNN(tTrueR;tlistttupletf_linenoR1R$RRWt co_filenametco_nameRtsystmodulestsplitt__file__trsplittostseptlstripR RCtupdateRGRS(R8R=tcapture_localsRJR/tresultt frame_infoR9RR!RVRWR[R]RRRRRt base_filenameRt frame_resultR?t stackinfo((sC/opt/alt/python27/lib/python2.7/site-packages/raven/utils/stacks.pytget_stack_infoäsf     $ 3       (t__doc__t __future__RRR6R treRiRdtraven.utils.serializerRtraven.utils.compatRtcompilet _coding_reRRR$R-R4R:RCRSRR^Rs(((sC/opt/alt/python27/lib/python2.7/site-packages/raven/utils/stacks.pyts&     =    4