ó
ÄqPc           @   sü   d  Z  d d l Z d d l m Z y e d ƒ Z Wn e k
 rQ e d ƒ ‚ n Xe j Z e j Z e j	 Z	 d d d d	 g Z
 d
 e j f d „  ƒ  YZ d e e j f d „  ƒ  YZ d „  Z e j d ƒ Z d e _ e e d <d	 e j f d „  ƒ  YZ d S(   sÄ   CSS Selectors based on XPath.

This module supports selecting XML/HTML tags based on CSS selectors.
See the `CSSSelector` class for details.

This is a thin wrapper around cssselect 0.7 or later.
iÿÿÿÿN(   t   etreet	   cssselectsN   cssselect seems not to be installed. See http://packages.python.org/cssselect/t   SelectorSyntaxErrort   ExpressionErrort   SelectorErrort   CSSSelectort   LxmlTranslatorc           B   s   e  Z d  Z d „  Z RS(   sR   
    A custom CSS selector to XPath translator with lxml-specific extensions.
    c         C   sd   | j  ƒ  d g d g f k r4 t d | j ƒ ‚ n  | j d j } | j d |  j | j ƒ  ƒ ƒ S(   Nt   STRINGt   IDENTs9   Expected a single string or ident for :contains(), got %ri    s7   contains(__lxml_internal_css:lower-case(string(.)), %s)(   t   argument_typesR   t	   argumentst   valuet   add_conditiont   xpath_literalt   lower(   t   selft   xpatht   functionR   (    (    s2   /usr/lib/python2.7/dist-packages/lxml/cssselect.pyt   xpath_contains_function"   s    (   t   __name__t
   __module__t   __doc__R   (    (    (    s2   /usr/lib/python2.7/dist-packages/lxml/cssselect.pyR      s   t   LxmlHTMLTranslatorc           B   s   e  Z d  Z RS(   s)   
    lxml extensions + HTML support.
    (   R   R   R   (    (    (    s2   /usr/lib/python2.7/dist-packages/lxml/cssselect.pyR   /   s   c         C   s
   | j  ƒ  S(   N(   R   (   t   contextt   s(    (    s2   /usr/lib/python2.7/dist-packages/lxml/cssselect.pyt   _make_lower_case5   s    s   http://codespeak.net/lxml/css/t   __lxml_internal_csss
   lower-casec           B   s&   e  Z d  Z d d d „ Z d „  Z RS(   s–  A CSS selector.

    Usage::

        >>> from lxml import etree, cssselect
        >>> select = cssselect.CSSSelector("a tag > child")

        >>> root = etree.XML("<a><b><c/><tag><child>TEXT</child></tag></b></a>")
        >>> [ el.tag for el in select(root) ]
        ['child']

    To use CSS namespaces, you need to pass a prefix-to-namespace
    mapping as ``namespaces`` keyword argument::

        >>> rdfns = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
        >>> select_ns = cssselect.CSSSelector('root > rdf|Description',
        ...                                   namespaces={'rdf': rdfns})

        >>> rdf = etree.XML((
        ...     '<root xmlns:rdf="%s">'
        ...       '<rdf:Description>blah</rdf:Description>'
        ...     '</root>') % rdfns)
        >>> [(el.tag, el.text) for el in select_ns(rdf)]
        [('{http://www.w3.org/1999/02/22-rdf-syntax-ns#}Description', 'blah')]

    t   xmlc         C   sƒ   | d k r t  ƒ  } n6 | d k r0 t ƒ  } n | d k rN t d t ƒ } n  | j | ƒ } t j j |  | d | ƒ| |  _ d  S(   NR   t   htmlt   xhtmlt
   namespaces(   R   R   t   Truet   css_to_xpathR    t   XPatht   __init__t   css(   R   R#   R   t
   translatort   path(    (    s2   /usr/lib/python2.7/dist-packages/lxml/cssselect.pyR"   X   s    c         C   s0   d |  j  j t t t |  ƒ ƒ ƒ d |  j f S(   Ns   <%s %s for %r>i   (   t	   __class__R   t   hext   abst   idR#   (   R   (    (    s2   /usr/lib/python2.7/dist-packages/lxml/cssselect.pyt   __repr__c   s    	N(   R   R   R   t   NoneR"   R*   (    (    (    s2   /usr/lib/python2.7/dist-packages/lxml/cssselect.pyR   =   s   (   R   t   syst   lxmlR    t
   __import__t   external_cssselectt   ImportErrorR   R   R   t   __all__t   GenericTranslatorR   t   HTMLTranslatorR   R   t   FunctionNamespacet   nst   prefixR!   R   (    (    (    s2   /usr/lib/python2.7/dist-packages/lxml/cssselect.pyt   <module>   s$   							
