o Qa @sddlmZmZddlZddlmZddlmZddlm Z m Z ddl m Z z ddl mmZWney@ddlmZYnwejdkZgZGd d d eZed ed kreZeeeed eeed eeedeeeeedSdS))absolute_importprint_functionN)S3Uri)ParameterError)getTreeFromXmldecode_from_s3)GranteeAnonRead)rc@s^eZdZdZdZdddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ dS) AccessLogz+z[NcCs$|s|j}t||_d|jjd<dS)Nz&http://doc.s3.amazonaws.com/2006-03-01xmlns) LOG_DISABLEDrtreeattrib)selfxmlr./usr/lib/python3/dist-packages/S3/AccessLog.py__init__s zAccessLog.__init__cCs|jdduSN.//LoggingEnabled)rfindrrrrisLoggingEnabled$zAccessLog.isLoggingEnabledcCs$|jd}|r|j|dSdSr)rrremove)relrrrdisableLogging's zAccessLog.disableLoggingcCsJ|jd}|st|j}|j|||d_||d_dS)Nrz.//TargetBucketz.//TargetPrefix)rrr LOG_TEMPLATEappendbuckettextobject)rtarget_prefix_urirrrr enableLogging,s   zAccessLog.enableLoggingcCs6|rd|jdj|jdjf}t|SdS)Nz s3://%s/%sz.//LoggingEnabled//TargetBucketz.//LoggingEnabled//TargetPrefix)rrrr!r)r target_prefixrrr targetPrefix4s   zAccessLog.targetPrefixcCsh|jd}|durtd|d}|s |sdS||dSt}|s-t|d}||dS)Nrz3Logging not enabled, can't set default ACL for logsz.//TargetGrants TargetGrants) rrrrr getElementET SubElementr)r acl_publicletg anon_readrrr setAclPublic=s    zAccessLog.setAclPubliccCstN)NotImplementedErrorrrrr isAclPublicPszAccessLog.isAclPubliccCstt|jSr1)rr*tostringrrrrr __unicode__SrzAccessLog.__unicode__cCs tr tj|jddSt|jS)Nunicode)encoding)PY3r*r4rrrrr__str__Vs zAccessLog.__str__r1)__name__ __module__ __qualname__r rrrrr$r'r0r3r5r9rrrrr s   r __main__zs3://targetbucket/prefix/log-TF) __future__rrsysr%r Exceptionsr BaseUtilsrrACLr xml.etree.ElementTreeetree ElementTreer* ImportErrorelementtree.ElementTree version_infor8__all__r"r rr:logprintr$r0rrrrrs6      D