ó
u›XQc           @   sB  d  Z  d Z d Z d Z d Z d g Z d d l Z d d l Z d d	 l m	 Z	 d d
 l
 m Z d d l m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z d Z 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! ƒ Z" e" j# ƒ  GHn  d S(   sP  Beautiful Soup
Elixir and Tonic
"The Screen-Scraper's Friend"
http://www.crummy.com/software/BeautifulSoup/

Beautiful Soup uses a pluggable XML or HTML parser to parse a
(possibly invalid) document into a tree representation. Beautiful Soup
provides provides methods and Pythonic idioms that make it easy to
navigate, search, and modify the parse tree.

Beautiful Soup works with Python 2.6 and up. It works better if lxml
and/or html5lib is installed.

For more than you ever wanted to know about Beautiful Soup, see the
documentation:
http://www.crummy.com/software/BeautifulSoup/bs4/doc/
s*   Leonard Richardson (leonardr@segfault.org)s   4.1.3s*   Copyright (c) 2004-2012 Leonard Richardsont   MITt   BeautifulSoupiÿÿÿÿNi   (   t   builder_registry(   t   UnicodeDammit(   t   CDatat   Commentt   DEFAULT_OUTPUT_ENCODINGt   Declarationt   Doctypet   NavigableStringt   PageElementt   ProcessingInstructiont	   ResultSett   SoupStrainert   TaguÖ   You are trying to run the Python 2 version of Beautiful Soup under Python 3. This will not work. You need to convert the code, either by installing it (`python setup.py install`) or by running 2to3 (`2to3 -w bs4`).c           B   s  e  Z d  Z d Z d d g Z i d d 6d d 6d d 6d d 6d d 6Z d	 d d d d d
 „ Z d „  Z d „  Z	 d d d „ Z
 d „  Z d „  Z d „  Z d „  Z d „  Z e d „ Z d „  Z d e d „ Z d „  Z d d „ Z d „  Z e e d d „ Z RS(   s  
    This class defines the basic interface called by the tree builders.

    These methods will be called by the parser:
      reset()
      feed(markup)

    The tree builder may call these methods from its feed() implementation:
      handle_starttag(name, attrs) # See note about return value
      handle_endtag(name)
      handle_data(data) # Appends to the current data node
      endData(containerClass=NavigableString) # Ends the current data node

    No matter how complicated the underlying parser is, you should be
    able to build a tree using 'start tag' events, 'end tag' events,
    'data' events, and "done with data" events.

    If you encounter an empty-element tag (aka a self-closing tag,
    like HTML's <br> tag), call handle_starttag and then
    handle_endtag.
    u
   [document]t   htmlt   fasti	   i
   i   i   i    t    c   
         sf  d ˆ  k r t  j d ƒ n  d ˆ  k r? ˆ  d =t  j d ƒ n  d ˆ  k rb ˆ  d =t  j d ƒ n  d ˆ  k r… ˆ  d =t  j d ƒ n  d	 ˆ  k r¨ ˆ  d	 =t  j d
 ƒ n  ‡  f d †  } | pÉ | d d ƒ } | pÞ | d d ƒ } t ˆ  ƒ d k rˆ  j ƒ  j ƒ  } t d | ƒ ‚ n  | d k r¬t | t ƒ r?| g } n  | d k s]t | ƒ d k ri|  j	 } n  t
 j | Œ  }	 |	 d k r t d d j | ƒ ƒ ‚ n  |	 ƒ  } n  | |  _ | j |  _ |  |  j _ | |  _ |  j ƒ  t | d ƒ rþ| j ƒ  } n  |  j j | | ƒ \ |  _ |  _ |  _ |  _ y |  j ƒ  Wn t k
 rLn Xd |  _ d |  j _ d S(   sª   The Soup object is initialized as the 'root tag', and the
        provided markup (which can be a string or a file-like object)
        is fed into the underlying parser.t   convertEntitiessˆ   BS4 does not respect the convertEntities argument to the BeautifulSoup constructor. Entities are always converted to Unicode characters.t   markupMassages“   BS4 does not respect the markupMassage argument to the BeautifulSoup constructor. The tree builder is responsible for any necessary markup massage.t   smartQuotesTosŠ   BS4 does not respect the smartQuotesTo argument to the BeautifulSoup constructor. Smart quotes are always converted to Unicode characters.t   selfClosingTagss˜   BS4 does not respect the selfClosingTags argument to the BeautifulSoup constructor. The tree builder is responsible for understanding self-closing tags.t   isHTMLs³   BS4 does not respect the isHTML argument to the BeautifulSoup constructor. You can pass in features='html' or features='xml' to get a builder capable of handling one or the other.c            s<   |  ˆ  k r8 t  j d |  | f ƒ ˆ  |  } ˆ  |  =| Sd  S(   NsL   The "%s" argument to the BeautifulSoup constructor has been renamed to "%s."(   t   warningst   warnt   None(   t   old_namet   new_namet   value(   t   kwargs(    s1   /scratch/rashmi/Condor_Script/src/bs4/__init__.pyt   deprecated_argument|   s    
t   parseOnlyTheset
   parse_onlyt   fromEncodingt   from_encodingi    s2   __init__() got an unexpected keyword argument '%s'sj   Couldn't find a tree builder with the features you requested: %s. Do you need to install a parser library?t   ,t   readN(   R   R   t   lent   keyst   popt	   TypeErrorR   t
   isinstancet
   basestringt   DEFAULT_BUILDER_FEATURESR   t   lookupt   FeatureNotFoundt   joint   buildert   is_xmlt   soupR    t   resett   hasattrR$   t   prepare_markupt   markupt   original_encodingt   declared_html_encodingt   contains_replacement_characterst   _feedt   StopParsing(
   t   selfR5   t   featuresR/   R    R"   R   R   t   argt   builder_class(    (   R   s1   /scratch/rashmi/Condor_Script/src/bs4/__init__.pyt   __init__S   sj    





				
-	c         C   sT   |  j  j ƒ  |  j  j |  j ƒ |  j ƒ  x# |  j j |  j k rO |  j ƒ  q- Wd  S(   N(	   R/   R2   t   feedR5   t   endDatat
   currentTagt   namet   ROOT_TAG_NAMEt   popTag(   R;   (    (    s1   /scratch/rashmi/Condor_Script/src/bs4/__init__.pyR9   µ   s
    
c         C   s^   t  j |  |  |  j |  j ƒ d |  _ |  j j ƒ  g  |  _ d  |  _ g  |  _	 |  j
 |  ƒ d  S(   Ni   (   R   R?   R/   RD   t   hiddenR2   t   currentDataR   RB   t   tagStackt   pushTag(   R;   (    (    s1   /scratch/rashmi/Condor_Script/src/bs4/__init__.pyR2   ¿   s    				c         K   s   t  d |  j | | | | ƒ S(   s+   Create a new tag associated with this soup.N(   R   R   R/   (   R;   RC   t	   namespacet   nsprefixt   attrs(    (    s1   /scratch/rashmi/Condor_Script/src/bs4/__init__.pyt   new_tagÈ   s    c         C   s   t  | ƒ } | j ƒ  | S(   s7   Create a new NavigableString associated with this soup.(   R	   t   setup(   R;   t   st	   navigable(    (    s1   /scratch/rashmi/Condor_Script/src/bs4/__init__.pyt
   new_stringÌ   s    
c         C   s   t  d ƒ ‚ d  S(   Ns4   BeautifulSoup objects don't support insert_before().(   t   NotImplementedError(   R;   t	   successor(    (    s1   /scratch/rashmi/Condor_Script/src/bs4/__init__.pyt   insert_beforeÒ   s    c         C   s   t  d ƒ ‚ d  S(   Ns3   BeautifulSoup objects don't support insert_after().(   RR   (   R;   RS   (    (    s1   /scratch/rashmi/Condor_Script/src/bs4/__init__.pyt   insert_afterÕ   s    c         C   s2   |  j  j ƒ  } |  j  r+ |  j  d |  _ n  |  j S(   Niÿÿÿÿ(   RH   R'   RB   (   R;   t   tag(    (    s1   /scratch/rashmi/Condor_Script/src/bs4/__init__.pyRE   Ø   s    	c         C   sC   |  j  r |  j  j j | ƒ n  |  j j | ƒ |  j d |  _  d  S(   Niÿÿÿÿ(   RB   t   contentst   appendRH   (   R;   RV   (    (    s1   /scratch/rashmi/Condor_Script/src/bs4/__init__.pyRI   ß   s    	c         C   sñ   |  j  rí d j |  j  ƒ } | j |  j ƒ d k r† t g  |  j D] } | j ^ q@ ƒ j |  j j	 ƒ r† d | k r} d } q† d } n  g  |  _  |  j
 rÑ t |  j ƒ d k rÑ |  j
 j sÍ |  j
 j | ƒ rÑ d  S| | ƒ } |  j | ƒ n  d  S(   Nu    R   s   
t    i   (   RG   R.   t	   translatet   STRIP_ASCII_SPACESt   setRH   RC   t   intersectionR/   t   preserve_whitespace_tagsR    R%   t   textt   searcht   object_was_parsed(   R;   t   containerClassRG   RV   t   o(    (    s1   /scratch/rashmi/Condor_Script/src/bs4/__init__.pyRA   æ   s    	%			c         C   sN   | j  |  j |  j ƒ |  j r. | |  j _ n  | |  _ |  j j j | ƒ d S(   s    Add an object to the parse tree.N(   RN   RB   t   previous_elementt   next_elementRW   RX   (   R;   Rc   (    (    s1   /scratch/rashmi/Condor_Script/src/bs4/__init__.pyRa   ø   s
    		c         C   sÉ   | |  j  k r d Sd } d } xj t t |  j ƒ d d d ƒ D]I } | |  j | j k r? | |  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ÿÿÿÿ(   RD   R   t   rangeR%   RH   RC   t   prefixRE   (   R;   RC   RK   t   inclusivePopt   numPopst   mostRecentTagt   i(    (    s1   /scratch/rashmi/Condor_Script/src/bs4/__init__.pyt	   _popToTag   s    &c         C   sº   |  j  ƒ  |  j rN t |  j ƒ d k rN |  j j sJ |  j j | | ƒ rN d St |  |  j | | | | |  j	 |  j
 ƒ } | d k rˆ | S|  j
 r  | |  j
 _ n  | |  _
 |  j | ƒ | S(   s  Push a start tag on to the stack.

        If this method returns None, the tag was rejected by the
        SoupStrainer. You should proceed as if the tag had not occured
        in the document. For instance, if this was a self-closing tag,
        don't call handle_endtag.
        i   N(   RA   R    R%   RH   R_   t
   search_tagR   R   R/   RB   Rd   Re   RI   (   R;   RC   RJ   RK   RL   RV   (    (    s1   /scratch/rashmi/Condor_Script/src/bs4/__init__.pyt   handle_starttag  s    

		c         C   s   |  j  ƒ  |  j | | ƒ d  S(   N(   RA   Rl   (   R;   RC   RK   (    (    s1   /scratch/rashmi/Condor_Script/src/bs4/__init__.pyt   handle_endtag3  s    
c         C   s   |  j  j | ƒ d  S(   N(   RG   RX   (   R;   t   data(    (    s1   /scratch/rashmi/Condor_Script/src/bs4/__init__.pyt   handle_data8  s    t   minimalc         C   sp   |  j  r5 d } | d k r( d | } n  d | } n d } | sJ d } n d } | t t |  ƒ j | | | ƒ S(   sl   Returns a string or Unicode representation of this document.
        To get Unicode, pass None for encoding.R   s    encoding="%s"u   <?xml version="1.0"%s?>
u    i    N(   R0   R   t   superR   t   decode(   R;   t   pretty_printt   eventual_encodingt	   formattert   encoding_partRg   t   indent_level(    (    s1   /scratch/rashmi/Condor_Script/src/bs4/__init__.pyRt   ;  s    		N(   t   __name__t
   __module__t   __doc__RD   R+   R   R[   R?   R9   R2   RM   RQ   RT   RU   RE   RI   R	   RA   Ra   t   TrueRl   Rn   Ro   Rq   t   FalseR   Rt   (    (    (    s1   /scratch/rashmi/Condor_Script/src/bs4/__init__.pyR   1   s.   )	a	
										t   BeautifulStoneSoupc           B   s   e  Z d  Z d „  Z RS(   s&   Deprecated interface to an XML parser.c         O   s4   d | d <t  j d ƒ t t |  ƒ j | | Ž  d  S(   Nt   xmlR<   sx   The BeautifulStoneSoup class is deprecated. Instead of using it, pass features="xml" into the BeautifulSoup constructor.(   R   R   Rs   R   R?   (   R;   t   argsR   (    (    s1   /scratch/rashmi/Condor_Script/src/bs4/__init__.pyR?   S  s    
(   Rz   R{   R|   R?   (    (    (    s1   /scratch/rashmi/Condor_Script/src/bs4/__init__.pyR   P  s   R:   c           B   s   e  Z RS(    (   Rz   R{   (    (    (    s1   /scratch/rashmi/Condor_Script/src/bs4/__init__.pyR:   [  s   R-   c           B   s   e  Z RS(    (   Rz   R{   (    (    (    s1   /scratch/rashmi/Condor_Script/src/bs4/__init__.pyR-   _  s   t   __main__($   R|   t
   __author__t   __version__t   __copyright__t   __license__t   __all__t   reR   R/   R   t   dammitR   t   elementR   R   R   R   R   R	   R
   R   R   R   R   t   syntax_errorR   R   t	   ExceptionR:   t
   ValueErrorR-   Rz   t   syst   stdinR1   t   prettify(    (    (    s1   /scratch/rashmi/Condor_Script/src/bs4/__init__.pyt   <module>   s(   	Lÿ  