ó {r Qc@sæddlZddlZddlZddlZddlZddlZddlZddlmZmZddl m Z ddl m Z ddl m Z ddlmZdefd„ƒYZed „Zd efd „ƒYZdS( iÿÿÿÿN(tconfigtstorage_uri_for_key(tAWSAuthConnection(tResumableDownloadException(tResumableTransferDisposition(tKeyFiletByteTranslatingCallbackHandlercBs eZdZd„Zd„ZRS(s” Proxy class that translates progress callbacks made by boto.s3.Key.get_file(), taking into account that we're resuming a download. cCs||_||_dS(N(t proxied_cbtdownload_start_point(tselfRR((sE/tmp/tmp.yUYbTOKr8o/gsutil/boto/boto/s3/resumable_download_handler.pyt__init__?s cCs|j|j||ƒdS(N(RR(R ttotal_bytes_uploadedt total_size((sE/tmp/tmp.yUYbTOKr8o/gsutil/boto/boto/s3/resumable_download_handler.pytcallCs(t__name__t __module__t__doc__R R (((sE/tmp/tmp.yUYbTOKr8o/gsutil/boto/boto/s3/resumable_download_handler.pyR9s cCswt|tƒr#| r#|jƒjS|s8|jƒ}n|jdtjƒ|jƒ}|ss|j|tjƒn|S(sH Returns size of file, optionally leaving fp positioned at EOF. i( t isinstanceRtgetkeytsizettelltseektostSEEK_ENDtSEEK_SET(tfptposition_to_eoftcur_post cur_file_size((sE/tmp/tmp.yUYbTOKr8o/gsutil/boto/boto/s3/resumable_download_handler.pytget_cur_file_sizeHs  tResumableDownloadHandlercBsweZdZdZejeejej fZ d d d„Z d„Z d„Zd„Zd„Zd ded d„ZRS( s* Handler for resumable downloads. s([a-z0-9]{32}) cCs;||_||_d|_|r.|jƒnd|_dS(s Constructor. Instantiate once for each downloaded file. :type tracker_file_name: string :param tracker_file_name: optional file name to save tracking info about this download. If supplied and the current process fails the download, it can be retried in a new process. If called with an existing file containing an unexpired timestamp, we'll resume the transfer for this file; else we'll start a new resumable download. :type num_retries: int :param num_retries: the number of times we'll re-try a resumable download making no progress. (Count resets every time we get progress, so download can span many more than this number of retries.) N(ttracker_file_namet num_retriestNonetetag_value_for_current_downloadt_load_tracker_file_etagR(R RR ((sE/tmp/tmp.yUYbTOKr8o/gsutil/boto/boto/s3/resumable_download_handler.pyR bs     cCsÃd}z¢y^t|jdƒ}|jƒ}tj|j|ƒ}|rZ|jdƒ|_n d|jGHWn=t k r¦}|j t j kr§d|j|j fGHq§nXWd|r¾|j ƒnXdS(NtrisJCouldn't read etag in tracker file (%s). Restarting download from scratch.sJCouldn't read URI tracker file (%s): %s. Restarting download from scratch.(R!topenRtreadlinetretsearcht ETAG_REGEXtgroupR"tIOErrorterrnotENOENTtstrerrortclose(R tft etag_linetmte((sE/tmp/tmp.yUYbTOKr8o/gsutil/boto/boto/s3/resumable_download_handler.pyR#~s   cCs©|jjdƒ|_|js"dSd}zfy*t|jdƒ}|jd|jƒWn5tk rŒ}td|j|j ft j ƒ‚nXWd|r¤|j ƒnXdS(Ns"'tws%s s·Couldn't write tracker file (%s): %s. This can happenif you're using an incorrectly configured download tool (e.g., gsutil configured to save tracker files to an unwritable directory)( tetagtstripR"RR!R%twriteR+RR.RtABORTR/(R tkeyR0R3((sE/tmp/tmp.yUYbTOKr8o/gsutil/boto/boto/s3/resumable_download_handler.pyt_save_tracker_info–s cCs5|jr1tjj|jƒr1tj|jƒndS(N(RRtpathtexiststunlink(R ((sE/tmp/tmp.yUYbTOKr8o/gsutil/boto/boto/s3/resumable_download_handler.pyt_remove_tracker_fileªs c Cs„t|dtƒ}|r|jr|j|jjdƒkr||jkr‚td|j|tt |ƒƒ|jft j ƒ‚n0||jkr²|j j jdkr®dGHndS|j j jdkrÏdGHn|jƒ}d||jdf|d tRETRYABLE_EXCEPTIONSt__repr__RR+R,tEPIPERIRt dispositionRtABORT_CUR_PROCESStmessageR8R/thttplibtIncompleteReadttimetsleep( R R9RRKRLRMRNRORFtprogress_less_iterationsthad_file_bytes_before_attemptR3tsleep_time_secs((sE/tmp/tmp.yUYbTOKr8o/gsutil/boto/boto/s3/resumable_download_handler.pyRIÛsl%       !             N(RRRR)RYt HTTPExceptionR+tsocketterrortgaierrorRSR!R R#R:R>RPtFalseRI(((sE/tmp/tmp.yUYbTOKr8o/gsutil/boto/boto/s3/resumable_download_handler.pyRXs     , (R,RYRR'RaR[tbotoRRtboto.connectionRtboto.exceptionRRtboto.s3.keyfileRtobjectRRdRR(((sE/tmp/tmp.yUYbTOKr8o/gsutil/boto/boto/s3/resumable_download_handler.pyts