U e%@svddlmZmZddlmZmZddlmZmZmZm Z ddlm Z ddl Z ze Wne k rleZ YnXdddd d d gZGd ddeZed deidZeddddDdeidZeddeidZedZd2ddZd3ddZddZddZddZddZd d!Zd"d#Zd4d$d%Zd&d'Z Gd(d d Z!e!Z"ddd)e"fd*d Z#d+d Z$d,d-Z%d.d/Z&d0d1Z'dS)5)XPath ElementBase) fromstringXHTML_NAMESPACE) _forms_xpath_options_xpath_nons_transform_result)defsN FormNotFound fill_formfill_form_html insert_errorsinsert_errors_htmlDefaultErrorCreatorc@seZdZdZdS)r z* Raised when no form can be found N)__name__ __module__ __qualname____doc__rrB/opt/hc_python/lib64/python3.8/site-packages/lxml/html/formfill.pyr szKdescendant-or-self::form[name=$name]|descendant-or-self::x:form[name=$name]x) namespaces|cCsg|] }d|qS)zdescendant-or-self::r).0Z_tagrrr sr)inputselecttextareazx:inputzx:selectz x:textareaz-//label[@for=$for_id]|//x:label[@for=$for_id]z"descendant-or-self::*[@name=$name]cCst|||d}t||dSNform_id form_index) _find_form _fill_form)elvaluesr!r"rrrr scCs@t|}t|trt|}n t|}t||||dt||Sr)type isinstance basestringrcopydeepcopyr r )htmlr&r!r" result_typedocrrrr &s    c Csi}t|dr|}t|}|D]}|d}|s6q"t|rj||g}t|ttfs^|g}t||q"||krvq"q"||d}|d||<||}t|ttfrz ||}Wqt k rYq"YqXn |dkrq"t ||q"dS)Nmixednamer) hasattrr/ _input_xpathget_takes_multipler(listtuple_fill_multiple IndexError _fill_single)r%r&countsinputsrr0valueindexrrrr$/s4        r$cCs<t|jdkr|drdS|dd}|dkr8dSdS)NrZmultipleTr')radiocheckboxF)rtagr4lower)rr'rrrr5Ms r5cCs|dd}|dkrj|d}|dkrZ|s4d}n|d}t|trN|dk}t||qt|||knj|dkr|d}t|||knHt|jd kstt|D],}|d}|dkr| }t |||kqdS) Nr'r?rAr=Fronr@r) r4rCr(r)_checkrrBAssertionErrorrZ text_content_select)rr=r'vresultoptionrrrr8Vs(      r8cCs(|r|ddnd|jkr$|jd=dS)Ncheckedr?setZattrib)r%checkrrrrErs rEcCs(|r|ddnd|jkr$|jd=dS)Nselectedr?rL)r%rrrrrGys rGcCs&t|jdkr||_n |d|dS)Nrr=)rrBtextrM)rr=rrrr:sr:cCs|dkr0|dkr0t|}|D] }|Std|dk r||}|dk rN|St||d}|rf|dStdtdt|f|dk rt|}z ||WStk rtd|t|fYnXdS)NzNo forms in pager0rz-No form with the name or id of %r (forms: %s)z, z3There is no form with the index %r (%i forms found)) rr get_element_by_id_form_name_xpathidjoin_find_form_idsr9len)r%r!r"formsformrrrr#s:    r#ccst|}|sdVdSt|D]h\}}|drd|drVd|d|dfVq|dVq|dr||dVqd|VqdS)Nz (no forms)rTr0z%s or %sz(unnamed form %s))r enumerater4)r%rXr>rYrrrrVs     rVc@s4eZdZdZdZdZdZdZdZddZ dd Z d S) rTdivz error-messagez error-blockZInvalidcKs8|D]*\}}t||s&td|t|||qdS)NzUnexpected keyword argument: %s)itemsr2 TypeErrorsetattr)selfkwr0r=rrr__init__s  zDefaultErrorCreator.__init__cCs||j}|jr |d|j|rH|jrH|d|ddd|j|dksX|dkr^|j}t|trt| |n"t|t st d||p|j|_ |r|j r|jr|j |_d|_ |d|n | |nD|}||}|jr|||n|j|_d|_||d|dS)Nclassr? z.Bad message; should be a string or element: %rrr1)Z makeelementerror_container_tagerror_message_classrMerror_block_classr4default_messager(rappendr)rFrP block_inside insert_beforetailinsertZ getparentr>)r_r%is_blockmessageerror_elparentposrrr__call__s4         zDefaultErrorCreator.__call__N) rrrrjrirdrerfrgrarrrrrrrserrorc Csrt|||d}|D]V\}}|dkr(qt|||D]6\}} t| ttdtfs\td| t|| ||q4qdS)Nr zBad message: %r) r#r\_find_elements_for_namer(r)r'rrF _insert_error) r%errorsr!r" error_class error_creatorr0rsrornrrrrscKs>t|}t|trt|}n t|}t||f|t||S)N)r'r(r)rr*r+rr )r,r&r`r-r.rrrrs    cCst|jtjkst|jdkr$d}nd}t|jdkrD|rDt|||drxt||dd}|rx|D]}t||qh||||dS)NrFTrYrT)Zfor_id)rrBr Z empty_tags _add_classr4_label_for_xpath)r%rsrwrxrmlabelslabelrrrrus   rucCs6|dr&|d|dd|n |d|dS)Nrbrc)r4rM)r% class_namerrrrys ryccs|dkr||fVdS|drH||dd}|dk rD||fVdSt||d}|s\dSt|ttfs||d|fVdSt||D]\}}|dkrq||fVqdS)N#r1rQr) startswithrR _name_xpathr(r6r7zip)rYr0rsr%Zelserrrrrrts$    rt)NN)NN)NN)(Z lxml.etreerrZ lxml.htmlrrrrrr r r*r) NameErrorstr__all__ LookupErrorr rSrUr3rzrr r r$r5r8rErGr:r#rVrZdefault_error_creatorrrruryrtrrrrsZ     .