ó
Þ™xTc           @   s^   d  d l  m Z d  d l Z d e f d „  ƒ  YZ d „  Z d „  Z d e f d „  ƒ  YZ d S(	   iÿÿÿÿ(   t   divisionNt   errorc           B   s   e  Z d  Z RS(   s    libtbx.python_frame error (   t   __name__t
   __module__t   __doc__(    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pyframe.pyR      s   c         C   sV   t  j ƒ  } x= | j j |  k rK | j d k r? t d ƒ ‚ n  | j } q Wt | ƒ S(   sZ   Returns an object representing the frame of the function of the given name.
      This frame will be searched upward from the current frame

      Synopsis:

      from libtbx import pyframe

      def f(i):
        for j in xrange(i):
          g(j)

      def g(j):
        return k(j)

      def k(j):
        f = pyframe.named('f')
        if f.j == 3: ....

      This is particularly useful for conditional breakpoints in the WingIDE debugger.
      Let's say we have a function 'test' which tests a function 'clever_algorithm' and that
      one wants to put a breakpoint in the latter that only triggers
      for one particular test (that we know is going to fail e.g.). Let's say tests are
      identified by a local variable 'idx' in function 'test'. Then we can put a conditional
      breakpoint somewhere in function 'clever_algorithm' like so:

        pyframe.named('test').idx == 5

      The advantage of conditional tests is that they don't require modifying code for
      debugging purposes, which is always a dangerous thing to do as one may inadvertantly
      leave debugging code in.

  sF   frame '%s' cannot be found among the frames calling the current frame.N(   t   inspectt   currentframet   f_codet   co_namet   f_backt   NoneR   t   frame_locals(   t   namet   f(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pyframe.pyt   named	   s    !c         C   sf   t  j ƒ  } | j } | j j } x8 t |  ƒ D]* } | d k rO t d ƒ ‚ n  | j } q. Wt | ƒ S(   s   Returns an object representing the frame of the function that is n steps up in
      the calling stack, starting from the function that called this function 'up'.
      Thus n=0 corresponds to the function F that called this, n=1 to the function
      that called F, etc.
  sY   asked for the frame %i steps up the function '%s' but the calling stack is not that tall.N(	   R   R   R	   R   R   t   xrangeR
   R   R   (   t   nR   t   caller_namet   i(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pyframe.pyt   up2   s    	R   c           B   s   e  Z d  „  Z RS(   c         C   s   |  j  j | j ƒ d  S(   N(   t   __dict__t   updatet   f_locals(   t   selfR   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pyframe.pyt   __init__E   s    (   R   R   R   (    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pyframe.pyR   C   s   (	   t
   __future__R    R   t	   ExceptionR   R   R   t   objectR   (    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/libtbx/pyframe.pyt   <module>   s
   	)	