;
E@c           @   so  d  Z  d Z d k Z d k Z d k Z d k l Z l Z d k l	 Z	 l
 Z
 d k l Z l Z d e	 f d     YZ d e	 f d	     YZ d
 f  d     YZ d f  d     YZ d e
 f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d   Z d   Z d   Z d e
 f d     YZ d   Z e d  Z d   Z d   Z d   Z d S(    s:   
Miscellaneous utilities for the documentation utilities.
s   reStructuredTextN(   s
   StringTypes   UnicodeType(   s   ApplicationErrors	   DataError(   s   frontends   nodess   SystemMessagec           B   s   t  Z d   Z RS(   Nc         C   s#   t  i |  | i    | |  _ d  S(   N(   s	   Exceptions   __init__s   selfs   system_messages   astexts   level(   s   selfs   system_messages   level(    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   __init__   s    (   s   __name__s
   __module__s   __init__(    (    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   SystemMessage   s   s   SystemMessagePropagationc           B   s   t  Z RS(   N(   s   __name__s
   __module__(    (    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   SystemMessagePropagation   s    s   Reporterc           B   s   t  Z d  Z d i   Z e d d d d  Z e d d  Z d   Z e Z	 d   Z
 e
 Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s 	  
    Info/warning/error reporter and ``system_message`` element generator.

    Five levels of system messages are defined, along with corresponding
    methods: `debug()`, `info()`, `warning()`, `error()`, and `severe()`.

    There is typically one Reporter object per process.  A Reporter object is
    instantiated with thresholds for reporting (generating warnings) and
    halting processing (raising exceptions), a switch to turn debug output on
    or off, and an I/O stream for warnings.  These are stored in the default
    reporting category, '' (zero-length string).

    Multiple reporting categories [#]_ may be set, each with its own reporting
    and halting thresholds, debugging switch, and warning stream
    (collectively a `ConditionSet`).  Categories are hierarchical dotted-name
    strings that look like attribute references: 'spam', 'spam.eggs',
    'neeeow.wum.ping'.  The 'spam' category is the ancestor of
    'spam.bacon.eggs'.  Unset categories inherit stored conditions from their
    closest ancestor category that has been set.

    When a system message is generated, the stored conditions from its
    category (or ancestor if unset) are retrieved.  The system message level
    is compared to the thresholds stored in the category, and a warning or
    error is generated as appropriate.  Debug messages are produced iff the
    stored debug switch is on.  Message output is sent to the stored warning
    stream if not set to ''.

    The default category is '' (empty string).  By convention, Writers should
    retrieve reporting conditions from the 'writer' category (which, unless
    explicitly set, defaults to the conditions of the default category).

    The Reporter class also employs a modified form of the "Observer" pattern
    [GoF95]_ to track system messages generated.  The `attach_observer` method
    should be called before parsing, with a bound method or function which
    accepts system messages.  The observer can be removed with
    `detach_observer`, and another added in its place.

    .. [#] The concept of "categories" was inspired by the log4j project:
       http://jakarta.apache.org/log4j/.

    .. [GoF95] Gamma, Helm, Johnson, Vlissides. *Design Patterns: Elements of
       Reusable Object-Oriented Software*. Addison-Wesley, Reading, MA, USA,
       1995.
    s   DEBUG INFO WARNING ERROR SEVEREi    s   asciis   replacec         C   s   | |  _  | t j o t i } n t |  t t f j og | d j oV t |  t j o t	 | d  } q t |  t j o t	 | i
   d  } q q n | |  _ | |  _ h  d t | | | |  <|  _ g  |  _ d |  _ d S(   s  
        Initialize the `ConditionSet` forthe `Reporter`'s default category.

        :Parameters:

            - `source`: The path to or description of the source data.
            - `report_level`: The level at or above which warning output will
              be sent to `stream`.
            - `halt_level`: The level at or above which `SystemMessage`
              exceptions will be raised, halting execution.
            - `debug`: Show debug (level=0) system messages?
            - `stream`: Where warning output is sent.  Can be file-like (has a
              ``.write`` method), a string (file name, opened for writing), 
              '' (empty string, for discarding all stream messages) or
              `None` (implies `sys.stderr`; default).
            - `encoding`: The encoding for stderr output.
            - `error_handler`: The error handler for stderr output encoding.
        s    s   wiN(   s   sources   selfs   streams   Nones   syss   stderrs   types
   StringTypes   UnicodeTypes   opens   encodes   encodings   error_handlers   ConditionSets   debugs   report_levels
   halt_levels
   categoriess	   observerss	   max_level(   s   selfs   sources   report_levels
   halt_levels   streams   debugs   encodings   error_handler(    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   __init__Q   s,     	 !	 	  	 	c         C   s:   | t j o t i } n t | | | |  |  i	 | <d  S(   N(   s   streams   Nones   syss   stderrs   ConditionSets   debugs   report_levels
   halt_levels   selfs
   categoriess   category(   s   selfs   categorys   report_levels
   halt_levels   streams   debug(    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   set_conditions   s    	c         C   s,   | o |  i i |  o |  i | =n d  S(   N(   s   categorys   selfs
   categoriess   has_key(   s   selfs   category(    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   unset_conditions   s    c         C   sF   x4 |  i i |  o | | i d  d  d  } q W|  i | Sd  S(   Ns   .i   i(   s   selfs
   categoriess   has_keys   categorys   rfind(   s   selfs   category(    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   get_conditions   s      c         C   s   |  i i |  d S(   s   
        The `observer` parameter is a function or bound method which takes one
        argument, a `nodes.system_message` instance.
        N(   s   selfs	   observerss   appends   observer(   s   selfs   observer(    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   attach_observer   s     c         C   s   |  i i |  d  S(   N(   s   selfs	   observerss   removes   observer(   s   selfs   observer(    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   detach_observer   s    c         C   s"   x |  i D] } | |  q
 Wd  S(   N(   s   selfs	   observerss   observers   message(   s   selfs   messages   observer(    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   notify_observers   s    
 c         O   s  | i   } | i d d  } | i d  o | d =n | i d  oc t | d  \ } }
 | d =| t	 j	 o | i
 d |  n |
 t	 j	 o | i
 d |
  q n | i
 d |  i  t i | d | d |  i | | | } |  | i   \ }	 } } } | | j p |	 o
 | d j o | oK | i   i |  i |  i  } | o | | Id	 | IJqv| | IJn | | j o t | |   n | d j p |	 o |  i |  n t | |  i   |  _  | Sd
 S(   ss   
        Return a system_message object.

        Raise an exception or generate a warning if appropriate.
        s   categorys    s	   base_nodes   sources   lines   levels   typei    s   [%s]N(!   s   kwargss   copys
   attributess   gets   categorys   has_keys   get_source_lines   sources   lines   Nones
   setdefaults   selfs   nodess   system_messages   messages   levels   levelss   childrens   msgs   astuples   debugs   report_levels
   halt_levels   streams   astexts   encodes   encodings   error_handlers   msgtexts   SystemMessages   notify_observerss   maxs	   max_level(   s   selfs   levels   messages   childrens   kwargss   categorys   msgtexts
   halt_levels   streams   debugs   lines   sources   report_levels   msgs
   attributes(    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   system_message   s6     (c         O   s   |  i d | |  Sd S(   s   
        Level-0, "DEBUG": an internal reporting issue. Typically, there is no
        effect on the processing. Level-0 system messages are handled
        separately from the others.
        i    N(   s   selfs   system_messages   argss   kwargs(   s   selfs   argss   kwargs(    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   debug   s     c         O   s   |  i d | |  Sd S(   s   
        Level-1, "INFO": a minor issue that can be ignored. Typically there is
        no effect on processing, and level-1 system messages are not reported.
        i   N(   s   selfs   system_messages   argss   kwargs(   s   selfs   argss   kwargs(    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   info   s     c         O   s   |  i d | |  Sd S(   s   
        Level-2, "WARNING": an issue that should be addressed. If ignored,
        there may be unpredictable problems with the output.
        i   N(   s   selfs   system_messages   argss   kwargs(   s   selfs   argss   kwargs(    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   warning   s     c         O   s   |  i d | |  Sd S(   sz   
        Level-3, "ERROR": an error that should be addressed. If ignored, the
        output will contain errors.
        i   N(   s   selfs   system_messages   argss   kwargs(   s   selfs   argss   kwargs(    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   error   s     c         O   s   |  i d | |  Sd S(   s   
        Level-4, "SEVERE": a severe error that must be addressed. If ignored,
        the output will contain severe errors. Typically level-4 system
        messages are turned into exceptions which halt processing.
        i   N(   s   selfs   system_messages   argss   kwargs(   s   selfs   argss   kwargs(    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   severe   s     (   s   __name__s
   __module__s   __doc__s   splits   levelss   Nones   __init__s   set_conditionss   unset_conditionss   __delitem__s   get_conditionss   __getitem__s   attach_observers   detach_observers   notify_observerss   system_messages   debugs   infos   warnings   errors   severe(    (    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   Reporter   s$   -  2						#				s   ConditionSetc           B   s    t  Z d  Z d   Z d   Z RS(   s   
    A set of two thresholds (`report_level` & `halt_level`), a switch
    (`debug`), and an I/O stream (`stream`), corresponding to one `Reporter`
    category.
    c         C   s(   | |  _  | |  _ | |  _ | |  _ d  S(   N(   s   debugs   selfs   report_levels
   halt_levels   stream(   s   selfs   debugs   report_levels
   halt_levels   stream(    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   __init__   s    			c         C   s    |  i |  i |  i |  i f Sd  S(   N(   s   selfs   debugs   report_levels
   halt_levels   stream(   s   self(    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   astuple   s    (   s   __name__s
   __module__s   __doc__s   __init__s   astuple(    (    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   ConditionSet   s    	s   ExtensionOptionErrorc           B   s   t  Z RS(   N(   s   __name__s
   __module__(    (    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   ExtensionOptionError  s    s   BadOptionErrorc           B   s   t  Z RS(   N(   s   __name__s
   __module__(    (    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   BadOptionError  s    s   BadOptionDataErrorc           B   s   t  Z RS(   N(   s   __name__s
   __module__(    (    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   BadOptionDataError  s    s   DuplicateOptionErrorc           B   s   t  Z RS(   N(   s   __name__s
   __module__(    (    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   DuplicateOptionError  s    c         C   s#   t  |   } t | |  } | Sd S(   sC  
    Return a dictionary mapping extension option names to converted values.

    :Parameters:
        - `field_list`: A flat field list without field arguments, where each
          field body consists of a single paragraph only.
        - `options_spec`: Dictionary mapping known option names to a
          conversion function such as `int` or `float`.

    :Exceptions:
        - `KeyError` for unknown option names.
        - `ValueError` for invalid option values (raised by the conversion
           function).
        - `TypeError` for invalid option value types (raised by conversion
           function).
        - `DuplicateOptionError` for duplicate options.
        - `BadOptionError` for invalid fields.
        - `BadOptionDataError` for invalid option data (missing name,
          missing data, bad quotes, etc.).
    N(   s   extract_optionss
   field_lists   option_lists   assemble_option_dicts   options_specs   option_dict(   s
   field_lists   options_specs   option_dicts   option_list(    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   extract_extension_options  s     c         C   s.  g  } x|  D]} t | d i   i    d j o t d   n t | d i   i    } | d } t |  d j o
 t } n t |  d j pH t | d t i  p0 t | d  d j p t | d d t i  o t d |   n | d d i   } | i | | f  q W| Sd S(   s  
    Return a list of option (name, value) pairs from field names & bodies.

    :Parameter:
        `field_list`: A flat field list, where each field name is a single
        word and each field body consists of a single paragraph only.

    :Exceptions:
        - `BadOptionError` for invalid fields.
        - `BadOptionDataError` for invalid option data (missing name,
          missing data, bad quotes, etc.).
    i    i   s:   extension option field name may not contain multiple wordssM   extension option field body may contain
a single paragraph only (option "%s")N(   s   option_lists
   field_lists   fields   lens   astexts   splits   BadOptionErrors   strs   lowers   names   bodys   Nones   datas
   isinstances   nodess	   paragraphs   Texts   BadOptionDataErrors   append(   s
   field_lists   bodys   names   fields   option_lists   data(    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   extract_options   s      #

^c         C   s   h  } x |  D] \ } } | | } | t j o t |   n | i |  o t	 d |   n y | |  | | <Wq t
 t f j
 o% } | i d | | | f   q Xq W| Sd S(   sa  
    Return a mapping of option names to values.

    :Parameters:
        - `option_list`: A list of (name, value) pairs (the output of
          `extract_options()`).
        - `options_spec`: Dictionary mapping known option names to a
          conversion function such as `int` or `float`.

    :Exceptions:
        - `KeyError` for unknown option names.
        - `DuplicateOptionError` for duplicate options.
        - `ValueError` for invalid option values (raised by conversion
           function).
        - `TypeError` for invalid option value types (raised by conversion
           function).
    s   duplicate option "%s"s   (option: "%s"; value: %r)
%sN(   s   optionss   option_lists   names   values   options_specs	   convertors   Nones   KeyErrors   has_keys   DuplicateOptionErrors
   ValueErrors	   TypeErrors   details	   __class__(   s   option_lists   options_specs   names   values   details	   convertors   options(    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   assemble_option_dict@  s      
%s   NameValueErrorc           B   s   t  Z RS(   N(   s   __name__s
   __module__(    (    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   NameValueErrora  s    c         C   s  g  } x|  o|  i d  } | d j o t d   n |  |  i   } | d j p | o t d   n |  | d i   }  |  o t d |   n |  d d j o |  i |  d d  } | d j o t d	 | |  d f   n t	 |   | d j o |  | d i   o t d
 | |  d f   n |  d | !} |  | d i   }  nK |  i d  } | d j o |  } d }  n |  |  } |  | d i   }  | i | i   | f  q	 W| Sd S(   s   
    Return a list of (name, value) from a line of the form "name=value ...".

    :Exception:
        `NameValueError` for invalid input (missing name, missing data, bad
        quotes, etc.).
    s   =is   missing "="i    s!   missing attribute name before "="i   s   missing value after "%s="s   '"s%   attribute "%s" missing end quote (%s)s8   attribute "%s" end quote (%s) not followed by whitespaces    s    N(   s   attlists   lines   finds   equalss   NameValueErrors   strips   attnames   lstrips   endquotes   lens   datas   spaces   appends   lower(   s   lines   endquotes   spaces   datas   equalss   attnames   attlist(    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   extract_name_valued  s:      ,

c         C   s   | t j o t i   i   } n t |  | i | i d | i	 d | i
 d | i d | i } t i | | d |  } | i |  d  | Sd S(   s  
    Return a new empty document object.

    :Parameters:
        `source` : string
            The path to or description of the source text of the document.
        `settings` : optparse.Values object
            Runtime settings.  If none provided, a default set will be used.
    s   streams   debugs   encodings   error_handlers   sourceiN(   s   settingss   Nones   frontends   OptionParsers   get_default_valuess   Reporters   sources   report_levels
   halt_levels   warning_streams   debugs   error_encodings   error_encoding_error_handlers   reporters   nodess   documents   note_source(   s   sources   settingss   documents   reporter(    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   new_document  s    	 	c         C   s   t  |   d j o t |  d t i  o^ |  d } xQ | D]E \ } } | i	 | i
  } | o  | i | | i
  | _
 d  Sq; q; Wn d  S(   Ni   i    (   s   lens	   paragraphs
   isinstances   nodess   Texts   textnodes   keyword_substitutionss   patterns   substitutions   searchs   datas   matchs   sub(   s	   paragraphs   keyword_substitutionss   textnodes   patterns   substitutions   match(    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   clean_rcs_keywords  s    *
 c         C   s   t  i i |  p d  i t  i  } t  i i |  i t  i  } | d  | d  j o d i	 |  Sn | i
   | i
   x< | o | o | d | d j o | i   | i   q W| i
   d g t |  d | } d i	 |  Sd S(   s   
    Build and return a path to `target`, relative to `source` (both files).

    If there is no common prefix, return the absolute path to `target`.
    s
   dummy_filei   s   /is   ..i   N(   s   oss   paths   abspaths   sources   splits   seps   source_partss   targets   target_partss   joins   reverses   pops   lens   parts(   s   sources   targets   source_partss   target_partss   parts(    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   relative_path  s     %

 #

c         C   sN   x= |  o5 |  i p |  i o |  i |  i f Sn |  i }  q Wt t f Sd S(   sk   
    Return the "source" and "line" attributes from the `node` given or from
    its closest ancestor.
    N(   s   nodes   sources   lines   parents   None(   s   node(    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   get_source_line  s      (   s   __doc__s   __docformat__s   syss   oss   os.paths   typess
   StringTypes   UnicodeTypes   docutilss   ApplicationErrors	   DataErrors   frontends   nodess   SystemMessages   SystemMessagePropagations   Reporters   ConditionSets   ExtensionOptionErrors   BadOptionErrors   BadOptionDataErrors   DuplicateOptionErrors   extract_extension_optionss   extract_optionss   assemble_option_dicts   NameValueErrors   extract_name_values   Nones   new_documents   clean_rcs_keywordss   relative_paths   get_source_line(   s   frontends   get_source_lines   __docformat__s   extract_extension_optionss
   StringTypes   Reporters   assemble_option_dicts   extract_name_values   SystemMessages   ExtensionOptionErrors   new_documents	   DataErrors   ApplicationErrors   relative_paths   syss   DuplicateOptionErrors   clean_rcs_keywordss   nodess   BadOptionErrors   oss   ConditionSets   UnicodeTypes   extract_optionss   BadOptionDataErrors   SystemMessagePropagations   NameValueError(    (    sC   /mit/golem/arch/share/lib/python2.3/site-packages/docutils/utils.pys   ?	   s0   					 	!	,			