
BXQc           @   s  d  Z  d d l m Z d Z d Z d Z d Z d Z d d l m	 Z	 m
 Z
 d d	 l Z d d	 l Z d d	 l Z d
 e f d     YZ e j e  Z d f  d     YZ d e f d     YZ d e e f d     YZ d e e f d     YZ d e f d     YZ d   Z d   Z d e e	 f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d  e f d!     YZ d" e f d#     YZ  d$ e f d%     YZ! d& e f d'     YZ" e# d( k rd d	 l$ Z$ e e$ j% j&    Z' e' j(   GHn  d	 S()   s/  Beautiful Soup
Elixir and Tonic
"The Screen-Scraper's Friend"
v2.1.1
http://www.crummy.com/software/BeautifulSoup/

Beautiful Soup parses arbitrarily invalid XML- or HTML-like substance
into a tree representation. It provides methods and Pythonic idioms
that make it easy to search and modify the tree.

A well-formed XML/HTML document will yield a well-formed data
structure. An ill-formed XML/HTML document will yield a
correspondingly ill-formed data structure. If your document is only
locally well-formed, you can use this library to find and process the
well-formed part of it. The BeautifulSoup class has heuristics for
obtaining a sensible parse tree in the face of common HTML errors.

Beautiful Soup has no external dependencies. It works with Python 2.2
and up.

Beautiful Soup defines classes for four different parsing strategies:

 * BeautifulStoneSoup, for parsing XML, SGML, or your domain-specific
   language that kind of looks like XML.

 * BeautifulSoup, for parsing run-of-the-mill HTML code, be it valid
   or invalid.

 * ICantBelieveItsBeautifulSoup, for parsing valid but bizarre HTML
   that trips up BeautifulSoup.

 * BeautifulSOAP, for making it easier to parse XML documents that use
   lots of subelements containing a single string, where you'd prefer
   they put that string into an attribute (such as SOAP messages).

You can subclass BeautifulStoneSoup or BeautifulSoup to create a
parsing strategy specific to an XML schema or a particular bizarre
HTML document. Typically your subclass would just override
SELF_CLOSING_TAGS and/or NESTABLE_TAGS.
i(   t
   generatorss*   Leonard Richardson (leonardr@segfault.org)s   2.1.1s   $Date: 2004/10/18 00:14:20 $s*   Copyright (c) 2004-2005 Leonard Richardsont   PSF(   t
   SGMLParsert   SGMLParseErrorNt   NullTypec           B   sh   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z RS(   s  Similar to NoneType with a corresponding singleton instance
    'Null' that, unlike None, accepts any message and returns itself.

    Examples:
    >>> Null("send", "a", "message")("and one more",
    ...      "and what you get still") is Null
    True
    c         C   s   t  S(   N(   t   Null(   t   cls(    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   __new__A   s    c         O   s   t  S(   N(   R   (   t   selft   argst   kwargs(    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   __call__B   s    c         C   s   t  S(   N(   R   (   R   t   attr(    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   __getattr__D   s    c         C   s   t  S(   N(   R   (   R   t   item(    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   __getitem__E   s    c         C   s   d  S(   N(    (   R   R   t   value(    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   __setattr__F   s    c         C   s   d  S(   N(    (   R   R   R   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   __setitem__G   s    c         C   s   d S(   Ni    (    (   R   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   __len__H   s    c         C   s
   t  g   S(   N(   t   iter(   R   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   __iter__K   s    c         C   s   t  S(   N(   t   False(   R   R   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   __contains__L   s    c         C   s   d S(   NR   (    (   R   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   __repr__M   s    (   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   R   R   R   R   (    (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR   6   s   										t   PageElementc           B   s@  e  Z d  Z e e d  Z d i  d d  Z e Z d i  d d d  Z d i  d d  Z	 e	 Z
 d i  d d d  Z d i  d d  Z d i  d d d  Z e Z d i  d d  Z e Z d i  d d d	  Z d i  d
  Z e Z d i  d d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   se   Contains the navigational information for some part of the page
    (either a tag or a piece of text)c         C   sh   | |  _  | |  _ t |  _ t |  _ t |  _ |  j  rd |  j  j rd |  j  j d |  _ |  |  j _ n  d S(   sN   Sets up the initial relations between this element and
        other elements.iN(   t   parentt   previousR   t   nextt   previousSiblingt   nextSiblingt   contents(   R   R   R   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   setupT   s    					c         C   s   |  j  |  j | | |  S(   sj   Returns the first item that matches the given criteria and
        appears after this Tag in the document.(   t   _firstt	   fetchNext(   R   t   namet   attrst   text(    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   findNext`   s    c         C   s   |  j  | | | | |  j  S(   sd   Returns all items that match the given criteria and appear
        before after Tag in the document.(   t   _fetcht   nextGenerator(   R   R&   R'   R(   t   limit(    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR%   f   s    c         C   s   |  j  |  j | | |  S(   s{   Returns the closest sibling to this Tag that matches the
        given criteria and appears after this Tag in the document.(   R$   t   fetchNextSiblings(   R   R&   R'   R(   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   findNextSiblingk   s    c         C   s   |  j  | | | | |  j  S(   sq   Returns the siblings of this Tag that match the given
        criteria and appear after this Tag in the document.(   R*   t   nextSiblingGenerator(   R   R&   R'   R(   R,   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR-   q   s    c         C   s   |  j  |  j | | |  S(   sk   Returns the first item that matches the given criteria and
        appears before this Tag in the document.(   R$   t   fetchPrevious(   R   R&   R'   R(   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   findPreviousv   s    c         C   s   |  j  | | | | |  j  S(   sc   Returns all items that match the given criteria and appear
        before this Tag in the document.(   R*   t   previousGenerator(   R   R&   R'   R(   R,   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR0   {   s    c         C   s   |  j  |  j | | |  S(   s|   Returns the closest sibling to this Tag that matches the
        given criteria and appears before this Tag in the document.(   R$   t   fetchPreviousSiblings(   R   R&   R'   R(   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   findPreviousSibling   s    c         C   s   |  j  | | | | |  j  S(   sr   Returns the siblings of this Tag that match the given
        criteria and appear before this Tag in the document.(   R*   t   previousSiblingGenerator(   R   R&   R'   R(   R,   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR3      s    c         C   s2   t  } |  j | | d  } | r. | d } n  | S(   sO   Returns the closest parent of this Tag that matches the given
        criteria.i   i    (   R   t   fetchParents(   R   R&   R'   t   rt   l(    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt
   findParent   s
    c         C   s   |  j  | | d | |  j  S(   sF   Returns the parents of this Tag that match the given
        criteria.N(   R*   t   Nonet   parentGenerator(   R   R&   R'   R,   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR6      s    c         C   s2   t  } | | | | d  } | r. | d } n  | S(   Ni   i    (   R   (   R   t   methodR&   R'   R(   R7   R8   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR$      s
    c         C   sT  t  | d  s i | d 6} n  g  } |   } xt rOy | j   } Wn t k
 r[ Pn Xd }	 t | t  r | s| s |  j | |  r t }
 xE | j   D]7 \ } } | j	 |  } |  j | |  s t
 }
 Pq q W|
 r | }	 q q qn$ | r|  j | |  r| }	 qn  |	 r1 | j |	  | rLt |  | k rLPqLq1 q1 W| S(   s8   Iterates over a generator looking for things that match.t   itemst   classN(   t   hasattrt   TrueR   t   StopIterationR:   t
   isinstancet   Tagt   _matchesR=   t   getR   t   appendt   len(   R   R&   R'   R(   R,   t	   generatort   resultst   gt   it   foundt   matchR   t   matchAgainstt   check(    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR*      s:    		c         c   s%   |  } x | r  | j  } | Vq	 Wd  S(   N(   R   (   R   RK   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR+      s    		c         c   s%   |  } x | r  | j  } | Vq	 Wd  S(   N(   R!   (   R   RK   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR/      s    		c         c   s%   |  } x | r  | j  } | Vq	 Wd  S(   N(   R   (   R   RK   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR2      s    		c         c   s%   |  } x | r  | j  } | Vq	 Wd  S(   N(   R    (   R   RK   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR5      s    		c         c   s%   |  } x | r  | j  } | Vq	 Wd  S(   N(   R   (   R   RK   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR;      s    		c         C   s  t  |  rV t | t  rV x3 | D]+ } t | t  r# |  j | |  r# t Sq# Wt St |  rl | |  St | t  r | j } n  t | t	  s t
 |  } n  t | d  r | j |  St  |  r | | k St | d  r | j |  St
 |  | k S(   NRM   R=   (   t   isListRB   RC   t   NavigableTextRD   R@   R   t   callableR&   t
   basestringt   strR?   t   searcht   has_key(   R   t   chunkt
   howToMatcht   tag(    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyRD      s$    !

N(   R   R   R   R   R#   R:   R)   t	   firstNextR%   R.   t   firstNextSiblingR-   R1   R0   t   firstPreviousR4   t   firstPreviousSiblingR3   R9   t   firstParentR6   R$   R*   R+   R/   R2   R5   R;   RD   (    (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR   P   s4   			#					RQ   c           B   s   e  Z d    Z RS(   c         C   s-   | d k r |  St  d |  j j | f  d S(   s7   For backwards compatibility, text.string gives you textt   strings!   '%s' object has no attribute '%s'N(   t   AttributeErrort	   __class__R   (   R   R   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR     s    (   R   R   R   (    (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyRQ     s   t   NavigableStringc           B   s   e  Z RS(    (   R   R   (    (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyRb     s   t   NavigableUnicodeStringc           B   s   e  Z RS(    (   R   R   (    (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyRc     s   RC   c           B   sL  e  Z d  Z d e e d  Z d d  Z d   Z d   Z d   Z	 d   Z
 d   Z d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d d d  Z d d  Z d d d  Z e d  Z e d d  Z d i  e d d  Z e Z d i  e d d d  Z e Z d   Z d   Z d   Z  d   Z! d   Z" RS(   s=   Represents a found HTML tag with its attributes and contents.c         C   sM   | |  _  | d k r g  } n  | |  _ g  |  _ |  j | |  t |  _ d S(   s   Basic constructor.N(   R&   R:   R'   R"   R#   R   t   hidden(   R   R&   R'   R   R   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   __init__  s    				c         C   s   |  j    j | |  S(   s   Returns the value of the 'key' attribute for the tag, or
        the value given for 'default' if it doesn't have that
        attribute.(   t   _getAttrMapRE   (   R   t   keyt   default(    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyRE   !  s    c         C   s   |  j    | S(   sq   tag[key] returns the value of the 'key' attribute for the tag,
        and throws an exception if it's not there.(   Rf   (   R   Rg   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR   '  s    c         C   s   t  |  j  S(   s0   Iterating over a tag iterates over its contents.(   R   R"   (   R   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR   ,  s    c         C   s   t  |  j  S(   s:   The length of a tag is the length of its list of contents.(   RG   R"   (   R   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR   0  s    c         C   s   | |  j  k S(   N(   R"   (   R   t   x(    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR   4  s    c         C   s   t  S(   s-   A tag is non-None even if it has no contents.(   R@   (   R   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   __nonzero__7  s    c         C   s   |  j    | |  j | <t } xS t d t |  j   D]9 } |  j | d | k r6 | | f |  j | <t } q6 q6 W| s |  j j | | f  n  | |  j    | <d S(   sK   Setting tag[key] sets the value of the 'key' attribute for the
        tag.i    N(   Rf   t   attrMapR   t   rangeRG   R'   R@   RF   (   R   Rg   R   RL   RK   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR   ;  s    
c         C   sd   x] |  j  D]R } | d | k r3 |  j  j |  n  |  j   |  j j |  r
 |  j | =q
 q
 Wd S(   s;   Deleting tag[key] deletes all 'key' attributes for the tag.i    N(   R'   t   removeRf   Rk   RV   (   R   Rg   R   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   __delitem__I  s    
c         O   s   t  |  j | |  S(   s   Calling a tag like a function is the same as calling its
        fetch() method. Eg. tag('a') returns a list of all the A tags
        found within this tag.(   t   applyt   fetch(   R   R	   R
   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR   T  s    c         C   sh   t  |  d k rB | j d  t  |  d k rB |  j | d   S| j d  d k rd |  j |  Sd  S(   Ni   RC   it   __i    (   RG   t   rfindt   firstt   find(   R   RY   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR   Z  s    1c      	   C   s   t  | d  sl t  | d  sl t  | d  sl |  j | j k sl |  j | j k sl t |   t |  k rp t Sx> t d t |  j   D]$ } |  j | | j | k r t Sq Wt S(   s  Returns true iff this tag has the same name, the same attributes,
        and the same contents (recursively) as the given tag.

        NOTE: right now this will return false if two tags have the
        same attributes in a different order. Should this be fixed?R&   R'   R"   i    (   R?   R&   R'   RG   R   Rl   R"   R@   (   R   t   otherRK   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   __eq__`  s    lc         C   s   |  | k S(   sZ   Returns true iff this tag is not identical to the other tag,
        as defined in __eq__.(    (   R   Ru   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   __ne__m  s    c         C   s
   t  |   S(   s   Renders this tag as a string.(   RT   (   R   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR   r  s    c         C   s   |  j  d  S(   Ni   (   t   __str__(   R   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   __unicode__v  s    c         C   s  g  } |  j  rC x1 |  j  D]# \ } } | j d | | f  q Wn  d } d } |  j   rd d } n d |  j } d
 } | d
 k r | } |  j s | d 7} q n  |  j | d | }	 | r d d | }
 n  |  j r |	 } n g  } d } | rd d j |  } n  | r| j |
  n  | j d	 |  j | | f  | j |	  | rj| d
 k rj| j |
  n  | j |  d j |  } t |  t	 j
 k } | r| rt |  } n! | r| t k rt |  } n  | S(   s   Returns a string or Unicode representation of this tag and
        its contents.

        NOTE: since Python's HTML parser consumes whitespace, this
        method is not certain to reproduce the whitespace present in
        the original string.s   %s="%s"t    s    /s   </%s>i   t   needUnicodes   
%st    s   <%s%s%s>N(   R'   RF   t   isSelfClosingR&   R:   Rd   t   renderContentst   joint   typet   typest   UnicodeTypet   unicodeR   RT   (   R   R{   t   showStructureIndentR'   Rg   t   valt   closet   closeTagt   indentIncrementR"   t   spacet   st   attributeStringt	   isUnicode(    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyRx   y  sJ    					c         C   s   |  j  | d t S(   NR   (   Rx   R@   (   R   R{   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   prettify  s    c         C   s   g  } x |  D] } d } t | t  s= t |  t j k rL t |  } nL t | t  rw | j | j	 | |   n! | r t |  } n t
 |  } | r | d k r | d d k r | d  } q n  | j |  q q Wd j |  S(   sI   Renders the contents of this tag as a (possibly Unicode) 
        string.is   
Rz   N(   R:   RB   Rc   R   R   R   R   RC   RF   Rx   RT   R   (   R   R   R{   R   t   cR(   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR~     s     $c         C   s   |  j  d | d |  S(   s   Convenience method to retrieve the first piece of text matching the
        given criteria. 'text' can be a string, a regular expression object,
        a callable that takes a string and returns whether or not the
        string 'matches', etc.t	   recursiveR(   (   Rs   (   R   R(   R   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt	   firstText  s    c         C   s   |  j  d | d | d |  S(   s   Convenience method to retrieve all pieces of text matching the
        given criteria. 'text' can be a string, a regular expression object,
        a callable that takes a string and returns whether or not the
        string 'matches', etc.R   R(   R,   (   Rp   (   R   R(   R   R,   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt	   fetchText  s    c         C   s8   t  } |  j | | | | d  } | r4 | d } n  | S(   sL   Return only the first child of this
        Tag matching the given criteria.i   i    (   R   Rp   (   R   R&   R'   R   R(   R7   R8   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyRs     s
    c         C   s4   |  j  } | s |  j } n  |  j | | | | |  S(   s  Extracts a list of Tag objects that match the given
        criteria.  You can specify the name of the Tag and any
        attributes you want the Tag to have.

        The value of a key-value pair in the 'attrs' map can be a
        string, a list of strings, a regular expression object, or a
        callable that takes a string and returns whether or not the
        string matches for some custom definition of 'matches'. The
        same is true of the tag name.(   t   recursiveChildGeneratort   childGeneratorR*   (   R   R&   R'   R   R(   R,   RH   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyRp     s    	c         C   s   |  j  t j k S(   s   Returns true iff this is a self-closing tag as defined in the HTML
        standard.

        TODO: This is specific to BeautifulSoup and its subclasses, but it's
        used by __str__(   R&   t   BeautifulSoupt   SELF_CLOSING_TAGS(   R   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR}     s    c         C   s   |  j  j |  d S(   s2   Appends the given tag to the contents of this tag.N(   R"   RF   (   R   RY   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyRF     s    c         C   sI   t  |  d  sB i  |  _ x' |  j D] \ } } | |  j | <q" Wn  |  j S(   s^   Initializes a map representation of this tag's attributes,
        if not already initialized.Rk   (   t   getattrRk   R'   (   R   Rg   R   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyRf     s
    	c         c   s9   x, t  d t |  j   D] } |  j | Vq Wt  d  S(   Ni    (   Rl   RG   R"   RA   (   R   RK   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR     s    c         c   s   |  d f g } x | r | j    \ } } t | t  r x t | t | j   D]z } | j | } | Vt | t  rR | j rR | t | j  d k  r | j | | d f  n  | j | d f  PqR qR Wq q Wt  d  S(   Ni    i   (   t   popRB   RC   Rl   RG   R"   RF   RA   (   R   t   stackRY   t   startRK   t   a(    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR     s    	N(#   R   R   R   R:   R   Re   RE   R   R   R   R   Rj   R   Rn   R   R   Rv   Rw   R   Ry   Rx   R   R~   R@   R   R   Rs   t	   findChildRp   t   fetchChildrenR}   RF   Rf   R   R   (    (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyRC     s>   
													0			
	c         C   s+   t  |  d  p* t |   t j t j f k S(   st   Convenience method that works with all 2.x versions of Python
    to determine whether or not something is listlike.R   (   R?   R   R   t   ListTypet	   TupleType(   R8   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyRP     s    c         G   s   i  } x{ | D]s } t  | d  rL x[ | j   D] \ } } | | | <q/ Wq t |  rv x% | D] } |  | | <q_ Wq |  | | <q W| S(   s   Turns a list of maps, lists, or scalars into a single map.
    Used to build the SELF_CLOSING_TAGS and NESTABLE_TAGS maps out
    of lists and partial maps.R=   (   R?   R=   RP   (   Rh   R	   t   builtt   portiont   kt   v(    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   buildTagMap!  s    t   BeautifulStoneSoupc           B   s  e  Z d  Z i  Z i  Z i  Z i  Z i  d d 6d d 6d d 6d d 6d	 d
 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d  6d! d" 6d# d$ 6d% d& 6d' d( 6d) d* 6d+ d, 6d- d. 6d/ d0 6d1 d2 6d3 d4 6d5 d6 6d7 d8 6d d9 6d: d; 6d< d= 6Z e j	 d>  d?   f e j	 d@  dA   f e j	 dB  dC   f g Z
 dD Z dY e e dE  Z dF   Z dG   Z dH   Z dI   Z dJ   Z dK   Z dL   Z e dM  Z dN   Z dO dP  Z dQ   Z dR   Z dS   Z dT   Z dU   Z dV   Z dW   Z dX   Z  RS(Z   sd  This class contains the basic parser and fetch code. It defines
    a parser that knows nothing about tag behavior except for the
    following:
   
      You can't close a tag without closing all the tags it encloses.
      That is, "<foo><bar></foo>" actually means
      "<foo><bar></bar></foo>".

    [Another possible explanation is "<foo><bar /></foo>", but since
    this class defines no SELF_CLOSING_TAGS, it will never use that
    explanation.]

    This class is useful for parsing XML or made-up markup languages,
    or when BeautifulSoup makes an assumption counter to what you were
    expecting.s   &euro;s   R|   s   s   &sbquo;s   s   &fnof;s   s   &bdquo;s   s   &hellip;s   s   &dagger;s   s   &Dagger;s   s   &caret;s   t   %s   s   &Scaron;s   s   &lt;s   s   &OElig;s   t   ?s   t   Zs   s   s   s   &lsquo;s   s   &rsquo;s   s   &ldquo;s   s   &rdquo;s   s   &bull;s   s   &ndash;s   s   &mdash;s   s   &tilde;s   s   &trade;s   s   &scaron;s   s   &gt;s   s   &oelig;s   s   t   zs   s   &Yuml;s   s   (<[^<>]*)/>c         C   s   |  j  d  d S(   Ni   s    />(   t   group(   Ri   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   <lambda>o  s    s   <!\s+([^<>]*)>c         C   s   d |  j  d  d S(   Ns   <!i   t   >(   R   (   Ri   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR   q  s    s   ([-])c         C   s   t  j j |  j d   S(   Ni   (   R   t   MS_CHARSRE   R   (   Ri   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR   s  s    s
   [document]c         C   s   t  j |  |  j  | r2 t |  r2 |  j } n  | |  _ t j |   g  |  _ d |  _ |  j	   t
 | d  r | j   } n  | r |  j |  n  | r |  j   n  d S(   s  Initialize this as the 'root tag' and feed in any text to
        the parser.

        NOTE about avoidParserProblems: sgmllib will process most bad
        HTML, and BeautifulSoup has tricks for dealing with some HTML
        that kills sgmllib, but Beautiful Soup can nonetheless choke
        or lose data if your data uses self-closing tags or
        declarations incorrectly. By default, Beautiful Soup sanitizes
        its input to avoid the vast majority of these problems. The
        problems are relatively rare, even in bad HTML, so feel free
        to pass in False to avoidParserProblems if they don't apply to
        you, and you'll get better performance. The only reason I have
        this turned on by default is so I don't get so many tech
        support questions.

        The two most common instances of invalid HTML that will choke
        sgmllib are fixed by the default parser massage techniques:

         <br/> (No space between name of closing tag and tag close)
         <! --Comment--> (Extraneous whitespace in declaration)

        You can pass in a custom list of (RE object, replace method)
        tuples to get Beautiful Soup to scrub your input the way you
        want.i   t   readN(   RC   Re   t   ROOT_TAG_NAMERP   t   PARSER_MASSAGEt   avoidParserProblemsR   t
   quoteStackRd   t   resetR?   R   t   feedt   done(   R   R(   R   t   initialTextIsEverything(    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyRe   x  s    			
c         C   s~   | j  d  d k s? | j  d  d k s? | j  d  d k rO t j |  |  S| j  d  d k rt t j |  |  St  d S(   s   This method routes method call requests to either the SGMLParser
        superclass or the Tag superclass, depending on the method name.t   start_i    t   end_t   do_Rq   N(   Rt   R   R   RC   R`   (   R   t
   methodName(    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR     s    *c         C   sL   |  j  r8 x, |  j  D] \ } } | j | |  } q Wn  t j |  |  d  S(   N(   R   t   subR   R   (   R   R(   t   fixt   m(    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR     s    	c         C   s4   |  j    x# |  j j |  j k r/ |  j   q Wd S(   s^   Called when you're done parsing, so that the unclosed tags can be
        correctly processed.N(   t   endDatat
   currentTagR&   R   t   popTag(   R   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR     s    
c         C   s9   t  j |   g  |  _ d  |  _ g  |  _ |  j |   d  S(   N(   R   R   t   currentDataR:   R   t   tagStackt   pushTag(   R   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR     s
    			c         C   s|   |  j  j   } t |  j j  d k rY t |  j j d t  rY |  j j d |  j _ n  |  j  ru |  j  d |  _ n  |  j S(   Ni   i    i(   R   R   RG   R   R"   RB   RQ   R_   (   R   RY   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR     s    	c         C   s@   |  j  r |  j  j |  n  |  j j |  |  j d |  _  d  S(   Ni(   R   RF   R   (   R   RY   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR     s    	c         C   s   d j  |  j  } | r | j   sB d | k r9 d } qB d } n  t } t |  t j k rf t } n  | |  } | j |  j	 |  j
  |  j
 r | |  j
 _ n  | |  _
 |  j	 j j |  n  g  |  _ d  S(   NRz   s   
R|   (   R   R   t   stripRb   R   R   R   Rc   R#   R   R   R   R"   RF   (   R   R   R   t   o(    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR     s     					c         C   s   | |  j  k r d Sd } d } xT t t |  j  d d d  D]3 } | |  j | j k r? t |  j  | } Pq? q? W| s | d } n  x# t d |  D] } |  j   } q W| S(   s   Pops the tag stack up to and including the most recent
        instance of the given tag. If inclusivePop is false, pops the tag
        stack up to but *not* including the most recent instqance of
        the given tag.Ni    i   i(   R   R:   Rl   RG   R   R&   R   (   R   R&   t   inclusivePopt   numPopst   mostRecentTagRK   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt	   _popToTag  s    &c   	   	   C   s  |  j  j |  } | d k } |  j j |  } d } t } x t t |  j  d d d  D] } |  j | } | s | j	 | k r | r | } Pn  | d k r | j	 | k s | d k r | r |  j j | j	  r | j	 } t
 } Pn  | j } q\ W| r|  j | |  n  d S(   s   We need to pop up to the previous tag of this type, unless
        one of this tag's nesting reset triggers comes between this
        tag and the previous tag of this type, OR unless this tag is a
        generic nesting trigger and another generic nesting trigger
        comes between this tag and the previous tag of this type.

        Examples:
         <p>Foo<b>Bar<p> should pop to 'p', not 'b'.
         <p>Foo<table>Bar<p> should pop to 'table', not 'p'.
         <p>Foo<table><tr>Bar<p> should pop to 'tr', not 'p'.
         <p>Foo<b>Bar<p> should pop to 'p', not 'b'.

         <li><ul><li> *<li>* should pop to 'ul', not the first 'li'.
         <tr><table><tr> *<tr>* should pop to 'table', not the first 'tr'
         <td><tr><td> *<td>* should pop to 'tr', not the first 'td'
        i   i    iN(   t   NESTABLE_TAGSRE   R:   t   RESET_NESTING_TAGSRV   R@   Rl   RG   R   R&   R   R   R   (	   R   R&   t   nestingResetTriggerst
   isNestablet   isResetNestingt   popTot	   inclusiveRK   t   p(    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt	   _smartPop  s(    &	i    c         C   s	  |  j  r? d j t d   |   } |  j d | | f  d  S|  j   | |  j k ro | ro |  j |  n  t | | |  j |  j	  } |  j	 r | |  j	 _
 n  | |  _	 |  j |  | s | |  j k r |  j   n  | |  j k r|  j  j |  d |  _ n  d  S(   NRz   c         S   s   |  \ } } d | | f S(   Ns    %s="%s"(    (   t   .0Ri   t   y(    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR   4  s    s   <%s%s>i   (   R   R   t   mapt   handle_dataR   R   R   RC   R   R   R   R   R   t
   QUOTE_TAGSRF   t   literal(   R   R&   R'   t   selfClosingRY   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   unknown_starttag/  s"    	
		c         C   s   |  j  r1 |  j  d | k r1 |  j d |  d  S|  j   |  j |  |  j  r |  j  d | k r |  j  j   t |  j   d k |  _ n  d  S(   Nis   </%s>i    (   R   R   R   R   R   RG   R   (   R   R&   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   unknown_endtagF  s    
c         C   s   |  j  j |  d  S(   N(   R   RF   (   R   t   data(    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR   R  s    c         C   s   |  j  d |  d S(   s0   Propagate processing instructions right through.s   <?%s>N(   R   (   R   R(   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt	   handle_piU  s    c         C   s   |  j  d |  d S(   s!   Propagate comments right through.s	   <!--%s-->N(   R   (   R   R(   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   handle_commentY  s    c         C   s   |  j  d |  d S(   s"   Propagate char refs right through.s   &#%s;N(   R   (   R   t   ref(    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   handle_charref]  s    c         C   s   |  j  d |  d S(   s$   Propagate entity refs right through.s   &%s;N(   R   (   R   R   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   handle_entityrefa  s    c         C   s   |  j  d |  d S(   s.   Propagate DOCTYPEs and the like right through.s   <!%s>N(   R   (   R   R   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   handle_decle  s    c         C   s   d } |  j | | d !d k r{ |  j j d |  } | d k rS t |  j  } n  |  j |  j | d | ! | d } nT y t j |  |  } Wn; t k
 r |  j | } |  j |  | t |  } n X| S(   s^   Treat a bogus SGML declaration as raw data. Treat a CDATA
        declaration as regular data.i	   s	   <![CDATA[s   ]]>ii   N(   R:   t   rawdataRt   RG   R   R   t   parse_declarationR   (   R   RK   t   jR   t   toHandle(    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR   i  s    N(!   R   R   R   R   R   R   R   R   t   ret   compileR   R   R:   R@   Re   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR   4  s   

		*								0							R   c           B   s-  e  Z d  Z e d* d d d d d d d d d	 g	  Z i d* d
 6Z d d d d d d d d g Z d d d d d g Z i g  d 6g  d 6d d g d 6g  d 6d g d 6d g d 6Z	 i g  d 6d d d  d! g d" 6d" g d# 6d" g d$ 6Z
 d% d& d' d( g Z e d* e d) e e	 e
  Z e g  e e e	 e
  Z RS(+   s  This parser knows the following facts about HTML:

    * Some tags have no closing tag and should be interpreted as being
      closed as soon as they are encountered.

    * The text inside some tags (ie. 'script') may contain tags which
      are not really part of the document and which should be parsed
      as text, not tags. If you want to parse the text as tags, you can
      always fetch it and parse it explicitly.

    * Tag nesting rules:

      Most tags can't be nested at all. For instance, the occurance of
      a <p> tag should implicitly close the previous <p> tag.

       <p>Para1<p>Para2
        should be transformed into:
       <p>Para1</p><p>Para2

      Some tags can be nested arbitrarily. For instance, the occurance
      of a <blockquote> tag should _not_ implicitly close the previous
      <blockquote> tag.

       Alice said: <blockquote>Bob said: <blockquote>Blah
        should NOT be transformed into:
       Alice said: <blockquote>Bob said: </blockquote><blockquote>Blah

      Some tags can be nested, but the nesting is reset by the
      interposition of other tags. For instance, a <tr> tag should
      implicitly close the previous <tr> tag within the same <table>,
      but not close a <tr> tag in another table.

       <table><tr>Blah<tr>Blah
        should be transformed into:
       <table><tr>Blah</tr><tr>Blah
        but,
       <tr>Blah<table><tr>Blah
        should NOT be transformed into
       <tr>Blah<table></tr><tr>Blah

    Differing assumptions about tag nesting rules are a major source
    of problems with the BeautifulSoup class. If BeautifulSoup is not
    treating as nestable a tag your page author treats as nestable,
    try ICantBelieveItsBeautifulSoup before writing your own
    subclass.t   brt   hrt   inputt   imgt   metat   spacert   linkt   framet   baset   scriptt   spant   fontt   qt   objectt   bdoR   t   supt   centert
   blockquotet   divt   fieldsett   inst   delt   olt   ult   lit   dlt   ddt   dtt   tablet   tbodyt   tfoott   theadt   trt   tdt   tht   addresst   formR   t   pret   noscriptN(   R   R   R   R   R:   R   R   t   NESTABLE_INLINE_TAGSt   NESTABLE_BLOCK_TAGSt   NESTABLE_LIST_TAGSt   NESTABLE_TABLE_TAGSt   NON_NESTABLE_BLOCK_TAGSR   R   (    (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR   |  s0   .	



	t   ICantBelieveItsBeautifulSoupc           B   sh   e  Z d  Z d d d d d d d d d	 d
 d d d d d d d g Z d g Z e g  e j e e  Z RS(   s  The BeautifulSoup class is oriented towards skipping over
    common HTML errors like unclosed tags. However, sometimes it makes
    errors of its own. For instance, consider this fragment:

     <b>Foo<b>Bar</b></b>

    This is perfectly valid (if bizarre) HTML. However, the
    BeautifulSoup class will implicitly close the first b tag when it
    encounters the second 'b'. It will think the author wrote
    "<b>Foo<b>Bar", and didn't close the first 'b' tag, because
    there's no real-world reason to bold something that's already
    bold. When it encounters '</b></b>' it will close two more 'b'
    tags, for a grand total of three tags closed instead of two. This
    can throw off the rest of your document structure. The same is
    true of a number of other tags, listed below.

    It's much more common for someone to forget to close (eg.) a 'b'
    tag than to actually use nested 'b' tags, and the BeautifulSoup
    class handles the common case. This class handles the
    not-co-common case: where you can't believe someone wrote what
    they did, but it's valid HTML and BeautifulSoup screwed up by
    assuming it wouldn't be.

    If this doesn't do what you need, try subclassing this class or
    BeautifulSoup, and providing your own list of NESTABLE_TAGS.t   emt   bigRK   t   smallt   ttt   abbrt   acronymt   strongt   citet   codet   dfnt   kbdt   sampt   vart   bR  (   R   R   R   t*   I_CANT_BELIEVE_THEYRE_NESTABLE_INLINE_TAGSt)   I_CANT_BELIEVE_THEYRE_NESTABLE_BLOCK_TAGSR   R   R   (    (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR    s   		t   BeautifulSOAPc           B   s   e  Z d  Z d   Z RS(   s  This class will push a tag with only a single string child into
    the tag's parent as an attribute. The attribute's name is the tag
    name, and the value is the string child. An example should give
    the flavor of the change:

    <foo><bar>baz</bar></foo>
     =>
    <foo bar="baz"><bar>baz</bar></foo>

    You can then access fooTag['bar'] instead of fooTag.barTag.string.

    This is, of course, useful for scraping structures that tend to
    use subelements instead of attributes, such as SOAP messages. Note
    that it modifies its input, so don't print the modified version
    out.

    I'm not sure how many people really want to use this class; let me
    know if you do. Mainly I like the name.c         C   s   t  |  j  d k r |  j d } |  j d } | j   t | t  r t  | j  d k r t | j d t  r | j j | j	  r | j d | | j	 <q n  t
 j |   d  S(   Ni   iii    (   RG   R   Rf   RB   RC   R"   RQ   Rk   RV   R&   R   R   (   R   RY   R   (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR     s    
$(   R   R   R   R   (    (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR%    s   t   RobustXMLParserc           B   s   e  Z RS(    (   R   R   (    (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR&  %  s   t   RobustHTMLParserc           B   s   e  Z RS(    (   R   R   (    (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR'  '  s   t   RobustWackAssHTMLParserc           B   s   e  Z RS(    (   R   R   (    (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR(  )  s   t   SimplifyingSOAPParserc           B   s   e  Z RS(    (   R   R   (    (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyR)  +  s   t   __main__()   R   t
   __future__R    t
   __author__t   __version__t   __date__t   __copyright__t   __license__t   _sgmllib_copyR   R   R   R   t   sgmllibR   R   R   R   R   RQ   RT   Rb   R   Rc   RC   RP   R   R   R   R  R%  R&  R'  R(  R)  R   t   syst   stdinR   t   soupR   (    (    (    s=   /scratch/rashmi/Condor_Script/src/mechanize/_beautifulsoup.pyt   <module>(   sB   	 			 I[''