
BXQc            @   sv  d  Z  d d d d d d d d d	 d
 d d d d d d d d d d d d d d d d d d d d d d  g  Z d! d" l Z d! d# l m Z d! d" l Z d! d" l Z d! d" l Z d! d" l Z d! d" l	 Z	 d! d" l
 Z
 d! d" l Z d! d" l Z d! d" l Z d! d" l Z d! d" l Z d! d" l Z d$ Z d% Z d& Z e j d'  Z e a d(   Z d)   Z d* d+  Z d f  d,     YZ e j d-  Z d.   Z d/   Z e d0  Z  d1   Z! d2   Z" d3   Z# d4   Z$ d5   Z% d6 f  d7     YZ& d e' f d8     YZ( d e( f d9     YZ) d e( f d:     YZ* d e( f d;     YZ+ d e' f d<     YZ, d e j- e j. f d=     YZ/ d> f  d?     YZ0 d  e0 e j f d@     YZ1 dA e0 f dB     YZ2 d e2 e j3 f dC     YZ4 dD e2 f dE     YZ5 dF e5 e j6 f dG     YZ7 dH e5 e j8 f dI     YZ9 e: e4 e j; e< e e j= e j e j> dJ  Z? e: e4 e j; e< e e j= e j e j> dK  Z@ dL   ZA dM   ZB dN   ZC e: e: e4 e j; e< e e e j= e j e j> dO 
 ZD d f  dP     YZE dQ   ZF d f  dR     YZG d eG f dS     YZH d eH f dT     YZI d eH f dU     YZJ d eH f dV     YZK d	 eH f dW     YZL d f  dX     YZM dY   ZN d eG f dZ     YZO d eO f d[     YZP d eO f d\     YZQ d eO f d]     YZR d eH f d^     YZS d
 eS f d_     YZT d eI f d`     YZU d eI f da     YZV d eI f db     YZW d eS f dc     YZX dd   ZY d f  de     YZZ d" S(f   s  HTML form handling for web clients.

HTML form handling for web clients: useful for parsing HTML forms, filling them
in and returning the completed forms to the server.  This code developed from a
port of Gisle Aas' Perl module HTML::Form, from the libwww-perl library, but
the interface is not the same.

The most useful docstring is the one for HTMLForm.

RFC 1866: HTML 2.0
RFC 1867: Form-based File Upload in HTML
RFC 2388: Returning Values from Forms: multipart/form-data
HTML 3.2 Specification, W3C Recommendation 14 January 1997 (for ISINDEX)
HTML 4.01 Specification, W3C Recommendation 24 December 1999


Copyright 2002-2007 John J. Lee <jjl@pobox.com>
Copyright 2005 Gary Poster
Copyright 2005 Zope Corporation
Copyright 1998-2000 Gisle Aas.

This code is free software; you can redistribute it and/or modify it
under the terms of the BSD or ZPL 2.1 licenses (see the file
COPYING.txt included with the distribution).

t   AmbiguityErrort   CheckboxControlt   Controlt   ControlNotFoundErrort   FileControlt
   FormParsert   HTMLFormt   HiddenControlt   IgnoreControlt   ImageControlt   IsindexControlt   Itemt   ItemCountErrort   ItemNotFoundErrort   Labelt   ListControlt   LocateErrort   Missingt
   ParseErrort	   ParseFilet   ParseFileExt   ParseResponset   ParseResponseExt   PasswordControlt   RadioControlt   ScalarControlt   SelectControlt   SubmitButtonControlt   SubmitControlt   TextControlt   TextareaControlt   XHTMLCompatibleFormParseriN(   t   StringIOs   0.2.11i   s   latin-1s   mechanize.formsc         O   sL   t  r
 d  St j   d d } d |  } | f | } t j | | |  d  S(   Ni   i   s   %%s %s(   t   OPTIMIZATION_HACKt   inspectt   stackt   _loggert   debug(   t   msgt   argst   kwdst   caller_namet   extended_msgt   extended_args(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR%   [   s    
c          C   sI   t  a t j t j  t j t j  }  |  j t j  t j	 |   d  S(   N(
   t   FalseR!   R$   t   setLevelt   loggingt   DEBUGt   StreamHandlert   syst   stdoutt
   addHandler(   t   handler(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   _show_debug_messagesd   s
    i    c         C   s   t  j |  t d d | d  S(   Nt
   stackleveli   (   t   warningst   warnt   DeprecationWarning(   t   messaget   stack_offset(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   deprecationm   s    c           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   q   s    s   \s+c         C   s   t  j d |  j    S(   Nt    (   t   _compress_ret   subt   strip(   t   text(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   compress_textt   s    c         C   s   t  j d d |   S(   Ns   (?:(?<!\r)\n)|(?:\r(?!\n))s   
(   t   reRA   (   RC   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   normalize_line_endingsv   s    c         C   s>   |  d  k s d |  k r |  S| | d  } t j d | |   S(   Nt   &c         S   s   |  j    } | d d k r0 t | d d !|  S| j |  } | d  k	 r t |  t d  k r y | j |  } Wq t k
 r | } q Xq n | } | S(   Ni   t   #i   it    (   t   groupt   unescape_charreft   gett   Nonet   typet   encodet   UnicodeError(   t   matcht   entitiest   encodingt   entt   repl(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   replace_entities~   s    s   &#?[A-Za-z0-9]+?;(   RM   RE   RA   (   t   dataRR   RS   RV   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   unescapez   s    c         C   s   |  d } } | j  d  r0 | d d } } n  t t | |   } | d  k rU | Sy | j |  } Wn t k
 r d |  } n X| Sd  S(   Ni
   t   xi   i   s   &#%s;(   t
   startswitht   unichrt   intRM   RO   RP   (   RW   RS   t   namet   baset   ucRU   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyRK      s    c          C   s   d d  l  }  d d l m } i  } y |  j Wn t k
 r i  } x |  j j   D]a \ } } | |  d } | j d  r | j d  r t	 | d d !d   } n  | | d | <qS Wn5 Xx1 |  j j   D]  \ } } t |  | d | <q W| S(   Ni(   t   latin_1_decodei    s   &#t   ;i   s   &%s;(   t   htmlentitydefst   codecsR`   t   name2codepointt   AttributeErrort
   entitydefst   itemsRZ   t   endswithRK   RM   R[   (   Rb   R`   Rf   R]   t   charR_   t	   codepoint(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   get_entitydefs   s    c         C   s;   y |  d Wn( t  t f k
 r& t St k
 r6 n Xt S(   Ni    (   t	   TypeErrort   KeyErrorR,   t
   IndexErrort   True(   RY   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt
   issequence   s    c         C   s   y |  d Wn t  SXt Sd  S(   NRI   (   R,   Ro   (   RY   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   isstringlike   s
      c          C   sG   d j  g  d D]% }  t t j d t j d   ^ q  } d d | S(   s/   Return a string usable as a multipart boundary.RI   i    i   i   t   -i   (   i    i   i   (   t   joint   strt   randomt   randintR1   t   maxint(   t   it   nonce(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   choose_boundary   s    ;t
   MimeWriterc           B   st   e  Z d  Z d
 d  Z d d d  Z d   Z d
 g  d d d d  Z d
 g  d d d d  Z d   Z	 d	   Z
 RS(   sO  Generic MIME writer.

    Methods:

    __init__()
    addheader()
    flushheaders()
    startbody()
    startmultipartbody()
    nextpart()
    lastpart()

    A MIME writer is much more primitive than a MIME parser.  It
    doesn't seek around on the output file, and it doesn't use large
    amounts of buffer space, so you have to write the parts in the
    order they should occur on the output file.  It does buffer the
    headers you add, allowing you to rearrange their order.

    General usage is:

    f = <open the output file>
    w = MimeWriter(f)
    ...call w.addheader(key, value) 0 or more times...

    followed by either:

    f = w.startbody(content_type)
    ...call f.write(data) for body data...

    or:

    w.startmultipartbody(subtype)
    for each part:
        subwriter = w.nextpart()
        ...use the subwriter's methods to create the subpart...
    w.lastpart()

    The subwriter is another MimeWriter instance, and should be
    treated in the same way as the toplevel MimeWriter.  This way,
    writing recursive body parts is easy.

    Warning: don't forget to call lastpart()!

    XXX There should be more state so calls made in the wrong order
    are detected.

    Some special cases:

    - startbody() just returns the file passed to the constructor;
      but don't use this knowledge, as it may be changed.

    - startmultipartbody() actually returns a file as well;
      this can be used to write the initial 'if you can read this your
      mailer is not MIME-aware' message.

    - If you call flushheaders(), the headers accumulated so far are
      written out (and forgotten); this is useful if you don't need a
      body part at all, e.g. for a subpart of type message/rfc822
      that's (mis)used to store some header-like information.

    - Passing a keyword argument 'prefix=<flag>' to addheader(),
      start*body() affects where the header is inserted; 0 means
      append at the end, 1 means insert at the start; default is
      append for addheader(), but insert for start*body(), which use
      it to determine where the Content-type header goes.

    c         C   s1   | |  _  | |  _ g  |  _ g  |  _ t |  _ d  S(   N(   t
   _http_hdrst   _fpt   _headerst	   _boundaryRo   t   _first_part(   t   selft   fpt	   http_hdrs(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   __init__  s
    				i    c         C   s  | j  d  } x | r- | d r- | d =q Wx | rL | d rL | d =q1 W| r d j |  } |  j j | j   | f  n x5 t d t |   D] } d | | j   | | <q Wd j |  d } | j   d | } | r |  j	 j
 d |  n |  j	 j |  d S(	   s@   
        prefix is ignored if add_to_http_hdrs is true.
        s   
ii    RI   i   s       s   : N(   t   splitRs   R|   t   appendt
   capitalizet   ranget   lenRB   t   titleR~   t   insert(   R   t   keyt   valuet   prefixt   add_to_http_hdrst   linesRx   t   line(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt	   addheader  s      c         C   s    |  j  j |  j  g  |  _ d  S(   N(   R}   t
   writelinesR~   (   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   flushheaders-  s    i   c         C   s   | rV | rV x( | D]  \ } } | d | | f } q W|  j  d | d | d | n  |  j   | sy |  j j d  n  t |  _ |  j S(   s@   
        prefix is ignored if add_to_http_hdrs is true.
        s	   ;
 %s=%ss   Content-TypeR   R   s   
(   R   R   R}   t   writeRo   R   (   R   t   ctypet   plistR   R   t   content_typeR]   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt	   startbody1  s    

 	c      
   C   sR   | p t    } |  j j |  |  j d | d | f g | d | d | d | S(   Ns
   multipart/t   boundaryR   R   R   (   Rz   R   R   R   (   R   t   subtypeR   R   R   R   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   startmultipartbody@  s    c         C   sZ   |  j  d } |  j r" t |  _ n |  j j d  |  j j d | d  |  j |  j  S(   Nis   
s   --(   R   R   R,   R}   R   t	   __class__(   R   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   nextpartJ  s    	c         C   sA   |  j  r |  j   n  |  j j   } |  j j d | d  d  S(   Ns   
--s   --
(   R   R   R   t   popR}   R   (   R   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   lastpartS  s    	N(   R=   R>   t   __doc__RM   R   R   R   R   R   R   R   (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR{      s   D						c           B   s   e  Z RS(    (   R=   R>   (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   Z  s    c           B   s   e  Z RS(    (   R=   R>   (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR    [  s    c           B   s   e  Z RS(    (   R=   R>   (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   \  s    c           B   s   e  Z RS(    (   R=   R>   (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   ]  s    c           B   s   e  Z RS(    (   R=   R>   (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   _  s    c           B   s   e  Z d    Z d   Z RS(   c         O   s   t  j |  | |  d  S(   N(   t	   ExceptionR   (   R   R'   R(   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   g  s    c         C   s   t  j |   S(   N(   R   t   __str__(   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   j  s    (   R=   R>   R   R   (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   d  s   	t   _AbstractFormParserc           B   s  e  Z d  Z d e 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 RS(   s:   forms attribute contains HTMLForm instances on completion.c         C   s   | d  k r t   } n  | |  _ | |  _ d  |  _ g  |  _ g  |  _ d  |  _ d  |  _ d  |  _	 d  |  _
 d  |  _ d  |  _ d  |  _ |  j g   |  j   |  j d |  _ |  _ d  S(   Ni    (   RM   Rk   t   _entitydefst	   _encodingR^   t   formst   labelst   _current_labelt   _current_formt   _selectt	   _optgroupt   _optiont	   _textareat   _global_formt
   start_formt   end_form(   R   Rf   RS   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   q  s"    												
c         C   sI   t  d |  x5 | D]- \ } } | d k r |  j |  |  _ q q Wd  S(   Ns   %st   href(   R%   t   unescape_attr_if_requiredR^   (   R   t   attrsR   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   do_base  s    c         C   sI   t  d  |  j d  k	 r& |  j   n  |  j |  j k	 rE |  j   n  d  S(   NRI   (   R%   R   RM   t	   end_labelR   R   R   (   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   end_body  s
    
c   
      C   s"  t  d |  |  j |  j k	 r. t d   n  d  } d  } d } d } i  } x | D] \ } } | d k r} |  j |  } nf | d k r |  j |  } nH | d k r |  j | j    } n$ | d k r |  j | j    } n  |  j |  | | <qS Wg  }	 | | | | f | |	 f |  _ d  S(	   Ns   %ss   nested FORMss!   application/x-www-form-urlencodedt   GETR]   t   actiont   methodt   enctype(   R%   R   R   R   RM   R   t   uppert   lower(
   R   R   R]   R   R   R   t   dR   R   t   controls(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s(    c         C   sj   t  d  |  j d  k	 r& |  j   n  |  j |  j k rG t d   n  |  j j |  j  |  j |  _ d  S(   NRI   s   end of FORM before start(	   R%   R   RM   R   R   R   R   R   R   (   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s    
c         C   s   t  d |  |  j d  k	 r+ t d   n  |  j d  k	 rI t d   n  i  } x' | D] \ } } |  j |  | | <qV W| |  _ |  j |  |  j i | d 6 d  S(   Ns   %ss   nested SELECTss   SELECT inside TEXTAREAt   __select(   R%   R   RM   R   R   R   t
   _add_labelt   _append_select_control(   R   R   R   R   t   val(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   start_select  s    	c         C   sQ   t  d  |  j d  k r( t d   n  |  j d  k	 rD |  j   n  d  |  _ d  S(   NRI   s   end of SELECT before start(   R%   R   RM   R   R   t   _end_option(   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt
   end_select  s    
c         C   sh   t  d |  |  j d  k r+ t d   n  i  } x' | D] \ } } |  j |  | | <q8 W| |  _ d  S(   Ns   %ss   OPTGROUP outside of SELECT(   R%   R   RM   R   R   R   (   R   R   R   R   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   start_optgroup  s    c         C   s5   t  d  |  j d  k r( t d   n  d  |  _ d  S(   NRI   s   end of OPTGROUP before start(   R%   R   RM   R   (   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   end_optgroup  s    
c         C   s   t  d |  |  j d  k r+ t d   n  |  j d  k	 rG |  j   n  i  } x' | D] \ } } |  j |  | | <qT Wi  |  _ |  j j |  |  j r |  j j	 d  r |  j j	 d  r d  |  j d <n  d  S(   Ns   %ss   OPTION outside of SELECTt   disabled(
   R%   R   RM   R   R   R   R   t   updateR   t   has_key(   R   R   R   R   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   _start_option  s    	c         C   s   t  d  |  j d  k r( t d   n  |  j j d d  j   } | |  j d <|  j j d  sr | |  j d <n  |  j j d  s | |  j d <n  |  j |  j d <|  j |  j  d  |  _ d  S(   NRI   s   end of OPTION before startt   contentsR   t   labelR   (	   R%   R   RM   R   RL   RB   R   R   R   (   R   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s    
c         C   sF   t  d |  |  j d } |  j j d  } | j d | | f  d  S(   Ns   %si   R]   t   select(   R%   R   R   RL   R   (   R   R   R   R]   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s    c         C   s   t  d |  |  j d  k	 r+ t d   n  |  j d  k	 rI t d   n  i  } x' | D] \ } } |  j |  | | <qV W|  j |  | |  _ d  S(   Ns   %ss   nested TEXTAREAss   TEXTAREA inside SELECT(   R%   R   RM   R   R   R   R   (   R   R   R   R   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   start_textarea  s    c         C   sm   t  d  |  j d  k r( t d   n  |  j d } |  j j d  } | j d | |  j f  d  |  _ d  S(   NRI   s   end of TEXTAREA before starti   R]   t   textarea(   R%   R   RM   R   R   RL   R   (   R   R   R]   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   end_textarea  s    
c         C   s   t  d |  |  j r# |  j   n  i  } x' | D] \ } } |  j |  | | <q0 Wt | j d   } d | d <| | d <| r |  j j |  n  | |  _ d  S(   Ns   %st   forRI   t   __textt   __taken(   R%   R   R   R   t   boolRL   R   R   (   R   R   R   R   R   t   taken(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   start_label  s    	

c         C   s7   t  d  |  j } | d  k r# d  Sd  |  _ | d =d  S(   NRI   R   (   R%   R   RM   (   R   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   )  s    
		c         C   s@   |  j  d  k	 r< |  j  d s< t |  j  d <|  j  | d <q< n  d  S(   NR   t   __label(   R   RM   Ro   (   R   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   3  s    c         C   s   t  d |  |  j d  k	 r. |  j } d } nR |  j d  k	 r[ |  j } d } t |  } n% |  j d  k	 r| |  j } d } n d  S| r | j |  r | d d !d k r | d } n  | d d !d k r | d } n  | | | <n | | | | | <d  S(   Ns   %sR   R   R   i    i   s   
i   s   
s   (   s   
s   (   R%   R   RM   R   RF   R   R   (   R   RW   t   mapR   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   handle_data:  s&    					c         C   s   t  d |  i  } d | d <x' | D] \ } } |  j |  | | <q$ W|  j d } | d } | j d  } | d } |  j |  | j | | | f  d  S(   Ns   %st   submitRN   i   R]   t   button(   R%   R   R   RL   R   R   (   R   R   R   R   R   R   RN   R]   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt	   do_button]  s    


c         C   s   t  d |  i  } d | d <x' | D] \ } } |  j |  | | <q$ W|  j d } | d } | j d  } |  j |  | j | | | f  d  S(   Ns   %sRC   RN   i   R]   (   R%   R   R   RL   R   R   (   R   R   R   R   R   R   RN   R]   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   do_inputo  s    

c         C   sq   t  d |  i  } x' | D] \ } } |  j |  | | <q W|  j d } |  j |  | j d d  | f  d  S(   Ns   %si   t   isindex(   R%   R   R   R   R   RM   (   R   R   R   R   R   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt
   do_isindex|  s    c         C   s'   |  j  t d | |  j |  j   d  S(   Ns   &%s;(   R   RX   R   R   (   R   R]   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   handle_entityref  s    	c         C   s   |  j  t | |  j   d  S(   N(   R   RK   R   (   R   R]   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   handle_charref  s    c         C   s   t  | |  j |  j  S(   N(   RX   R   R   (   R   R]   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   unescape_attr  s    c         C   sl   i  } x_ | j    D]Q \ } } y | j  Wn$ t k
 rP |  j |  | | <q X|  j |  | | <q W| S(   N(   Rg   Re   R   t   unescape_attrs(   R   R   t   escaped_attrsR   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s    c         C   s   |  j  d |  d  S(   Ns   &%s;(   R   (   R   t   ref(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   unknown_entityref  s    c         C   s   |  j  d |  d  S(   Ns   &#%s;(   R   (   R   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   unknown_charref  s    N(    R=   R>   R   RM   t   DEFAULT_ENCODINGR   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   n  s8   							
	
									
		#								c           B   sn   e  Z d  Z d e d  Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d   Z d	   Z d
   Z RS(   s4   Good for XHTML, bad for tolerance of incorrect HTML.c         C   s'   t  j  j |   t j |  | |  d  S(   N(   t
   HTMLParserR   R   (   R   Rf   RS   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s    c         C   s@   y t  j  j |  |  Wn" t  j k
 r; } t |   n Xd  S(   N(   R   t   feedt   HTMLParseErrorR   (   R   RW   t   exc(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s    c         C   s   t  j |  |  d  S(   N(   R   R   (   R   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   start_option  s    c         C   s   t  j |   d  S(   N(   R   R   (   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt
   end_option  s    c         C   sn   y t  |  d |  } WnF t k
 r_ y t  |  d |  } Wn t k
 rQ qj X| |  n X| |  d  S(   Nt   start_t   do_(   t   getattrRe   (   R   t   tagR   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   handle_starttag  s    c         C   s6   y t  |  d |  } Wn t k
 r* n X|   d  S(   Nt   end_(   R   Re   (   R   R   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   handle_endtag  s
    c         C   s   |  j  |  S(   N(   R   (   R   R]   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyRX     s    c         C   s   | S(   N(    (   R   R]   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s    c         C   s   | S(   N(    (   R   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   unescape_attrs_if_required  s    c         C   s   t  j  j |   |  j   d  S(   N(   R   t   closeR   (   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s    N(   R=   R>   R   RM   R   R   R   R   R   R   R   RX   R   R   R   (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s   								t   _AbstractSgmllibParserc           B   sD   e  Z d    Z e j d  Z d   Z d   Z d   Z d   Z	 RS(   c         C   s   t  j |  |  d  S(   N(   R   R   (   R   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt	   do_option  s    s3   &(?:([a-zA-Z][-.a-zA-Z0-9]*)|#(x?[0-9a-fA-F]+))(;?)c         C   s   t  d | |  j |  j  S(   Ns   &%s;(   RX   R   R   (   R   R]   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   convert_entityref  s    c         C   s   t  d | |  j  S(   Ns   %s(   RK   R   (   R   R]   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   convert_charref  s    c         C   s   | S(   N(    (   R   R]   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s    c         C   s   | S(   N(    (   R   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s    (
   R=   R>   R   RE   t   compilet   entity_or_charrefR   R   R   R   (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s   					c           B   s/   e  Z d  Z d e d  Z d   Z d   Z RS(   s4   Good for tolerance of incorrect HTML, bad for XHTML.c         C   s'   t  j j |   t j |  | |  d  S(   N(   t   _sgmllib_copyt
   SGMLParserR   R   (   R   Rf   RS   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s    c         C   s@   y t  j j |  |  Wn" t  j k
 r; } t |   n Xd  S(   N(   R   R  R   t   SGMLParseErrorR   (   R   RW   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s    c         C   s   t  j j |   |  j   d  S(   N(   R   R  R   R   (   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s    N(   R=   R>   R   RM   R   R   R   R   (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s   	t   _AbstractBSFormParserc           B   s8   e  Z d Z d e d   Z d   Z d   Z d   Z RS(   c         C   s'   t  j |  | |  |  j j |   d  S(   N(   R   R   t   bs_base_class(   R   Rf   RS   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s    c         C   s'   t  j |  |  |  j j |  |  d  S(   N(   R   R   R  (   R   RW   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s    c         C   s@   y |  j  j |  |  Wn" t j k
 r; } t |   n Xd  S(   N(   R  R   R   R  R   (   R   RW   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s    c         C   s   |  j  j |   |  j   d  S(   N(   R  R   R   (   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s    N(	   R=   R>   RM   R  R   R   R   R   R   (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR    s
   		t   RobustFormParserc           B   s   e  Z d  Z e j Z RS(   s.   Tries to be highly tolerant of incorrect HTML.(   R=   R>   R   t   _beautifulsoupt   BeautifulSoupR  (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR    s   t   NestingRobustFormParserc           B   s   e  Z d  Z e j Z RS(   s   Tries to be highly tolerant of incorrect HTML.

    Different from RobustFormParser in that it more often guesses nesting
    above missing end tags (see BeautifulSoup docs).
    (   R=   R>   R   R  t   ICantBelieveItsBeautifulSoupR  (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR    s   c	   	      C   s:   t  |  |  j   | t | | | t | d | d | d | 	S(   sS  Identical to ParseResponse, except that:

    1. The returned list contains an extra item.  The first form in the list
    contains all controls not contained in any FORM element.

    2. The arguments ignore_errors and backwards_compat have been removed.

    3. Backwards-compatibility mode (backwards_compat=True) is not available.
    t   _urljoint	   _urlparset   _urlunparse(   t   _ParseFileExt   geturlR,   (	   t   responset   select_defaultt   form_parser_classt   request_classRf   RS   R
  R  R  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   -  s    c
   
      C   s4   t  |  | | t | | | t | d | d | d |	 	S(   sO  Identical to ParseFile, except that:

    1. The returned list contains an extra item.  The first form in the list
    contains all controls not contained in any FORM element.

    2. The arguments ignore_errors and backwards_compat have been removed.

    3. Backwards-compatibility mode (backwards_compat=True) is not available.
    R
  R  R  (   R  R,   (
   t   filet   base_uriR  R  R  Rf   RS   R
  R  R  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   O  s    	c         O   s   t  |   } t | | | |  S(   N(   R    R   (   RC   R  R'   R(   t   fh(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   ParseStringq  s    c         O   s   t  |  |  j   | |  d S(   s~  Parse HTTP response and return a list of HTMLForm instances.

    The return value of mechanize.urlopen can be conveniently passed to this
    function as the response parameter.

    mechanize.ParseError is raised on parse errors.

    response: file-like object (supporting read() method) with a method
     geturl(), returning the URI of the HTTP response
    select_default: for multiple-selection SELECT controls and RADIO controls,
     pick the first item as the default if none are selected in the HTML
    form_parser_class: class to instantiate and use to pass
    request_class: class to return from .click() method (default is
     mechanize.Request)
    entitydefs: mapping like {"&amp;": "&", ...} containing HTML entity
     definitions (a sensible default is used)
    encoding: character encoding used for encoding numeric character references
     when matching link text.  mechanize does not attempt to find the encoding
     in a META HTTP-EQUIV attribute in the document itself (mechanize, for
     example, does do that and will pass the correct value to mechanize using
     this parameter).

    backwards_compat: boolean that determines whether the returned HTMLForm
     objects are backwards-compatible with old code.  If backwards_compat is
     true:

     - ClientForm 0.1 code will continue to work as before.

     - Label searches that do not specify a nr (number or count) will always
       get the first match, even if other controls match.  If
       backwards_compat is False, label searches that have ambiguous results
       will raise an AmbiguityError.

     - Item label matching is done by strict string comparison rather than
       substring matching.

     - De-selecting individual list items is allowed even if the Item is
       disabled.

    The backwards_compat argument will be removed in a future release.

    Pass a true value for select_default if you want the behaviour specified by
    RFC 1866 (the HTML 2.0 standard), which is to select the first item in a
    RADIO or multiple-selection SELECT control if none were selected in the
    HTML.  Most browsers (including Microsoft Internet Explorer (IE) and
    Netscape Navigator) instead leave all items unselected in these cases.  The
    W3C HTML 4.0 standard leaves this behaviour undefined in the case of
    multiple-selection SELECT controls, but insists that at least one RADIO
    button should be checked at all times, in contradiction to browser
    behaviour.

    There is a choice of parsers.  mechanize.XHTMLCompatibleFormParser (uses
    HTMLParser.HTMLParser) works best for XHTML, mechanize.FormParser (uses
    bundled copy of sgmllib.SGMLParser) (the default) works better for ordinary
    grubby HTML.  Note that HTMLParser is only available in Python 2.2 and
    later.  You can pass your own class in here as a hack to work around bad
    HTML, but at your own risk: there is no well-defined interface.

    i   (   R  R  (   R  R'   R(   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   u  s    <c         O   s   t  |  | | |  d S(   s  Parse HTML and return a list of HTMLForm instances.

    mechanize.ParseError is raised on parse errors.

    file: file-like object (supporting read() method) containing HTML with zero
     or more forms to be parsed
    base_uri: the URI of the document (note that the base URI used to submit
     the form will be that given in the BASE element if present, not that of
     the document)

    For the other arguments and further details, see ParseResponse.__doc__.

    i   (   R  (   R  R  R'   R(   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s    c         C   s.  | r t  d d  n  | | |  } x[ |  j t  } y | j |  Wn t k
 ri } | | _   n Xt |  t k r( Pq( q( | j   | j d  k	 r | j } n  g  } i  } xl | j
 D]a } t |  } | j |  | d } | j |  } | d  k r| g | | <q | j |  q Wg  } x | j D] \ \ } } } } } } | d  k rc| } n |	 | |  } t | | | | | | | | | | 
 } |
 | _ | | _ xP t t |   D]< } | | \ } } } | j | | | d | d | d qW| j |  q3Wx | D] } | j   qW| S(   Ns)   operating in backwards-compatibility modei   R   R  t   indexi
   (   R<   t   readt   CHUNKR   R   R  R   R   R^   RM   R   R   R   RL   R   R   R  R  R   t   new_controlt   fixup(   R  R  R  t   ignore_errorsR  R  Rf   t   backwards_compatRS   R
  R  R  R   RW   t   eR   t   id_to_labelst   lR   t   for_idt   collR   R]   R   R   R   R   R   t   formt   iiRN   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR    sV    	 

%			!c           B   s,   e  Z d    Z d   Z d   Z d   Z RS(   c         C   sR   | j  d  |  _ | j  d  j   |  _ t |  j  |  _ | |  _ t |  _ d  S(   NR   R   (	   RL   t   idRB   t   _textRD   t   _ctextR   R,   t   _backwards_compat(   R   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s
    	c         C   s3   | d k r& |  j  r |  j S|  j Sn  t t |  S(   NRC   (   R(  R&  R'  R   R   (   R   R]   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   __getattr__  s
    	
c         C   s,   | d k r t  d   n  | |  j | <d  S(   NRC   s   text attribute is read-only(   Re   t   __dict__(   R   R]   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   __setattr__  s    c         C   s   d |  j  |  j f S(   Ns   <Label(id=%r, text=%r)>(   R%  RC   (   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s    (   R=   R>   R   R)  R+  R   (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR      s   			c         C   s-   |  j  d  } | d  k	 r% t |  Sd  Sd  S(   NR   (   RL   RM   R   (   R   RC   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt
   _get_label  s    
c           B   s}   e  Z d  Z d d  Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z d
   Z d   Z d   Z RS(   s	  An HTML form control.

    An HTMLForm contains a sequence of Controls.  The Controls in an HTMLForm
    are accessed using the HTMLForm.find_control method or the
    HTMLForm.controls attribute.

    Control instances are usually constructed using the ParseFile /
    ParseResponse functions.  If you use those functions, you can ignore the
    rest of this paragraph.  A Control is only properly initialised after the
    fixup method has been called.  In fact, this is only strictly necessary for
    ListControl instances.  This is necessary because ListControls are built up
    from ListControls each containing only a single item, and their initial
    value(s) can only be known after the sequence is complete.

    The types and values that are acceptable for assignment to the value
    attribute are defined by subclasses.

    If the disabled attribute is true, this represents the state typically
    represented by browsers by 'greying out' a control.  If the disabled
    attribute is true, the Control will raise AttributeError if an attempt is
    made to change its value.  In addition, the control will not be considered
    'successful' as defined by the W3C HTML 4 standard -- ie. it will
    contribute no data to the return value of the HTMLForm.click* methods.  To
    enable a control, set the disabled attribute to a false value.

    If the readonly attribute is true, the Control will raise AttributeError if
    an attempt is made to change its value.  To make a control writable, set
    the readonly attribute to a false value.

    All controls have the disabled and readonly attributes, not only those that
    may have the HTML attributes of the same names.

    On assignment to the value attribute, the following exceptions are raised:
    TypeError, AttributeError (if the value attribute should not be assigned
    to, because the control is disabled, for example) and ValueError.

    If the name or value attributes are None, or the value is an empty list, or
    if the control is disabled, the control is not successful.

    Public attributes:

    type: string describing type of control (see the keys of the
     HTMLForm.type2class dictionary for the allowable values) (readonly)
    name: name of control (readonly)
    value: current value of control (subclasses may allow a single value, a
     sequence of values, or either)
    disabled: disabled state
    readonly: readonly state
    id: value of id HTML attribute

    c         C   s   t     d S(   s   
        type: string describing type of control (see the keys of the
         HTMLForm.type2class dictionary for the allowable values)
        name: control name
        attrs: HTML attributes of control's HTML element

        N(   t   NotImplementedError(   R   RN   R]   R   R  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   U  s    c         C   s   | |  _  | j j |   d  S(   N(   t   _formR   R   (   R   R#  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   add_to_form_  s    	c         C   s   d  S(   N(    (   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR  c  s    c         C   s   t     d  S(   N(   R-  (   R   t   kind(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt
   is_of_kindf  s    c         C   s   t     d  S(   N(   R-  (   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   cleari  s    c         C   s   t     d  S(   N(   R-  (   R   R]   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR)  l  s    c         C   s   t     d  S(   N(   R-  (   R   R]   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR+  m  s    c         C   s,   g  |  j    D] \ } } } | | f ^ q S(   sM   Return list of (key, value) pairs suitable for passing to urlencode.
        (   t   _totally_ordered_pairs(   R   Rx   t   kt   v(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   pairso  s    c         C   s   t     d S(   s   Return list of (key, value, index) tuples.

        Like pairs, but allows preserving correct ordering even where several
        controls are involved.

        N(   R-  (   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR3  t  s    c         C   sF   | j    } | j d d | d  | j d d  } | j |  d S(   s9   Write data for a subitem of this control to a MimeWriter.s   Content-Dispositions   form-data; name="%s"i   R   i    N(   R   R   R   R   (   R   t   mwR]   R   t   mw2t   f(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   _write_mime_data}  s
    	c         C   s   t     d  S(   N(   R-  (   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s    c         C   sT   g  } |  j  r" | j |  j   n  |  j rP | j |  j j j |  j d   n  | S(   s  Return all labels (Label instances) for this control.
        
        If the control was surrounded by a <label> tag, that will be the first
        label; all other labels, connected by 'for' and 'id', are in the order
        that appear in the HTML.

        (    (   t   _labelR   R%  t   extendR.  t   _id_to_labelsRL   (   R   t   res(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt
   get_labels  s    		%N(   R=   R>   R   RM   R   R/  R  R1  R2  R)  R+  R6  R3  R:  R   R?  (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   !  s   3
												c           B   sG   e  Z d  Z d d  Z d   Z d   Z d   Z d   Z d   Z	 RS(   sX  Control whose value is not restricted to one of a prescribed set.

    Some ScalarControls don't accept any value attribute.  Otherwise, takes a
    single value, which must be string-like.

    Additional read-only public attribute:

    attrs: dictionary mapping the names of original HTML attributes of the
     control to their values

    c         C   s   | |  _  t |  |  _ | j   |  j d <| |  j d <| j d  |  _ | j d  |  _ | j d  |  _	 | j d  |  _
 | j   |  _ t |  _ t j |  _ t j |  _ d  S(   NRN   R]   R   R   t   readonlyR%  (   t   _indexR,  R;  R   R*  RL   t   _valueR   R   R@  R%  t   copyR   R,   t   _clickedt   urlparseR  t
   urlunparseR  (   R   RN   R]   R   R  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s    		c         C   s7   | d k r |  j  d St d |  j j | f   d  S(   NR   RB  s!   %s instance has no attribute '%s'(   R*  Re   R   R=   (   R   R]   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR)    s    c         C   s   | d k ru t  |  s' t d   n> |  j rF t d |  j   n |  j re t d |  j   n  | |  j d <n, | d	 k r t d |   n | |  j | <d  S(
   NR   s   must assign a strings   control '%s' is readonlys   control '%s' is disabledRB  R]   RN   s   %s attribute is readonly(   s   names   type(   Rq   Rl   R@  Re   R]   R   R*  (   R   R]   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR+    s    		c         C   sJ   |  j  } |  j } | d  k s3 | d  k s3 |  j r7 g  S|  j | | f g S(   N(   R]   R   RM   R   RA  (   R   R]   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR3    s
    		!c         C   s0   |  j  r t d |  j   n  d  |  j d <d  S(   Ns   control '%s' is readonlyRB  (   R@  Re   R]   RM   R*  (   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR2    s    	c         C   s   |  j  } |  j } | d  k r' d } n  | d  k r< d } n  g  } |  j r[ | j d  n  |  j rt | j d  n  d j |  } | r d | } n  d |  j j | | | f S(   Ns   <None>R   R@  s   , s    (%s)s   <%s(%s=%s)%s>(	   R]   R   RM   R   R   R@  Rs   R   R=   (   R   R]   R   t   infost   info(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s    		 	 		 	  N(
   R=   R>   R   RM   R   R)  R+  R3  R2  R   (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s   				c           B   s#   e  Z d  Z d d  Z d   Z RS(   sj   Textual input control.

    Covers:

    INPUT/TEXT
    INPUT/PASSWORD
    INPUT/HIDDEN
    TEXTAREA

    c         C   sS   t  j |  | | | |  |  j d k r4 t |  _ n  |  j d  k rO d |  _ n  d  S(   Nt   hiddenRI   (   R   R   RN   Ro   R@  RB  RM   (   R   RN   R]   R   R  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s
     c         C   s
   | d k S(   NRC   (    (   R   R0  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR1    s    N(   R=   R>   R   RM   R   R1  (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s   
c           B   s_   e  Z d  Z d	 d  Z d   Z d   Z d   Z d	 d	 d  Z d   Z	 d   Z
 d   Z RS(
   s   File upload with INPUT TYPE=FILE.

    The value attribute of a FileControl is always None.  Use add_file instead.

    Additional public method: add_file

    c         C   s/   t  j |  | | | |  d  |  _ g  |  _ d  S(   N(   R   R   RM   RB  t   _upload_data(   R   RN   R]   R   R  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s    	c         C   s
   | d k S(   NR  (    (   R   R0  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR1  
  s    c         C   s,   |  j  r t d |  j   n  g  |  _ d  S(   Ns   control '%s' is readonly(   R@  Re   R]   RJ  (   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR2    s    	c         C   s0   | d k r t  d |   n | |  j | <d  S(   NR   R]   RN   s   %s attribute is readonly(   s   values   names   type(   Re   R*  (   R   R]   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR+    s    c         C   s   t  | d  s t d   n  | d  k	 rF t |  rF t d   n  | d  k	 rn t |  rn t d   n  | d  k r d } n  |  j j | | | f  d  S(   NR  s&   file-like object must have read methods(   content type must be None or string-likes$   filename must be None or string-likes   application/octet-stream(   t   hasattrRl   RM   Rq   RJ  R   (   R   t   file_objectR   t   filename(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   add_file  s    	c         C   s2   |  j  d  k s |  j r g  S|  j |  j  d f g S(   NRI   (   R]   RM   R   RA  (   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR3  "  s    c         C   s  t  |  j  d k  r t  |  j  d k rB t   } d } d } n+ |  j d \ } } } | d  k rm d } n  | j   } d | } d |  j | f }	 | j d |	 d d	 | j | d d }
 |
 j | j	    n | j   } d
 |  j }	 | j d |	 d d	 | j
 d d d }
 x |  j D] \ } } } | j   } | d  k rUd } n  d | } d | }	 | j d |	 d d	 | j | d d } | j | j	    q%W| j   d  S(   Ni   i    s   application/octet-streamRI   s   ; filename="%s"s   form-data; name="%s"%ss   Content-DispositionR   i   s   form-data; name="%s"t   mixeds   file%s(   R   RJ  R    RM   R   R]   R   R   R   R  R   R   (   R   R7  t   _nameRB  RL  R   RM  R8  t   fn_partt   dispR  t   mw3t   fh2(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR:  ,  s8    			
	

c         C   s   |  j  } | d  k r d } n  |  j s0 d } n[ g  } xC |  j D]8 \ } } } | d  k rk | j d  q@ | j |  q@ Wd j |  } g  } |  j r | j d  n  |  j r | j d  n  d j |  } | r d | } n  d |  j j | | | f S(	   Ns   <None>s   <No files added>s   <Unnamed file>s   , R   R@  s    (%s)s   <%s(%s=%s)%s>(	   R]   RM   RJ  R   Rs   R   R@  R   R=   (   R   R]   R   R  R   RM  RH  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   O  s(    	 				 	  N(   R=   R>   R   RM   R   R1  R2  R+  RN  R3  R:  R   (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s   				
	#c           B   sD   e  Z d  Z d d  Z d   Z d   Z e j d  Z	 d   Z
 RS(   s  ISINDEX control.

    ISINDEX is the odd-one-out of HTML form controls.  In fact, it isn't really
    part of regular HTML forms at all, and predates it.  You're only allowed
    one ISINDEX per HTML document.  ISINDEX and regular form submission are
    mutually exclusive -- either submit a form, or the ISINDEX.

    Having said this, since ISINDEX controls may appear in forms (which is
    probably bad HTML), ParseFile / ParseResponse will include them in the
    HTMLForm instances it returns.  You can set the ISINDEX's value, as with
    any other control (but note that ISINDEX controls have no name, so you'll
    need to use the type argument of set_value!).  When you submit the form,
    the ISINDEX will not be successful (ie., no data will get returned to the
    server as a result of its presence), unless you click on the ISINDEX
    control, in which case the ISINDEX gets submitted instead of the form:

    form.set_value("my isindex value", type="isindex")
    mechanize.urlopen(form.click(type="isindex"))

    ISINDEX elements outside of FORMs are ignored.  If you want to submit one
    by hand, do it like so:

    url = urlparse.urljoin(page_uri, "?"+urllib.quote_plus("my isindex value"))
    result = mechanize.urlopen(url)

    c         C   s8   t  j |  | | | |  |  j d  k r4 d |  _ n  d  S(   NRI   (   R   R   RB  RM   (   R   RN   R]   R   R  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s    c         C   s
   | d k S(   NRC   t	   clickable(   s   textRU  (    (   R   R0  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR1    s    c         C   s   g  S(   N(    (   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR3    s    c         C   s   |  j  | j  } | d  | d } \ } } | t j |  j  d  f } |  j |  }	 |	 d  g  f }
 | d k rw g  S| d k r |
 S| |	  Sd  S(   NiR6  t   request_data(   R  R   t   urllibt
   quote_plusR   RM   R  (   R   R#  t   coordt   return_typeR  t   partst   restt   queryt   fragt   urlt   req_data(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   _click  s    c         C   s   |  j  } | d  k r d } n  g  } |  j r= | j d  n  |  j rV | j d  n  d j |  } | rx d | } n  d |  j j | | f S(   Ns   <None>R   R@  s   , s    (%s)s
   <%s(%s)%s>(   R   RM   R   R   R@  Rs   R   R=   (   R   R   RG  RH  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s    	 		 	  N(   R=   R>   R   RM   R   R1  R3  t   _requestt   RequestRa  R   (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR
   h  s   		c           B   s,   e  Z d  Z d d  Z d   Z d   Z RS(   s  Control that we're not interested in.

    Covers:

    INPUT/RESET
    BUTTON/RESET
    INPUT/BUTTON
    BUTTON/BUTTON

    These controls are always unsuccessful, in the terminology of HTML 4 (ie.
    they never require any information to be returned to the server).

    BUTTON/BUTTON is used to generate events for script embedded in HTML.

    The value attribute of IgnoreControl is always None.

    c         C   s&   t  j |  | | | |  d  |  _ d  S(   N(   R   R   RM   RB  (   R   RN   R]   R   R  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s    c         C   s   t  S(   N(   R,   (   R   R0  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR1    s    c         C   sR   | d k r" t  d |  j   n, | d k rA t  d |   n | |  j | <d  S(   NR   s(   control '%s' is ignored, hence read-onlyR]   RN   s   %s attribute is readonly(   s   names   type(   Re   R]   R*  (   R   R]   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR+    s    N(   R=   R>   R   RM   R   R1  R+  (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s   	c           B   sA   e  Z d d   Z d   Z d   Z d   Z d   Z d   Z RS(   c         C   s   t  |  } |  j j i | d d 6| r2 | g p5 g  d 6| d 6| d 6| j d  d 6t d 6| j d  d 6| d	 6 | j j |   d  S(
   NR   R]   t   _labelsR   t   _controlR   t	   _selectedR%  RA  (   R,  R*  R   R   R,   RL   Rg   R   (   R   t   controlR   R  R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s    c         C   sK   g  } | j  |  j  |  j rG | j  |  j j j j |  j d   n  | S(   sC  Return all labels (Label instances) for this item.
        
        For items that represent radio buttons or checkboxes, if the item was
        surrounded by a <label> tag, that will be the first label; all other
        labels, connected by 'for' and 'id', are in the order that appear in
        the HTML.
        
        For items that represent select options, if the option had a label
        attribute, that will be the first label.  If the option has contents
        (text within the option tags) and it is not the same as the label
        attribute (if any), that will be a label.  There is nothing in the
        spec to my knowledge that makes an option with an id unable to be the
        target of a label's for attribute, so those are included, if any, for
        the sake of consistency and completeness.

        (    (   R<  Rd  R%  Re  R.  R=  RL   (   R   R>  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR?    s
    	(c         C   s#   | d k r |  j  St |   d  S(   Nt   selected(   Rf  Re   (   R   R]   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR)    s    c         C   sT   | d k r" |  j  j |  |  n. | d k rD t |  |  j d <n t |   d  S(   NRh  R   (   Re  t   _set_selected_stateR   R*  Re   (   R   R]   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR+     s
    c         C   s9   |  j  } |  j r d | } n  |  j r5 d | } n  | S(   Nt   *s   (%s)(   R]   Rh  R   (   R   R>  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s    			c         C   sk   d |  j  f d |  j f g |  j j   } d |  j j d j g  | D] \ } } d | | f ^ qD  f S(   NR]   R%  s   <%s %s>R?   s   %s=%r(   R]   R%  R   Rg   R   R=   Rs   (   R   R   R4  R5  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   __repr__  s    +	N(	   R=   R>   RM   R   R?  R)  R+  R   Rk  (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s   				c         K   s   g  } x1 | j    D]# \ } } | j d | | f  q Wd j |  } |  s^ t |   n  | d  k r t |   d k r t |   n  d } n  t |   | k r t |   n  |  | S(   Ns   %s=%rR?   i   i    (   Rg   R   Rs   R   RM   R   R    (   Rg   t   nrR(   t   msgsR   R   R&   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   disambiguate  s    	c           B   s|  e  Z d  Z d  Z i  e e d  d  Z d   Z d   Z d  d  d  e d  Z	 d  d  d  d  e d  Z
 e d  e d  Z e d  d  Z e d  d  Z d	   Z d  d
  Z d  d  Z e d  d  Z e d  d  Z d   Z e d  d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d d  Z d   Z d   Z d   Z d   Z  e d  Z! d   Z" d   Z# RS(!   s  Control representing a sequence of items.

    The value attribute of a ListControl represents the successful list items
    in the control.  The successful list items are those that are selected and
    not disabled.

    ListControl implements both list controls that take a length-1 value
    (single-selection) and those that take length >1 values
    (multiple-selection).

    ListControls accept sequence values only.  Some controls only accept
    sequences of length 0 or 1 (RADIO, and single-selection SELECT).
    In those cases, ItemCountError is raised if len(sequence) > 1.  CHECKBOXes
    and multiple-selection SELECTs (those having the "multiple" HTML attribute)
    accept sequences of any length.

    Note the following mistake:

    control.value = some_value
    assert control.value == some_value    # not necessarily true

    The reason for this is that the value attribute always gives the list items
    in the order they were listed in the HTML.

    ListControl items can also be referred to by their labels instead of names.
    Use the label argument to .get(), and the .set_value_by_label(),
    .get_value_by_label() methods.

    Note that, rather confusingly, though SELECT controls are represented in
    HTML by SELECT elements (which contain OPTION elements, representing
    individual list items), CHECKBOXes and RADIOs are not represented by *any*
    element.  Instead, those controls are represented by a collection of INPUT
    elements.  For example, this is a SELECT control, named "control1":

    <select name="control1">
     <option>foo</option>
     <option value="1">bar</option>
    </select>

    and this is a CHECKBOX control, named "control2":

    <input type="checkbox" name="control2" value="foo" id="cbe1">
    <input type="checkbox" name="control2" value="bar" id="cbe2">

    The id attribute of a CHECKBOX or RADIO ListControl is always that of its
    first element (for example, "cbe1" above).


    Additional read-only public attribute: multiple.

    c         C   s   | s t     n  | j   |  j d <| |  j d <| j d  |  _ t |  _ t |  _ | j d  |  _ t |  _	 g  |  _
 d |  _ | |  _ t |  _ d S(   s   
        select_default: for RADIO and multiple-selection SELECT controls, pick
         the first item as the default if no 'selected' HTML attribute is
         present

        RN   R]   R   R%  N(   R-  R   R*  RL   RB  R,   R   R@  R%  t   _closedRg   RM   R.  t   _select_defaultRD  (   R   RN   R]   R   R  t   called_as_base_classR  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   s  s    						c         C   s   g  |  _  d  S(   N(   R   (   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR2    s    c         C   sE   | d k r t  S| d k r) t |  j  S| d k r= |  j St Sd  S(   Nt   listt	   multilistt
   singlelist(   Ro   R   t   multipleR,   (   R   R0  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR1    s    c   	      C   sg  | d k	 r( t |  r( t d   n  | d k	 rP t |  rP t d   n  | d k	 rx t |  rx t d   n  g  } |  j j } x |  j D] } | r | j r q n  | d k	 r | j | k r q n  | d k	 r1xR | j   D]> } | r| j	 | k s#| r | j	 j
 |  d k r Pq q Wq n  | d k	 rR| j | k rRq n  | j |  q W| S(   sj   Return matching items by name or label.

        For argument docs, see the docstring for .get()

        s   item name must be string-likes   item label must be string-likes   item id must be string-likeiN(   RM   Rq   Rl   R.  R  Rg   R   R]   R?  RC   t   findR%  R   (	   R   R]   R   R%  t   exclude_disabledRg   t   compatt   oR   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt	   get_items  s.    c      
   C   sX   | d k r! |  j j r! d } n  |  j | | | |  } t | | d | d | d | S(   s  Return item by name or label, disambiguating if necessary with nr.

        All arguments must be passed by name, with the exception of 'name',
        which may be used as a positional argument.

        If name is specified, then the item must have the indicated name.

        If label is specified, then the item must have a label whose
        whitespace-compressed, stripped, text substring-matches the indicated
        label string (e.g. label="please choose" will match
        "  Do  please  choose an item ").

        If id is specified, then the item must have the indicated id.

        nr is an optional 0-based index of the items matching the query.

        If nr is the default None value and more than item is found, raises
        AmbiguityError (unless the HTMLForm instance's backwards_compat
        attribute is true).

        If no item is found, or if items are found but nr is specified and not
        found, raises ItemNotFoundError.

        Optionally excludes disabled items.

        i    R]   R   R%  N(   RM   R.  R  Rz  Rn  (   R   R]   R   R%  Rl  Rw  Rg   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyRL     s    	c         C   s9   | r d  | } } n | d  } } |  j | | | |  S(   N(   RM   RL   (   R   R]   t   by_labelRl  Rw  R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   _get  s    c         C   s7   t  d  |  j | | |  } |  j | | j  d S(   sN  Deprecated: given a name or label and optional disambiguating index
        nr, toggle the matching item's selection.

        Selecting items follows the behavior described in the docstring of the
        'get' method.

        if the item is disabled, or this control is disabled or readonly,
        raise AttributeError.

        s:   item = control.get(...); item.selected = not item.selectedN(   R<   R|  Ri  Rh  (   R   R]   R{  Rl  Ry  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   toggle  s    c         C   s-   t  d  |  j |  j | | |  |  d S(   si  Deprecated: given a name or label and optional disambiguating index
        nr, set the matching item's selection to the bool value of selected.

        Selecting items follows the behavior described in the docstring of the
        'get' method.

        if the item is disabled, or this control is disabled or readonly,
        raise AttributeError.

        s%   control.get(...).selected = <boolean>N(   R<   Ri  R|  (   R   Rh  R]   R{  Rl  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   set  s    c         C   s   |  j  r t d |  j   n  |  j r> t d |  j   n  | t |  k |  j j } | ry | j  ry t d   n | r | j  r | r t d   n  |  j r | | j d <nD | s t	 | j d <n. x |  j
 D] } t	 | j d <q Wt | j d <d  S(   Ns   control '%s' is disableds   control '%s' is readonlys   item is disabledRf  (   R   Re   R]   R@  R   R.  R  Ru  R*  R,   Rg   Ro   (   R   t   itemR   Rx  Ry  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyRi    s"    			c         C   sZ   t  d  t |  j  d k r5 t d |  j   n  |  j d } |  j | | j  d S(   s
  Deprecated: toggle the selection of the single item in this control.
        
        Raises ItemCountError if the control does not contain only one item.
        
        by_label argument is ignored, and included only for backwards
        compatibility.

        s9   control.items[0].selected = not control.items[0].selectedi   s!   '%s' is not a single-item controli    N(   R<   R   Rg   R   R]   Ri  Rh  (   R   R{  R  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   toggle_single  s    	c         C   sP   t  d  t |  j  d k r5 t d |  j   n  |  j |  j d |  d S(   s  Deprecated: set the selection of the single item in this control.
        
        Raises ItemCountError if the control does not contain only one item.
        
        by_label argument is ignored, and included only for backwards
        compatibility.

        s%   control.items[0].selected = <boolean>i   s!   '%s' is not a single-item controli    N(   R<   R   Rg   R   R]   Ri  (   R   Rh  R{  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt
   set_single/  s    	c         C   s    t  d  |  j | | |  j S(   s7   Get disabled state of named list item in a ListControl.s   control.get(...).disabled(   R<   R|  R   (   R   R]   R{  Rl  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   get_item_disabled?  s    c         C   s&   t  d  | |  j | | |  _ d S(   sk   Set disabled state of named list item in a ListControl.

        disabled: boolean disabled state

        s%   control.get(...).disabled = <boolean>N(   R<   R|  R   (   R   R   R]   R{  Rl  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   set_item_disabledE  s    c         C   s!   x |  j  D] } | | _ q
 Wd S(   sj   Set disabled state of all list items in a ListControl.

        disabled: boolean disabled state

        N(   Rg   R   (   R   R   Ry  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   set_all_items_disabledO  s    c         C   s    t  d  |  j | | |  j S(   s<  Return dictionary of HTML attributes for a single ListControl item.

        The HTML element types that describe list items are: OPTION for SELECT
        controls, INPUT for the rest.  These elements have HTML attributes that
        you may occasionally want to know about -- for example, the "alt" HTML
        attribute gives a text string describing the item (graphical browsers
        usually display this as a tooltip).

        The returned dictionary maps HTML attribute names to values.  The names
        and values are taken from the original HTML.

        s   control.get(...).attrs(   R<   R|  R   (   R   R]   R{  Rl  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   get_item_attrsX  s    c         C   s   t  |  _ d  S(   N(   Ro   Ro  (   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   close_controli  s    c         C   s   |  j  d  k s' | |  j  k s' t d  | |  _  |  j d  k rR t j |  |  n x t t | j  d d d  D]d } | j | } | j |  j k rr | j	 |  j	 k rr | j
 r t j |  |  n | j |   Pqr qr Wt j |  |  d  S(   Ns'   can't add control to more than one formi   i(   R.  RM   t   AssertionErrorR]   R   R/  R   R   R   RN   Ro  t   merge_control(   R   R#  R$  Rg  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR/  l  s    !	&$	c         C   s;   t  | j  t  |  j  k s$ t  |  j j | j  d  S(   N(   R   Ru  R  Rg   R<  (   R   Rg  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR    s    $c         C   s%   x |  j  D] } |  | j d <q
 Wd S(   s  
        ListControls are built up from component list items (which are also
        ListControls) during parsing.  This method should be called after all
        items have been added.  See ListControl.__doc__ for the reason this is
        required.

        Re  N(   Rg   R*  (   R   Ry  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR    s     c         C   s   | d k ra |  j  j } |  j d  k r+ g  Sg  |  j D]( } | j r5 | j sT | r5 | j ^ q5 St d |  j j	 | f   d  S(   NR   s!   %s instance has no attribute '%s'(
   R.  R  R]   RM   Rg   Rh  R   Re   R   R=   (   R   R]   Rx  Ry  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR)    s    c         C   s   | d k rZ |  j  r+ t d |  j   n  |  j rJ t d |  j   n  |  j |  n, | d k ry t d |   n | |  j | <d  S(	   NR   s   control '%s' is disableds   control '%s' is readonlyR]   RN   Ru  s   %s attribute is readonly(   s   names   types   multiple(   R   Re   R]   R@  t
   _set_valueR*  (   R   R]   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR+    s    		c         C   s   | d  k s t |  r' t d   n  | sl |  j j } xw |  j D]" } | j sY | rC t | _ qC qC WnG |  j	 r |  j
 |  n. t |  d k r t d   n |  j |  d  S(   Ns    ListControl, must set a sequencei   s9   single selection list, must set sequence of length 0 or 1(   RM   Rq   Rl   R.  R  Rg   R   R,   Rh  Ru  t   _multiple_set_valueR   R   t   _single_set_value(   R   R   Rx  Ry  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR    s    	i   c         C   s   |  j  |  } g  | D] } | j s | ^ q } t |  | k  r{ t |  | k  rh t d |   q{ t d |   n  g  } g  } x4 | D], } | j r | j |  q | j |  q W| | f S(   Ns   insufficient items with name %rs,   insufficient non-disabled items with name %s(   Rz  R   R   R   Re   Rh  R   (   R   R]   t   targett	   all_itemsRy  Rg   t   ont   off(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt
   _get_items  s    "	c         C   sc   t  |  d k s t  |  j | d  \ } } t  |  d k sI t  | s_ t | d _ n  d  S(   Ni   i    (   R   R  R  Ro   Rh  (   R   R   R  R  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR    s
    c         C   sY  |  j  j } g  } g  |  j D]% } | j r | j s; | r | ^ q } i  } x= | D]5 } | | j   k r | | c d 7<qT d | | <qT Wx | j   D] \ } }	 |  j | |	  \ }
 } x\ t |	  D]N } |
 r |
 d } |
 d =| | j |  =q | d } | d =| j	 |  q Wq Wx | D] } t
 | _ q(Wx | D] } t | _ qBWd  S(   Ni   i    (   R.  R  Rg   Rh  R   t   keysR  R   R  R   R,   Ro   (   R   R   Rx  t   turn_onR  t   turn_offt   namest   nnR]   t   countR  R  Rx   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR    s.    %

c         C   sR  t  |  r t |   n  |  j rF t |  d k rF t d   n  g  } x | D] } |  j d |  } t |  d k r |  j j s | d j } g  | d D] } | j | k r | ^ q r t	 |   q q | d  } n  xC | D]/ } |  j j s| | k r | j
 |  Pq q Wt |   qS Wg  |  _ x | D] } t | _ q;Wd S(   s  Set the value of control by item labels.

        value is expected to be an iterable of strings that are substrings of
        the item labels that should be selected.  Before substring matching is
        performed, the original label text is whitespace-compressed
        (consecutive whitespace characters are converted to a single space
        character) and leading and trailing whitespace is stripped.  Ambiguous
        labels are accepted without complaint if the form's backwards_compat is
        True; otherwise, it will not complain as long as all ambiguous labels
        share the same item name (e.g. OPTION value).

        i   s9   single selection list, must set sequence of length 0 or 1R   i    N(   Rq   Rl   Ru  R   R   Rz  R.  R  R]   R    R   R   R   Ro   Rh  (   R   R   Rg   R  t   foundt   opt_nameRy  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   set_value_by_label  s,    ,	c         C   s   g  } |  j  j } xn |  j D]c } | j s2 | r | j r xA | j   D]# } | j rH | j | j  PqH qH W| j d  q q W| S(   s>   Return the value of the control as given by normalized labels.N(	   R.  R  Rg   R   Rh  R?  RC   R   RM   (   R   R>  Rx  Ry  R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   get_value_by_label3  s    	c         C   s   t  d  | ro g  } xR |  j D]G } x> | j   D]# } | j r3 | j | j  Pq3 q3 W| j d  q  W| Sg  |  j D] } | j ^ qy S(   s   Deprecated: return the names or labels of all possible items.

        Includes disabled items, which may be misleading for some use cases.

        s"   [item.name for item in self.items]N(   R<   Rg   R?  RC   R   RM   R]   (   R   R{  R>  Ry  R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   possible_itemsA  s    	c         C   s_   |  j  s |  j d  k r g  Sg  |  j D]1 } | j r& | j  r& | j |  j | j f ^ q& Sd  S(   N(   R   R]   RM   Rg   Rh  RA  (   R   Ry  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR3  U  s    c         C   s   |  j  } | d  k r d } n  g  |  j D] } t |  ^ q( } g  } |  j r_ | j d  n  |  j rx | j d  n  d j |  } | r d | } n  d |  j j	 | d j |  | f S(   Ns   <None>R   R@  s   , s    (%s)s   <%s(%s=[%s])%s>(
   R]   RM   Rg   Rt   R   R   R@  Rs   R   R=   (   R   R]   Ry  t   displayRG  RH  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   \  s    	 	"	 	  N($   R=   R>   R   RM   R;  R,   R   R2  R1  Rz  RL   R|  R}  R~  Ri  R  R  R  R  R  R  R  R/  R  R  R)  R+  R  R  R  R  R  R  R  R3  R   (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   (  sF   3		
	 	
						$						.		c           B   s/   e  Z d  Z e d d  Z d   Z d   Z RS(   s#   
    Covers:

    INPUT/RADIO

    c      
   C   sn   | j  d d  t j |  | | | | d t d | t |  j d <t |  | |  } | j d  | j d <d  S(   NR   R  Rq  R  Ru  t   checkedRf  (   t
   setdefaultR   R   Ro   R,   R*  R   R   (   R   RN   R]   R   R  R  Ry  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   s  s    c         C   s   t  j |   g  |  j D] } | j r | j r | ^ q } | s{ |  j r x* |  j D] } | j sU t | _ PqU qU Wq n x | d  D] } t | _ q Wd  S(   Ni(   R   R  Rg   Rh  R   Rp  Ro   R,   (   R   Ry  R  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR  {  s    /			c         C   s   g  S(   N(    (   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR?    s    N(   R=   R>   R   R,   RM   R   R  R?  (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   l  s   	c           B   s&   e  Z d  Z e d d  Z d   Z RS(   s&   
    Covers:

    INPUT/CHECKBOX

    c      
   C   sn   | j  d d  t j |  | | | | d t d | t |  j d <t |  | |  } | j d  | j d <d  S(   NR   R  Rq  R  Ru  R  Rf  (   R  R   R   Ro   R*  R   R   (   R   RN   R]   R   R  R  Ry  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s    c         C   s   g  S(   N(    (   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR?    s    N(   R=   R>   R   R,   RM   R   R?  (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s   c           B   s&   e  Z d  Z e d d  Z d   Z RS(   s@  
    Covers:

    SELECT (and OPTION)


    OPTION 'values', in HTML parlance, are Item 'names' in mechanize parlance.

    SELECT control values and labels are subject to some messy defaulting
    rules.  For example, if the HTML representation of the control is:

    <SELECT name=year>
      <OPTION value=0 label="2002">current year</OPTION>
      <OPTION value=1>2001</OPTION>
      <OPTION>2000</OPTION>
    </SELECT>

    The items, in order, have labels "2002", "2001" and "2000", whereas their
    names (the OPTION values) are "0", "1" and "2000" respectively.  Note that
    the value of the last OPTION in this example defaults to its contents, as
    specified by RFC 1866, as do the labels of the second and third OPTIONs.

    The OPTION labels are sometimes more meaningful than the OPTION values,
    which can make for more maintainable code.

    Additional read-only public attribute: attrs

    The attrs attribute is a dictionary of the original HTML attributes of the
    SELECT element.  Other ListControls do not have this attribute, because in
    other cases the control as a whole does not correspond to any single HTML
    element.  control.get(...).attrs may be used as usual to get at the HTML
    attributes of the HTML elements corresponding to individual list items (for
    SELECT controls, these are OPTION elements).

    Another special case is that the Item.attrs dictionaries have a special key
    "contents" which does not correspond to any real HTML attribute, but rather
    contains the contents of the OPTION element:

    <OPTION>this bit</OPTION>

    c   	   
   C   s  | d j    |  _ t |  j  |  j d <|  j j d  |  j d <|  j j d  |  j d <| j d  } | j    } | d =t j |  | | |  j | d t d | |  j j d  |  _	 |  j j d	  |  _
 | j d
  rt |  | |  } | j d  | j d <| j d  } | rm| j j t i | d 6  | r| | k r| j j t i | d 6  qq| r| j j t i | d 6  qn  d  S(   NR   R;  R%  Ru  R   Rq  R  R   R@  R   Rh  Rf  R   R   (   RC  R   R,  R*  RL   R   R   R   Ro   R   R@  R   Rd  R   R   (	   R   RN   R]   R   R  R  R   Ry  R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s*    #c         C   s   t  j |   g  |  j D] } | j r | ^ q } | s |  j sK |  j r xM |  j D]? } | j sU |  j } t |  _ z t | _ Wd  | | _ XPqU qU Wq n* |  j s x | d  D] } t | _ q Wn  d  S(   Ni(	   R   R  Rg   Rh  Ru  Rp  R   R,   Ro   (   R   Ry  R  t   was_disabled(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR    s    %			
	N(   R=   R>   R   R,   RM   R   R  (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR     s   )"c           B   sD   e  Z d  Z d d  Z d   Z d   Z e j d  Z	 d   Z
 RS(   s6   
    Covers:

    INPUT/SUBMIT
    BUTTON/SUBMIT

    c         C   sA   t  j |  | | | |  |  j d  k r4 d |  _ n  t |  _ d  S(   NRI   (   R   R   R   RM   Ro   R@  (   R   RN   R]   R   R  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   	  s     c         C   sI   g  } |  j  r/ | j t i |  j  d 6  n  | j t j |    | S(   NR   (   R   R   R   R<  R   R?  (   R   R>  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR?  #	  s
    	 c         C   s
   | d k S(   NRU  (    (   R   R0  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR1  *	  s    c         C   s(   | |  _  | j | |  } t |  _  | S(   N(   RD  t   _switch_clickR,   (   R   R#  RY  RZ  R  t   r(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyRa  ,	  s    		c         C   s   |  j  s g  St j |   S(   N(   RD  R   R3  (   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR3  2	  s    	N(   R=   R>   R   RM   R   R?  R1  Rb  Rc  Ra  R3  (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   	  s   		c           B   s,   e  Z d  Z d d  Z d   Z e j Z RS(   sl   
    Covers:

    INPUT/IMAGE

    Coordinates are specified using one of the HTMLForm.click* methods.

    c         C   s&   t  j |  | | | |  t |  _ d  S(   N(   R   R   R,   R@  (   R   RN   R]   R   R  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   B	  s    c         C   s   |  j  } |  j s | r g  S|  j } | d  k r6 g  S|  j d | t | d  f |  j d d | t | d  f g } |  j } | r | j |  j d | | f  n  | S(   Ns   %s.xi    i   s   %s.yi   (   RD  R   R]   RM   RA  Rt   RB  R   (   R   t   clickedR]   R6  R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR3  F	  s    		 '	 N(   R=   R>   R   RM   R   R3  R   R?  (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR	   9	  s   	c           B   s   e  Z RS(    (   R=   R>   (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   X	  s    c           B   s   e  Z RS(    (   R=   R>   (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   Y	  s    c           B   s   e  Z RS(    (   R=   R>   (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   Z	  s    c           B   s   e  Z RS(    (   R=   R>   (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   [	  s    c         C   s   |  j  d  S(   NRr  (   R1  (   Rg  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   is_listcontrol^	  s    c        
   B   s$  e  Z d  Z i e d 6e d 6e d 6e d 6e d 6e d 6e	 d 6e	 d 6e	 d	 6e	 d
 6e
 d 6e d 6e d 6e d 6e d 6e d 6Z d d d6 d6 e j d6 d6 d6 e d 	 Z d   Z d   Z e e d6 d  Z d   Z d   Z d   Z d   Z d   Z d6 d6 d6 d6 d6 e d6 d  Z d6 d6 d6 d6 d6 e d6 d  Z  d6 d6 d6 d6 d6 d6 d  Z! d6 d6 d6 d6 d6 d6 d  Z" d    Z# d!   Z$ d6 d6 d6 d6 d6 d6 d"  Z% d6 d6 d6 d6 d6 e d6 d#  Z& d6 d6 d6 d6 d6 e d6 d$  Z' d6 d6 d6 d6 d6 e d6 d%  Z( d6 d6 d6 d6 d6 d6 d6 d&  Z) d6 d6 d6 d6 d6 d6 d6 d'  Z* d6 d6 d6 d6 d6 d6 d(  Z+ d6 d6 d6 d) d7 e j d6 d+  Z, d6 d6 d6 d) d8 e j d6 d,  Z- d6 d6 d6 d) d9 d6 d-  Z. d6 d6 d6 d6 d6 d6 d6 d.  Z/ d6 d6 d6 d6 d6 d6 d/  Z0 d0   Z1 e j d1  Z2 d2   Z3 d3   Z4 d4   Z5 e j d5  Z6 RS(:   s"  Represents a single HTML <form> ... </form> element.

    A form consists of a sequence of controls that usually have names, and
    which can take on various values.  The values of the various types of
    controls represent variously: text, zero-or-one-of-many or many-of-many
    choices, and files to be uploaded.  Some controls can be clicked on to
    submit the form, and clickable controls' values sometimes include the
    coordinates of the click.

    Forms can be filled in with data to be returned to the server, and then
    submitted, using the click method to generate a request object suitable for
    passing to mechanize.urlopen (or the click_request_data or click_pairs
    methods for integration with third-party code).

    import mechanize
    forms = mechanize.ParseFile(html, base_uri)
    form = forms[0]

    form["query"] = "Python"
    form.find_control("nr_results").get("lots").selected = True

    response = mechanize.urlopen(form.click())

    Usually, HTMLForm instances are not created directly.  Instead, the
    ParseFile or ParseResponse factory functions are used.  If you do construct
    HTMLForm objects yourself, however, note that an HTMLForm instance is only
    properly initialised after the fixup method has been called (ParseFile and
    ParseResponse do this for you).  See ListControl.__doc__ for the reason
    this is required.

    Indexing a form (form["control_name"]) returns the named Control's value
    attribute.  Assignment to a form index (form["control_name"] = something)
    is equivalent to assignment to the named Control's value attribute.  If you
    need to be more specific than just supplying the control's name, use the
    set_value and get_value methods.

    ListControl values are lists of item names (specifically, the names of the
    items that are selected and not disabled, and hence are "successful" -- ie.
    cause data to be returned to the server).  The list item's name is the
    value of the corresponding HTML element's"value" attribute.

    Example:

      <INPUT type="CHECKBOX" name="cheeses" value="leicester"></INPUT>
      <INPUT type="CHECKBOX" name="cheeses" value="cheddar"></INPUT>

    defines a CHECKBOX control with name "cheeses" which has two items, named
    "leicester" and "cheddar".

    Another example:

      <SELECT name="more_cheeses">
        <OPTION>1</OPTION>
        <OPTION value="2" label="CHEDDAR">cheddar</OPTION>
      </SELECT>

    defines a SELECT control with name "more_cheeses" which has two items,
    named "1" and "2" (because the OPTION element's value HTML attribute
    defaults to the element contents -- see SelectControl.__doc__ for more on
    these defaulting rules).

    To select, deselect or otherwise manipulate individual list items, use the
    HTMLForm.find_control() and ListControl.get() methods.  To set the whole
    value, do as for any other control: use indexing or the set_/get_value
    methods.

    Example:

    # select *only* the item named "cheddar"
    form["cheeses"] = ["cheddar"]
    # select "cheddar", leave other items unaffected
    form.find_control("cheeses").get("cheddar").selected = True

    Some controls (RADIO and SELECT without the multiple attribute) can only
    have zero or one items selected at a time.  Some controls (CHECKBOX and
    SELECT with the multiple attribute) can have multiple items selected at a
    time.  To set the whole value of a ListControl, assign a sequence to a form
    index:

    form["cheeses"] = ["cheddar", "leicester"]

    If the ListControl is not multiple-selection, the assigned list must be of
    length one.

    To check if a control has an item, if an item is selected, or if an item is
    successful (selected and not disabled), respectively:

    "cheddar" in [item.name for item in form.find_control("cheeses").items]
    "cheddar" in [item.name for item in form.find_control("cheeses").items and
                  item.selected]
    "cheddar" in form["cheeses"]  # (or "cheddar" in form.get_value("cheeses"))

    Note that some list items may be disabled (see below).

    Note the following mistake:

    form[control_name] = control_value
    assert form[control_name] == control_value  # not necessarily true

    The reason for this is that form[control_name] always gives the list items
    in the order they were listed in the HTML.

    List items (hence list values, too) can be referred to in terms of list
    item labels rather than list item names using the appropriate label
    arguments.  Note that each item may have several labels.

    The question of default values of OPTION contents, labels and values is
    somewhat complicated: see SelectControl.__doc__ and
    ListControl.get_item_attrs.__doc__ if you think you need to know.

    Controls can be disabled or readonly.  In either case, the control's value
    cannot be changed until you clear those flags (see example below).
    Disabled is the state typically represented by browsers by 'greying out' a
    control.  Disabled controls are not 'successful' -- they don't cause data
    to get returned to the server.  Readonly controls usually appear in
    browsers as read-only text boxes.  Readonly controls are successful.  List
    items can also be disabled.  Attempts to select or deselect disabled items
    fail with AttributeError.

    If a lot of controls are readonly, it can be useful to do this:

    form.set_all_readonly(False)

    To clear a control's value attribute, so that it is not successful (until a
    value is subsequently set):

    form.clear("cheeses")

    More examples:

    control = form.find_control("cheeses")
    control.disabled = False
    control.readonly = False
    control.get("gruyere").disabled = True
    control.items[0].selected = True

    See the various Control classes for further documentation.  Many methods
    take name, type, kind, id, label and nr arguments to specify the control to
    be operated on: see HTMLForm.find_control.__doc__.

    ControlNotFoundError (subclass of ValueError) is raised if the specified
    control can't be found.  This includes occasions where a non-ListControl
    is found, but the method (set, for example) requires a ListControl.
    ItemNotFoundError (subclass of ValueError) is raised if a list item can't
    be found.  ItemCountError (subclass of ValueError) is raised if an attempt
    is made to select more than one item and the control doesn't allow that, or
    set/get_single are called and the control contains more than one item.
    AttributeError is raised if a control or item is readonly or disabled and
    an attempt is made to alter its value.

    Security note: Remember that any passwords you store in HTMLForm instances
    will be saved to disk in the clear if you pickle them (directly or
    indirectly).  The simplest solution to this is to avoid pickling HTMLForm
    objects.  You could also pickle before filling in any password, or just set
    the password to "" before pickling.


    Public attributes:

    action: full (absolute URI) form action
    method: "GET" or "POST"
    enctype: form transfer encoding MIME type
    name: name of form (None if no name was specified)
    attrs: dictionary mapping original HTML form attributes to their values

    controls: list of Control instances; do not alter this list
     (instead, call form.new_control to make a Control and add it to the
     form, or control.add_to_form if you already have a Control instance)



    Methods for form filling:
    -------------------------

    Most of the these methods have very similar arguments.  See
    HTMLForm.find_control.__doc__ for details of the name, type, kind, label
    and nr arguments.

    def find_control(self,
                     name=None, type=None, kind=None, id=None, predicate=None,
                     nr=None, label=None)

    get_value(name=None, type=None, kind=None, id=None, nr=None,
              by_label=False,  # by_label is deprecated
              label=None)
    set_value(value,
              name=None, type=None, kind=None, id=None, nr=None,
              by_label=False,  # by_label is deprecated
              label=None)

    clear_all()
    clear(name=None, type=None, kind=None, id=None, nr=None, label=None)

    set_all_readonly(readonly)


    Method applying only to FileControls:

    add_file(file_object,
             content_type="application/octet-stream", filename=None,
             name=None, id=None, nr=None, label=None)


    Methods applying only to clickable controls:

    click(name=None, type=None, id=None, nr=0, coord=(1,1), label=None)
    click_request_data(name=None, type=None, id=None, nr=0, coord=(1,1),
                       label=None)
    click_pairs(name=None, type=None, id=None, nr=0, coord=(1,1), label=None)

    RC   t   passwordRI  R   R   R  R   t   buttonbuttont   resett   resetbuttonR   t   submitbuttont   imaget   radiot   checkboxR   R   s!   application/x-www-form-urlencodedc         C   s   | |  _  | |  _ | |  _ | |  _ | d k	 rB | j   |  _ n	 i  |  _ g  |  _ | |  _ | |  _	 | |  _
 |	 |  _ |
 |  _ t j |  _ t j |  _ d S(   s\  
        In the usual case, use ParseResponse (or ParseFile) to create new
        HTMLForm objects.

        action: full (absolute URI) form action
        method: "GET" or "POST"
        enctype: form transfer encoding MIME type
        name: name of form
        attrs: dictionary mapping original HTML form attributes to their values

        N(   R   R   R   R]   RM   RC  R   R   t   _request_classt   _formsRd  R=  R  RE  RF  R  R  (   R   R   R   R   R]   R   R  R   R   R  R  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   Q
  s    											c         C   s    | d k r |  j  St t |  S(   NR  (   R(  R   R   (   R   R]   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR)  w
  s    c         C   s   | d k r d } t  |  } xi |  j D][ } y | j } Wn t k
 rQ q( q( Xx. | D]& } x | j   D] } | | _ ql WqY Wq( Wn  | |  j | <d  S(   NR  R(  (   R   R   Rg   Re   R?  R(  R*  (   R   R]   R   t   ccRg   R$  t   ll(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR+  |
  s    c         C   s+  | j    } |  j j |  } | d k rB | r9 t } qB t } n  | j   } t | t  rx | | | | | |  }	 n | | | | |  }	 | d k rt	 |  d k rxT t
 t	 |  j  d d d  D]0 }
 |  j |
 } | j d k r | j   Pq q Wn  |	 j |   |  j |	 _ |  j |	 _ d S(   s  Adds a new control to the form.

        This is usually called by ParseFile and ParseResponse.  Don't call it
        youself unless you're building your own Control instances.

        Note that controls representing lists of items are built up from
        controls holding only a single list item.  See ListControl.__doc__ for
        further information.

        type: type of control (see Control.__doc__ for a list)
        attrs: HTML attributes of control
        ignore_unknown: if true, use a dummy Control instance for controls of
         unknown type; otherwise, use a TextControl
        select_default: for RADIO and multiple-selection SELECT controls, pick
         the first item as the default if no 'selected' HTML attribute is
         present (this defaulting happens when the HTMLForm.fixup method is
         called)
        index: index of corresponding element in HTML (see
         MoreFormTests.test_interspersed_controls for motivation)

        R   i   iN(   R   t
   type2classRL   RM   R   R   RC  t
   issubclassR   R   R   R   RN   R  R/  R  R  (   R   RN   R]   R   t   ignore_unknownR  R  t   klasst   aRg  R$  t   ctl(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR  
  s&    		&
c         C   s.   x |  j  D] } | j   q
 W|  j |  _ d S(   s7  Normalise form after all controls have been added.

        This is usually called by ParseFile and ParseResponse.  Don't call it
        youself unless you're building your own Control instances.

        This method should only be called once, after all controls have been
        added to the form.

        N(   R   R  R(  R  (   R   Rg  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR  
  s    
c         C   sz   d |  j  r |  j  d p d |  j |  j |  j f } | g } x( |  j D] } | j d t |   qH Wd d j |  S(   Ns
   %s%s %s %sR?   RI   s     %ss   <%s>s   
(   R]   R   R   R   R   R   Rt   Rs   (   R   t   headert   repRg  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   
  s    	c         C   s   |  j  |  j S(   N(   t   find_controlR   (   R   R]   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   __getitem__
  s    c         C   s   t  |  j |   S(   N(   R   R  (   R   R]   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   __contains__
  s    c         C   sH   |  j  |  } y | | _ Wn% t k
 rC } t t |    n Xd  S(   N(   R  R   Re   t
   ValueErrorRt   (   R   R]   R   Rg  R  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   __setitem__
  s
    c   
   	   C   s   | r t  d  n  |  j | | | | d | d | } | r{ y | j }	 Wn$ t k
 rp t d | j   q X|	   Sn | j Sd S(   s|   Return value of control.

        If only name and value arguments are supplied, equivalent to

        form[name]

        s   form.get_value_by_label(...)R   Rl  s*   control '%s' does not yet support by_labelN(   R<   R  R  Re   R-  R]   R   (
   R   R]   RN   R0  R%  Rl  R{  R   t   ct   meth(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt	   get_value
  s    $
c	      	   C   s   | r t  d  n  |  j | | | | d | d | }	 | r~ y |	 j }
 Wn$ t k
 rp t d |	 j   q X|
 |  n	 | |	 _ d S(   s   Set value of control.

        If only name and value arguments are supplied, equivalent to

        form[name] = value

        s   form.get_value_by_label(...)R   Rl  s*   control '%s' does not yet support by_labelN(   R<   R  R  Re   R-  R]   R   (   R   R   R]   RN   R0  R%  Rl  R{  R   R  R  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt	   set_value
  s    $c      	   C   s.   |  j  | | | | d | d | } | j   S(   s;   

        All arguments should be passed by name.

        R   Rl  (   R  R  (   R   R]   RN   R0  R%  R   Rl  R  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR    s    $c   	   	   C   s5   |  j  | | | | d | d | } | j |  d S(   s;   

        All arguments should be passed by name.

        R   Rl  N(   R  R  (	   R   R   R]   RN   R0  R%  R   Rl  R  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR    s    $c         C   s'   x  |  j  D] } t |  | _ q
 Wd  S(   N(   R   R   R@  (   R   R@  Rg  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   set_all_readonly'  s    c         C   s"   x |  j  D] } | j   q
 Wd S(   sf   Clear the value attributes of all controls in the form.

        See HTMLForm.clear.__doc__.

        N(   R   R2  (   R   Rg  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt	   clear_all+  s    c      	   C   s2   |  j  | | | | d | d | } | j   d S(   s   Clear the value attribute of a control.

        As a result, the affected control will not be successful until a value
        is subsequently set.  AttributeError is raised on readonly controls.

        R   Rl  N(   R  R2  (   R   R]   RN   R0  R%  Rl  R   R  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR2  4  s    $c   	      C   s+   |  j  | | | | | |  } | j |  S(   s@   Return a list of all values that the specified control can take.(   t   _find_list_controlR  (	   R   R]   RN   R0  R%  Rl  R{  R   R  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR  C  s    c
   
      C   s/   |  j  | | | | |	 |  j | | |  d S(   sV   Select / deselect named list item.

        selected: boolean selected state

        N(   R  R~  (
   R   Rh  t	   item_nameR]   RN   R0  R%  Rl  R{  R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR~  J  s    c	   	      C   s,   |  j  | | | | | |  j | |  d S(   s)   Toggle selected state of named list item.N(   R  R}  (	   R   R  R]   RN   R0  R%  Rl  R{  R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR}  T  s    c	   	      C   s)   |  j  | | | | | |  j |  d S(   s  Select / deselect list item in a control having only one item.

        If the control has multiple list items, ItemCountError is raised.

        This is just a convenience method, so you don't need to know the item's
        name -- the item name in these single-item controls is usually
        something meaningless like "1" or "on".

        For example, if a checkbox has a single item named "on", the following
        two calls are equivalent:

        control.toggle("on")
        control.toggle_single()

        N(   R  R  (	   R   Rh  R]   RN   R0  R%  Rl  R{  R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR  [  s    c         C   s&   |  j  | | | | | |  j   d S(   s   Toggle selected state of list item in control having only one item.

        The rest is as for HTMLForm.set_single.__doc__.

        N(   R  R  (   R   R]   RN   R0  R%  Rl  R{  R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR  o  s    c      	   C   s5   |  j  | d d | d | d | j | | |  d S(   s'  Add a file to be uploaded.

        file_object: file-like object (with read method) from which to read
         data to upload
        content_type: MIME content type of data to upload
        filename: filename to pass to server

        If filename is None, no filename is sent to the server.

        If content_type is None, the content type is guessed based on the
        filename and the data from read from the file object.

        XXX
        At the moment, guessed content type is always application/octet-stream.
        Use sndhdr, imghdr modules.  Should also try to guess HTML, XML, and
        plain text.

        Note the following useful HTML attributes of file upload controls (see
        HTML 4.01 spec, section 17):

        accept: comma-separated list of content types that the server will
         handle correctly; you can use this to filter out non-conforming files
        size: XXX IIRC, this is indicative of whether form wants multiple or
         single files
        maxlength: XXX hint of max content length in bytes?

        R  R%  R   Rl  N(   R  RN  (   R   RL  R   RM  R]   R%  Rl  R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyRN  {  s    $i    i   c      	   C   s%   |  j  | | | | | | d |  j  S(   s  Return request that would result from clicking on a control.

        The request object is a mechanize.Request instance, which you can pass
        to mechanize.urlopen.

        Only some control types (INPUT/SUBMIT & BUTTON/SUBMIT buttons and
        IMAGEs) can be clicked.

        Will click on the first clickable control, subject to the name, type
        and nr arguments (as for find_control).  If no name, type, id or number
        is specified and there are no clickable controls, a request will be
        returned for the form in its current, un-clicked, state.

        IndexError is raised if any of name, type, id or nr is specified but no
        matching control is found.  ValueError is raised if the HTMLForm has an
        enctype attribute that is not recognised.

        You can optionally specify a coordinate to click at, which only makes a
        difference if you clicked on an image.

        t   request(   Ra  R  (   R   R]   RN   R%  Rl  RY  R  R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   click  s    c      	   C   s%   |  j  | | | | | | d |  j  S(   s  As for click method, but return a tuple (url, data, headers).

        You can use this data to send a request to the server.  This is useful
        if you're using httplib or urllib rather than mechanize.  Otherwise,
        use the click method.

        # Untested.  Have to subclass to add headers, I think -- so use
        # mechanize instead!
        import urllib
        url, data, hdrs = form.click_request_data()
        r = urllib.urlopen(url, data)

        # Untested.  I don't know of any reason to use httplib -- you can get
        # just as much control with mechanize.
        import httplib, urlparse
        url, data, hdrs = form.click_request_data()
        tup = urlparse(url)
        host, path = tup[1], urlparse.urlunparse((None, None)+tup[2:])
        conn = httplib.HTTPConnection(host)
        if data:
            httplib.request("POST", path, data, hdrs)
        else:
            httplib.request("GET", path, headers=hdrs)
        r = conn.getresponse()

        RV  (   Ra  R  (   R   R]   RN   R%  Rl  RY  R  R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   click_request_data  s    c      	   C   s%   |  j  | | | | | | d |  j  S(   s  As for click_request_data, but returns a list of (key, value) pairs.

        You can use this list as an argument to urllib.urlencode.  This is
        usually only useful if you're using httplib or urllib rather than
        mechanize.  It may also be useful if you want to manually tweak the
        keys and/or values, but this should not be necessary.  Otherwise, use
        the click method.

        Note that this method is only useful for forms of MIME type
        x-www-form-urlencoded.  In particular, it does not return the
        information required for file upload.  If you need file upload and are
        not using mechanize, use click_request_data.
        R6  (   Ra  R  (   R   R]   RN   R%  Rl  RY  R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   click_pairs  s    c         C   s   | d k rc | d k rc | d k rc | d k rc | d k rc | d k rc | d k rc t d   n  |  j | | | | | | |  S(   s  Locate and return some specific control within the form.

        At least one of the name, type, kind, predicate and nr arguments must
        be supplied.  If no matching control is found, ControlNotFoundError is
        raised.

        If name is specified, then the control must have the indicated name.

        If type is specified then the control must have the specified type (in
        addition to the types possible for <input> HTML tags: "text",
        "password", "hidden", "submit", "image", "button", "radio", "checkbox",
        "file" we also have "reset", "buttonbutton", "submitbutton",
        "resetbutton", "textarea", "select" and "isindex").

        If kind is specified, then the control must fall into the specified
        group, each of which satisfies a particular interface.  The types are
        "text", "list", "multilist", "singlelist", "clickable" and "file".

        If id is specified, then the control must have the indicated id.

        If predicate is specified, then the control must match that function.
        The predicate function is passed the control as its single argument,
        and should return a boolean value indicating whether the control
        matched.

        nr, if supplied, is the sequence number of the control (where 0 is the
        first).  Note that control 0 is the first control matching all the
        other arguments (if supplied); it is not necessarily the first control
        in the form.  If no nr is supplied, AmbiguityError is raised if
        multiple controls match the other arguments (unless the
        .backwards-compat attribute is true).

        If label is specified, then the control must have this label.  Note
        that radio controls and checkboxes never have labels: their items do.

        s9   at least one argument must be supplied to specify controlN(   RM   R  t   _find_control(   R   R]   RN   R0  R%  t	   predicateRl  R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR    s    ($$c         C   sv   | d  k rW | d  k rW | d  k rW | d  k rW | d  k rW | d  k rW t d   n  |  j | | | | | t |  S(   Ns9   at least one argument must be supplied to specify control(   RM   R  R  R  (   R   R]   RN   R0  R%  R   Rl  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR  "  s    $$c         C   s  | d  k	 r4 | t k	 r4 t |  r4 t d   n  | d  k	 r\ t |  r\ t d   n  | d  k	 r t |  r t d   n  | d  k	 r t |  r t d   n  | d  k	 r t |  r t d   n  | d  k	 r t |  r t d   n  | d  k	 r#| d k  r#t d   n  | } d  }	 t }
 | d  k rS|  j rSd } n  xK|  j D]@} | d  k	 r| | j	 k r| t k	 s]| j	 d  k	 rq]n  | d  k	 r| | j
 k rq]n  | d  k	 r| j |  rq]n  | d  k	 r| | j k rq]n  | r| |  rq]n  | r[x6 | j   D]" } | j j |  d	 k r/Pq/q/Wq]n  | d  k	 r| d k rw| S| d
 8} q]n  |	 rt }
 Pn  | }	 q]W|	 r|
 r|	 Sg  } | d  k	 r| j d t |   n  | d  k	 r| j d |  n  | d  k	 r| j d |  n  | d  k	 r>| j d |  n  | d  k	 r^| j d |  n  | d  k	 r~| j d |  n  | r| j d |  n  d j |  } |
 rt d |   n |	 st d |   n  t st  d  S(   Ns    control name must be string-likes    control type must be string-likes    control kind must be string-likes   control id must be string-likes!   control label must be string-likes"   control predicate must be callablei    s)   control number must be a positive integerii   s   name %ss	   type '%s's	   kind '%s's   id '%s's
   label '%s's   predicate %ss   nr %ds   , s   more than one control matching s   no control matching (   RM   R   Rq   Rl   t   callableR  R,   R  R   R]   RN   R1  R%  R?  RC   Rv  Ro   R   t   reprRs   R    R   R  (   R   R]   RN   R0  R%  R   R  Rl  t   orig_nrR  t	   ambiguousRg  R   t   description(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR  -  s    	

      c	   
      C   s   y% |  j  | | d | | d  |  }	 Wn` t k
 r | d  k	 sq | d  k	 sq | d  k	 sq | d  k	 sq | d k rw   n  |  j | |  SX|	 j |  | | |  Sd  S(   NRU  i    (   R  RM   R   R  Ra  (
   R   R]   RN   R%  R   Rl  RY  RZ  R  Rg  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyRa  t  s    $c         C   s/   g  |  j    D] \ } } } } | | f ^ q S(   s?   Return sequence of (key, value) pairs suitable for urlencoding.(   t   _pairs_and_controls(   R   Rx   R4  R5  t   c_i(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   _pairs  s    c         C   sz   g  } xc t  t |  j   D]L } |  j | } x6 | j   D]( \ } } } | j | | | | f  q< Wq W| j   | S(   s   Return sequence of (index, key, value, control_index)
        of totally ordered pairs suitable for urlencoding.

        control_index is the index of the control in self.controls
        (   R   R   R   R3  R   t   sort(   R   R6  t   control_indexRg  R$  R   R   (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR    s    !
c         C   s  |  j  j   } |  j |  j  } | d  | d } \ } } | d k r |  j d k rm t d |  j   n  | t j |  j    d f } |  j
 |  } | d g  f S| d k r| | d f } |  j
 |  } |  j d k r
| t j |  j    d |  j f g f S|  j d k rt   } g  } t | |  }	 |	 j d d	 t d
 d x: |  j   D], \ }
 } } } |  j | j |	 | |  q]W|	 j   | | j   | f St d |  j   n t d |   d S(   s$   Return a tuple (url, data, headers).iR   s!   application/x-www-form-urlencodeds#   unknown GET form encoding type '%s't   POSTs   Content-Types   multipart/form-datas	   form-dataR   R   i    s$   unknown POST form encoding type '%s's   Unknown method '%s'N(   R   R   R  R   R   R  RW  t	   urlencodeR  RM   R  R    R{   R   Ro   R  R   R:  R   t   getvalue(   R   R   R[  R\  R]  R^  t   uriRW   R   R7  R$  R4  R5  R  (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   _request_data  s:    	
c         C   s   | d k r |  j    S| d k r, |  j   S|  j   } | | d | d  } xd | d D]X \ } } | j } | j   d k r y | j } Wq t k
 r q Xn  | | |  qZ W| Sd  S(   NR6  RV  i    i   i   s   content-type(   R  R  t
   add_headerR   t   add_unredirected_headerRe   (   R   RZ  R  R`  t   reqR   R   t   add_hdr(    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR    s    

	N(   i   i   (   i   i   (   i   i   (7   R=   R>   R   R   R   R   R   R
   R   R   R   R   R	   R   R   R   R  RM   Rb  Rc  Ro   R   R)  R+  R,   R  R  R   R  R  R  R  R  R  R  R  R  R2  R  R~  R}  R  R  RN  R  R  R  R  R  R  Ra  R  R  R  R  (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyR   a	  s   
	!		/								
	"		0		H			$([   R   t   __all__R   t	   cStringIOR    R"   R.   Ru   RE   R1   RW  RE  R7   R  Rb  t   sgmllibR   t   VERSIONR  R   t	   getLoggerR$   Ro   R!   R%   R5   R<   R   R   R@   RD   RF   RX   RK   Rk   Rp   Rq   Rz   R{   R  R   R    R   R   R   R  R   R   R   R   R   R  R   R  R  R  R	  R  R,   Rc  RM   t   urljoinRF  R   R   R  R   R   R  R   R,  R   R   R   R   R
   R   R   Rn  R   R   R   R   R   R	   R   R   R   R   R  R   (    (    (    s4   /scratch/rashmi/Condor_Script/src/mechanize/_form.pyt   <module>   s   																		 87		>	3	yNlF'D	  F!s&	