ó
)2Pc           @   sº  d  Z  d d l Z d d l Z d d l Z d d l m Z m Z d d l m Z m	 Z	 m
 Z
 m Z d d l Z d d l m Z m Z d d l m Z m Z d d l Z y  d d l m Z m Z e Z Wn e k
 rá Z e Z n Xe j d k  Z e j d
 d k oe j d k  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e j  f d „  ƒ  YZ! d e f d „  ƒ  YZ" d e j  f d „  ƒ  YZ# d e f d „  ƒ  YZ$ d e j  f d „  ƒ  YZ% d S(   s#   Tests of Beautiful Soup as a whole.iÿÿÿÿN(   t   BeautifulSoupt   BeautifulStoneSoup(   t   CharsetMetaAttributeValuet   ContentMetaAttributeValuet   SoupStrainert   NamespacedAttribute(   t   EntitySubstitutiont   UnicodeDammit(   t   SoupTestt   skipIf(   t   LXMLTreeBuildert   LXMLTreeBuilderForXMLi   i   i    i   t"   TestDeprecatedConstructorArgumentsc           B   s<   e  Z d  „  Z d „  Z d „  Z e e d ƒ d „  ƒ Z RS(   c      	   C   s‰   t  j d t ƒ " } |  j d d t d ƒ ƒ} Wd  QXt | d j ƒ } |  j d | k ƒ |  j d | k ƒ |  j d | j	 ƒ  ƒ d  S(   Nt   records   <a><b></b></a>t   parseOnlyTheset   bi    t
   parse_onlys   <b></b>(
   t   warningst   catch_warningst   Truet   soupR   t   strt   messaget
   assertTruet   assertEqualt   encode(   t   selft   wR   t   msg(    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt)   test_parseOnlyThese_renamed_to_parse_only$   s    !c         C   s†   t  j d t ƒ " } d } |  j | d d ƒ} Wd  QXt | d j ƒ } |  j d | k ƒ |  j d | k ƒ |  j d | j ƒ d  S(   NR   s   Ã©t   fromEncodingt   utf8i    t   from_encoding(	   R   R   R   R   R   R   R   R   t   original_encoding(   R   R   R   R   R   (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt*   test_fromEncoding_renamed_to_from_encoding,   s    c         C   s    |  j  t |  j d d t ƒd  S(   Ns   <a>t   no_such_argument(   t   assertRaisest	   TypeErrorR   R   (   R   (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt"   test_unrecognized_keyword_argument5   s    s1   lxml not present, not testing BeautifulStoneSoup.c         C   sN   t  j d t ƒ 6 } t d ƒ } |  j t | t ƒ ƒ |  j d ƒ Wd  QXd  S(   NR   s   <markup>s&   BeautifulStoneSoup class is deprecated(   R   R   R   R   R   t
   isinstanceR    (   R   R   R   (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt   test_beautifulstonesoup9   s    (   t   __name__t
   __module__R   R"   R&   R	   t   LXML_PRESENTR(   (    (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyR   "   s   				t   TestSelectiveParsingc           B   s   e  Z d  „  Z RS(   c         C   sA   d } t  d ƒ } |  j | d | ƒ} |  j | j ƒ  d ƒ d  S(   Ns&   No<b>Yes</b><a>No<b>Yes <c>Yes</c></b>R   R   s   <b>Yes</b><b>Yes <c>Yes</c></b>(   R   R   R   R   (   R   t   markupt   strainerR   (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt   test_parse_with_soupstrainerD   s    (   R)   R*   R/   (    (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyR,   B   s   t   TestEntitySubstitutionc           B   sz   e  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 RS(   s1   Standalone tests of the EntitySubstitution class.c         C   s   t  |  _ d  S(   N(   R   t   sub(   R   (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt   setUpM   s    c         C   s&   d } |  j  |  j j | ƒ d ƒ d  S(   Nu   fooâˆ€â˜ƒÃµbaru   foo&forall;â˜ƒ&otilde;bar(   R   R1   t   substitute_html(   R   t   s(    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt   test_simple_html_substitutionP   s    c         C   s5   d } t  | ƒ } |  j |  j j | j ƒ d ƒ d  S(   Ns   ‘’foo“”s   &lsquo;&rsquo;foo&ldquo;&rdquo;(   R   R   R1   R3   R-   (   R   t   quotest   dammit(    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt   test_smart_quote_substitutionW   s    c         C   s)   d } |  j  |  j j | t ƒ | ƒ d  S(   Ns   Welcome to "my bar"(   R   R1   t   substitute_xmlt   False(   R   R4   (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pytI   test_xml_converstion_includes_no_quotes_if_make_quoted_attribute_is_false_   s    c         C   sB   |  j  |  j j d t ƒ d ƒ |  j  |  j j d t ƒ d ƒ d  S(   Nt   Welcomes	   "Welcome"s	   Bob's Bars   "Bob's Bar"(   R   R1   R9   R   (   R   (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt6   test_xml_attribute_quoting_normally_uses_double_quotesc   s    c         C   s)   d } |  j  |  j j | t ƒ d ƒ d  S(   Ns   Welcome to "my bar"s   'Welcome to "my bar"'(   R   R1   R9   R   (   R   R4   (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pytO   test_xml_attribute_quoting_uses_single_quotes_when_value_contains_double_quotesi   s    c         C   s)   d } |  j  |  j j | t ƒ d ƒ d  S(   Ns   Welcome to "Bob's Bar"s"   "Welcome to &quot;Bob's Bar&quot;"(   R   R1   R9   R   (   R   R4   (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pytb   test_xml_attribute_quoting_escapes_single_quotes_when_value_contains_both_single_and_double_quotesn   s    c         C   s&   d } |  j  |  j j | ƒ | ƒ d  S(   Ns   Welcome to "Bob's Bar"(   R   R1   R9   (   R   t   quoted(    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt<   test_xml_quotes_arent_escaped_when_value_is_not_being_quotedt   s    c         C   s    |  j  |  j j d ƒ d ƒ d  S(   Ns   foo<bar>s   foo&lt;bar&gt;(   R   R1   R9   (   R   (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt'   test_xml_quoting_handles_angle_bracketsx   s    c         C   s    |  j  |  j j d ƒ d ƒ d  S(   Ns   AT&Ts   AT&amp;T(   R   R1   R9   (   R   (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt#   test_xml_quoting_handles_ampersands}   s    c         C   s    |  j  |  j j d ƒ d ƒ d  S(   Ns   &Aacute;T&Ts   &Aacute;T&amp;T(   R   R1   R9   (   R   (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pytC   test_xml_quoting_ignores_ampersands_when_they_are_part_of_an_entity€   s    c         C   s&   d } |  j  |  j j | ƒ | ƒ d S(   s:   There's no need to do this except inside attribute values.s   Bob's "bar"N(   R   R1   R3   (   R   t   text(    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt    test_quotes_not_html_substituted…   s    (   R)   R*   t   __doc__R2   R5   R8   R;   R=   R>   R?   RA   RB   RC   RD   RF   (    (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyR0   K   s   											t   TestEncodingConversionc           B   sS   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z e e p? e	 d ƒ d „  ƒ Z
 RS(   c         C   sH   t  t |  ƒ j ƒ  d |  _ |  j j d ƒ |  _ |  j |  j d ƒ d  S(   NuU   <html><head><meta charset="utf-8"/></head><body><foo>SacrÃ© bleu!</foo></body></html>s   utf-8sU   <html><head><meta charset="utf-8"/></head><body><foo>SacrÃ© bleu!</foo></body></html>(   t   superRH   R2   t   unicode_dataR   t	   utf8_dataR   (   R   (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyR2      s    	c         C   ss   d } |  j  | ƒ } | j ƒ  } |  j t | t ƒ ƒ |  j | |  j | j ƒ  ƒ ƒ |  j | j j ƒ  d ƒ d  S(   Ns   <foo>a</foo>t   ascii(	   R   t   decodeR   R'   t   unicodeR   t   document_forR!   t   lower(   R   RL   t   soup_from_asciit   unicode_output(    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt   test_ascii_in_unicode_out˜   s    c         C   sX   |  j  |  j ƒ } |  j | j ƒ  |  j ƒ |  j | j j d ƒ |  j | j d  ƒ d  S(   Nu   SacrÃ© bleu!(   R   RJ   R   RM   t   foot   stringR!   t   None(   R   t   soup_from_unicode(    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt   test_unicode_in_unicode_out¢   s    c         C   sE   |  j  |  j ƒ } |  j | j ƒ  |  j ƒ |  j | j j d ƒ d  S(   Nu   SacrÃ© bleu!(   R   RK   R   RM   RJ   RT   RU   (   R   t   soup_from_utf8(    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt   test_utf8_in_unicode_outª   s    c         C   s2   |  j  |  j ƒ } |  j | j d ƒ |  j ƒ d  S(   Ns   utf-8(   R   RJ   R   R   RK   (   R   RW   (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt   test_utf8_out±   s    sQ   Bad HTMLParser detected; skipping test of non-ASCII characters in attribute name.c         C   s8   d } |  j  |  j | ƒ j j d ƒ | j d ƒ ƒ d  S(   Nu    <div><a â˜ƒ="snowman"></a></div>R   (   R   R   t   divR   (   R   R-   (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt1   test_attribute_name_containing_unicode_characters¶   s    (   R)   R*   R2   RS   RX   RZ   R[   R	   t   PYTHON_2_PRE_2_7t   PYTHON_3_PRE_3_2R]   (    (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyRH   ‹   s   			
				t   TestUnicodeDammitc           B   sŒ   e  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 „  Z d „  Z RS(   s$   Standalone tests of Unicode, Dammit.c         C   s)   d } t  | ƒ } |  j | j d ƒ d  S(   Ns   <foo>‘’“”</foo>u   <foo>â€˜â€™â€œâ€</foo>(   R   R   t   unicode_markup(   R   R-   R7   (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt   test_smart_quotes_to_unicodeÀ   s    c         C   s/   d } t  | d d ƒ} |  j | j d ƒ d  S(   Ns   <foo>‘’“”</foo>t   smart_quotes_tot   xmls+   <foo>&#x2018;&#x2019;&#x201C;&#x201D;</foo>(   R   R   Ra   (   R   R-   R7   (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt!   test_smart_quotes_to_xml_entitiesÆ   s    c         C   s/   d } t  | d d ƒ} |  j | j d ƒ d  S(   Ns   <foo>‘’“”</foo>Rc   t   htmls'   <foo>&lsquo;&rsquo;&ldquo;&rdquo;</foo>(   R   R   Ra   (   R   R-   R7   (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt"   test_smart_quotes_to_html_entitiesÌ   s    c         C   s/   d } t  | d d ƒ} |  j | j d ƒ d  S(   Ns   <foo>‘’“”</foo>Rc   RL   s   <foo>''""</foo>(   R   R   Ra   (   R   R-   R7   (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt   test_smart_quotes_to_asciiÒ   s    c         C   sB   d } t  | ƒ } |  j | j d ƒ |  j | j j ƒ  d ƒ d  S(   Ns   Ã©u   Ã©s   utf-8(   R   R   Ra   R!   RP   (   R   R   R7   (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt   test_detect_utf8Ø   s    c         C   sH   d } t  | d g ƒ } |  j | j j ƒ  d ƒ |  j | j d ƒ d  S(   Ns   íåìùs
   iso-8859-8u   ××•×œ×©(   R   R   R!   RP   Ra   (   R   t   hebrewR7   (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt   test_convert_hebrewÞ   s    c         C   sK   d } t  | ƒ } |  j | j j ƒ  d ƒ |  j | j j d ƒ | ƒ d  S(   Ns   ã‚±ãƒ¼ã‚¿ã‚¤ Watchs   utf-8(   R   R   R!   RP   Ra   R   (   R   t   utf_8R7   (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt/   test_dont_see_smart_quotes_where_there_are_noneä   s    c         C   s>   d j  d ƒ } t | d g ƒ } |  j | j j ƒ  d ƒ d  S(   Nu   RÃ¤ksmÃ¶rgÃ¥ss   utf-8s
   iso-8859-8(   R   R   R   R!   RP   (   R   RK   R7   (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt    test_ignore_inappropriate_codecsê   s    c         C   sX   d j  d ƒ } xB d d d g D]1 } t | | g ƒ } |  j | j j ƒ  d ƒ q Wd  S(   Nu   RÃ¤ksmÃ¶rgÃ¥ss   utf-8s   .utf8s   ...s
   utF---16.!(   R   R   R   R!   RP   (   R   RK   t   bad_encodingR7   (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt   test_ignore_invalid_codecsï   s    c         C   s:   x3 d D]+ } t  | d t ƒ} |  j d | j ƒ q Wd  S(   Ns&   <html><meta charset="euc-jp" /></html>s&   <html><meta charset='euc-jp' /></html>s$   <html><meta charset=euc-jp /></html>s#   <html><meta charset=euc-jp/></html>t   is_htmls   euc-jp(   s&   <html><meta charset="euc-jp" /></html>s&   <html><meta charset='euc-jp' /></html>s$   <html><meta charset=euc-jp /></html>s#   <html><meta charset=euc-jp/></html>(   R   R   R   R!   (   R   t   dataR7   (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt    test_detect_html5_style_meta_tagõ   s       
c         C   s³   d } t  j j } t j t j ƒ zm d „  } | t  j _ t | ƒ } |  j t | j	 ƒ |  j
 d | j k ƒ t | d ƒ } |  j
 | j	 ƒ Wd  t j t j ƒ | t  j _ Xd  S(   NsT   ï»¿<?xml version="1.0" encoding="UTF-8"?>
<html><b>Ø¨ØªØ±</b>
<i>ÈÒÑÊÑíä</i></html>c         S   s   d  S(   N(   RV   (   R   (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt   noop  s    u   ï¿½s   html.parser(   t   bs4R7   t   chardet_dammitt   loggingt   disablet   WARNINGR   R   R   t   contains_replacement_charactersR   Ra   R    t   NOTSET(   R   t   doct   chardetRt   R7   R   (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt"   test_last_ditch_entity_replacement   s    	c         C   s<   d } t  | ƒ } |  j d | j ƒ |  j d | j ƒ d  S(   Ns   ÿþ< a > á é < / a > u   <a>Ã¡Ã©</a>s   utf-16le(   R   R   Ra   R!   (   R   Rr   R7   (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt   test_sniffed_xml_encoding#  s    c         C   sn   d j  d ƒ } d j  d ƒ } | | | } |  j t | j d ƒ t j | ƒ } |  j d | j d ƒ ƒ d  S(   Nu   â˜ƒi   R   u   â€œHi, I like Windows!â€t   windows_1252u+   â˜ƒâ˜ƒâ˜ƒâ€œHi, I like Windows!â€â˜ƒâ˜ƒâ˜ƒu	   â˜ƒâ˜ƒâ˜ƒ(   R   R$   t   UnicodeDecodeErrorRM   R   t	   detwingleR   (   R   R   R€   R|   t   fixed(    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt   test_detwingle+  s    	c         C   sY   xR d D]J } | j  d ƒ } |  j | j d ƒ ƒ t j | ƒ } |  j | | ƒ q Wd  S(   Nu   Å“u   â‚“u   Ã°ÂÂÂ“R   s   “(   u   Å“u   â‚“u   Ã°ÂÂÂ“(   R   R   t   endswithR   R‚   R   (   R   t   tricky_unicode_chart   inputt   output(    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt+   test_detwingle_ignores_multibyte_charactersC  s      
(   R)   R*   RG   Rb   Re   Rg   Rh   Ri   Rk   Rm   Rn   Rp   Rs   R~   R   R„   R‰   (    (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyR`   ½   s   											#		t   TestNamedspacedAttributec           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C   s#   t  d d  ƒ } |  j | d ƒ d  S(   Nt   xmlns(   R   RV   R   (   R   t   a(    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt   test_name_may_be_noneT  s    c         C   s#   t  d d ƒ } |  j d | ƒ d  S(   NRŒ   R   s   a:b(   R   R   (   R   RŒ   (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt6   test_attribute_is_equivalent_to_colon_separated_stringX  s    c         C   sž   t  d d d ƒ } t  d d d ƒ } |  j | | ƒ t  d d d  ƒ } |  j | | ƒ t  d d d ƒ } |  j | | ƒ t  d d d ƒ } |  j | | ƒ d  S(   NRŒ   R   t   ct   z(   R   R   RV   t   assertNotEqual(   R   RŒ   R   R   t   dt   e(    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt;   test_attributes_are_equivalent_if_prefix_and_name_identical\  s    (   R)   R*   R   RŽ   R”   (    (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyRŠ   R  s   		t)   TestAttributeValueWithCharsetSubstitutionc           B   s   e  Z d  „  Z d „  Z RS(   c         C   sL   t  d ƒ } |  j d | ƒ |  j d | j ƒ |  j d | j d ƒ ƒ d  S(   Ns   euc-jpR   (   R   R   t   original_valueR   (   R   t   value(    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt!   test_content_meta_attribute_valueo  s    c         C   sL   t  d ƒ } |  j d | ƒ |  j d | j ƒ |  j d | j d ƒ ƒ d  S(   Ns   text/html; charset=euc-jps   text/html; charset=utf8R   (   R   R   R–   R   (   R   R—   (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyR˜   v  s    (   R)   R*   R˜   (    (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyR•   m  s   	(   i   i   (   i   i   (&   RG   Rw   t   unittestt   sysRu   R    R   t   bs4.elementR   R   R   R   t
   bs4.dammitR   R   t   bs4.testingR   R	   R   t   bs4.builderR
   R   R   R+   t   ImportErrorR“   R:   t   version_infoR^   R_   R   R,   t   TestCaseR0   RH   R`   RŠ   R•   (    (    (    s4   ./lib/python2.7/site-packages/bs4/tests/test_soup.pyt   <module>   s.   "

" 	@2•