
bc           @@  sm  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l m Z d  d l m Z m Z m	 Z	 m
 Z
 y d  d l j j Z Wn  e k
 r d  d l j Z n Xd d l m Z d d l m Z d d l Td d	 l m Z m Z m Z m Z m Z m Z d d
 l m Z m Z m Z m Z m  Z  d d l! m" Z" d d l# m# Z# m$ Z$ d d l% m% Z% d d l& m& Z& e j' d d  f k Z( d Z) d i e) d 6Z* d   Z+ d   Z, d e- f d     YZ. d e- f d     YZ/ d e- f d     YZ0 d e- f d     YZ1 d e- f d     YZ2 d e- f d      YZ3 d! e- f d"     YZ4 d# e- f d$     YZ5 d% e- f d&     YZ6 d S('   i    (   t   absolute_importN(   t   datetime(   t   debugt   infot   warningt   errori   (   t   S3(   t   Config(   t   *(   t   getTreeFromXmlt   appendXmlTextNodet   getDictFromTreet   dateS3toPythont   encode_to_s3t   decode_from_s3(   t   getBucketFromHostnamet   getHostnameFromBuckett   deunicodiset   urlencode_stringt   convertHeaderTupleListToDict(   t   sign_string_v2(   t   S3Urit   S3UriS3(   t   ConnMan(   t
   SortedDicti   s
   2010-11-01s   /%(api_ver)s/distributiont   api_verc         C@  s   t  j j |  d  d  S(   Ns   
(   t   syst   stdoutt   write(   t   message(    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyt   output'   s    c         C@  s+   d |  j  d  }  t d |  | f  d  S(   Ns   %s:i   s   %s %s(   t   ljustR   (   t   labelR   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyt   pretty_output*   s    t   DistributionSummaryc           B@  s#   e  Z d    Z d   Z d   Z RS(   c         C@  s6   | j  d k r% t d | j    n  |  j |  d  S(   NR"   s1   Expected <DistributionSummary /> xml, got: <%s />(   t   tagt
   ValueErrort   parse(   t   selft   tree(    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyt   __init__@   s    c         C@  su   t  |  |  _ |  j d j   d k |  j d <d |  j k rq t |  j d  t k rq |  j d g |  j d <n  d  S(   Nt   Enabledt   truet   CNAME(   R   R   t   lowert   typet   list(   R&   R'   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR%   E   s     (c         C@  s   t  d |  j d  S(   Nu   cf://%st   Id(   R   R   (   R&   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyt   uriK   s    (   t   __name__t
   __module__R(   R%   R0   (    (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR"   /   s   		t   DistributionListc           B@  s   e  Z d    Z d   Z RS(   c         C@  sB   t  |  } | j d k r1 t d | j   n  |  j |  d  S(   NR3   s.   Expected <DistributionList /> xml, got: <%s />(   R	   R#   R$   R%   (   R&   t   xmlR'   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR(   Z   s    c         C@  sl   t  |  |  _ |  j d j   d k |  j d <g  |  _ x- | j d  D] } |  j j t |   qH Wd  S(   Nt   IsTruncatedR*   s   .//DistributionSummary(   R   R   R,   t
   dist_summst   findallt   appendR"   (   R&   R'   t	   dist_summ(    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR%   `   s
     	(   R1   R2   R(   R%   (    (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR3   N   s   	t   Distributionc           B@  s#   e  Z d    Z d   Z d   Z RS(   c         C@  sB   t  |  } | j d k r1 t d | j   n  |  j |  d  S(   NR:   s*   Expected <Distribution /> xml, got: <%s />(   R	   R#   R$   R%   (   R&   R4   R'   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR(   v   s    c         C@  sL   t  |  |  _ t |  j d  |  j d <t d | j d   |  j d <d  S(   Nt   LastModifiedTimeR'   s   .//DistributionConfigt   DistributionConfig(   R   R   R   R<   t   find(   R&   R'   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR%   |   s    c         C@  s   t  d |  j d  S(   Nu   cf://%sR/   (   R   R   (   R&   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR0      s    (   R1   R2   R(   R%   R0   (    (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR:   i   s   		R<   c           B@  sR   e  Z d  Z d i e d 6Z d d d  Z d   Z d   Z d   Z	 d   Z
 RS(	   sq   <DistributionConfig><S3Origin><DNSName/></S3Origin><CallerReference/><Enabled>true</Enabled></DistributionConfig>s0   http://cloudfront.amazonaws.com/doc/%(api_ver)s/R   c         C@  si   | d  k r t j } n  | d  k r3 t |  } n  | j d k rX t d | j   n  |  j |  d  S(   NR<   s0   Expected <DistributionConfig /> xml, got: <%s />(   t   NoneR<   t   EMPTY_CONFIGR	   R#   R$   R%   (   R&   R4   R'   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR(      s    c         C@  sq  t  |  |  _ |  j d j   d k |  j d <d |  j k rN g  |  j d <n  t |  j d  t k r |  j d g |  j d <n  g  |  j d D] } | j   ^ q |  j d <d |  j k r d |  j d <n  d |  j k r d |  j d <n  | j d  } | r`t  | d  } t | d	  \ | d	 <} | sFt d
 | d	  n  t d |  |  j d <n d  |  j d <d  S(   NR)   R*   R+   t   Commentt    t   DefaultRootObjects
   .//Loggingi    t   Buckets%   Logging to unparsable bucket name: %su   s3://%(Bucket)s/%(Prefix)st   Logging(
   R   R   R,   R-   R.   R7   R   R   R   R>   (   R&   R'   t   cnamet   logging_nodest   logging_dictt   success(    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR%      s&     -c         C@  s~  t  j d  } t j | j d <t d d |  } t d |  j d d |  t d |  j d |  x+ |  j d D] } t d | j   |  qq W|  j d r t d |  j d |  n  t d	 t |  j d	  j   |  t |  j d
  rt d
 t |  j d
  |  n  |  j d rzt  j d  } t d t	 |  j d j
    |  t d |  j d j   |  | j |  n  | S(   NR<   t   xmlnst   S3OriginRA   t   DNSNamet   CallerReferenceR+   R@   R)   RB   RD   RC   t   Prefix(   t   ETt   ElementR<   RI   t   attribR
   R   R,   t   strR   t   buckett   objectR8   (   R&   R'   t   s3orgRE   t
   logging_el(    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyt   get_printable_tree   s$    # #c         C@  s   t  t j |  j     S(   N(   R   RN   t   tostringRV   (   R&   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyt   __unicode__   s    c         C@  s6   t  r t j |  j   d d St j |  j    Sd  S(   Nt   encodingt   unicode(   t   PY3RN   RW   RV   (   R&   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyt   __str__   s    N(   R1   R2   R?   t   cloudfront_api_versionRI   R>   R(   R%   RV   RX   R\   (    (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR<      s   			t   Invalidationc           B@  s#   e  Z d    Z d   Z d   Z RS(   c         C@  sB   t  |  } | j d k r1 t d | j   n  |  j |  d  S(   NR^   s*   Expected <Invalidation /> xml, got: <%s />(   R	   R#   R$   R%   (   R&   R4   R'   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR(      s    c         C@  s   t  |  |  _ d  S(   N(   R   R   (   R&   R'   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR%      s    c         C@  s   t  |  j  S(   N(   RQ   R   (   R&   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR\      s    (   R1   R2   R(   R%   R\   (    (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR^      s   		t   InvalidationListc           B@  s#   e  Z d    Z d   Z d   Z RS(   c         C@  sB   t  |  } | j d k r1 t d | j   n  |  j |  d  S(   NR_   s.   Expected <InvalidationList /> xml, got: <%s />(   R	   R#   R$   R%   (   R&   R4   R'   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR(     s    c         C@  s   t  |  |  _ d  S(   N(   R   R   (   R&   R'   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR%     s    c         C@  s   t  |  j  S(   N(   RQ   R   (   R&   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR\     s    (   R1   R2   R(   R%   R\   (    (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR_      s   		t   InvalidationBatchc           B@  sG   e  Z d d g  d   Z d   Z d   Z d   Z d   Z d   Z RS(   c         C@  so   | r | |  _  nC | s! d } n  d | t j t j   d  t j d d  f |  _  g  |  _ |  j |  d  S(   Nt   0s   %s.%s.%ss   %Y%m%d%H%M%Si  i'  (   t	   referenceR   t   strftimet   nowt   randomt   randintt   pathst   add_objects(   R&   Rb   t   distributionRg   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR(     s    		c         C@  s   |  j  j |  d  S(   N(   Rg   t   extend(   R&   Rg   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyRh   *  s    c         C@  s   |  j  S(   N(   Rb   (   R&   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyt   get_reference-  s    c         C@  s   t  j d  } xV |  j D]K } t |  d k  sA | d d k rN d | } n  t d t |  |  q Wt d |  j |  | S(   NR`   i   i    t   /t   PathRL   (   RN   RO   Rg   t   lenR
   R   Rb   (   R&   R'   t   path(    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyRV   0  s    "c         C@  s   t  t j |  j     S(   N(   R   RN   RW   RV   (   R&   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyRX   9  s    c         C@  s6   t  r t j |  j   d d St j |  j    Sd  S(   NRY   RZ   (   R[   RN   RW   RV   (   R&   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR\   <  s    N(	   R1   R2   R>   R(   Rh   Rk   RV   RX   R\   (    (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR`     s   					t
   CloudFrontc           B@  s  e  Z i	 i d  d 6d d 6d 6i d d 6d d 6d 6i d d 6d d 6d	 6i d d 6d d 6d
 6i d d 6d d 6d 6i d d 6d d 6d 6i d  d 6d d 6d 6i d d 6d d 6d 6i d d 6d d 6d 6Z d Z d& Z d   Z d   Z g  d& d& d& d  Z g  g  d& d& d& d& d  Z	 d   Z
 d   Z d   Z d& d  Z d   Z d   Z d   Z d& d& d& d& e d   Z d& d& d& d!  Z d"   Z d#   Z d$   Z d%   Z RS('   t   POSTt   methodRA   t   resourcet
   CreateDistt   DELETEs   /%(dist_id)st
   DeleteDistt   GETt   GetListt   GetDistInfos   /%(dist_id)s/configt   GetDistConfigt   PUTt   SetDistConfigs   /%(dist_id)s/invalidationt
   Invalidatet   GetInvalLists(   /%(dist_id)s/invalidation/%(request_id)st   GetInvalInfoi   c         C@  s   | |  _  d  S(   N(   t   config(   R&   R   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR(   U  s    c         C@  sG   |  j  d  } t | d  | d <| d j d rC t d   n  | S(   NRx   t   datat	   dist_listR5   s3   List is truncated. Ask s3cmd author to add support.(   t   send_requestR3   R   t   NotImplementedError(   R&   t   response(    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyRx   \  s
    c   
      C@  s#  t    } t | j d <| j   | j d d <t |  | j d <| | j d <| d  k ro | j   | j d <n | | j d <xA | D]9 } | j d j |  d k r | j d j |  q q W| r t	 |  | j d	 <n  t |  } t
 d
 |  |  j d d | }	 t |	 d  |	 d <|	 S(   NR)   RJ   RK   RL   RB   R@   R+   i    RD   s&   CreateDistribution(): request_body: %sRt   t   bodyR   Ri   (   R<   t   TrueR   t	   host_nameRQ   R>   t
   public_urlt   countR8   R   R   R   R:   (
   R&   R0   t
   cnames_addt   commentt   loggingt   default_root_objectt   dist_configRE   t   request_bodyR   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyt   CreateDistributiond  s$    	c         C@  s  | j  d k r" t d |   n  t d |  |  j |  } | d }	 | d  k re | |	 j d <n  | d  k r | |	 j d <n  | d  k r | |	 j d <n  xA | D]9 }
 |	 j d j |
  d	 k r |	 j d j |
  q q WxE | D]= }
 x4 |	 j d j |
  d	 k r$|	 j d j |
  q Wq W| d  k rg| t k rQt |	 j d
 <qgt	 |  |	 j d
 <n  |  j
 | |	 | d d  } | S(   Nt   cfs   Expected CFUri instead of: %ss   Checking current status of %sR   R)   R@   RB   R+   i    RD   t   headerst   etag(   R-   R$   R   Rz   R>   R   R8   t   removet   FalseR   R|   (   R&   t   cfuriR   t   cnames_removeR   t   enabledR   R   R   t   dcRE   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyt   ModifyDistributiony  s.    
c         C@  sZ  | j  d k r" t d |   n  t d |  |  j |  } | d j d rt d  t | d j d <|  j | | d | d d  } t d	  t d
  xq t r|  j |  } | d } | j d d k r | j d t k r t d  Pn  t d  t	 j
 d  q Wn  t d t  } | d d | d <|  j d d | j   d | } | S(   NR   s   Expected CFUri instead of: %ss   Checking current status of %sR   R)   s)   Distribution is ENABLED. Disabling first.R   R   s,   Waiting for Distribution to become disabled.s+   This may take several minutes, please wait.Ri   t   Statust   Deployeds   Distribution is now disableds   Still waiting...i
   t   ignore_cases   if-matchRv   t   dist_id(   R-   R$   R   Rz   R   R|   R   R   Ry   t   timet   sleepR   R   R   (   R&   R   R   t   dR   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyt   DeleteDistribution  s0    


	
&

	c         C@  sU   | j  d k r" t d |   n  |  j d d | j   } t | d  | d <| S(   NR   s   Expected CFUri instead of: %sRy   R   R   Ri   (   R-   R$   R   R   R:   (   R&   R   R   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyRy     s
    c         C@  sU   | j  d k r" t d |   n  |  j d d | j   } t | d  | d <| S(   NR   s   Expected CFUri instead of: %sRz   R   R   R   (   R-   R$   R   R   R<   (   R&   R   R   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyRz     s
    c         C@  s   | d  k r0 t d  |  j |  d d } n  t d |  t |  } t d |  t d t  } | | d <|  j d d	 | j   d
 | d | } | S(   Ns1   SetDistConfig(): Etag not set. Fetching it first.R   R   s   SetDistConfig(): Etag = %ss!   SetDistConfig(): request_body: %sR   s   if-matchR|   R   R   (   R>   R   Rz   RQ   R   R   R   R   (   R&   R   R   R   R   R   R   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR|     s    

c      	   C@  s#  | d  k	 r | s | r g  } d | } xp | D]h } | j |  sQ | | k r | rg | j |  n  | r | j | t |    q q0 | j |  q0 W| } n  |  j |  }	 t |  d k rYyp t j   }
 t t |
  d  ' } | j	 t d j
 |  d   Wd  QXt d t |   t d |
  Wn t k
 rIn Xt d   n  g  } x |	 D] } t d | j   d	 |  } t d
 |  |  j d d | j   d t |  } | j   | d <| d d k r t | d  j } | d | d <n  t d |  | j |  qfW| S(   NRl   i  t   ws   
s2   Request to invalidate %d paths (max 999 supported)s"   All the paths are now saved in: %ss   Too many paths to invalidateRi   Rg   s%   InvalidateObjects(): request_body: %sR}   R   R   t   statusi   R   R/   t
   request_ids!   InvalidateObjects(): response: %s(   R>   t   endswithR8   Rn   t   get_dist_name_for_buckett   Utilst	   mktmpfilet   openR   R   t   joinR   t	   Exceptiont   ParameterErrorR`   R   R   R   RQ   R^   R   (   R&   R0   Rg   t   default_index_filet   invalidate_default_index_on_cft#   invalidate_default_index_root_on_cft	   new_pathst   default_index_suffixRo   t   cfurist   tmp_filenamet   fpt	   responsesR   t
   invalbatchR   t
   inval_info(    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyt   InvalidateObjects  sF    
	&c         C@  sU   | j  d k r" t d |   n  |  j d d | j   } t | d  | d <| S(   NR   s   Expected CFUri instead of: %sR~   R   R   t
   inval_list(   R-   R$   R   R   R_   (   R&   R   R   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR~     s
    c         C@  s   | j  d k r" t d |   n  | j   d  k rC t d   n  |  j d d | j   d | j   } t | d  | d <| S(	   NR   s   Expected CFUri instead of: %ss   Expected CFUri with Request IDR   R   R   R   t   inval_status(   R-   R$   R   R>   R   R   R^   (   R&   R   R   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR     s    'c         C@  s  | d  k r t d t  } n  |  j | } | r> d | d <n  |  j | | | |  } |  j   }	 t d | d | d f  |	 j j | d | d | | d  |	 j j	   }
 i  } |
 j
 | d <|
 j | d	 <t |
 j    | d <|
 j   | d
 <t j |	  t d |  | d d k rt |  } | rt d |  t t |   t d |  j |   t j |  j |   |  j | | d | d | d S|  n  | d d k  s| d d k rt |   n  | S(   NR   s
   text/plains   content-types   send_request(): %s %sRr   Rs   R   R   t   reasonR   s   CloudFront: response: %ri  u   Retrying failed request: %ss   Waiting %d sec...R   t   retriesi   i   i+  (   R>   R   R   t
   operationst   create_requestt   get_connectionR   t   ct   requestt   getresponseR   R   R   t
   getheaderst   readR   t   putt   CloudFrontErrorR   RZ   t
   _fail_waitR   R   R   (   R&   t   op_nameR   R   R   R   R   t	   operationR   t   connt   http_responseR   t   e(    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR     s:    % 	 c         C@  s%  t  | d i | d 6| d 6} | s8 t d t  } n  d | k rk d | k ra | d | d <n  | d =n  d | k r t j d t j    | d <n  t |  j j  d k r |  j j	   |  j j | d	 <n  |  j
 |  } d
 |  j j d | | d <i  } | | d <| | d <| d | d <| S(   NRs   R   R   R   t   dates
   x-amz-dates   %a, %d %b %Y %H:%M:%S +0000i    s   x-amz-security-tokens   AWS t   :t   AuthorizationR   Rr   (   t   cloudfront_resourceR   R   R   Rc   t   gmtimeRn   R   t   access_tokent   role_refresht   sign_requestt
   access_key(   R&   R   R   R   R   Rs   t	   signatureR   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR   2  s(    


c         C@  s:   | d } t  t t |    } t d | | f  | S(   Ns
   x-amz-dateu"   CloudFront.sign_request('%s') = %s(   R   R   R   R   (   R&   R   t   string_to_signR   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR   O  s    
c         C@  s   t  j |  j j d t } | S(   Nt   ssl(   R   t   getR   t   cloudfront_hostR   (   R&   R   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR   U  s    c         C@  s   |  j  | d d S(   Ni   i   (   t   _max_retries(   R&   R   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR   Y  s    c         C@  s  | j  d k r | g S| j  d k r8 t d |   n  t d |  t j d  k rW|  j   } i  t _ x | d j D] } d } d | j k r t	 | j d d  d	 } nF d
 | j k rx t	 | j d
 d  d	 } | t
 | j     } n qx t j j | d   d  k r%t   t j | <n  t j | j | j    qx Wt d t j  n  y t j | j   SWn- t k
 r} t |  t d |   n Xd  S(   NR   t   s3s,   CloudFront or S3 URI required instead of: %ss   _get_dist_name_for_bucket(%r)R   RA   RJ   RK   i    t   CustomOrigins   dist_list: %ss>   Unable to translate S3 URI to CloudFront distribution name: %s(   R-   R   R   Rp   R   R>   Rx   R6   R   R   Rn   RR   R   t   sett   addR0   R   (   R&   R0   R   R   t   distListIndexR   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR   ]  s2    	
N(   R1   R2   R   R   R>   R   R(   Rx   R   R   R   Ry   Rz   R|   R   R~   R   R   R   R   R   R   R   (    (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyRp   D  s>   							.		$			t   Cmdc           B@  s   e  Z d  Z d e f d     YZ e   Z e d    Z e d    Z e d    Z	 e d    Z
 e d    Z e d    Z RS(	   s3   
    Class that implements CloudFront commands
    t   Optionsc           B@  s>   e  Z g  Z g  Z d Z d Z d Z d Z d    Z	 d   Z
 RS(   c         C@  s,   g  t  |   D] } | j d  r | ^ q S(   Nt   cf_(   t   dirt
   startswith(   R&   t   opt(    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyt   option_list  s    c         C@  s   t  t j | |  d  S(   N(   t   setattrR   t   options(   R&   t   optiont   value(    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyt   update_option  s    N(   R1   R2   t   cf_cnames_addt   cf_cnames_removeR>   t
   cf_commentt	   cf_enablet
   cf_loggingt   cf_default_root_objectR   R   (    (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR     s   	c         C@  sL   t  t    } g  } x0 |  D]( } | j t |   } | j |  q W| S(   N(   Rp   R   R   R   Rj   (   t   argsR   R   t   argt   uris(    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyt   _parse_args  s    c         C@  s  t  t    } |  s*| j   } x| d j D] } d | j k ra t j | j d d  } n- d | j k r d | j d d } n d } t d |  t d | j    t d	 | j d	  d
 | j k r t d d j	 | j d
   n  t d | j d  t d | j d  t
 d  q/ Wnt j |   } xo| D]g} | j |  } | d } | j d } d | j k rt j | j d d  } n- d | j k rd | j d d } n d } t d |  t d | j    t d	 | j d	  d
 | j k r(t d d j	 | j d
   n  t d | j d  t d | j d  t d | j d  t d | j d  t d | j d pd  t d | d d  q@Wd  S(   NR   RJ   RK   R   s
   http://%s/s	   <unknown>t   Origint   DistIdt
   DomainNameR+   t   CNAMEss   , R   R)   RA   Ri   R<   R@   t   DfltRootObjectRB   RD   t   Disabledt   EtagR   R   (   Rp   R   Rx   R6   R   R   t   httpurl_to_s3uriR!   R0   R   R   R   R   Ry   (   R   R   R   R   t   originR   R   R   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR     sL     
 c         C@  s  t  t    } g  } x |  D]{ } t |  } | j d k rP t d |   n  | j   ro t d |   n  | j   s t d   n  | j |  q W| s t d   n  xF| D]>} t d |  | j	 | d t
 j j d t
 j j d	 t
 j j d
 t
 j j } | d } | j d } t d  t d t j | j d d   t d | j    t d | j d  t d d j | j d   t d | j d  t d | j d  t d | j d  t d | j d  t d | d d  q Wd  S(   NR   s@   Distribution can only be created from a s3:// URI instead of: %ss4   Use s3:// URI with a bucket name only instead of: %ss3   CloudFront can only handle lowercase-named buckets.s   No valid bucket names founds   Creating distribution from: %sR   R   R   R   Ri   R<   s   Distribution created:R   RJ   RK   R   R   R   s   , R+   R@   R   R)   RB   R   R   R   (   Rp   R   R   R-   R   RS   t   is_dns_compatibleR8   R   R   R   R   R   R   R   R   R   R!   R   R   R0   R   (   R   R   t   bucketsR   R0   R   R   R   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyt   create  s>    

!c         C@  s{   t  t    } t j |   } xV | D]N } | j |  } | d d k re t d | | d f  n  t d |  q% Wd  S(   NR   i  s(   Distribution %s could not be deleted: %sR   s   Distribution %s deleted(   Rp   R   R   R   R   R   R   (   R   R   R   R   R   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyt   delete  s    c         C@  s  t  t    } t |   d k r0 t d   n  y t j |   d } Wn t k
 rf t d   n X| j | d t j j	 d t j j
 d t j j d t j j d	 t j j d
 t j j } | d d k r t d | | d f  n  t d |  | j |  } | d } | j d } t d t j | j d d   t d | j    t d | j d  t d | j d  t d d j | j d   t d | j d  t d | j d  t d | j d  t d | d d   d  S(!   Ni   s7   Too many parameters. Modify one Distribution at a time.i    s    No valid Distribution URI found.R   R   R   R   R   R   R   i  s)   Distribution %s could not be modified: %sR   s   Distribution modified: %sRi   R<   R   RJ   RK   R   R   R   R   s   , R+   R@   R)   RB   R   R   R   (   Rp   R   Rn   R   R   R   t
   IndexErrorR   R   R   R   R   R   R   R   R   R   Ry   R   R!   R   R   R0   R   (   R   R   R   R   R   R   (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyt   modify  s:    
!c         C@  s  t  t    } t j |   } g  } x | D] } | j   rS | j t |   q+ | j |  } yI xB | d j d D]/ } | j d j	 d | j
   | d g   qw WWq+ t k
 r q+ q+ Xq+ Wx | D] } t |  } | j |  } | d j }	 |	 d d }
 t |
 t  r$t |
  n d	 } t d
 t |   t d |	 d  t d |	 d  t d |  t d |	 d d  t d  q Wd  S(   NR   t   InvalidationSummaryRl   s   cf:/R/   R   R`   Rm   i   t   URIR   t   Createdt
   CreateTimes   Nr of pathst	   ReferenceRL   RA   (   Rp   R   R   R   R   R8   RQ   R~   R   R   R   R   R   R   t
   isinstanceR.   Rn   R!   R   (   R   R   R   t   requestsR   R   t   it   reqR   t   stRg   t   nr_of_paths(    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyt	   invalinfo  s0    1!(   R1   R2   t   __doc__RS   R   R   t   staticmethodR   R   R  R  R  R  (    (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyR     s   		,"
 (7   t
   __future__R    R   R   Re   R   R   R   R   R   R   t   xml.etree.ElementTreet   etreet   ElementTreeRN   t   ImportErrort   elementtree.ElementTreeR   R   t
   Exceptionst	   BaseUtilsR	   R
   R   R   R   R   R   R   R   R   R   R   t   CryptoR   R   R   R   R   t   version_infoR[   R]   R   R   R!   RS   R"   R3   R:   R<   R^   R_   R`   Rp   R   (    (    (    sM   /oak/stanford/groups/akundaje/marinovg/programs/s3cmd-master/S3/CloudFront.pyt   <module>	   sB   "
.(		T1 @