
BXQc           @   s  d  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 y d d l Z e Z	 [ Wn& e
 k
 r d d l Z e Z	 [ n Xd Z d Z d d l m Z m Z d d l m Z d d l Z e j d  j Z f  d  Z e j d	  Z d
   Z d   Z d   Z d   Z e j d  Z d   Z d   Z d   Z  d   Z! d   Z" d   Z# d   Z$ d   Z% d Z& e j d  Z' d   Z( d   Z) d   Z* d   Z+ y e, Wn e- k
 rd   Z, n Xd f  d     YZ. d  f  d!     YZ/ d" e/ f d#     YZ0 d$   Z1 d% f  d&     YZ2 d' f  d(     YZ3 d) f  d*     YZ4 d+ e5 f d,     YZ6 d- e4 f d.     YZ7 d S(/   sw  HTTP cookie handling for web clients.

This module originally developed from my port of Gisle Aas' Perl module
HTTP::Cookies, from the libwww-perl library.

Docstrings, comments and debug strings in this code refer to the
attributes of the HTTP cookie system as cookie-attributes, to distinguish
them clearly from Python attributes.

                        CookieJar____
                        /     \                  FileCookieJar      \                   /    |   \         \       MozillaCookieJar | LWPCookieJar \                        |               |                        |   ---MSIEBase |                         |  /      |     |                          | /   MSIEDBCookieJar BSDDBCookieJar
                  |/    
               MSIECookieJar

Comments to John J Lee <jjl@pobox.com>.


Copyright 2002-2006 John J Lee <jjl@pobox.com>
Copyright 1997-1999 Gisle Aas (original libwww-perl code)
Copyright 2002-2003 Johnny Lee (original MSIE Perl code)

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).

iNsQ   a filename was not supplied (nor was the CookieJar instance initialised with one)t   80(   t   split_header_wordst   parse_ns_headers(   t   isstringlikes   mechanize.cookiesc         C   s   d d  l  } d d  l } | j s'   n  |  t t t f }  t j   d } t | |   r_   n  d d  l	 } d d  l
 } | j
   } | j d  |  | j   } | j d | d d d  S(   Nii    s   mechanize bug!
%st
   stackleveli   (   t	   mechanizet   warningst   USE_BARE_EXCEPTt   KeyboardInterruptt
   SystemExitt   MemoryErrort   syst   exc_infot
   issubclasst	   tracebackt   StringIOt	   print_exct   Nonet   getvaluet   warn(   t   unmaskedR   R   t   etypeR   R   t   ft   msg(    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   reraise_unmasked_exceptions6   s    	s   \.\d+$c         C   s:   t  j |   p8 |  d k p8 |  d d k p8 |  d d k S(   s*   Return True if text is a host domain name.t    i    t   .i(   t   IPV4_REt   search(   t   text(    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   is_HDNJ   s    c         C   s   |  j    }  | j    } |  | k r( t St |   s8 t S|  j |  } | d k p\ | d k } | o | j d  o t | d  S(   s  Return True if domain A domain-matches domain B, according to RFC 2965.

    A and B may be host domain names or IP addresses.

    RFC 2965, section 1:

    Host names can be specified either as an IP address or a HDN string.
    Sometimes we compare one host name with another.  (Such comparisons SHALL
    be case-insensitive.)  Host A's name domain-matches host B's if

         *  their host name strings string-compare equal; or

         * A is a HDN string and has the form NB, where N is a non-empty
            name string, B has the form .B', and B' is a HDN string.  (So,
            x.y.com domain-matches .Y.com but not Y.com.)

    Note that domain-match is not a commutative operation: a.b.c.com
    domain-matches .c.com, but not the reverse.

    ii    R   i   (   t   lowert   TrueR   t   Falset   rfindt
   startswith(   t   At   Bt   it   has_form_nb(    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   domain_matchU   s    c         C   s   t  j |   S(   sd   Return True if text is a sort-of-like a host domain name.

    For accepting/blocking domains.

    (   R   R   (   R   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   liberal_is_HDNz   s    c         C   s   |  j    }  | j    } t |   o- t |  sD |  | k r@ t St S| j d  } | rl |  j |  rl t S| r |  | k r t St S(   s\   For blocking/accepting domains.

    A and B may be host domain names or IP addresses.

    R   (   R   R)   R    R!   R#   t   endswith(   R$   R%   t   initial_dot(    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   user_domain_match   s    s   :\d+$c         C   sS   |  j    } t j |  d } | d k r@ |  j d d  } n  t j d | d  S(   s   Return request-host, as defined by RFC 2965.

    Variation from RFC: returned value is lowercased, for convenient
    comparison.

    i   t   HostR   N(   t   get_full_urlt   _rfc3986t   urlsplitR   t
   get_headert   cut_port_ret   sub(   t   requestt   urlt   host(    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   request_host   s
    c         C   s   t  |   j   S(   N(   R7   R   (   R4   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   request_host_lc   s    c         C   sL   t  |   } } | j d  d k rB t j |  rB | d } n  | | f S(   s;   Return a tuple (request-host, effective request-host name).R   is   .local(   R7   t   findR   R   (   R4   t   erhnt   req_host(    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   eff_request_host   s    %c         C   s(   t  |   \ } } | j   | j   f S(   N(   R<   R   (   R4   R;   R:   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   eff_request_host_lc   s    c         C   s   t  |   d S(   s:   Return the effective request-host, as defined by RFC 2965.i   (   R<   (   R4   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   effective_request_host   s    c         C   sE   |  j    } t t j |  d  } | j d  sA d | } n  | S(   s=   Return path component of request-URI, as defined by RFC 2965.i   t   /(   R.   t   escape_pathR/   R0   R#   (   R4   R5   t   path(    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   request_path   s
    c         C   sr   |  j    } | j d  } | d k rh | | d } y t |  Wqn t k
 rd t d |  d  SXn t } | S(   Nt   :i    i   s   nonnumeric port: '%s'(   t   get_hostR9   t   intt
   ValueErrort   debugR   t   DEFAULT_HTTP_PORT(   R4   R6   R&   t   port(    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   request_port   s    c         C   s?   y |  j    SWn* t k
 r: t |  d  r4 |  j S  n Xd  S(   Nt   unverifiable(   t   is_unverifiablet   AttributeErrort   hasattrRK   (   R4   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   request_is_unverifiable   s    s   %/;:@&=+$,!~*'()s   %([0-9a-fA-F][0-9a-fA-F])c         C   s   d |  j  d  j   S(   Ns   %%%si   (   t   groupt   upper(   t   match(    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   uppercase_escaped_char   s    c         C   sL   t  |  t j  r$ |  j d  }  n  t j |  t  }  t j t	 |   }  |  S(   sE   Escape any invalid characters in HTTP URL, and uppercase all escapes.s   utf-8(
   t
   isinstancet   typest   UnicodeTypet   encodet   urllibt   quotet   HTTP_PATH_SAFEt   ESCAPED_CHAR_RER3   RS   (   RA   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyR@      s
    
c         C   sk   |  j  d  } | d k rg |  | d } | j  d  } t |   rg | d k s\ | d k rg d | Sn  |  S(   sB  Return reach of host h, as defined by RFC 2965, section 1.

    The reach R of a host name H is defined as follows:

       *  If

          -  H is the host domain name of a host; and,

          -  H has the form A.B; and

          -  A has no embedded (that is, interior) dots; and

          -  B has at least one embedded dot, or B is the string "local".
             then the reach of H is .B.

       *  Otherwise, the reach of H is H.

    >>> reach("www.acme.com")
    '.acme.com'
    >>> reach("acme.com")
    'acme.com'
    >>> reach("acme.local")
    '.local'

    R   i    i   t   local(   R9   R   (   t   hR&   t   b(    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   reach   s    $c         C   s#   t  |   } t | t |  j   S(   s   

    RFC 2965, section 3.3.6:

        An unverifiable transaction is to a third-party host if its request-
        host U does not domain-match the reach R of the request-host O in the
        origin transaction.

    (   R8   R(   R_   t   origin_req_host(   R4   R;   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   is_third_party  s    
c         C   s   x |  D] } | s t  Sq Wt S(   N(   R!   R    (   t   iterablet   x(    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   all#  s    t   Cookiec           B   sw   e  Z d  Z d Z e d  Z d   Z d d  Z d   Z	 d   Z
 d d  Z d   Z d   Z d   Z d   Z RS(   sn  HTTP Cookie.

    This class represents both Netscape and RFC 2965 cookies.

    This is deliberately a very simple class.  It just holds attributes.  It's
    possible to construct Cookie instances that don't comply with the cookie
    standards.  CookieJar.make_cookies is the factory function for Cookie
    objects -- it deals with cookie parsing, supplying defaults, and
    normalising to the representation used in this class.  CookiePolicy is
    responsible for checking them to see whether they should be accepted from
    and returned to the server.

    version: integer;
    name: string;
    value: string (may be None);
    port: string; None indicates no attribute was supplied (e.g. "Port", rather
     than eg. "Port=80"); otherwise, a port string (eg. "80") or a port list
     string (e.g. "80,8080")
    port_specified: boolean; true if a value was supplied with the Port
     cookie-attribute
    domain: string;
    domain_specified: boolean; true if Domain was explicitly set
    domain_initial_dot: boolean; true if Domain as set in HTTP header by server
     started with a dot (yes, this really is necessary!)
    path: string;
    path_specified: boolean; true if Path was explicitly set
    secure:  boolean; true if should only be returned over secure connection
    expires: integer; seconds since epoch (RFC 2965 cookies should calculate
     this value from the Max-Age attribute)
    discard: boolean, true if this is a session cookie; (if no expires value,
     this should be true)
    comment: string;
    comment_url: string;
    rfc2109: boolean; true if cookie arrived in a Set-Cookie: (not
     Set-Cookie2:) header, but had a version cookie-attribute of 1
    rest: mapping of other cookie-attributes

    Note that the port may be present in the headers, but unspecified ("Port"
    rather than"Port=80", for example); if this is the case, port is None.

    t   versiont   namet   valueRI   t   port_specifiedt   domaint   domain_specifiedt   domain_initial_dotRA   t   path_specifiedt   securet   expirest   discardt   commentt   comment_urlt   rfc2109t   _restc         C   s	  | d  k	 r t |  } n  | d  k	 r6 t |  } n  | d  k r] | t k r] t d   n  | |  _ | |  _ | |  _ | |  _ | |  _ | j	   |  _
 | |  _ | |  _ |	 |  _ |
 |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ t j |  |  _ d  S(   Ns-   if port is None, port_specified must be false(   R   RE   R    RF   Rf   Rg   Rh   RI   Ri   R   Rj   Rk   Rl   RA   Rm   Rn   Ro   Rp   Rq   Rr   Rs   t   copyRt   (   t   selfRf   Rg   Rh   RI   Ri   Rj   Rk   Rl   RA   Rm   Rn   Ro   Rp   Rq   Rr   t   restRs   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   __init__]  s.      															c         C   s   |  j  j |  S(   N(   Rt   t   has_key(   Rv   Rg   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   has_nonstandard_attr  s    c         C   s   |  j  j | |  S(   N(   Rt   t   get(   Rv   Rg   t   default(    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   get_nonstandard_attr  s    c         C   s   | |  j  | <d  S(   N(   Rt   (   Rv   Rg   Rh   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   set_nonstandard_attr  s    c         C   s   |  j  j   S(   N(   Rt   t   keys(   Rv   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   nonstandard_attr_keys  s    c         C   s7   | d  k r t j   } n  |  j d  k	 o6 |  j | k S(   N(   R   t   timeRo   (   Rv   t   now(    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt
   is_expired  s     c            s    t     f d     j D  S(   Nc         3   s-   |  ]# } t   |  t    |  k Vq d  S(   N(   t   getattr(   t   .0t   a(   t   otherRv   (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pys	   <genexpr>  s    (   Rd   t   _attrs(   Rv   R   (    (   Rv   R   s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   __eq__  s    c         C   s   |  | k S(   N(    (   Rv   R   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   __ne__  s    c         C   sx   |  j  d  k r d } n d |  j  } |  j | |  j } |  j d  k	 ra d |  j |  j f } n	 |  j } d | | f S(   NR   RC   s   %s=%ss   <Cookie %s for %s>(   RI   R   Rj   RA   Rh   Rg   (   Rv   t   pt   limitt	   namevalue(    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   __str__  s     		c         C   s   g  } xg d d d d d d d d d	 d
 d d d d d g D]2 } t  |  |  } | j d | t |  f  q: W| j d t |  j   | j d t |  j   d d j |  S(   NRf   Rg   Rh   RI   Ri   Rj   Rk   Rl   RA   Rm   Rn   Ro   Rp   Rq   Rr   s   %s=%ss   rest=%ss
   rfc2109=%ss
   Cookie(%s)s   , (   R   t   appendt   reprRt   Rs   t   join(   Rv   t   argsRg   t   attr(    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   __repr__  s    	!(   s   versions   names   values   ports   port_specifieds   domains   domain_specifieds   domain_initial_dots   paths   path_specifieds   secures   expiress   discards   comments   comment_urls   rfc2109s   _restN(   t   __name__t
   __module__t   __doc__R   R!   Rx   Rz   R   R}   R~   R   R   R   R   R   R   (    (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyRe   *  s"   )      						
t   CookiePolicyc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s  Defines which cookies get accepted from and returned to server.

    May also modify cookies.

    The subclass DefaultCookiePolicy defines the standard rules for Netscape
    and RFC 2965 cookies -- override that if you want a customised policy.

    As well as implementing set_ok and return_ok, implementations of this
    interface must also supply the following attributes, indicating which
    protocols should be used, and how.  These can be read and set at any time,
    though whether that makes complete sense from the protocol point of view is
    doubtful.

    Public attributes:

    netscape: implement netscape protocol
    rfc2965: implement RFC 2965 protocol
    rfc2109_as_netscape:
       WARNING: This argument will change or go away if is not accepted into
                the Python standard library in this form!
     If true, treat RFC 2109 cookies as though they were Netscape cookies.  The
     default is for this attribute to be None, which means treat 2109 cookies
     as RFC 2965 cookies unless RFC 2965 handling is switched off (which it is,
     by default), and as Netscape cookies otherwise.
    hide_cookie2: don't add Cookie2 header to requests (the presence of
     this header indicates to the server that we understand RFC 2965
     cookies)

    c         C   s   t     d S(   sV  Return true if (and only if) cookie should be accepted from server.

        Currently, pre-expired cookies never get this far -- the CookieJar
        class deletes such cookies itself.

        cookie: mechanize.Cookie object
        request: object implementing the interface defined by
         CookieJar.extract_cookies.__doc__

        N(   t   NotImplementedError(   Rv   t   cookieR4   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   set_ok  s    c         C   s   t     d S(   s   Return true if (and only if) cookie should be returned to server.

        cookie: mechanize.Cookie object
        request: object implementing the interface defined by
         CookieJar.add_cookie_header.__doc__

        N(   R   (   Rv   R   R4   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt	   return_ok  s    c         C   s   t  S(   s\  Return false if cookies should not be returned, given cookie domain.

        This is here as an optimization, to remove the need for checking every
        cookie with a particular domain (which may involve reading many files).
        The default implementations of domain_return_ok and path_return_ok
        (return True) leave all the work to return_ok.

        If domain_return_ok returns true for the cookie domain, path_return_ok
        is called for the cookie path.  Otherwise, path_return_ok and return_ok
        are never called for that cookie domain.  If path_return_ok returns
        true, return_ok is called with the Cookie object itself for a full
        check.  Otherwise, return_ok is never called for that cookie path.

        Note that domain_return_ok is called for every *cookie* domain, not
        just for the *request* domain.  For example, the function might be
        called with both ".acme.com" and "www.acme.com" if the request domain
        is "www.acme.com".  The same goes for path_return_ok.

        For argument documentation, see the docstring for return_ok.

        (   R    (   Rv   Rj   R4   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   domain_return_ok  s    c         C   s   t  S(   s}   Return false if cookies should not be returned, given cookie path.

        See the docstring for domain_return_ok.

        (   R    (   Rv   RA   R4   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   path_return_ok   s    (   R   R   R   R   R   R   R   (    (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyR     s
   		
	t   DefaultCookiePolicyc           B   s,  e  Z d  Z d Z d Z d Z d Z e e BZ d d e	 e
 d e
 e
 e	 e
 e e
 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" RS(   s-  Implements the standard rules for accepting and returning cookies.

    Both RFC 2965 and Netscape cookies are covered.  RFC 2965 handling is
    switched off by default.

    The easiest way to provide your own policy is to override this class and
    call its methods in your overriden implementations before adding your own
    additional checks.

    import mechanize
    class MyCookiePolicy(mechanize.DefaultCookiePolicy):
        def set_ok(self, cookie, request):
            if not mechanize.DefaultCookiePolicy.set_ok(
                self, cookie, request):
                return False
            if i_dont_want_to_store_this_cookie():
                return False
            return True

    In addition to the features required to implement the CookiePolicy
    interface, this class allows you to block and allow domains from setting
    and receiving cookies.  There are also some strictness switches that allow
    you to tighten up the rather loose Netscape protocol rules a little bit (at
    the cost of blocking some benign cookies).

    A domain blacklist and whitelist is provided (both off by default).  Only
    domains not in the blacklist and present in the whitelist (if the whitelist
    is active) participate in cookie setting and returning.  Use the
    blocked_domains constructor argument, and blocked_domains and
    set_blocked_domains methods (and the corresponding argument and methods for
    allowed_domains).  If you set a whitelist, you can turn it off again by
    setting it to None.

    Domains in block or allow lists that do not start with a dot must
    string-compare equal.  For example, "acme.com" matches a blacklist entry of
    "acme.com", but "www.acme.com" does not.  Domains that do start with a dot
    are matched by more specific domains too.  For example, both "www.acme.com"
    and "www.munitions.acme.com" match ".acme.com" (but "acme.com" itself does
    not).  IP addresses are an exception, and must match exactly.  For example,
    if blocked_domains contains "192.168.1.2" and ".168.1.2" 192.168.1.2 is
    blocked, but 193.168.1.2 is not.

    Additional Public Attributes:

    General strictness switches

    strict_domain: don't allow sites to set two-component domains with
     country-code top-level domains like .co.uk, .gov.uk, .co.nz. etc.
     This is far from perfect and isn't guaranteed to work!

    RFC 2965 protocol strictness switches

    strict_rfc2965_unverifiable: follow RFC 2965 rules on unverifiable
     transactions (usually, an unverifiable transaction is one resulting from
     a redirect or an image hosted on another site); if this is false, cookies
     are NEVER blocked on the basis of verifiability

    Netscape protocol strictness switches

    strict_ns_unverifiable: apply RFC 2965 rules on unverifiable transactions
     even to Netscape cookies
    strict_ns_domain: flags indicating how strict to be with domain-matching
     rules for Netscape cookies:
      DomainStrictNoDots: when setting cookies, host prefix must not contain a
       dot (e.g. www.foo.bar.com can't set a cookie for .bar.com, because
       www.foo contains a dot)
      DomainStrictNonDomain: cookies that did not explicitly specify a Domain
       cookie-attribute can only be returned to a domain that string-compares
       equal to the domain that set the cookie (e.g. rockets.acme.com won't
       be returned cookies from acme.com that had no Domain cookie-attribute)
      DomainRFC2965Match: when setting cookies, require a full RFC 2965
       domain-match
      DomainLiberal and DomainStrict are the most useful combinations of the
       above flags, for convenience
    strict_ns_set_initial_dollar: ignore cookies in Set-Cookie: headers that
     have names starting with '$'
    strict_ns_set_path: don't allow setting cookies whose path doesn't
     path-match request URI

    i   i   i   i    c         C   s   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ |	 |  _ |
 |  _ | |  _ | |  _	 | d k	 rx t |  |  _ n	 d |  _ | d k	 r t |  } n  | |  _ d S(   s  
        Constructor arguments should be used as keyword arguments only.

        blocked_domains: sequence of domain names that we never accept cookies
         from, nor return cookies to
        allowed_domains: if not None, this is a sequence of the only domains
         for which we accept and return cookies

        For other arguments, see CookiePolicy.__doc__ and
        DefaultCookiePolicy.__doc__..

        N(    (   t   netscapet   rfc2965t   rfc2109_as_netscapet   hide_cookie2t   strict_domaint   strict_rfc2965_unverifiablet   strict_ns_unverifiablet   strict_ns_domaint   strict_ns_set_initial_dollart   strict_ns_set_pathR   t   tuplet   _blocked_domainst   _allowed_domains(   Rv   t   blocked_domainst   allowed_domainsR   R   R   R   R   R   R   R   R   R   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyRx   b  s     											c         C   s   |  j  S(   s4   Return the sequence of blocked domains (as a tuple).(   R   (   Rv   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyR     s    c         C   s   t  |  |  _ d S(   s$   Set the sequence of blocked domains.N(   R   R   (   Rv   R   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   set_blocked_domains  s    c         C   s+   x$ |  j  D] } t | |  r
 t Sq
 Wt S(   N(   R   R,   R    R!   (   Rv   Rj   t   blocked_domain(    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt
   is_blocked  s    c         C   s   |  j  S(   s=   Return None, or the sequence of allowed domains (as a tuple).(   R   (   Rv   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyR     s    c         C   s(   | d k	 r t |  } n  | |  _ d S(   s-   Set the sequence of allowed domains, or None.N(   R   R   R   (   Rv   R   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   set_allowed_domains  s    c         C   s>   |  j  d  k r t Sx$ |  j  D] } t | |  r t Sq Wt S(   N(   R   R   R!   R,   R    (   Rv   Rj   t   allowed_domain(    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   is_not_allowed  s    c         C   sc   t  d |  | j d	 k	 s" t  x: d
 D]2 } d | } t |  |  } | | |  s) t Sq) Wt S(   s   
        If you override set_ok, be sure to call this method.  If it returns
        false, so should your subclass (assuming your subclass wants to be more
        strict about which cookies to accept).

        s    - checking cookie %sRf   t   verifiabilityRg   RA   Rj   RI   t   set_ok_N(   s   versionR   s   names   paths   domains   port(   RG   Rg   R   t   AssertionErrorR   R!   R    (   Rv   R   R4   t   nt   fn_namet   fn(    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyR     s    
c         C   sr   | j  d  k r  t d |  t S| j  d k rG |  j rG t d  t S| j  d k rn |  j rn t d  t St S(   Ns-      Set-Cookie2 without version attribute (%s)i    s$      RFC 2965 cookies are switched offs$      Netscape cookies are switched off(   Rf   R   RG   R!   R   R   R    (   Rv   R   R4   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   set_ok_version  s    

c         C   sk   t  |  rg t |  rg | j d k r> |  j r> t d  t S| j d k rg |  j rg t d  t Sn  t S(   Ni    s>      third-party RFC 2965 cookie during unverifiable transactions>      third-party Netscape cookie during unverifiable transaction(   RO   Ra   Rf   R   RG   R!   R   R    (   Rv   R   R4   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   set_ok_verifiability  s    

c         C   sB   | j  d k r> |  j r> | j j d  r> t d | j  t St S(   Ni    t   $s'      illegal name (starts with '$'): '%s'(   Rf   R   Rg   R#   RG   R!   R    (   Rv   R   R4   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   set_ok_name  s
    c         C   sm   | j  ri t |  } | j d k s< | j d k ri |  j ri | j | j  ri t d | j |  t Sn  t S(   Ni    s7      path attribute %s is not a prefix of request path %s(	   Rm   RB   Rf   R   R#   RA   RG   R!   R    (   Rv   R   R4   t   req_path(    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   set_ok_path  s    	c         C   s   | j  r |  j r | j } | j d  s0 t  | j d  d k r | j d  } | | d } | d | !} | j   d k r t |  d k r t	 Sq n  t
 S(   s   Return False if explicit cookie domain is not acceptable.

        Called by set_ok_domain, for convenience of overriding by
        subclasses.

        R   i   i   t   cot   act   comt   edut   orgt   nett   govt   milRE   t   aerot   bizt   catt   coopt   infot   jobst   mobit   museumRg   t   prot   travel(   s   coR   R   R   R   R   R   R   s   intR   R   s   catR   s   infoR   R   R   s   nameR   R   (   Rk   R   Rj   R#   R   t   countR"   R   t   lenR!   R    (   Rv   R   R4   Rj   R&   t   tldt   sld(    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   set_ok_countrycode_domain  s    		   	
c   	   
   C   s  |  j  | j  r& t d | j  t S|  j | j  rL t d | j  t S|  j | |  sr t d | j  t S| j rt |  \ } } | j } | j d  r | d } n | } | j	 d  d k } | r | d k r t d |  t S| j
 d k rK| j |  rK| j d  rKd | j |  rKt d	 | |  t Sn  | j
 d k sj|  j |  j @rt | |  st d
 | |  t Sn  | j
 d k s|  j |  j @r| t |   } | j	 d  d k rt j |  rt d | |  t Sqn  t S(   Ns"      domain %s is in user block-lists&      domain %s is not in user allow-lists&      country-code second level domain %sR   i   i    s   .locals/      non-local domain %s contains no embedded dotsS      effective request-host %s (even with added initial dot) does not end end with %ss5      effective request-host %s does not domain-match %ss.      host prefix %s for domain %s contains a dot(   R   Rj   RG   R!   R   R   Rk   R=   R#   R9   Rf   R*   R   t   DomainRFC2965MatchR(   t   DomainStrictNoDotsR   R   R   R    (	   Rv   R   R4   R;   R:   Rj   t   undotted_domaint   embedded_dotst   host_prefix(    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   set_ok_domain  sT    		



c         C   s   | j  r t |  } | d  k r* d } n t |  } xt | j j d  D]F } y t |  Wn t k
 r~ t d |  t	 SX| | k rI PqI qI Wt d | | j  t	 Sn  t
 S(   NR    t   ,s      bad port %s (not numeric)s$      request port (%s) not found in %s(   Ri   RJ   R   t   strRI   t   splitRE   RF   RG   R!   R    (   Rv   R   R4   t   req_portR   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   set_ok_port9  s"    		c         C   sN   t  d |  x: d	 D]2 } d | } t |  |  } | | |  s t Sq Wt S(
   s   
        If you override return_ok, be sure to call this method.  If it returns
        false, so should your subclass (assuming your subclass wants to be more
        strict about which cookies to return).

        s    - checking cookie %sRf   R   Rn   Ro   RI   Rj   t
   return_ok_(   s   versions   verifiabilitys   secures   expiress   ports   domain(   RG   R   R!   R    (   Rv   R   R4   R   R   R   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyR   N  s    	

c         C   sR   | j  d k r' |  j r' t d  t S| j  d k rN |  j rN t d  t St S(   Ni    s$      RFC 2965 cookies are switched offs$      Netscape cookies are switched off(   Rf   R   RG   R!   R   R    (   Rv   R   R4   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   return_ok_versiona  s    

c         C   sk   t  |  rg t |  rg | j d k r> |  j r> t d  t S| j d k rg |  j rg t d  t Sn  t S(   Ni    s>      third-party RFC 2965 cookie during unverifiable transactions>      third-party Netscape cookie during unverifiable transaction(   RO   Ra   Rf   R   RG   R!   R   R    (   Rv   R   R4   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   return_ok_verifiabilityj  s    

c         C   s-   | j  r) | j   d k r) t d  t St S(   Nt   httpss(      secure cookie with non-secure request(   Rn   t   get_typeRG   R!   R    (   Rv   R   R4   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   return_ok_securev  s    
c         C   s$   | j  |  j  r  t d  t St S(   Ns      cookie expired(   R   t   _nowRG   R!   R    (   Rv   R   R4   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   return_ok_expires|  s    
c         C   su   | j  rq t |  } | d  k r* d } n  xD | j  j d  D] } | | k r= Pq= q= Wt d | | j   t Sn  t S(   NR    R   s0      request port %s does not match cookie port %s(   RI   RJ   R   R   RG   R!   R    (   Rv   R   R4   R   R   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   return_ok_port  s    		c      	   C   s   t  |  \ } } | j } | j d k r^ |  j |  j @r^ | j r^ | | k r^ t d  t S| j d k r t | |  r t d | |  t S| j d k r d | j	 |  r t d | |  t St
 S(   Ni    sQ      cookie with unspecified domain does not string-compare equal to request domainsQ      effective request-host name %s does not domain-match RFC 2965 cookie domain %sR   s;      request-host %s does not match Netscape cookie domain %s(   R=   Rj   Rf   R   t   DomainStrictNonDomainRk   RG   R!   R(   R*   R    (   Rv   R   R4   R;   R:   Rj   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   return_ok_domain  s     	

#
c         C   s   t  |  \ } } | j d  s. d | } n  | j d  sJ d | } n  | j |  pe | j |  sl t S|  j |  r t d |  t S|  j |  r t d |  t St S(   NR   s"      domain %s is in user block-lists&      domain %s is not in user allow-list(   R=   R#   R*   R!   R   RG   R   R    (   Rv   Rj   R4   t   dotted_req_hostt   dotted_erhn(    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyR     s    c         C   s@   t  d |  t |  } | j |  s< t  d | |  t St S(   Ns   - checking cookie path=%ss     %s does not path-match %s(   RG   RB   R#   R!   R    (   Rv   RA   R4   R   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyR     s    N(#   R   R   R   R   R   R   t   DomainLiberalt   DomainStrictR   R    R!   Rx   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyR   	  sN   P
"														.										c         C   s&   |  j    } | j   t |  j |  S(   N(   R   t   sortt   mapR{   (   t   adictR   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   vals_sorted_by_key  s    
t   MappingIteratorc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   sB   Iterates over nested mapping, depth-first, in sorted order by key.c         C   s   t  |  d d  f g |  _ d  S(   Ni    (   R   R   t   _s(   Rv   t   mapping(    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyRx     s    c         C   s   |  S(   N(    (   Rv   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   __iter__  s    c         C   s   x y |  j  j   \ } } } Wn t k
 r; t    n X| t |  k  r | | } | d } |  j  j | | | f  y | j Wn t k
 r Pq X|  j  j t |  d | f  q q q | S(   Ni   i    (	   R   t   popt
   IndexErrort   StopIterationR   R   t   itemsRM   R   (   Rv   t   valsR&   t	   prev_itemt   item(    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   next  s     

	(   R   R   R   Rx   R   R  (    (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyR     s   		t   Absentc           B   s   e  Z RS(    (   R   R   (    (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyR    s    t	   CookieJarc           B   sF  e  Z d  Z e j d  Z e j d  Z e j d  Z e j d  Z e j 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 d   Z d   Z d   Z d   Z d   Z d d d d  Z d   Z d   Z d   Z d   Z  d   Z! d   Z" d   Z# RS(    s  Collection of HTTP cookies.

    You may not need to know about this class: try mechanize.urlopen().

    The major methods are extract_cookies and add_cookie_header; these are all
    you are likely to need.

    CookieJar supports the iterator protocol:

    for cookie in cookiejar:
        # do something with cookie

    Methods:

    add_cookie_header(request)
    extract_cookies(response, request)
    get_policy()
    set_policy(policy)
    cookies_for_request(request)
    make_cookies(response, request)
    set_cookie_if_ok(cookie, request)
    set_cookie(cookie)
    clear_session_cookies()
    clear_expired_cookies()
    clear(domain=None, path=None, name=None)

    Public attributes

    policy: CookiePolicy object

    s   \Ws   ([\"\\])s   \.?[^.]*s   [^.]*s   ^\.+c         C   s7   | d k r t   } n  | |  _ i  |  _ d |  _ d S(   sD   
        See CookieJar.__doc__ for argument documentation.

        i    N(   R   R   t   _policyt   _cookiest   _prev_getitem_index(   Rv   t   policy(    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyRx     s
    		c         C   s   |  j  S(   N(   R  (   Rv   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt
   get_policy%  s    c         C   s   | |  _  d  S(   N(   R  (   Rv   R  (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt
   set_policy(  s    c         C   s   g  } |  j  j | |  s g  St d |  |  j | } x | j   D]~ } |  j  j | |  sg qF n  | | } xP | j   D]B } |  j  j | |  s t d  q~ n  t d  | j |  q~ WqF W| S(   Ns!   Checking %s for cookies to returns      not returning cookies      it's a match(	   R  R   RG   R  R   R   t   valuesR   R   (   Rv   Rj   R4   t   cookiest   cookies_by_pathRA   t   cookies_by_nameR   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   _cookies_for_domain+  s     


c         C   sH   t  t j    |  j _ |  _ |  j |  } d   } | j |  | S(   sO  Return a list of cookies to be returned to server.

        The returned list of cookie instances is sorted in the order they
        should appear in the Cookie: header for return to the server.

        See add_cookie_header.__doc__ for the interface required of the
        request argument.

        New in version 0.1.10

        c         S   s   t  t | j  t |  j   S(   N(   t   cmpR   RA   (   R   R^   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   decreasing_sizeL  s    (   RE   R   R  R   t   _cookies_for_requestR   (   Rv   R4   R  R  (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   cookies_for_request=  s
    	c         C   s=   g  } x0 |  j  j   D] } | j |  j | |   q W| S(   s2   Return a list of cookies to be returned to server.(   R  R   t   extendR  (   Rv   R4   R  Rj   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyR  P  s    c   	      C   s  t  } g  } x| D]} | j } | sQ t } | d k rQ | j d |  qQ n  | j d k	 r |  j j | j  r | d k r |  j j	 d | j  } n	 | j } | j d k r | j | j
  n | j d | j
 | f  | d k r | j r| j d | j  n  | j j d  rb| j } | j rN| j d  rN| d } n  | j d |  n  | j d k	 rd	 } | j r| d
 | j } n  | j |  qq q W| S(   sZ  Return a list of cookie-attributes to be returned to server.

        The $Version attribute is also added when appropriate (currently only
        once per request).

        >>> jar = CookieJar()
        >>> ns_cookie = Cookie(0, "foo", '"bar"', None, False,
        ...                   "example.com", False, False,
        ...                   "/", False, False, None, True,
        ...                   None, None, {})
        >>> jar._cookie_attrs([ns_cookie])
        ['foo="bar"']
        >>> rfc2965_cookie = Cookie(1, "foo", "bar", None, False,
        ...                         ".example.com", True, False,
        ...                         "/", False, False, None, True,
        ...                         None, None, {})
        >>> jar._cookie_attrs([rfc2965_cookie])
        ['$Version=1', 'foo=bar', '$Domain="example.com"']

        i    s   $Version=%ss   \\\1s   %s=%ss
   $Path="%s"R   i   s   $Domain="%s"s   $Ports   ="%s"N(   R!   Rf   R    R   Rh   R   t   non_word_reR   t   quote_reR3   Rg   Rm   RA   Rj   R#   Rl   RI   Ri   (	   Rv   R  t   version_sett   attrsR   Rf   Rh   Rj   R   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   _cookie_attrs[  s<    	!			
	c         C   s   t  d  |  j |  } |  j |  } | r\ | j d  s\ | j d d j |   q\ n  |  j j r |  j j r xD | D]9 } | j	 d k r| | j d  r| | j d d  Pq| q| Wn  |  j
   d S(   s  Add correct Cookie: header to request (mechanize.Request object).

        The Cookie2 header is also added unless policy.hide_cookie2 is true.

        The request object (usually a mechanize.Request instance) must support
        the methods get_full_url, get_host, is_unverifiable, get_type,
        has_header, get_header, header_items and add_unredirected_header, as
        documented by urllib2.
        t   add_cookie_headerRe   s   ; i   t   Cookie2s   $Version="1"N(   RG   R  R  t
   has_headert   add_unredirected_headerR   R  R   R   Rf   t   clear_expired_cookies(   Rv   R4   R  R  R   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyR    s    

c      
   C   s@  g  } d } d } x'| D]} | d \ } } t  } t  }	 i  }
 i  } x| d D]\ } } | j   } | | k s | | k r | } n  | | k r | d k r t } n  |
 j |  r qR n  | d k r | d k r t d  t }	 Pn  | j   } n  | d k r3| rqR n  | d k r3t d  qR q3n  | d k rt } | d k ret d  t }	 Pn  y t |  } Wn" t k
 rt d  t }	 Pn Xd } |  j | } n  | | k s| | k r| d k r| d k rt d |  t }	 Pn  | |
 | <qR | | | <qR W|	 rq n  | j	 | | |
 | f  q W| S(   s  Return list of tuples containing normalised cookie information.

        attrs_set is the list of lists of key,value pairs extracted from
        the Set-Cookie or Set-Cookie2 headers.

        Tuples are name, value, standard, rest, where name and value are the
        cookie name and value, standard is a dictionary containing the standard
        cookie-attributes (discard, secure, version, expires or max-age,
        domain, path and port) and rest is a dictionary containing the rest of
        the cookie-attributes.

        Rp   Rn   Rf   Ro   s   max-ageRj   RA   RI   Rq   t
   commenturli    i   s%      missing value for domain attributesM      missing or invalid value for expires attribute: treating as session cookies&      missing value for max-age attributes?      missing or invalid (non-numeric) value for max-age attributes!      missing value for %s attribute(   s   discards   secure(   s   versions   expiress   max-ages   domains   paths   ports   commentR  N(   s   ports   commentR  (
   R!   R   R   R    Ry   RG   RE   RF   R   R   (   Rv   t	   attrs_sett   cookie_tuplest   boolean_attrst   value_attrst   cookie_attrsRg   Rh   t   max_age_sett
   bad_cookiet   standardRw   t   kt   vt   lc(    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   _normalized_cookie_tuples  st       
		

	

c         C   s  | \ } } } } | j  d t  } | j  d t  } | j  d t  }	 | j  d t  }
 | j  d d   } | d  k	 r y t |  } Wq t k
 r d  SXn  | j  d t  } | j  d t  } | j  d d   } | j  d	 d   } | t k	 r| d
 k rt } t |  } nr t } t |  } | j	 d  } | d k rl| d k r[| |  } ql| | d  } n  t
 |  d k rd } n  | t k	 } t } | rt | j d   } n  | t k rt |  \ } } | } n | j d  sd | } n  t } |	 t k	 rE|	 d  k r't |  }	 qKt } t j d d
 |	  }	 n d  }	 |
 t k rfd  }
 t } n  t | | | |	 | | | | | | | |
 | | | |  S(   NRj   RA   RI   Ro   Rf   Rn   Rp   Rq   R  R   R?   ii    i   R   s   \s+(   R{   R  R   RE   RF   R!   R    R@   RB   R"   R   t   boolR#   R=   RJ   t   reR3   Re   (   Rv   t   tupR4   Rg   Rh   R&  Rw   Rj   RA   RI   Ro   Rf   Rn   Rp   Rq   Rr   Rm   R&   Rk   Rl   R;   R:   Ri   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   _cookie_from_cookie_tuple  sr     				c         C   sR   |  j  |  } g  } x6 | D]. } |  j | |  } | r | j |  q q W| S(   N(   R*  R.  R   (   Rv   R  R4   R   R  R-  R   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   _cookies_from_attrs_setq  s     c         C   sp   |  j  j d  k r" |  j  j } n |  j  j } x; | D]3 } | j d k r5 t | _ | rh d | _ qh q5 q5 Wd  S(   Ni   i    (   R  R   R   R   Rf   R    Rs   (   Rv   R  R   R   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   _process_rfc2109_cookiesz  s    	c         C   sq  | j    } | j d  } | j d  } |  j j } |  j j } | rP | sz | r^ | sz | rl | sz | r~ | r~ g  Sy |  j t |  |  } Wn t   g  } n X| rm| rmy |  j t |  |  }	 Wn t   g  }	 n X|  j	 |	  | rTi  }
 x* | D]" } d  |
 | j | j | j f <qW|
 d  } t | |	  }	 n  |	 rm| j |	  qmn  | S(   Ns   Set-Cookie2s
   Set-Cookiec         S   s&   |  j  |  j |  j f } | j |  S(   N(   Rj   RA   Rg   Ry   (   t	   ns_cookiet   lookupt   key(    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   no_matching_rfc2965  s    (   R   t
   getheadersR  R   R   R/  R   R   R   R0  R   Rj   RA   Rg   t   filterR  (   Rv   t   responseR4   t   headerst   rfc2965_hdrst   ns_hdrsR   R   R  t
   ns_cookiesR2  R   R4  (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   _make_cookies  sB    

 c         C   sd   t  t j    |  j _ |  _ g  |  j | |  D]. } | j d k sZ | j |  j k r2 | ^ q2 S(   s   Return sequence of Cookie objects extracted from response object.

        See extract_cookies.__doc__ for the interface required of the
        response and request arguments.

        N(   RE   R   R  R   R<  Ro   R   (   Rv   R7  R4   R   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   make_cookies  s    c         C   sH   t  t j    |  j _ |  _ |  j j | |  rD |  j |  n  d S(   s   Set a cookie if policy says it's OK to do so.

        cookie: mechanize.Cookie instance
        request: see extract_cookies.__doc__ for the required interface

        N(   RE   R   R  R   R   t
   set_cookie(   Rv   R   R4   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   set_cookie_if_ok  s    c         C   sx   |  j  } | j | j  s+ i  | | j <n  | | j } | j | j  sZ i  | | j <n  | | j } | | | j <d S(   ss   Set a cookie, without checking whether or not it should be set.

        cookie: mechanize.Cookie instance
        N(   R  Ry   Rj   RA   Rg   (   Rv   R   t   ct   c2t   c3(    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyR>    s    	  c         C   s   t  d | j    t t j    |  j _ |  _ x |  j | |  D] } | j d k	 r | j |  j k r y  |  j	 | j
 | j | j  Wn t k
 r n Xt  d | j
 | j | j  qE |  j j | |  rE t  d |  |  j |  qE qE Wd S(   s  Extract cookies from response, where allowable given the request.

        Look for allowable Set-Cookie: and Set-Cookie2: headers in the response
        object passed as argument.  Any of these headers that are found are
        used to update the state of the object (subject to the policy.set_ok
        method's approval).

        The response object (usually be the result of a call to
        mechanize.urlopen, or similar) should support an info method, which
        returns a mimetools.Message object (in fact, the 'mimetools.Message
        object' may be any object that provides a getheaders method).

        The request object (usually a mechanize.Request instance) must support
        the methods get_full_url, get_type, get_host, and is_unverifiable, as
        documented by mechanize, and the port attribute (the port number).  The
        request is used to set default values for cookie-attributes as well as
        for checking that the cookie is OK to be set.

        s   extract_cookies: %ss2   Expiring cookie, domain='%s', path='%s', name='%s's    setting cookie: %sN(   RG   R   RE   R   R  R   R<  Ro   R   t   clearRj   RA   Rg   t   KeyErrorR   R>  (   Rv   R7  R4   R   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   extract_cookies  s    ! c         C   s   | d k	 rH | d k s$ | d k r3 t d   n  |  j | | | =nZ | d k	 r | d k ro t d   n  |  j | | =n" | d k	 r |  j | =n	 i  |  _ d S(   s  Clear some cookies.

        Invoking this method without arguments will clear all cookies.  If
        given a single argument, only cookies belonging to that domain will be
        removed.  If given two arguments, cookies belonging to the specified
        path within that domain are removed.  If given three arguments, then
        the cookie with the specified name, path and domain is removed.

        Raises KeyError if no matching cookie exists.

        s8   domain and path must be given to remove a cookie by names.   domain must be given to remove cookies by pathN(   R   RF   R  (   Rv   Rj   RA   Rg   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyRC    s    c         C   s=   x6 |  D]. } | j  r |  j | j | j | j  q q Wd S(   s	  Discard all session cookies.

        Discards all cookies held by object which had either no Max-Age or
        Expires cookie-attribute or an explicit Discard cookie-attribute, or
        which otherwise have ended up with a true discard attribute.  For
        interactive browsers, the end of a session usually corresponds to
        closing the browser window.

        Note that the save method won't save session cookies anyway, unless you
        ask otherwise by passing a true ignore_discard argument.

        N(   Rp   RC  Rj   RA   Rg   (   Rv   R   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   clear_session_cookies  s    	c         C   sO   t  j    } x< |  D]4 } | j |  r |  j | j | j | j  q q Wd S(   s  Discard all expired cookies.

        You probably don't need to call this method: expired cookies are never
        sent back to the server (provided you're using DefaultCookiePolicy),
        this method is called by CookieJar itself every so often, and the save
        method won't save expired cookies anyway (unless you ask otherwise by
        passing a true ignore_expires argument).

        N(   R   R   RC  Rj   RA   Rg   (   Rv   R   R   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyR  0  s    
c         C   s{   | d k r |  j    |  _ n" |  j | d k r@ t d   n  | |  _ y |  j j   SWn t k
 rv t    n Xd  S(   Ni    i   s8   CookieJar.__getitem__ only supports sequential iteration(   R   t   _getitem_iteratorR  R   R  R   (   Rv   R&   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   __getitem__?  s     	c         C   s   t  |  j  S(   N(   R   R  (   Rv   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyR   J  s    c         C   s%   d } x |  D] } | d } q W| S(   s#   Return number of contained cookies.i    i   (    (   Rv   R&   R   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   __len__M  s     c         C   sD   g  } x! |  D] } | j  t |   q Wd |  j d j |  f S(   Ns   <%s[%s]>s   , (   R   R   t	   __class__R   (   Rv   t   rR   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyR   S  s     c         C   sD   g  } x! |  D] } | j  t |   q Wd |  j d j |  f S(   Ns   <%s[%s]>s   , (   R   R   RJ  R   (   Rv   RK  R   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyR   X  s     N($   R   R   R   R,  t   compileR  R  t   strict_domain_ret	   domain_ret   dots_reR   Rx   R  R	  R  R  R  R  R  R*  R.  R/  R0  R<  R=  R?  R>  RE  RC  RF  R  RH  R   RI  R   R   (    (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyR    s>   						D		e	R				5				%						t	   LoadErrorc           B   s   e  Z RS(    (   R   R   (    (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyRP  ^  s    t   FileCookieJarc           B   sV   e  Z d  Z d e d d  Z d e e d  Z d e e d  Z d e e d  Z RS(   s  CookieJar that can be loaded from and saved to a file.

    Additional methods

    save(filename=None, ignore_discard=False, ignore_expires=False)
    load(filename=None, ignore_discard=False, ignore_expires=False)
    revert(filename=None, ignore_discard=False, ignore_expires=False)

    Additional public attributes

    filename: filename for loading and saving cookies

    Additional public readable attributes

    delayload: request that cookies are lazily loaded from disk; this is only
     a hint since this only affects performance, not behaviour (unless the
     cookies on disk are changing); a CookieJar object may ignore it (in fact,
     only MSIECookieJar lazily loads cookies at the moment)

    c         C   sT   t  j |  |  | d k	 r8 t |  r8 t d   n  | |  _ t |  |  _ d S(   s   
        See FileCookieJar.__doc__ for argument documentation.

        Cookies are NOT loaded from the named file until either the load or
        revert method is called.

        s   filename must be string-likeN(   R  Rx   R   R   RF   t   filenameR+  t	   delayload(   Rv   RR  RS  R  (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyRx   v  s
    	c         C   s   t     d S(   s  Save cookies to a file.

        filename: name of file in which to save cookies
        ignore_discard: save even cookies set to be discarded
        ignore_expires: save even cookies that have expired

        The file is overwritten if it already exists, thus wiping all its
        cookies.  Saved cookies can be restored later using the load or revert
        methods.  If filename is not specified, self.filename is used; if
        self.filename is None, ValueError is raised.

        N(   R   (   Rv   RR  t   ignore_discardt   ignore_expires(    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   save  s    c         C   sn   | d k r6 |  j d k	 r' |  j } q6 t t   n  t |  } z |  j | | | |  Wd | j   Xd S(   s  Load cookies from a file.

        Old cookies are kept unless overwritten by newly loaded ones.

        Arguments are as for .save().

        If filename is not specified, self.filename is used; if self.filename
        is None, ValueError is raised.  The named file must be in the format
        understood by the class, or LoadError will be raised.  This format will
        be identical to that written by the save method, unless the load format
        is not sufficiently well understood (as is the case for MSIECookieJar).

        N(   R   RR  RF   t   MISSING_FILENAME_TEXTt   opent   _really_loadt   close(   Rv   RR  RT  RU  R   (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   load  s     c         C   s   | d k r6 |  j d k	 r' |  j } q6 t t   n  t j |  j  } i  |  _ y |  j | | |  Wn# t t	 f k
 r | |  _   n Xd S(   s   Clear all cookies and reload cookies from a saved file.

        Raises LoadError (or IOError) if reversion is not successful; the
        object's state will not be altered if this happens.

        N(
   R   RR  RF   RW  Ru   t   deepcopyR  R[  RP  t   IOError(   Rv   RR  RT  RU  t	   old_state(    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   revert  s     		N(	   R   R   R   R   R!   Rx   RV  R[  R_  (    (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyRQ  `  s   (8   R   R   R,  Ru   R   RX   RU   t   loggingt	   threadingt
   _threadingt   ImportErrort   dummy_threadingRW  RH   t   _headersutilR   R   t   _utilR   R/   t	   getLoggerRG   R   RL  R   R   R(   R)   R,   R2   R7   R8   R<   R=   R>   RB   RJ   RO   RZ   R[   RS   R@   R_   Ra   Rd   t	   NameErrorRe   R   R   R   R   R  R  t	   ExceptionRP  RQ  (    (    (    s<   /scratch/rashmi/Condor_Script/src/mechanize/_clientcookie.pyt   <module>!   sh   T  		%													#	V 	   p