;ς
ΞΡAHc           @   s  d  Z  d d g Z 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 Te	 i d Z e	 i d Z e Z e d h  e	 i e i <e	 i e i <e	 i e i <e
 i e i <e	 i e i <e	 i e i <e e i <e e i <d	 e i < Z e d h  e	 i e i <e	 i e i <e	 i e i <e
 i e i <e	 i e i <e	 i e i <e e i <e e i <d	 e i  < Z! e d
 h  e	 i e i" <e	 i e i# <e	 i e i# <e
 i e i <e	 i e i$ <e	 i e i <e e i% <e e i# <d	 e i  < Z& e' e e! e& g e  Z( d f  d     YZ) e* 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 $s   ANSICodeColorss   Parsers   LinuxN(   s   *i   i   s   NoColors   normals   LightBGc           B   sG   t  Z d  Z e e i d  Z e d d  Z e 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(   s   color_tables   ANSICodeColorss   selfs   out(   s   selfs   color_tables   out(    (    sB   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/PyColorize.pys   __init__s   s     s    c         C   s   |  i | | |  d Sd  S(   Ni    (   s   selfs   format2s   raws   outs   scheme(   s   selfs   raws   outs   scheme(    (    sB   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/PyColorize.pys   format{   s    c         C   s]  d } | d j p# |  i d j p t |  i t i  o" |  i }	 t i   |  _ d } n | t j	 o | |  _ n | d j o9 t
 } |  i i |  | o | | f Sq» t | f Sn |  i | i } | |  _ | i   i   |  _ d d g |  _ d } |  i i } |  i i } x6 n o. | d |  d } | o Pn | |  q W| 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 Sn t | f Sd 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    s   stri   s   NoColors   
s   %s

*** ERROR: %s%s%s
N(&   s   string_outputs   outs   selfs
   isinstances	   cStringIOs
   OutputTypes   out_olds   StringIOs   Nones   schemes   Falses   errors   writes   raws   color_tables   colorss
   expandtabss   rstrips   liness   poss   finds   raw_finds   appends   lines_appends   lens   texts   tokenizes   readlines
   TokenErrors   exs   msgs   lines   tokens
   ERRORTOKENs   normals   Trues   getvalues   output(   s   selfs   raws   outs   schemes   texts   poss   colorss   exs   string_outputs   out_olds   msgs   raw_finds   lines   lines_appends   errors   output(    (    sB   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/PyColorize.pys   format2~   sX     3	
	  	
8	c         C   s  | \ } } | \ } }	 |  i } |  i i } t	 i
 } |  i } |  i | | } | t |  |  _ | t i t i g j o | |  d Sn | | j o | |  i | | ! n | t i t i g j o | |  _ d Sn 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($   s   srows   scols   erows   ecols   selfs   colorss   outs   writes   owrites   oss   lineseps   poss   oldposs   liness   newposs   lens   toktexts   toktypes   tokens   NEWLINEs   tokenizes   NLs   raws   INDENTs   DEDENTs   LPARs   OPs   NAMEs   keywords	   iskeywords   _KEYWORDs   gets   _TEXTs   colors   replaces   normal(   s   selfs   toktypes   toktexts   .6s   .8s   lines   srows   scols   erows   ecols   colors   colorss   lineseps   oldposs   newposs   owrite(    (    sB   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/PyColorize.pys   __call__Η   s.    			
	  
&(
   s   __name__s
   __module__s   __doc__s   Nones   syss   stdouts   __init__s   formats   format2s   __call__(    (    (    sB   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/PyColorize.pys   Parsero   s
    Ic   	      C   si  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   } zY y  | i | i   d | i Wn2 t j
 o& } | i
 d d f j o   qB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.s   usages   -ss   --schemes   metavars   NAMEs   dests   scheme_names   actions   stores   choicess   Linuxs   LightBGs   NoColors   defaults   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    s   -s   schemei    s   Broken pipeN(   s	   usage_msgs   optparses   OptionParsers   parsers
   add_options   newopts   _scheme_defaults
   parse_argss   argvs   optss   argss   lens   errors   fnames   syss   stdins   streams   files   Parsers   formats   reads   scheme_names   IOErrors   msgs   close(	   s   argvs   newopts   streams   argss	   usage_msgs   parsers   fnames   msgs   opts(    (    sB   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/PyColorize.pys   mainφ   s4     	


	  s   __main__(-   s   __doc__s   __all__s   _scheme_defaults	   cStringIOs   keywords   oss   optparses   strings   syss   tokens   tokenizes   IPython.ColorANSIs	   NT_OFFSETs   _KEYWORDs   _TEXTs
   TermColorss   Colorss   ColorSchemes   NUMBERs   NoColors   OPs   STRINGs   COMMENTs   NAMEs
   ERRORTOKENs	   LightCyans   Yellows	   LightBlues   LightReds   Whites   Reds
   LightGreens   Normals   LinuxColorss   Cyans   Blues   Blacks   Greens   LightBGColorss   ColorSchemeTables   ANSICodeColorss   Parsers   Nones   mains   __name__(   s	   cStringIOs   ANSICodeColorss   __all__s   NoColors   LightBGColorss   tokenizes   mains   _KEYWORDs   strings   optparses   _scheme_defaults   syss   _TEXTs   keywords   Parsers   LinuxColorss   Colorss   tokens   os(    (    sB   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/PyColorize.pys   ?   s.   									6