³ò
ejOc           @   s­   d  d k  Z  d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k l Z e i	 e i
 ƒ  e  i  ƒ Z d d „ Z d h  d „ Z d h  d „ Z d S(   iÿÿÿÿN(   t   LSExceptionc         C   sB   y t  i |  | ƒ SWn' t i j
 o } d |  | f GHn Xd  S(   Ns   Error (%s): %s(   t   openert   opent   urllib2t   URLError(   t   urlt   paramst   details(    (    s@   /home/wjholcomb/.../projects/unsorted/mpp_migration/url_utils.pyt   getPage   s    c      
   C   s£  t  i |  d d ƒ} d } | d  j	 o | d | 7} n xb| i | ƒ D]Q} x~ | i d ƒ D]m } | i d ƒ i ƒ  } | d j o q` n | d j p | i d	 ƒ o  | i d
 ƒ | | i d ƒ <q` q` Wxˆ | i d ƒ D]w } | i d ƒ }	 t |	 ƒ d j o" d | i d ƒ t |	 ƒ f GHn x* |	 D]" }
 |
 i d
 ƒ | | i d ƒ <q2Wqá Wx< | i d ƒ D]+ } d i | i d ƒ ƒ | | i d ƒ <qlWqJ W| S(   Nt   htmli   s   //forms   [@name = '%s']s   .//inputt   typet   resett   checkboxt   checkedt   valuet   names	   .//selects   .//option[@selected]s5   Error: Multiple selected options not handled: %s (%d)t   textareat    s	   .//text()(	   t
   libxml2domt   parseStringt   Nonet   xpatht   getAttributet   lowert   hasAttributet   lent   join(   t   datat   formNameR   t   docR   t   formt   inputElmt   elmTypet	   selectElmt   optionst	   optionElmt   textElm(    (    s@   /home/wjholcomb/.../projects/unsorted/mpp_migration/url_utils.pyt	   getParams   s2      $ " $ -c      	   C   s(  |  d  j o d GH| Sn | d  j	 oY t i d | t i ƒ } | i |  ƒ } | d  j o d | GHd  Sn | i d ƒ }  n t i d t i ƒ } t i d t i ƒ } x²| i |  ƒ D]¡} h  } x7 | i | ƒ D]& }	 |	 d |	 d | |	 d i ƒ  <qÖ W| i d	 ƒ o, | d	 i ƒ  d
 j o | i d ƒ o qº | i d ƒ oŒ | i d ƒ o| | i | d ƒ oR t	 | | d t
 ƒ p | | d g | | d <n | | d i | d ƒ n | d | | d <qº | i d ƒ o d  | | d <qº | i d	 ƒ o& | d	 d j p | d	 d j o qº | d	 d j o d | d GHqº d | GHqº Wt i d t i t i Bƒ }
 t i d t i t i Bƒ } xI |
 i |  ƒ D]8 } | d } x% | i | d ƒ D] } | | | <qËWq§Wt i d t i ƒ } x) | i |  ƒ D] } | d | | d <qW| S(   Ns'   Error: No data passed to form processors1   ^.*(<form[^>]*name=['"]?%s['"]?[ >].*?</form>).*$s   Error: Form did not match: %si   s   <input([^>]*)>s   (\w+)(?:=(?:"([^"]*)"|(\S+)))?i   i    R
   R   R   R   R   R   t   submitt   buttons   Skipped button: %ss   Couldn't interpret: '%s's3   <select[^>]*name=["']?([^>"']*)[^>]*>(.*?)</select>s0   .*?<option[^>]*value=["']?([^>"']*)[^>]*selecteds=   <textarea.*name *= *(?:"([^"]*)"|(\S+))[^>]*>(.*?)</textarea>(   R   t   ret   compilet   DOTALLt   searcht   groupt   findallR   t   has_keyt
   isinstancet   listt   appendt
   IGNORECASE(   R   R   R   t   FORMREt	   formMatcht   INPUTREt   VALUEPAIRREt   inputt
   propertiest   pairt   SELECTREt   OPTIONREt   selectR   R   t
   TEXTAREARER   (    (    s@   /home/wjholcomb/.../projects/unsorted/mpp_migration/url_utils.pyt   getRegexParams-   s\    	  $8 2 
  (   t   MultipartPostHandlert   urllibR   t	   cookielibR(   t   sysR   t   libxml2dom.macrolibR    t   build_openert   HTTPCookieProcessorR   R   R   R%   R>   (    (    (    s@   /home/wjholcomb/.../projects/unsorted/mpp_migration/url_utils.pys   <module>   s   