ó
n€
\c        	   @   sù  d  d l  m Z m Z d  d l m Z m Z d  d l m Z m Z m Z m	 Z	 d  d l m
 Z
 d  d l Z y e Wn e k
 r‹ e Z n Xd d d d	 d
 d g Z d e f d „  ƒ  YZ e d d i e d 6ƒZ e d j g  d+ D] Z d e ^ qã ƒ d i e d 6ƒZ e d d i e d 6ƒZ e d ƒ Z d d d „ Z d d d „ Z d „  Z d „  Z d „  Z d „  Z d  „  Z d! „  Z  d d d" „ Z! d# „  Z" d e# f d$ „  ƒ  YZ$ e$ ƒ  Z% d d d% e% d& „ Z& d' „  Z' d( „  Z( d) „  Z) d* „  Z* d S(,   iÿÿÿÿ(   t   XPatht   ElementBase(   t
   fromstringt   XHTML_NAMESPACE(   t   _forms_xpatht   _options_xpatht   _nonst   _transform_result(   t   defsNt   FormNotFoundt	   fill_formt   fill_form_htmlt   insert_errorst   insert_errors_htmlt   DefaultErrorCreatorc           B   s   e  Z d  Z RS(   s*   
    Raised when no form can be found
    (   t   __name__t
   __module__t   __doc__(    (    (    sG   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/formfill.pyR	      s   sK   descendant-or-self::form[name=$name]|descendant-or-self::x:form[name=$name]t
   namespacest   xt   |t   inputt   selectt   textareas   x:inputs   x:selects
   x:textareas   descendant-or-self::s-   //label[@for=$for_id]|//x:label[@for=$for_id]s"   descendant-or-self::*[@name=$name]c         C   s)   t  |  d | d | ƒ}  t |  | ƒ d  S(   Nt   form_idt
   form_index(   t
   _find_formt
   _fill_form(   t   elt   valuesR   R   (    (    sG   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/formfill.pyR
      s    c         C   s_   t  |  ƒ } t |  t ƒ r* t |  ƒ } n t j |  ƒ } t | | d | d | ƒt | | ƒ S(   NR   R   (   t   typet
   isinstancet
   basestringR   t   copyt   deepcopyR
   R   (   t   htmlR   R   R   t   result_typet   doc(    (    sG   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/formfill.pyR   &   s    c         C   sG  i  } t  | d ƒ r$ | j ƒ  } n  t |  ƒ } x| D]} | j d ƒ } | sX q7 n  t | ƒ r§ | j | g  ƒ } t | t t f ƒ s— | g } n  t | | ƒ q7 | | k r¹ q7 q7 | j | d ƒ } | d | | <| | } t | t t f ƒ r y | | } Wq2t	 k
 rq7 q2Xn | d k r2q7 n  t
 | | ƒ q7 Wd  S(   Nt   mixedt   namei    i   (   t   hasattrR&   t   _input_xpatht   gett   _takes_multipleR   t   listt   tuplet   _fill_multiplet
   IndexErrort   _fill_single(   R   R   t   countst   inputsR   R'   t   valuet   index(    (    sG   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/formfill.pyR   /   s4    

c         C   sT   t  |  j ƒ d k r( |  j d ƒ r( t S|  j d d ƒ j ƒ  } | d k rP t St S(   NR   t   multipleR   t    t   radiot   checkbox(   R7   R8   (   R   t   tagR*   t   Truet   lowert   False(   R   R   (    (    sG   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/formfill.pyR+   M   s    $c         C   s@  |  j  d d ƒ j ƒ  } | d k rœ |  j  d ƒ } | d  k r† | sN t } n( | d } t | t ƒ rv | d k } n  t |  | ƒ q<t |  | | k ƒ n  | d k rÍ |  j  d ƒ } t |  | | k ƒ no t |  j ƒ d k sè t	 ‚ xQ t
 |  ƒ D]C } | j  d ƒ } | d  k r%| j ƒ  } n  t | | | k ƒ qõ Wd  S(	   NR   R6   R8   R3   i    t   onR7   R   (   R*   R;   t   NoneR<   R   R    t   _checkR   R9   t   AssertionErrorR   t   text_contentt   _select(   R   R3   R   t   vt   resultt   option(    (    sG   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/formfill.pyR.   V   s(    	
c         C   s9   | r |  j  d d ƒ n d |  j k r5 |  j d =n  d  S(   Nt   checkedR6   (   t   sett   attrib(   R   t   check(    (    sG   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/formfill.pyR?   r   s    c         C   s9   | r |  j  d d ƒ n d |  j k r5 |  j d =n  d  S(   Nt   selectedR6   (   RG   RH   (   R   R   (    (    sG   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/formfill.pyRB   y   s    c         C   s5   t  |  j ƒ d k r! | |  _ n |  j d | ƒ d  S(   NR   R3   (   R   R9   t   textRG   (   R   R3   (    (    sG   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/formfill.pyR0   €   s    c         C   s  | d  k rE | d  k rE t |  ƒ } x | D] } | SWt d ƒ ‚ n  | d  k	 r¸ |  j | ƒ } | d  k	 rp | St |  d | ƒ} | r | d St d t d j t |  ƒ ƒ f ƒ ‚ n  | d  k	 rt |  ƒ } y | | SWqt k
 rt d | t	 | ƒ f ƒ ‚ qXn  d  S(   Ns   No forms in pageR'   i    s-   No form with the name or id of %r (forms: %s)s   , s3   There is no form with the index %r (%i forms found)(
   R>   R   R	   t   get_element_by_idt   _form_name_xpatht   idt   joint   _find_form_idsR/   t   len(   R   R   R   t   formst   form(    (    sG   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/formfill.pyR   †   s0    "c         c   s¸   t  |  ƒ } | s d Vd  Sx– t | ƒ D]ˆ \ } } | j d ƒ r‡ | j d ƒ rv d | j d ƒ | j d ƒ f Vq° | j d ƒ Vq( | j d ƒ r§ | j d ƒ Vq( d | Vq( Wd  S(   Ns
   (no forms)RN   R'   s   %s or %ss   (unnamed form %s)(   R   t	   enumerateR*   (   R   RR   R4   RS   (    (    sG   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/formfill.pyRP   ¡   s    c           B   s>   e  Z e Z e Z d  Z d Z d Z d Z d „  Z	 d „  Z
 RS(   t   divs   error-messages   error-blockt   Invalidc         K   sS   xL | j  ƒ  D]> \ } } t |  | ƒ s; t d | ƒ ‚ n  t |  | | ƒ q Wd  S(   Ns   Unexpected keyword argument: %s(   t   itemsR(   t	   TypeErrort   setattr(   t   selft   kwR'   R3   (    (    sG   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/formfill.pyt   __init__¾   s
    c         C   s’  | j  |  j ƒ } |  j r1 | j d |  j ƒ n  | rj |  j rj | j d | j d d ƒ d |  j ƒ n  | d  k s‚ | d k rŽ |  j } n  t | t	 ƒ r­ | j
 | ƒ n1 t | t ƒ sÌ t d | ƒ ‚ | pØ |  j | _ | r.|  j r.|  j r| j | _ d  | _ | j d | ƒ qŽ| j
 | ƒ n` | j ƒ  } | j | ƒ } |  j re| j | | ƒ n) | j | _ d  | _ | j | d | ƒ d  S(   Nt   classR6   t    s.   Bad message; should be a string or element: %ri    i   (   t   makeelementt   error_container_tagt   error_message_classRG   t   error_block_classR*   R>   t   default_messageR   R   t   appendR    R@   RK   t   block_insidet   insert_beforet   tailt   insertt	   getparentR4   (   RZ   R   t   is_blockt   messaget   error_elt   parentt   pos(    (    sG   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/formfill.pyt   __call__Å   s2    	*				(   R   R   R:   Rf   Re   R`   Ra   Rb   Rc   R\   Ro   (    (    (    sG   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/formfill.pyR   ¶   s   	t   errorc   
      C   s¯   t  |  d | d | ƒ}  x | j ƒ  D]‚ \ } } | d  k rC q% n  xa t |  | | ƒ D]M \ } }	 t |	 t t d  ƒ t f ƒ s t d |	 ƒ ‚ t	 | |	 | | ƒ qV Wq% Wd  S(   NR   R   s   Bad message: %r(
   R   RW   R>   t   _find_elements_for_nameR   R    R   R   R@   t   _insert_error(
   R   t   errorsR   R   t   error_classt   error_creatorR'   Rp   Rl   Rk   (    (    sG   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/formfill.pyR   ç   s    !c         K   sV   t  |  ƒ } t |  t ƒ r* t |  ƒ } n t j |  ƒ } t | | |  t | | ƒ S(   N(   R   R   R    R   R!   R"   R   R   (   R#   R   R[   R$   R%   (    (    sG   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/formfill.pyR   ø   s    c         C   sÏ   t  |  j ƒ t j k s- t  |  j ƒ d k r6 t } n t } t  |  j ƒ d k rg | rg t |  | ƒ n  |  j d ƒ r» t |  d |  j d ƒ ƒ} | r» x | D] } t | | ƒ qž Wq» n  | |  | | ƒ d  S(   NR   RS   RN   t   for_id(	   R   R9   R   t
   empty_tagsR<   R:   t
   _add_classR*   t   _label_for_xpath(   R   Rp   Rt   Ru   Rj   t   labelst   label(    (    sG   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/formfill.pyRr     s    -	c         C   sG   |  j  d ƒ r3 |  j d |  j  d ƒ d | ƒ n |  j d | ƒ d  S(   NR]   R^   (   R*   RG   (   R   t
   class_name(    (    sG   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/formfill.pyRx     s    $c         c   sà   | d  k r |  | f Vd  S| j d ƒ r[ |  j | d ƒ } | d  k	 rW | | f Vn  d  St |  d | ƒ} | sw d  St | t t f ƒ sŸ | d | f Vd  Sx: t | | ƒ D]) \ } } | d  k rÍ q¯ n  | | f Vq¯ Wd  S(   Nt   #i   R'   i    (   R>   t
   startswithRL   t   _name_xpathR   R,   R-   t   zip(   RS   R'   Rp   R   t   elst   err(    (    sG   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/formfill.pyRq     s$    (   s   inputs   selects   textareas   x:inputs   x:selects
   x:textarea(+   t
   lxml.etreeR    R   t	   lxml.htmlR   R   R   R   R   R   R   R!   R    t	   NameErrort   strt   __all__t   LookupErrorR	   RM   RO   t   _tagR)   Ry   R   R>   R
   R   R   R+   R.   R?   RB   R0   R   RP   t   objectR   t   default_error_creatorR   R   Rr   Rx   Rq   (    (    (    sG   /data/av2000/b2b/venv/lib/python2.7/site-packages/lxml/html/formfill.pyt   <module>   sN   "
		)										.					