ó
ç'ÊUc           @   sç   d  d l  Z  d  d l 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 d  d l m Z d  d l m Z m Z m Z d e j f d „  ƒ  YZ d	 e j f d
 „  ƒ  YZ d e j f d „  ƒ  YZ d S(   iÿÿÿÿN(   t   unittest(   t   ScrapyDeprecationWarning(   t   TextResponset   HtmlResponset   XmlResponse(   t   Selector(   t   XmlXPathSelectort   HtmlXPathSelectort   XPathSelectort   SelectorTestCasec           B   s@  e  Z 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 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 e _  d „  Z! d „  Z" d „  Z# d  „  Z$ d! „  Z% RS("   c         C   s~  d } t  d d d | ƒ } |  j | ƒ } | j d ƒ } |  j d t | ƒ ƒ x& | D] } t | |  j ƒ sV t ‚ qV W|  j | j d ƒ j ƒ  g  | j d ƒ D] } | j ƒ  ^ q  ƒ |  j g  | j d ƒ D] } | j ƒ  ^ qÏ d g ƒ |  j g  | j d	 ƒ D] } | j ƒ  ^ qd
 g ƒ |  j | j d ƒ j ƒ  d g ƒ |  j g  | j d ƒ D] } | j ƒ  ^ q[d g ƒ d S(   s   Simple selector testss;   <p><input name='a'value='1'/><input name='b'value='2'/></p>t   urls   http://example.comt   bodys   //inputi   s   //input[@name='a']/@nameu   asD   number(concat(//input[@name='a']/@value, //input[@name='b']/@value))u   12.0s   concat('xpath', 'rules')u
   xpathruless<   concat(//input[@name='a']/@value, //input[@name='b']/@value)u   12N(   R   t   ssclst   xpatht   assertEqualt   lent
   isinstancet   AssertionErrort   extract(   t   selfR   t   responset   selt   xlt   x(    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_simple_selection   s"    )+
+

+c         C   ss   d j  d d ƒ } t d d d | d d ƒ } |  j | ƒ } |  j t t | j d	 ƒ ƒ d
 j  d d ƒ g ƒ d  S(   Nu$   <p><input name='{}' value='Â©'/></p>i2   t   bR
   s   http://example.comR   t   encodingt   utf8s   //input/@names+   <Selector xpath='//input/@name' data=u'{}'>i(   (   t   formatR   R   R   t   mapt   reprR   (   R   R   R   R   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_representation_slice(   s    c         C   sf   d j  d d ƒ } t d d d | d d ƒ } |  j | ƒ } |  j t t | j d	 ƒ ƒ d
 g ƒ d  S(   Nu$   <p><input name='{}' value='Â©'/></p>i2   R   R
   s   http://example.comR   R   R   u   //input[@value="Â©"]/@values>   <Selector xpath=u'//input[@value="\xa9"]/@value' data=u'\xa9'>(   R   R   R   R   R   R   R   (   R   R   R   R   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt!   test_representation_unicode_query2   s    c         C   sã   d } t  d d d | ƒ } |  j | ƒ } |  j | j d ƒ j ƒ  | j d ƒ j ƒ  d ƒ |  j | j d ƒ j ƒ  | j d ƒ j ƒ  d ƒ |  j | j d ƒ j ƒ  | j d ƒ j ƒ  d	 ƒ |  j | j d
 ƒ j ƒ  d ƒ d S(   s-   Test if extract_first() returns first elements+   <ul><li id="1">1</li><li id="2">2</li></ul>R
   s   http://example.comR   s   //ul/li/text()i    s   //ul/li[@id="1"]/text()s   //ul/li[2]/text()i   s!   /ul/li[@id="doesnt-exist"]/text()N(   R   R   R   R   t   extract_firstR   t   None(   R   R   R   R   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_extract_first;   s    c         C   sS   d } t  d d d | ƒ } |  j | ƒ } |  j | j d ƒ j d d ƒ d ƒ d S(	   sC   Test if extract_first() returns default value when no results founds+   <ul><li id="1">1</li><li id="2">2</li></ul>R
   s   http://example.comR   s   //div/text()t   defaultt   missingN(   R   R   R   R   R!   (   R   R   R   R   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_extract_first_defaultL   s    c         C   s  d } t  d d d | ƒ } |  j | ƒ } |  j | j d ƒ j d ƒ | j d ƒ j d ƒ d ƒ |  j | j d ƒ j d ƒ | j d ƒ j d ƒ d ƒ |  j | j d	 ƒ j d ƒ | j d ƒ j d ƒ d
 ƒ |  j | j d ƒ j d ƒ d ƒ |  j | j d ƒ j d ƒ d ƒ d S(   s0   Test if re_first() returns first matched elements+   <ul><li id="1">1</li><li id="2">2</li></ul>R
   s   http://example.comR   s   //ul/li/text()s   \di    s   //ul/li[@id="1"]/text()s   //ul/li[2]/text()i   s   /ul/li/text()s   \w+s!   /ul/li[@id="doesnt-exist"]/text()N(   R   R   R   R   t   re_firstt   reR"   (   R   R   R   R   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_re_firstT   s    "c         C   sV   d } t  d d d | d d ƒ } |  j | ƒ } |  j | j d ƒ j ƒ  d g ƒ d  S(	   Nu#   <p><input name='Â©' value='1'/></p>R
   s   http://example.comR   R   R   u   //input[@name="Â©"]/@valueu   1(   R   R   R   R   R   (   R   R   R   R   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_select_unicode_queryf   s    c         C   sl   d } t  |  j d | ƒ j d ƒ d |  j ƒ s7 t ‚ t  |  j d | ƒ j d ƒ d |  j ƒ sh t ‚ d S(   s:   Test Selector returning the same type in selection methodss
   <p>test<p>t   texts   //pi    t   pN(   R   R   R   R   t   css(   R   R+   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_list_elements_typel   s    1c         C   sr   d } t  d d d | ƒ } |  j | ƒ } |  j | j d ƒ j ƒ  d g ƒ |  j | j d ƒ j ƒ  d g ƒ d  S(	   Ns;   <p><input name='a'value='1'/><input name='b'value='2'/></p>R
   s   http://example.comR   s   //input[@name='a']/@name='a'u   1s   //input[@name='a']/@name='n'u   0(   R   R   t   assertEqualsR   R   (   R   R   R   t   xs(    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_boolean_resultr   s
    "c         C   s~   d } |  j  d | d d ƒ } |  j | j d ƒ j ƒ  d g ƒ |  j  d | d d ƒ } |  j | j d ƒ j ƒ  d g ƒ d	 S(
   s4   Test that XML and HTML Selector's behave differentlys$   <div><img src="a.jpg"><p>Hello</div>R+   t   typet   htmls   //divu(   <div><img src="a.jpg"><p>Hello</p></div>t   xmlu.   <div><img src="a.jpg"><p>Hello</p></img></div>N(   R   R   R   R   (   R   R+   t   hsR0   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt$   test_differences_parsing_xml_vs_htmly   s    
c         C   sª   d } |  j  t d d | ƒƒ } |  j | j d ƒ |  j | j d ƒ j ƒ  d g ƒ |  j  t d d | ƒƒ } |  j | j d ƒ |  j | j d ƒ j ƒ  d g ƒ d  S(	   Ns$   <div><img src="a.jpg"><p>Hello</div>s   http://example.comR   R4   s   //divu.   <div><img src="a.jpg"><p>Hello</p></img></div>R3   u(   <div><img src="a.jpg"><p>Hello</p></div>(   R   R   R   R2   R   R   R   (   R   R+   R   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_flavor_detection…   s    
c         C   sÚ   d } t  d d d | ƒ } |  j | ƒ } | j d ƒ } |  j | j d ƒ j ƒ  d d d	 d
 d g ƒ |  j | j d ƒ j ƒ  d	 d
 d g ƒ |  j | j d ƒ j ƒ  d	 d
 d g ƒ |  j | j d ƒ j ƒ  g  ƒ d S(   s   Nested selector testss€  <body>
                    <div class='one'>
                      <ul>
                        <li>one</li><li>two</li>
                      </ul>
                    </div>
                    <div class='two'>
                      <ul>
                        <li>four</li><li>five</li><li>six</li>
                      </ul>
                    </div>
                  </body>R
   s   http://example.comR   s   //div[@class="two"]s   //lis   <li>one</li>s   <li>two</li>s   <li>four</li>s   <li>five</li>s   <li>six</li>s   ./ul/lis   .//lis   ./liN(   R   R   R   R   R   (   R   R   R   R   t   divtwo(    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_nested_selectors‘   s    c         C   sr   d } |  j  d | ƒ } |  j | j d ƒ j d ƒ j ƒ  d g ƒ |  j | j d ƒ j d ƒ j ƒ  d g ƒ d  S(   Nsž   <body>
                    <div id=1>not<span>me</span></div>
                    <div class="dos"><p>text</p><a href='#'>foo</a></div>
               </body>R+   s   //div[@id="1"]s
   span::textu   mes   #1s   ./span/text()(   R   R   R   R-   R   (   R   R   R   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_mixed_nested_selectors«   s    +c         C   s;   |  j  d d ƒ } |  j | j d ƒ j ƒ  d d g ƒ d  S(   NR+   s#   <div>fff: <a href="#">zzz</a></div>s   //text()u   fff: u   zzz(   R   R   R   R   (   R   R   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_dont_strip´   s    c         C   s`   d } t  d d d | ƒ } |  j | ƒ } | j d d ƒ |  j | j d ƒ j ƒ  d g ƒ d  S(	   Ns–   
        <test xmlns:somens="http://scrapy.org">
           <somens:a id="foo">take this</a>
           <a id="bar">found</a>
        </test>
        R
   s   http://example.comR   t   somenss   http://scrapy.orgs   //somens:a/text()u	   take this(   R   R   t   register_namespaceR   R   R   (   R   R   R   R   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_namespaces_simple¸   s    c         C   s5  d } t  d d d | ƒ } |  j | ƒ } | j d d ƒ | j d d ƒ | j d	 d
 ƒ |  j t | j d ƒ ƒ d ƒ |  j | j d ƒ j ƒ  d d ƒ |  j | j d ƒ j ƒ  d d ƒ |  j | j d ƒ j ƒ  d d ƒ |  j | j d ƒ j d ƒ d j ƒ  d ƒ |  j | j d ƒ j ƒ  d d ƒ d  S(   Ns¸  <?xml version="1.0" encoding="UTF-8"?>
<BrowseNode xmlns="http://webservices.amazon.com/AWSECommerceService/2005-10-05"
            xmlns:b="http://somens.com"
            xmlns:p="http://www.scrapy.org/product" >
    <b:Operation>hello</b:Operation>
    <TestTag b:att="value"><Other>value</Other></TestTag>
    <p:SecondTestTag><material>iron</material><price>90</price><p:name>Dried Rose</p:name></p:SecondTestTag>
</BrowseNode>
        R
   s   http://example.comR   t   xmlnss<   http://webservices.amazon.com/AWSECommerceService/2005-10-05R,   s   http://www.scrapy.org/productR   s   http://somens.coms   //xmlns:TestTagi   s   //b:Operation/text()i    t   hellos   //xmlns:TestTag/@b:attt   values$   //p:SecondTestTag/xmlns:price/text()t   90s   //p:SecondTestTags   ./xmlns:price/text()s'   //p:SecondTestTag/xmlns:material/text()t   iron(   R   R   R=   R   R   R   R   (   R   R   R   R   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_namespaces_multipleÇ   s    	###,c         C   s   d } t  d d d | ƒ } |  j | ƒ } t j d ƒ } |  j | j d ƒ j | ƒ d d g ƒ |  j | j d ƒ j d	 ƒ d
 d g ƒ d  S(   Ns  <div>Name: Mary
                    <ul>
                      <li>Name: John</li>
                      <li>Age: 10</li>
                      <li>Name: Paul</li>
                      <li>Age: 20</li>
                    </ul>
                    Age: 20
                  </div>R
   s   http://example.comR   s   Name: (\w+)s   //ul/lit   Johnt   Pauls
   Age: (\d+)t   10t   20(   R   R   R(   t   compileR   R   (   R   R   R   R   t   name_re(    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_reÝ   s    	c         C   sY   d } t  d d d | d d ƒ } |  j | ƒ } |  j | j d ƒ j d ƒ d	 g ƒ d  S(
   Ns   <div>Evento: cumpleaÃ±os</div>R
   s   http://example.comR   R   s   utf-8s   //divs   Evento: (\w+)u   cumpleaÃ±os(   R   R   R   R   R(   (   R   R   R   R   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_re_intlð   s    c         C   s|   |  j  d d ƒ } |  j | j ƒ  d ƒ |  j  d d d d ƒ } |  j | j ƒ  d ƒ |  j | j d ƒ j ƒ  d g ƒ d  S(   NR+   s   <root>lala</root>u+   <html><body><root>lala</root></body></html>R2   R4   u   <root>lala</root>t   .(   R   R   R   R   (   R   R5   R0   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_selector_over_textö   s
    c         C   sP   t  d d d d ƒ } |  j | ƒ } d } |  j t t j | ƒ | j | ƒ d S(   s;   Test invalid xpath raises ValueError with the invalid xpathR
   s   http://example.comR   s   <html></html>s   //test[@foo='bar]N(   R   R   t   assertRaisesRegexpt
   ValueErrorR(   t   escapeR   (   R   R   R   R   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_invalid_xpathý   s    c         C   sn   t  d d d d ƒ } |  j | ƒ } d } t j r9 | n | j d ƒ } |  j t t j | ƒ | j	 | ƒ d S(   sE   Test *Unicode* invalid xpath raises ValueError with the invalid xpathR
   s   http://example.comR   s   <html></html>u   //test[@foo='Ð±ar]t   unicode_escapeN(
   R   R   t   sixt   PY3t   encodeRO   RP   R(   RQ   R   (   R   R   R   R   t   encoded(    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_invalid_xpath_unicode  s
    c         C   s¯   d } d | d } d } d | d } d | | d } d	 } | j  | ƒ } i d
 g d 6} t d d d | d | ƒ }	 |  j |	 ƒ }
 |  j |
 j d ƒ j ƒ  d g ƒ d  S(   NuH   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">u   <head>u   </head>u   <span id="blank">Â£</span>u   <body>u   </body>u   <html>u   </html>s   utf-8s   text/html; charset=utf-8s   Content-TypeR
   s   http://example.comt   headersR   s   //span[@id='blank']/text()u   Â£(   RV   R   R   R/   R   R   (   R   t   metat   headt   body_contentR   R3   R   t	   html_utf8RY   R   R   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt$   test_http_header_encoding_precedence  s    c         C   s2   t  d d d ƒ} |  j | ƒ j d ƒ j ƒ  d  S(   Ns   http://www.example.comR   t    s   //text()(   R   R   R   R   (   R   t   r1(    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_empty_bodies  s    c         C   s8   t  d d d d d ƒ} |  j | ƒ j d ƒ j ƒ  d  S(   Ns   http://www.example.comR   s   <root>pre post</root>R   s   utf-8s   //text()(   R   R   R   R   (   R   R`   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_null_bytes$  s    		c         C   s8   t  d d d d d ƒ} |  j | ƒ j d ƒ j ƒ  d  S(   Ns   http://www.example.comR   s   <html><p>an José de</p><html>R   s   utf-8s   //text()(   R   R   R   R   (   R   R`   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_badly_encoded_body+  s    		c         C   s¤   |  j  d d ƒ } | j d ƒ } |  j | j ƒ  d g ƒ |  j | j d ƒ j ƒ  g  ƒ | j d ƒ } |  j | j ƒ  d g ƒ |  j | j d ƒ j ƒ  g  ƒ d  S(	   NR+   u"   <span class="big">some text</span>s   //text()u	   some texts   .//bs   //span/@classu   bigs	   .//text()(   R   R   R/   R   (   R   t   rt   x1(    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt    test_select_on_unevaluable_nodes2  s    c         C   sf   |  j  d d ƒ } | j d ƒ } |  j | j ƒ  d g ƒ | j d ƒ } |  j | j ƒ  d g ƒ d  S(   NR+   u9   <div><b>Options:</b>opt1</div><div><b>Other</b>opt2</div>sK   //div/descendant::text()[preceding-sibling::b[contains(text(), 'Options')]]u   opt1sJ   //div/descendant::text()/preceding-sibling::b[contains(text(), 'Options')]u   <b>Options:</b>(   R   R   R/   R   (   R   Rd   Re   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_select_on_text_nodes=  s
    c         C   sM   |  j  d d ƒ } | j d ƒ } | j d ƒ } |  j | j ƒ  d g ƒ d  S(   NR+   u9   <div><b>Options:</b>opt1</div><div><b>Other</b>opt2</div>s   //div/descendant::text()s3   ./preceding-sibling::b[contains(text(), 'Options')]u   <b>Options:</b>(   R   R   R/   R   (   R   Rd   Re   t   x2(    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt    test_nested_select_on_text_nodesE  s    s-   Text nodes lost parent node reference in lxmlc         C   sC   |  j  ƒ  } t j | ƒ t | d ƒ s? t d | j j ƒ ‚ d S(   s=   Check that classes are using slots and are weak-referenceablet   __dict__s   %s does not use __slots__N(   R   t   weakreft   reft   hasattrR   t	   __class__t   __name__(   R   R   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_weakref_slotsM  s    c         C   sm   d } |  j  t d d | ƒƒ } |  j t | j d ƒ ƒ d ƒ | j ƒ  |  j t | j d ƒ ƒ d ƒ d  S(   NsÖ   <?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US" xmlns:media="http://search.yahoo.com/mrss/">
  <link type="text/html">
  <link type="application/atom+xml">
</feed>
s   http://example.com/feed.atomR   s   //linki    i   (   R   R   R   R   R   t   remove_namespaces(   R   R4   R   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_remove_namespacesT  s
    
c         C   sm   d } |  j  t d d | ƒƒ } |  j t | j d ƒ ƒ d ƒ | j ƒ  |  j t | j d ƒ ƒ d ƒ d  S(   Nså   <?xml version="1.0" encoding="UTF-8"?>
<feed xmlns:atom="http://www.w3.org/2005/Atom" xml:lang="en-US" xmlns:media="http://search.yahoo.com/mrss/">
  <link atom:type="text/html">
  <link atom:type="application/atom+xml">
</feed>
s   http://example.com/feed.atomR   s   //link/@typei    i   (   R   R   R   R   R   Rq   (   R   R4   R   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt!   test_remove_attributes_namespaces`  s
    
c         C   s  d t  f d „  ƒ  Y} d } t d d d | ƒ } |  j | ƒ } | j d ƒ } |  j t t d „  | ƒ ƒ ƒ | j d	 ƒ } |  j t t d
 „  | ƒ ƒ ƒ | | ƒ } | j d ƒ } |  j t t d „  | ƒ ƒ ƒ | j d	 ƒ } |  j t t d „  | ƒ ƒ ƒ d S(   s    Lxml smart strings return valuest   SmartStringsSelectorc           B   s   e  Z e Z RS(    (   Ro   t
   __module__t   Truet   _lxml_smart_strings(    (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyRt   o  s   s€  <body>
                    <div class='one'>
                      <ul>
                        <li>one</li><li>two</li>
                      </ul>
                    </div>
                    <div class='two'>
                      <ul>
                        <li>four</li><li>five</li><li>six</li>
                      </ul>
                    </div>
                  </body>R
   s   http://example.comR   s   //li/text()c         S   s   t  |  j d ƒ S(   Nt	   getparent(   Rm   t   _root(   t   e(    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   <lambda>…  s    s   //div/@classc         S   s   t  |  j d ƒ S(   NRx   (   Rm   Ry   (   Rz   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyR{   ‡  s    c         S   s   t  |  j d ƒ S(   NRx   (   Rm   Ry   (   Rz   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyR{   ‹  s    c         S   s   t  |  j d ƒ S(   NRx   (   Rm   Ry   (   Rz   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyR{     s    N(	   R   R   R   R   t   assertFalset   anyR   t
   assertTruet   all(   R   Rt   R   R   R   t   li_textt	   div_class(    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_smart_stringsl  s    c         C   sD   d } t  d d | ƒ} |  j d | ƒ } |  j | j ƒ  d ƒ d  S(   Ns‹   <?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE foo [ <!ELEMENT foo ANY > <!ENTITY xxe SYSTEM "file:///etc/passwd" >]><foo>&xxe;</foo>s   http://example.comR   R   s   <foo>&xxe;</foo>(   R   R   R   R   (   R   t   malicious_xmlR   R   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_xml_entity_expansion  s    (&   Ro   Ru   R   R   R   R   R    R#   R&   R)   R*   R.   R1   R6   R7   R9   R:   R;   R>   RD   RK   RL   RN   RR   RX   R^   Ra   Rb   Rc   Rf   Rg   Ri   t   skipRp   Rr   Rs   R‚   R„   (    (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyR	      sF   		
																																	#t   DeprecatedXpathSelectorTestc           B   sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s$   <div><img src="a.jpg"><p>Hello</div>c         C   sK  t  } t j d t ƒ -} d | f d „  ƒ  Y} |  j t | ƒ d t | ƒ ƒ |  j d t | d j ƒ ƒ | d |  j	 ƒ } |  j t | ƒ d ƒ | d |  j	 ƒ } |  j t | ƒ d t | g  | D] } | j ^ qÆ f ƒ ƒ |  j d t | d j ƒ ƒ |  j
 t | t ƒ ƒ |  j
 t | t ƒ ƒ |  j
 t | t ƒ ƒ Wd  QXd  S(	   Nt   recordt	   UserClassc           B   s   e  Z RS(    (   Ro   Ru   (    (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyRˆ   ¡  s   i   s   scrapy.Selectori    R+   i   (   R   t   warningst   catch_warningsRv   R   R   t   strt   assertInt   messageR+   R~   t
   issubclassR   R   (   R   t   clst   wRˆ   t   uselR   R   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_warnings_xpathselectorž  s    ;c         C   s  t  } t j d t ƒ o} d | f d „  ƒ  Y} |  j t | ƒ d t | ƒ ƒ |  j d t | d j ƒ ƒ | d |  j	 ƒ } |  j t | ƒ d ƒ | d |  j	 ƒ } |  j t | ƒ d t | g  | D] } | j ^ qÆ f ƒ ƒ |  j d t | d j ƒ ƒ |  j
 t | t ƒ ƒ |  j
 t | t ƒ ƒ |  j
 t | t ƒ ƒ |  j
 t | t ƒ ƒ |  j
 t | t ƒ ƒ |  j
 t | t ƒ ƒ Wd  QXd  S(	   NR‡   Rˆ   c           B   s   e  Z RS(    (   Ro   Ru   (    (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyRˆ   ¹  s   i   s   scrapy.Selectori    R+   i   (   R   R‰   RŠ   Rv   R   R   R‹   RŒ   R   R+   R~   RŽ   R   R   R   (   R   R   R   Rˆ   R‘   R   R   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_warnings_xmlxpathselector¶  s     ;c         C   s  t  } t j d t ƒ o} d | f d „  ƒ  Y} |  j t | ƒ d t | ƒ ƒ |  j d t | d j ƒ ƒ | d |  j	 ƒ } |  j t | ƒ d ƒ | d |  j	 ƒ } |  j t | ƒ d t | g  | D] } | j ^ qÆ f ƒ ƒ |  j d t | d j ƒ ƒ |  j
 t | t ƒ ƒ |  j
 t | t ƒ ƒ |  j
 t | t ƒ ƒ |  j
 t | t ƒ ƒ |  j
 t | t ƒ ƒ |  j
 t | t ƒ ƒ Wd  QXd  S(	   NR‡   Rˆ   c           B   s   e  Z RS(    (   Ro   Ru   (    (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyRˆ   Ô  s   i   s   scrapy.Selectori    R+   i   (   R   R‰   RŠ   Rv   R   R   R‹   RŒ   R   R+   R~   RŽ   R   R   R   (   R   R   R   Rˆ   R‘   R   R   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_warnings_htmlxpathselectorÑ  s     ;c         C   sg   t  j d t ƒ O t d |  j ƒ } |  j | j d ƒ j ƒ  d g ƒ |  j t	 | j
 d ƒ Wd  QXd  S(   NR‡   R+   s   //divu(   <div><img src="a.jpg"><p>Hello</p></div>t   div(   R‰   RŠ   Rv   R   R+   R   t   selectR   t   assertRaisest   RuntimeErrorR-   (   R   R5   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_xpathselectorì  s
    
c         C   sg   t  j d t ƒ O t d |  j ƒ } |  j | j d ƒ j ƒ  d g ƒ |  j t	 | j
 d ƒ Wd  QXd  S(   NR‡   R+   s   //divu(   <div><img src="a.jpg"><p>Hello</p></div>R•   (   R‰   RŠ   Rv   R   R+   R   R–   R   R—   R˜   R-   (   R   R5   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_htmlxpathselectoró  s
    
c         C   sg   t  j d t ƒ O t d |  j ƒ } |  j | j d ƒ j ƒ  d g ƒ |  j t	 | j
 d ƒ Wd  QXd  S(   NR‡   R+   s   //divu.   <div><img src="a.jpg"><p>Hello</p></img></div>R•   (   R‰   RŠ   Rv   R   R+   R   R–   R   R—   R˜   R-   (   R   R0   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_xmlxpathselectorú  s
    
(	   Ro   Ru   R+   R’   R“   R”   R™   Rš   R›   (    (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyR†   š  s   					t   ExsltTestCasec           B   s    e  Z e Z d  „  Z d „  Z RS(   c         C   sa  d } t  d d d | ƒ } |  j | ƒ } |  j | j d ƒ j ƒ  g  | j d ƒ D] } | j ƒ  ^ qR ƒ |  j g  | j d ƒ D] } | j ƒ  ^ q d d g ƒ |  j g  | j d	 ƒ D] } | j ƒ  ^ q¹ d g ƒ |  j g  | j d
 ƒ D] } | j ƒ  ^ qî d g ƒ |  j | j d ƒ j ƒ  d d d d d g ƒ |  j | j d ƒ j ƒ  d g ƒ d S(   s   EXSLT regular expression testss>  
        <p><input name='a' value='1'/><input name='b' value='2'/></p>
        <div class="links">
        <a href="/first.html">first link</a>
        <a href="/second.html">second link</a>
        <a href="http://www.bayes.co.uk/xml/index.xml?/xml/utils/rechecker.xml">EXSLT match example</a>
        </div>
        R
   s   http://example.comR   s&   //input[re:test(@name, "[A-Z]+", "i")]s%   //a[re:test(@href, "\.html$")]/text()u
   first linku   second links#   //a[re:test(@href, "first")]/text()s$   //a[re:test(@href, "second")]/text()sX   re:match(//a[re:test(@href, "\.xml$")]/@href,"(\w+):\/\/([^/:]+)(:\d*)?([^# ]*)")/text()u=   http://www.bayes.co.uk/xml/index.xml?/xml/utils/rechecker.xmlu   httpu   www.bayes.co.uku    u'   /xml/index.xml?/xml/utils/rechecker.xmls[   re:replace(//a[re:test(@href, "\.xml$")]/@href,"(\w+)://(.+)(\.xml)", "","https://\2.html")u?   https://www.bayes.co.uk/xml/index.xml?/xml/utils/rechecker.htmlN(   R   R   R   R   R   (   R   R   R   R   R   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_regexp  s@    	)

	
c         C   sœ   d } t  d d d | ƒ } |  j | ƒ } |  j | j d ƒ j ƒ  d d d d	 d d
 d d d d d g ƒ |  j | j d ƒ j ƒ  d d d d	 d g ƒ d S(   s   EXSLT set manipulation testss[  
        <div itemscope itemtype="http://schema.org/Event">
          <a itemprop="url" href="nba-miami-philidelphia-game3.html">
          NBA Eastern Conference First Round Playoff Tickets:
          <span itemprop="name"> Miami Heat at Philadelphia 76ers - Game 3 (Home Game 1) </span>
          </a>

          <meta itemprop="startDate" content="2016-04-21T20:00">
            Thu, 04/21/16
            8:00 p.m.

          <div itemprop="location" itemscope itemtype="http://schema.org/Place">
            <a itemprop="url" href="wells-fargo-center.html">
            Wells Fargo Center
            </a>
            <div itemprop="address" itemscope itemtype="http://schema.org/PostalAddress">
              <span itemprop="addressLocality">Philadelphia</span>,
              <span itemprop="addressRegion">PA</span>
            </div>
          </div>

          <div itemprop="offers" itemscope itemtype="http://schema.org/AggregateOffer">
            Priced from: <span itemprop="lowPrice">$35</span>
            <span itemprop="offerCount">1938</span> tickets left
          </div>
        </div>
        R
   s   http://example.comR   sR   //div[@itemtype="http://schema.org/Event"]
                            //@itempropu   urlu   nameu	   startDateu   locationu   addressu   addressLocalityu   addressRegionu   offersu   lowPriceu
   offerCounts  
                set:difference(//div[@itemtype="http://schema.org/Event"]
                                    //@itemprop,
                               //div[@itemtype="http://schema.org/Event"]
                                    //*[@itemscope]/*/@itemprop)N(   R   R   R   R   R   (   R   R   R   R   (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   test_set@  s(    
(   Ro   Ru   R   R   R   Rž   (    (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyRœ     s   	:(   R(   R‰   Rk   RT   t   twisted.trialR    t   scrapy.exceptionsR   t   scrapy.httpR   R   R   t   scrapy.selectorR   t   scrapy.selector.lxmlselR   R   R   t   TestCaseR	   R†   Rœ   (    (    (    s7   /home/travis/build/scrapy/scrapy/tests/test_selector.pyt   <module>   s   ÿ h