o Qal%@sddlmZmZddlZddlZddlmZddlmZm Z m Z ddl Z ddl mmZddlmZzddlZWneyRejdejeeYnwzddlmZWneyjddlmZYnwzeWn eyzeZYnwgZ e!d Z"e!d ej#Z$d d Z%e &d d dZ'e &dddZ(e &dddZ)e &dddZ*e &dd;ddZ+e &dd;ddZ,e &ddd#d$Z0e &d$d?d%d&Z1e &d&d'd(Z2e &d(d)d*Z3e &d*d+d,Z4e &d,d-d.Z5e &d.d/d0Z6e &d0d1d2Z7e &d2d3d4Z8e &d4d5d6Z9e &d6d7d8Z:e &d8d9d:Z;e &d:dS)@)absolute_importdivisionN)timegm)debugwarningerror) EX_OSFILEa* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ImportError trying to import dateutil.parser. Please install the python dateutil module: $ sudo apt-get install python-dateutil or $ sudo yum install python-dateutil or $ pip install python-dateutil !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! )quotez\.[0-9]*(?:[Z\-\+]*?)s9^(]+?>\s*|\s*)(<\w+) xmlns=['"](https?://[^'"]+)['"]cCstd|}tjj|ddS)Nz.000Tfuzzy)RE_S3_DATESTRINGsubdateutilparserparsedater./usr/lib/python3/dist-packages/S3/BaseUtils.pydateS3toPython?s rcCtt|SN)rr utctimetuplerrrr dateS3toUnixFsrcCstjj|ddS)zV Convert a string formated like '2020-06-27T15:56:34Z' into a python datetime Tr )rrrrrrrdateRFC822toPythonLsrcCrr)rrrrrrrdateRFC822toUnixTsrcCstjj|dd}|dS)NTr z%Y-%m-%d %H:%M)rrrstrftime) s3timestampdate_objrrrformatDateTimeYs r UTF-8replaceFcCsNt|tkr|S|std||fzt|||WSty&td|w)z< Convert 'string' to Unicode or raise an exception. zUnicodising %r using %sz Conversion to unicode failed: %r)typeunicoderUnicodeDecodeErrorstringencodingerrorssilentrrrbase_unicodisebs   r+cCsNt|tkr|S|std||fz|||WSty&td|w)z Convert unicode 'string' to , by default replacing all invalid characters with '?' or raise an exception. zDeUnicodising %r using %sz"Conversion from unicode failed: %r)r#r$rencodeUnicodeEncodeErrorr&rrrbase_deunicodisers   r.cCt|d|dS)zE Convert S3 UTF-8 'string' to Unicode or raise an exception. r!T)r+r'r)rrrdecode_from_s3sr1cCr/)z Convert Unicode to S3 UTF-8 'string', by default replacing all invalid characters with '?' or raise an exception. r!T)r.r0rrr encode_to_s3sr2TcCs>|rd}nd}t|}t||d}|rt|}|St|}|S)a URI encode every byte. UriEncode() must enforce the following rules: - URI encode every byte except the unreserved characters: 'A'-'Z', 'a'-'z', '0'-'9', '-', '.', '_', and '~'. - The space character is a reserved character and must be encoded as "%20" (and not as "+"). - Each URI encoded byte is formed by a '%' and the two-digit hexadecimal value of the byte. - Letters in the hexadecimal value must be uppercase, for example "%1A". - Encode the forward slash character, '/', everywhere except in the object key name. For example, if the object key name is photos/Jan/sample.jpg, the forward slash in the key name is not encoded. ~~/safe)r2r r1)paramquote_backslashesunicode_output safe_charsrrrs3_quotes  r;cCsDt|}|dkr |St|dd}td||f|rt|St|S)Nverbatimr4r5zString '%s' encoded to '%s')r2r rr1)r'urlencoding_moder9encodedrrrbase_urlencode_strings r?cCsd}d}|D],}t|}|dkr!|dttd|7}|d7}q|dkr.|d7}|d7}q||7}q|r?|r?td ||f|S) z replace_nonprintables(string) Replaces all non-printable characters 'ch' in 'string' where ord(ch) <= 26 with ^@, ^A, ... ^Z r^@rz^?z+%d non-printable characters replaced in: %s)ordchrr)r' with_message new_stringmodifiedcorrrbase_replace_nonprintabless   rLcCs~g}|D]8}i}|D]*}t|j}t|rt|g||<q |d|j}|dur0t|||<q d||<q |r<||q|SNz.//%s)r1taglen parseNodesfindtextappend)nodesretvalnode retval_itemchildname found_textrrrrPs   rPcCstjj|}|Sr)xmldomminidom parseString toprettyxml)xmlstr xmlparserrrrgetPrettyFromXmlsracCs:t|}|r|d}td|d}||fSd}||fS)zy removeNameSpace(xml) -- remove top-level AWS namespace Operate on raw byte(utf-8) xml string. (Not unicode) z\1\2rN)RE_XML_NAMESPACEmatchgroupr)rZ xmlns_matchxmlnsrrrstripNameSpaces  rhc Cs\tt|\}}zt|}|r||jd<|WSty-}z td|t|d}~ww)NrgzError parsing xml: %s)rhr2ET fromstringattrib Exceptionr)rZrgtreeerrrgetTreeFromXmls   rocCst|}|d|}t|SrM)rofindallrP)rZrUrmrSrrrgetListFromXmlsrqcCsi}|D]?}t|rt|}n |jdurt|jnd}t|j}||vr=t||tks3||g||<|||p:dq|p@d||<q|S)Nr@)rOgetDictFromTreetextr1rNr#listrR)rmret_dictrWcontent child_tagrrrrrs  rrcCsJt|}|j|r|jdurt|jSdS||}|dur#t|SdSr)rorNendswithrsr1rQ)rZxpathrmresultrrrgetTextFromXml.s   r{cCs t|}|jdurt|jSdSr)rorNr1)rZrmrrrgetRootTagName8sr|cCst|}t||_|Sr)riElementr1rs)tag_namerselrrr xmlTextNode>s  rcCst||}|||S)z Creates a new Node and sets its content to 'text'. Then appends the created Node to 'parent' element if given. Returns the newly created Node. )rrR)r~rsparentrrrrappendXmlTextNodeEs  r)r!r"F)r")TF)NF)F)< __future__rrresyscalendarrloggingrrrxml.dom.minidomrZxml.etree.ElementTreeetree ElementTreeri ExitCodesr dateutil.parserr ImportErrorstderrwriteflushexiturllibr urllib.parser$ NameErrorstr__all__compiler MULTILINErcrrRrrrr r+r.r1r2r;r?rLrPrarhrorqrrr{r|rrrrrrs