;ò
òŒü?c           @   sG  d  Z  d k Z d k Z d k Z d k Z d k Z d k Z d k Z d k Z d k	 Z	 y d k
 Z
 e
 Z Wn e j
 o d k Z n Xd „  Z d Z e i d ƒ Z d f  d „  ƒ  YZ d „  Z d „  Z d	 f  d
 „  ƒ  YZ d „  Z d „  Z d „  Z d „  Z d f  d „  ƒ  YZ d „  Z e d „ Z e d j o e ƒ  n d S(   s  program/module to trace Python program or function execution

Sample use, command line:
  trace.py -c -f counts --ignore-dir '$prefix' spam.py eggs
  trace.py -t --ignore-dir '$prefix' spam.py eggs

Sample use, programmatically
   # create a Trace object, telling it what to ignore, and whether to
   # do tracing or line-counting or both.
   trace = trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix,], trace=0,
                       count=1)
   # run the new command using the given trace
   trace.run(coverage.globaltrace, 'main()')
   # make a report, telling it where you want output
   r = trace.results()
   r.write_results(show_missing=True)
Nc         C   s   |  i d t i d ƒ d  S(   NsÃ  Usage: %s [OPTIONS] <file> [ARGS]

Meta-options:
--help                Display this help then exit.
--version             Output version information then exit.

Otherwise, exactly one of the following three options must be given:
-t, --trace           Print each line to sys.stdout before it is executed.
-c, --count           Count the number of times each line is executed
                      and write the counts to <module>.cover for each
                      module executed, in the module's directory.
                      See also `--coverdir', `--file', `--no-report' below.
-l, --listfuncs       Keep track of which functions are executed at least
                      once and write the results to sys.stdout after the
                      program exits.
-r, --report          Generate a report from a counts file; do not execute
                      any code.  `--file' must specify the results file to
                      read, which must have been created in a previous run
                      with `--count --file=FILE'.

Modifiers:
-f, --file=<file>     File to accumulate counts over several runs.
-R, --no-report       Do not generate the coverage report files.
                      Useful if you want to accumulate over several runs.
-C, --coverdir=<dir>  Directory where the report files.  The coverage
                      report for <package>.<module> is written to file
                      <dir>/<package>/<module>.cover.
-m, --missing         Annotate executable lines that were not executed
                      with '>>>>>> '.
-s, --summary         Write a brief summary on stdout for each file.
                      (Can only be used with --count or --report.)

Filters, may be repeated multiple times:
--ignore-module=<mod> Ignore the given module and its submodules
                      (if it is a package).
--ignore-dir=<dir>    Ignore files in the given directory (multiple
                      directories can be joined by os.pathsep).
i    (   s   outfiles   writes   syss   argv(   s   outfile(    (    s"   /mit/python/lib/python2.3/trace.pys   usage@   s    s   #pragma NO COVERs   ^\s*(#.*)?$s   Ignorec           B   s    t  Z e e d „ Z d „  Z RS(   Nc         C   sQ   | p g  |  _ | p g  |  _ t t i i |  i ƒ |  _ h  d d <|  _	 d  S(   Ns   <string>i   (
   s   moduless   selfs   _modss   dirss   _dirss   maps   oss   paths   normpaths   _ignore(   s   selfs   moduless   dirs(    (    s"   /mit/python/lib/python2.3/trace.pys   __init__n   s    c         C   s  |  i i | ƒ o |  i | Sn xv |  i D]k } | | j o d |  i | <d Sn t | ƒ } | | |  j o | | d j o d |  i | <d Sq, q, W| t	 j o d |  i | <d Sn x= |  i
 D]2 } | i | t i ƒ o d |  i | <d SqÇ qÇ Wd |  i | <d Sd  S(   Ni   s   .i    (   s   selfs   _ignores   has_keys
   modulenames   _modss   mods   lens   ns   filenames   Nones   _dirss   ds
   startswiths   oss   sep(   s   selfs   filenames
   modulenames   ds   ns   mod(    (    s"   /mit/python/lib/python2.3/trace.pys   namesu   s*    
 "
 (   s   __name__s
   __module__s   Nones   __init__s   names(    (    (    s"   /mit/python/lib/python2.3/trace.pys   Ignorem   s   c         C   s2   t  i i |  ƒ } t  i i | ƒ \ } } | Sd S(   s-   Return a plausible module name for the patch.N(   s   oss   paths   basenames   bases   splitexts   filenames   ext(   s   paths   exts   bases   filename(    (    s"   /mit/python/lib/python2.3/trace.pys   modname¢   s     c         C   sÅ   d } xe t i D]Z } |  i | ƒ o |  t | ƒ t i i j o' t | ƒ t | ƒ j o
 | } qj q q W| o |  t | ƒ d } n |  } | i	 d d ƒ } t i i
 | ƒ \ } } | Sd S(   s,   Return a plausible module name for the path.s    i   s   /s   .N(   s   longests   syss   paths   dirs
   startswiths   lens   oss   seps   bases   replaces   splitexts   filenames   ext(   s   paths   filenames   exts   bases   longests   dir(    (    s"   /mit/python/lib/python2.3/trace.pys   fullmodname©   s     
 -s   CoverageResultsc           B   sA   t  Z e e e e d „ Z d „  Z e e e d „ Z d „  Z RS(   Nc         C   s  | |  _  |  i  t j o h  |  _  n |  i  i ƒ  |  _ | |  _ |  i t j o h  |  _ n |  i i ƒ  |  _ | |  _ | |  _ |  i o} y> t i	 t
 |  i d ƒ ƒ \ } } |  i |  i | | ƒ ƒ Wq	t t t f j
 o# } t i d |  i | f IJq	Xn d  S(   Ns   rbs   Skipping counts file %r: %s(   s   countss   selfs   Nones   copys   counters   calledfuncss   infiles   outfiles   pickles   loads   opens   updates	   __class__s   IOErrors   EOFErrors
   ValueErrors   errs   syss   stderr(   s   selfs   countss   calledfuncss   infiles   outfiles   err(    (    s"   /mit/python/lib/python2.3/trace.pys   __init__À   s     				
!c         C   s~   |  i } |  i } | i } | i } x2 | i ƒ  D]$ } | i | d ƒ | | | | <q1 Wx | i ƒ  D] } d | | <qf Wd S(   s.   Merge in the data from another CoverageResultsi    i   N(	   s   selfs   countss   calledfuncss   others   other_countss   other_calledfuncss   keyss   keys   get(   s   selfs   others   other_countss   other_calledfuncss   calledfuncss   keys   counts(    (    s"   /mit/python/lib/python2.3/trace.pys   updateÕ   s     				 " c         C   sÍ  x2 |  i i ƒ  D]! \ } } } d | | | f GHq Wh  } xN |  i i ƒ  D]= \ } }
 | i	 | h  ƒ } | | <|  i | |
 f | |
 <qK Wh  } xm| i ƒ  D]_\ } } | d j o qŸ n | i d ƒ p | i d ƒ o | d  } n | t j o. t i i t i i | ƒ ƒ } t | ƒ } n8 | } t i i | ƒ o t i | ƒ n t | ƒ } | o t | ƒ } n h  } t i | ƒ }	 t i i  | | d ƒ } |  i" | |	 | | ƒ \ } } | o | o. t& d | | ƒ } | | | | f | | <qŸ qŸ W| o | oS | i ƒ  } | i) ƒ  d GHx5 | D]) } | | \ } } } } d	 | | GHq2Wn |  i+ o\ y/ t, i- |  i |  i f t. |  i+ d
 ƒ d ƒ WqÉt/ j
 o } t1 i2 d | IJqÉXn d S(   s!   
        @param coverdir
        s*   filename: %s, modulename: %s, funcname: %ss   <string>s   .pycs   .pyoiÿÿÿÿs   .coverid   s   lines   cov%   module   (path)s   %5d   %3d%%   %s   (%s)s   wbi   s"   Can't save counts files because %sN(3   s   selfs   calledfuncss   keyss   filenames
   modulenames   funcnames   per_files   countss   linenos   gets	   lines_hits   sumss	   iteritemss   counts   endswiths   coverdirs   Nones   oss   paths   dirnames   abspaths   dirs   modnames   existss   makedirss   fullmodnames   show_missings   find_executable_linenoss   lnotabs	   linecaches   getliness   sources   joins	   coverpaths   write_results_files   n_hitss   n_liness   summarys   ints   percents   modss   sorts   ms   outfiles   pickles   dumps   opens   IOErrors   errs   syss   stderr(   s   selfs   show_missings   summarys   coverdirs
   modulenames	   lines_hits   per_files   percents   filenames   sources   linenos	   coverpaths   n_liness   sumss   counts   modss   n_hitss   errs   ms   funcnames   lnotabs   dir(    (    s"   /mit/python/lib/python2.3/trace.pys   write_resultsâ   s^         
 
c         C   sM  y t  | d ƒ }	 Wn0 t j
 o$ } t i d | | f IJd Sn Xd } d } xà t	 | ƒ D]Ò \ } } | d }
 |
 | j o- |	 i d | |
 ƒ | d 7} | d 7} ni t i | ƒ o |	 i d ƒ nH |
 | j o t | | j o |	 i d ƒ | d 7} n |	 i d ƒ |	 i | | i d	 ƒ ƒ q_ W|	 i ƒ  | | f Sd S(
   s'   Return a coverage results file in path.s   ws2   trace: Could not open %r for writing: %s- skippingNi    i   s   %5d: s          s   >>>>>> i   (   s   opens   paths   outfiles   IOErrors   errs   syss   stderrs   n_liness   n_hitss	   enumerates   liness   is   lines   linenos	   lines_hits   writes   rx_blanks   matchs   lnotabs   PRAGMA_NOCOVERs
   expandtabss   close(   s   selfs   paths   liness   lnotabs	   lines_hits   n_hitss   errs   is   n_liness   outfiles   linenos   line(    (    s"   /mit/python/lib/python2.3/trace.pys   write_results_file%  s0     	 


(	   s   __name__s
   __module__s   Nones   __init__s   updates   Trues   Falses   write_resultss   write_results_file(    (    (    s"   /mit/python/lib/python2.3/trace.pys   CoverageResults¿   s   	Cc   
      C   sœ   h  } g  i } |  i d d d … D] } | t | ƒ ƒ q$ ~ } t | ƒ }	 t
 } |  i } x3 | D]+ } | | 7} | | j o d | | <qe qe W| Sd S(   s:   Return dict where keys are lines in the line number table.i   Ni   (   s   linenoss   appends   _[1]s   codes	   co_lnotabs   cs   ords   line_incrementss   lens   table_lengths   Falses	   docstrings   co_firstlinenos   linenos   lis   strs(
   s   codes   strss   cs	   docstrings   linenoss   lis   _[1]s   linenos   line_incrementss   table_length(    (    s"   /mit/python/lib/python2.3/trace.pys   find_lines_from_codeI  s     =	 
c         C   sX   t  |  | ƒ } x> |  i D]3 } t | t i ƒ o | i	 t
 | | ƒ ƒ q q W| Sd S(   s<   Return lineno dict for all code objects reachable from code.N(   s   find_lines_from_codes   codes   strss   linenoss	   co_constss   cs
   isinstances   typess   CodeTypes   updates
   find_lines(   s   codes   strss   cs   linenos(    (    s"   /mit/python/lib/python2.3/trace.pys
   find_linesY  s     
 c         C   sÇ   h  } t i } t |  ƒ } x— t i | i	 ƒ D]ƒ \ }	 } } } }
 |	 t i j oX | t i j oD | \ } } | \ } } x) t | | d ƒ D] } d | | <q Wq« n |	 } q. W| i ƒ  | Sd S(   sÄ   Return a dict of possible docstring positions.

    The dict maps line numbers to strings.  There is an entry for
    line that contains only a string or a part of a triple-quoted
    string.
    i   N(   s   ds   tokens   INDENTs
   prev_ttypes   opens   filenames   fs   tokenizes   generate_tokenss   readlines   ttypes   tstrs   starts   ends   lines   STRINGs   slines   scols   elines   ecols   ranges   is   close(   s   filenames   ends   ds   fs
   prev_ttypes   ecols   elines   scols   starts   ttypes   lines   is   tstrs   sline(    (    s"   /mit/python/lib/python2.3/trace.pys   find_stringse  s      	  

c         C   sx   y t  |  ƒ i ƒ  } Wn0 t j
 o$ } t i d |  | f IJh  Sn Xt | |  d ƒ } t
 |  ƒ } t | | ƒ Sd S(   sA   Return dict where keys are line numbers in the line number table.s%   Not printing coverage data for %r: %ss   execN(   s   opens   filenames   reads   progs   IOErrors   errs   syss   stderrs   compiles   codes   find_stringss   strss
   find_lines(   s   filenames   codes   errs   strss   prog(    (    s"   /mit/python/lib/python2.3/trace.pys   find_executable_linenos|  s      	s   Tracec           B   s}   t  Z d d d f  f  e e d „ Z d „  Z e e d „ Z d „  Z d „  Z d „  Z d	 „  Z	 d
 „  Z
 d „  Z d „  Z RS(   Ni   i    c         C   sî   | |  _  | |  _ t | | ƒ |  _ h  |  _ h  |  _ h  |  _	 d |  _
 | |  _ h  |  _ | o |  i |  _ nz | o | o |  i |  _ |  i |  _ nP | o |  i |  _ |  i |  _ n- | o |  i |  _ |  i |  _ n
 d |  _
 d S(   s9  
        @param count true iff it should count number of times each
                     line is executed
        @param trace true iff it should print out each line that is
                     being counted
        @param countfuncs true iff it should just output a list of
                     (filename, modulename, funcname,) for functions
                     that were called at least once;  This overrides
                     `count' and `trace'
        @param ignoremods a list of the names of modules to ignore
        @param ignoredirs a list of the names of directories to ignore
                     all of the (recursive) contents of
        @param infile file from which to read stored counts to be
                     added into the results
        @param outfile file in which to write the results
        i    i   N(   s   infiles   selfs   outfiles   Ignores
   ignoremodss
   ignoredirss   ignores   countss   blabbeds   pathtobasenames	   donothings   traces   _calledfuncss
   countfuncss   globaltrace_countfuncss   globaltraces   counts   globaltrace_lts   localtrace_trace_and_counts
   localtraces   localtrace_traces   localtrace_count(   s   selfs   counts   traces
   countfuncss
   ignoremodss
   ignoredirss   infiles   outfile(    (    s"   /mit/python/lib/python2.3/trace.pys   __init__Š  s,     								c         B   s€   d  k  } | i } |  i o$ e i |  i ƒ e i |  i ƒ n z | | | UWd  |  i o e i e
 ƒ e i e
 ƒ n Xd  S(   N(   s   __main__s   __dict__s   dicts   selfs	   donothings   syss   settraces   globaltraces	   threadings   cmds   None(   s   selfs   cmds   dicts   __main__(    (    s"   /mit/python/lib/python2.3/trace.pys   run´  s    		 c         B   sœ   | e j o
 h  } n | e j o
 h  } n |  i o$ e i |  i ƒ e i |  i ƒ n z | | | UWd  |  i o e i e ƒ e i e ƒ n Xd  S(   N(
   s   globalss   Nones   localss   selfs	   donothings   syss   settraces   globaltraces	   threadings   cmd(   s   selfs   cmds   globalss   locals(    (    s"   /mit/python/lib/python2.3/trace.pys   runctxÁ  s     
 
 c         O   s`   t  } |  i o t i |  i ƒ n z | | | Ž  } Wd  |  i o t i t  ƒ n X| Sd  S(   N(
   s   Nones   results   selfs	   donothings   syss   settraces   globaltraces   funcs   argss   kw(   s   selfs   funcs   argss   kws   result(    (    s"   /mit/python/lib/python2.3/trace.pys   runfuncÎ  s     c         C   sc   | d j oR | i } | i } | i } | o t | ƒ } n t
 } d |  i | | | f <n d S(   so   Handler for call events.

        Adds (filename, modulename, funcname) to the self._calledfuncs dict.
        s   calli   N(   s   whys   frames   f_codes   codes   co_filenames   filenames   co_names   funcnames   modnames
   modulenames   Nones   selfs   _calledfuncs(   s   selfs   frames   whys   args   codes   filenames
   modulenames   funcname(    (    s"   /mit/python/lib/python2.3/trace.pys   globaltrace_countfuncsÙ  s     			c         C   s›   | d j oŠ | i } | i } | oi t | ƒ } | t j	 oL |  i
 i | | ƒ } | o+ |  i o d | | i f GHn |  i Sq‹ q“ q— t Sn d S(   s’   Handler for call events.

        If the code block being entered is to be ignored, returns `None',
        else returns self.localtrace.
        s   calls!    --- modulename: %s, funcname: %sN(   s   whys   frames   f_codes   codes   co_filenames   filenames   modnames
   modulenames   Nones   selfs   ignores   namess	   ignore_its   traces   co_names
   localtrace(   s   selfs   frames   whys   args   codes	   ignore_its   filenames
   modulename(    (    s"   /mit/python/lib/python2.3/trace.pys   globaltrace_ltè  s     		
c         C   sŒ   | d j ot | i i } | i } | | f } |  i	 i
 | d ƒ d |  i	 | <t i i | ƒ } d | | t i | | ƒ f Gn |  i Sd  S(   Ns   linei    i   s
   %s(%d): %s(   s   whys   frames   f_codes   co_filenames   filenames   f_linenos   linenos   keys   selfs   countss   gets   oss   paths   basenames   bnames	   linecaches   getlines
   localtrace(   s   selfs   frames   whys   args   filenames   bnames   linenos   key(    (    s"   /mit/python/lib/python2.3/trace.pys   localtrace_trace_and_countÿ  s    	 !c         C   s`   | d j oH | i i } | i } t i i	 | ƒ } d | | t i | | ƒ f Gn |  i Sd  S(   Ns   lines
   %s(%d): %s(   s   whys   frames   f_codes   co_filenames   filenames   f_linenos   linenos   oss   paths   basenames   bnames	   linecaches   getlines   selfs
   localtrace(   s   selfs   frames   whys   args   filenames   bnames   lineno(    (    s"   /mit/python/lib/python2.3/trace.pys   localtrace_trace  s    	!c         C   s]   | d j oE | i i } | i } | | f } |  i	 i
 | d ƒ d |  i	 | <n |  i Sd  S(   Ns   linei    i   (   s   whys   frames   f_codes   co_filenames   filenames   f_linenos   linenos   keys   selfs   countss   gets
   localtrace(   s   selfs   frames   whys   args   filenames   linenos   key(    (    s"   /mit/python/lib/python2.3/trace.pys   localtrace_count  s    	$c         C   s,   t  |  i d |  i d |  i d |  i ƒSd  S(   Ns   infiles   outfiles   calledfuncs(   s   CoverageResultss   selfs   countss   infiles   outfiles   _calledfuncs(   s   self(    (    s"   /mit/python/lib/python2.3/trace.pys   results  s    	(   s   __name__s
   __module__s   Nones   __init__s   runs   runctxs   runfuncs   globaltrace_countfuncss   globaltrace_lts   localtrace_trace_and_counts   localtrace_traces   localtrace_counts   results(    (    (    s"   /mit/python/lib/python2.3/trace.pys   Trace‰  s   *							c         C   s2   t  i i d t  i d |  f ƒ t  i d ƒ d  S(   Ns   %s: %s
i    i   (   s   syss   stderrs   writes   argvs   msgs   exit(   s   msg(    (    s"   /mit/python/lib/python2.3/trace.pys	   _err_exit$  s    !c         C   s¥  d  k  } |  t j o t i }  n yJ | i  |  d d d d d d d d d	 d
 d d d d d g ƒ \ } } Wna | i j
 oR } t i i	 d t i d | f ƒ t i i	 d t i d ƒ t i
 d ƒ n Xd }	 d } d } d } t } d }
 g  } g  } t } d } t } x³| D]«\ } } | d j o t t i ƒ t i
 d ƒ n | d j o! t i i	 d ƒ t i
 d ƒ n | d j p
 | d j o t } qn | d j p
 | d j o d }	 qn | d j p
 | d j o d } qn | d j p
 | d j o d } qn | d j p
 | d j o d } qn | d  j p
 | d! j o | } qn | d" j p
 | d# j o d }
 qn | d$ j p
 | d% j o | } qn | d& j p
 | d' j o d } qn | d( j o | i | ƒ qn | d) j o¹ x¯ | i t i ƒ D]› } t i! i" | ƒ } | i# d* t i! i$ t i% d+ d, t i& d-  ƒ ƒ } | i# d. t i! i$ t i' d+ d, t i& d-  ƒ ƒ } t i! i( | ƒ } | i | ƒ qWqqqW| o | p |	 o t) d/ ƒ n | o |	 o | o | o t) d0 ƒ n | o | o t) d1 ƒ n | o | o t) d2 ƒ n | o t* | ƒ d j o t) d3 ƒ n | o2 t+ d4 | d5 | ƒ } | i- |
 d	 | d6 | ƒnî | t _ | d } t i! i | ƒ d t i! d <t/ | |	 d7 | d8 | d9 | d4 | d5 | ƒ} y | i1 d: | d; ƒ WnB t2 j
 o$ } t) d< t i d | f ƒ n t4 j
 o n X| i, ƒ  } | o | i- |
 d	 | d6 | ƒn d  S(=   Ni   s   tcrRf:d:msC:ls   helps   versions   traces   counts   reports	   no-reports   summarys   file=s   missings   ignore-module=s   ignore-dir=s	   coverdir=s	   listfuncss   %s: %s
i    s%   Try `%s --help' for more information
s   --helps	   --versions
   trace 2.0
s   -ls   --listfuncss   -ts   --traces   -cs   --counts   -rs   --reports   -Rs   --no-reports   -fs   --files   -ms	   --missings   -Cs
   --coverdirs   -ss	   --summarys   --ignore-modules   --ignore-dirs   $prefixs   libs   pythoni   s   $exec_prefixs8   cannot specify both --listfuncs and (--trace or --count)s=   must specify one of --trace, --count, --report or --listfuncss,   cannot specify both --report and --no-reports   --report requires a --files   missing name of file to runs   infiles   outfiles   coverdirs
   countfuncss
   ignoremodss
   ignoredirss	   execfile(s   )s   Cannot run file %r because: %s(5   s   getopts   argvs   Nones   syss   optss	   prog_argvs   errors   msgs   stderrs   writes   exits   traces   counts   reports	   no_reports   counts_files   missings   ignore_moduless   ignore_dirss   coverdirs   summarys   Falses	   listfuncss   opts   vals   usages   stdouts   Trues   appends   splits   oss   pathseps   ss   paths
   expandvarss   replaces   joins   prefixs   versions   exec_prefixs   normpaths	   _err_exits   lens   CoverageResultss   resultss   write_resultss   prognames   Traces   ts   runs   IOErrors   errs
   SystemExit(   s   argvs   errs	   no_reports	   prog_argvs   vals   ts   getopts   ignore_dirss   opts   traces   missings   prognames   resultss   msgs   reports	   listfuncss   counts   coverdirs   counts_files   summarys   ss   ignore_moduless   opts(    (    s"   /mit/python/lib/python2.3/trace.pys   main(  sÊ    	:!  		 	
s   __main__(   s   __doc__s	   linecaches   marshals   oss   res   syss	   threadings   tokens   tokenizes   typess   cPickles   pickles   ImportErrors   usages   PRAGMA_NOCOVERs   compiles   rx_blanks   Ignores   modnames   fullmodnames   CoverageResultss   find_lines_from_codes
   find_liness   find_stringss   find_executable_linenoss   Traces	   _err_exits   Nones   mains   __name__(   s	   _err_exits	   linecaches   fullmodnames   find_executable_linenoss   Traces
   find_liness   find_lines_from_codes   tokenizes   usages   mains   CoverageResultss   cPickles   find_stringss   Ignores   res   typess   syss   modnames   oss	   threadings   tokens   PRAGMA_NOCOVERs   rx_blanks   pickles   marshal(    (    s"   /mit/python/lib/python2.3/trace.pys   ?.   s<   										
	(5		Š				›	‰