Ñò
ÎÑAHc           @   sf  d  Z  d d g Z d Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k Z d d k	 Z	 d d k
 Z
 d d k Te	 i d Z e	 i d Z e Z e d	 h	 e i e	 i 6e i e	 i 6e i e	 i 6e i e
 i 6e i e	 i 6e i e	 i 6e i e 6e i e 6e i d
 6ƒ Z e d h	 e i e	 i 6e i e	 i 6e i e	 i 6e i e
 i 6e i e	 i 6e i e	 i 6e i e 6e i e 6e i  d
 6ƒ Z! e d h	 e i" e	 i 6e i# e	 i 6e i# e	 i 6e i e
 i 6e i$ e	 i 6e i e	 i 6e i% e 6e i# e 6e i  d
 6ƒ Z& e' e e! e& g e ƒ Z( d d d „  ƒ  YZ) d d „ Z+ e, d j o e+ ƒ  n d S(   s÷  
    Class and program to colorize python source code for ANSI terminals.

    Based on an HTML code highlighter by Jurgen Hermann found at:
    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52298

    Modifications by Fernando Perez (fperez@colorado.edu).

    Information on the original HTML highlighter follows:
    
    MoinMoin - Python Source Parser

    Title: Colorize Python source using the built-in tokenizer
           
    Submitter: Jurgen Hermann
    Last Updated:2001/04/06
           
    Version no:1.2

    Description:

    This code is part of MoinMoin (http://moin.sourceforge.net/) and converts
    Python source code to HTML markup, rendering comments, keywords,
    operators, numeric and string literals in different colors.

    It shows how to use the built-in keyword, token and tokenize modules to
    scan Python source code and re-emit it with no changes to its original
    formatting (which is the hard part).

    $Id: PyColorize.py 2586 2007-08-06 19:30:09Z vivainio $t   ANSICodeColorst   Parsert   LinuxiÿÿÿÿN(   t   *i   i   t   NoColort   normalt   LightBGc           B   sG   e  Z d  Z d e i d „ Z d d d „ Z d d d „ Z d „  Z	 RS(   s#    Format colored Python source.
    c         C   s$   | o | p t  |  _ | |  _ d S(   sr    Create a parser with a specified color table and output channel.

        Call format() to process code.
        N(   R    t   color_tablet   out(   t   selfR   R   (    (    sJ   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/PyColorize.pyt   __init__s   s    t    c         C   s   |  i  | | | ƒ d S(   Ni    (   t   format2(   R	   t   rawR   t   scheme(    (    sJ   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/PyColorize.pyt   format{   s    c         C   sI  d } | d j p& |  i  d j p t |  i  t i ƒ o" |  i  } t i ƒ  |  _  d } n | d j	 o | |  _  n | d j o6 t } |  i  i | ƒ | o | | f Sd | f Sn |  i | i	 } | |  _	 | i
 ƒ  i ƒ  |  _ d d g |  _ d } |  i i }	 |  i i }
 x, |	 d | ƒ d } | p Pn |
 | ƒ q|
 t |  i ƒ ƒ d |  _ t i |  i ƒ } t } y t i | i |  ƒ Wnn t i j
 o_ } | d } | d d } |  i  i d | t i | |  i |  i | | i f ƒ t } n X|  i  i | i d ƒ | o# |  i  i ƒ  } | |  _  | | f Sd | f S(   s4   Parse and send the colored source.

        If out and scheme are not specified, the defaults (given to
        constructor) are used.

        out should be a file-type object. Optionally, out can be given as the
        string 'str' and the parser will automatically return the output in a
        string.i    t   stri   R   s   
s   %s

*** ERROR: %s%s%s
N(   R   t
   isinstancet	   cStringIOt
   OutputTypet   StringIOt   Nonet   Falset   writeR   t   colorst
   expandtabst   rstripR   t   linest   findt   appendt   lent   post   tokenizet   readlinet
   TokenErrort   tokent
   ERRORTOKENR   t   Truet   getvalue(   R	   R   R   R   t   string_outputt   out_oldt   errorR   R   t   raw_findt   lines_appendt   textt   ext   msgt   linet   output(    (    sJ   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/PyColorize.pyR   ~   s\    
	
	 	

	c         C   s•  | \ } } | \ } }	 |  i  }
 |  i i } t i } |  i } |  i | | } | t | ƒ |  _ | t i	 t
 i g j o | | ƒ d S| | j o | |  i | | !ƒ n | t i t i g j o | |  _ d St i | j o | t i j o t i } n+ | t i j o t i | ƒ o
 t } n |
 i | |
 t ƒ } | | j o& | i | d |
 i | | f ƒ } n | d | | |
 i f ƒ d S(   s)    Token handler, with syntax highlighting.Ns   %s%s%s(   R   R   R   t   ost   linesepR   R   R   R#   t   NEWLINER    t   NLR   t   INDENTt   DEDENTt   LPARt   OPt   NAMEt   keywordt	   iskeywordt   _KEYWORDt   gett   _TEXTt   replaceR   (   R	   t   toktypet   toktextt   .3t   .4R/   t   srowt   scolt   erowt   ecolR   t   owriteR2   t   oldpost   newpost   color(    (    sJ   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/PyColorize.pyt   __call__Ç   s0    			
	  
N(
   t   __name__t
   __module__t   __doc__R   t   syst   stdoutR
   R   R   RL   (    (    (    sJ   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/PyColorize.pyR   o   s
   Ic   	      C   sc  d } t  i d | ƒ } | i } | d d d d d d d	 d
 d d d d g d t d d ƒ| i |  ƒ \ } } t | ƒ d j o | i d ƒ n t | ƒ d j o
 d } n | d } | d j o t i } n t	 | ƒ } t
 ƒ  } zS y  | i | i ƒ  d | i ƒWn, t j
 o  } | i d j o ‚  q<n XWd | t i j	 o | i ƒ  n Xd S(   s   Run as a command-line script: colorize a python file or stdin using ANSI
    color escapes and print to stdout.

    Inputs:

      - argv(None): a list of strings like sys.argv[1:] giving the command-line
        arguments. If None, use sys.argv[1:].
    s¬   %prog [options] [filename]

Colorize a python file or stdin using ANSI color escapes and print to stdout.
If no filename is given, or if filename is -, read standard input.t   usages   -ss   --schemet   metavarR9   t   destt   scheme_namet   actiont   storet   choicesR   R   R   t   defaultt   helps€   give the color scheme to use. Currently only 'Linux' (default) and 'LightBG' and 'NoColor' are implemented (give without quotes)i   s#   you must give at most one filename.i    t   -R   i    s   Broken pipeN(   i    s   Broken pipe(   t   optparset   OptionParsert
   add_optiont   _scheme_defaultt
   parse_argsR   R)   RP   t   stdint   fileR   R   t   readRU   t   IOErrort   argst   close(	   t   argvt	   usage_msgt   parsert   newoptt   optsRe   t   fnamet   streamR.   (    (    sJ   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/PyColorize.pyt   mainö   s0    	

	 t   __main__(    (-   RO   t   __all__R_   R   R:   R1   R\   t   stringRP   R#   R    t   IPython.ColorANSIt	   NT_OFFSETR<   R>   t
   TermColorst   Colorst   ColorSchemeR   t   NUMBERR8   t   STRINGt   COMMENTR9   R$   t	   LightCyant   Yellowt	   LightBluet   LightRedt   Whitet   Redt
   LightGreent   Normalt   LinuxColorst   Cyant   Bluet   Blackt   Greent   LightBGColorst   ColorSchemeTableR    R   R   Rn   RM   (    (    (    sJ   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/PyColorize.pyt   <module>   sj   






	‡6