o ckF[¦ã@s‚ddlZddlZddlZddlmZdZdeZdZefdd„Zefdd „Z d d „Z dd d „Z dd„Z dd„Z Gdd„deƒZdS)éN)Úsixééé'cCspt}|t|kr4|dtdkrtd|ƒ‚|d}d}||kr.t t|¡}|d7}||ks t|ƒ}|S|}|S)a"Calculate the minimum part size needed for a multipart upload. Glacier allows a maximum of 10,000 parts per upload. It also states that the maximum archive size is 10,000 * 4 GB, which means the part size can range from 1MB to 4GB (provided it is one 1MB multiplied by a power of 2). This function will compute what the minimum part size must be in order to upload a file of size ``size_in_bytes``. It will first check if ``default_part_size`` is sufficient for a part size given the ``size_in_bytes``. If this is not the case, then the smallest part size than can accomodate a file of size ``size_in_bytes`` will be returned. If the file size is greater than the maximum allowed archive size of 10,000 * 4GB, a ``ValueError`` will be raised. irzFile size too large: %séé)Ú _MEGABYTEÚMAXIMUM_NUMBER_OF_PARTSÚ ValueErrorÚmathÚldexpÚint)Ú size_in_bytesÚdefault_part_sizeÚ part_sizeÚ min_part_sizeÚpower©rú4/usr/lib/python3/dist-packages/boto/glacier/utils.pyÚminimum_part_size"s   þÿrcCsttt t|ƒt|ƒ¡ƒ}g}t|ƒD]}||}|d|}| t |||…¡  ¡¡q|s8t d¡  ¡gS|S)Nró) r r ÚceilÚlenÚfloatÚrangeÚappendÚhashlibÚsha256Údigest)Ú bytestringÚ chunk_sizeÚ chunk_countÚhashesÚiÚstartÚendrrrÚ chunk_hashesJs  r&cCsžg}| |¡t|ƒdkrKg} t|ƒdkr-| d¡}| d¡}| t ||¡ ¡¡nt|ƒdkr>| d¡}| |¡nnq| |¡t|ƒdks |dS)z¤ Given a hash of each 1MB chunk (from chunk_hashes) this will hash together adjacent hashes until it ends up with one big one. So a tree of hashes. rTr)ÚextendrÚpoprrrr)Úfor"Ú new_hashesÚfirstÚsecondÚonlyrrrÚ tree_hashVs"        ÷ ô r.cCs°tjrt|dƒrd|jvrtdƒ‚t ¡}g}| |¡}|rDt|t ƒs.|  t |ddƒp,d¡}|  |¡|  t |¡ ¡¡| |¡}|s|sNt d¡ ¡g}| ¡tt|ƒƒfS)aÎCompute the linear and tree hash from a fileobj. This function will compute the linear/tree hash of a fileobj in a single pass through the fileobj. :param fileobj: A file like object. :param chunk_size: The size of the chunks to use for the tree hash. This is also the buffer size used to read from `fileobj`. :rtype: tuple :return: A tuple of (linear_hash, tree_hash). Both hashes are returned in hex. ÚmodeÚbz/File-like object must be opened in binary mode!ÚencodingÚzutf-8r)rÚPY3Úhasattrr/r rrÚreadÚ isinstanceÚbytesÚencodeÚgetattrÚupdaterrÚ hexdigestÚ bytes_to_hexr.)Úfileobjr Ú linear_hashÚchunksÚchunkrrrÚcompute_hashes_from_fileobjns    ø rAcCs t |¡S©N)ÚbinasciiÚhexlify©Ú str_as_bytesrrrr<”s r<cCsttt|ƒƒƒS)z² :type str_as_bytes: str :param str_as_bytes: The string for which to compute the tree hash. :rtype: str :return: The computed tree hash, returned as hex. )r<r.r&rErrrÚtree_hash_from_str˜s rGc@seZdZdd„Zdd„ZdS)ÚResettingFileSendercCs||_| ¡|_dSrB)Ú_archiveÚtellÚ_starting_offset)ÚselfÚarchiverrrÚ__init__¦szResettingFileSender.__init__c Cs<z| |||j|¡| ¡W|j |j¡S|j |j¡wrB)ÚrequestrIÚ getresponseÚseekrK)rLÚ connectionÚmethodÚpathÚbodyÚheadersrrrÚ__call__ªs zResettingFileSender.__call__N)Ú__name__Ú __module__Ú __qualname__rNrWrrrrrH¥s rH)r)rr rCÚ boto.compatrrÚDEFAULT_PART_SIZEr rr&r.rAr<rGÚobjectrHrrrrÚs   ( &