FRTc@sddlZddlZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z m Z ddl mZddlmZddlmZddlmZddlmZd efd YZdS( iN(tmd5(tconfigt UserAgent(tAWSAuthConnection(tInvalidUriError(tResumableTransferDisposition(tResumableUploadException(tKeyFiletResumableUploadHandlercBseZdZejeejejfZ dZ dddZ dZ dZdZdZdZd Zd d d Zd Zd ZddZdZdZdZdZeddZddddZRS(i iicCsD||_||_d|_d|_|r7|jnd|_dS(s  Constructor. Instantiate once for each uploaded file. :type tracker_file_name: string :param tracker_file_name: optional file name to save tracker URI. If supplied and the current process fails the upload, it can be retried in a new process. If called with an existing file containing a valid tracker URI, we'll resume the upload from this URI; else we'll start a new resumable upload (and write the URI to this tracker file). :type num_retries: int :param num_retries: the number of times we'll re-try a resumable upload making no progress. (Count resets every time we get progress, so upload can span many more than this number of retries.) iN(ttracker_file_namet num_retriestserver_has_bytestNonet tracker_urit_load_tracker_uri_from_filetupload_start_point(tselfR R ((sM/opt/freeware/lib/python2.7/site-packages/boto/gs/resumable_upload_handler.pyt__init__@s     cCsd}zy5t|jd}|jj}|j|Wnatk r}}|jtjkrd|j|j fGHqn%t k r}d||jfGHnXWd|r|j nXdS(NtrsHCouldn't read URI tracker file (%s): %s. Restarting upload from scratch.sXInvalid tracker URI (%s) found in URI tracker file (%s). Restarting upload from scratch.( R topenR treadlinetstript_set_tracker_uritIOErrorterrnotENOENTtstrerrorRtclose(Rtfturite((sM/opt/freeware/lib/python2.7/site-packages/boto/gs/resumable_upload_handler.pyR[scCs|js dSd}yKtjtj|jtjtjBdd}|j|jWdQXWn5t k r}t d|j|j ft j nXdS(sM Saves URI to tracker file if one was passed to constructor. NitwsCouldn't write URI tracker file (%s): %s. This can happenif you're using an incorrectly configured upload tool (e.g., gsutil configured to save tracker files to an unwritable directory)(R R tostfdopenRtO_WRONLYtO_CREATtwriteR RRRRtABORT(RRR((sM/opt/freeware/lib/python2.7/site-packages/boto/gs/resumable_upload_handler.pyt_save_tracker_uri_to_filess cCs|tj|}|jjdks.|j rAtd|n||_|j|_d|j|jf|_ d|_ dS(s Called when we start a new resumable upload or get a new tracker URI for the upload. Saves URI and resets upload state. Raises InvalidUriError if URI is syntactically invalid. thttpthttpssInvalid tracker URI (%s)s%s?%siN(shttpshttps( turlparsetschemetlowertnetlocRR ttracker_uri_hosttpathtqueryttracker_uri_pathR (RRt parse_result((sM/opt/freeware/lib/python2.7/site-packages/boto/gs/resumable_upload_handler.pyRs   cCs|jS(sX Returns upload tracker URI, or None if the upload has not yet started. (R (R((sM/opt/freeware/lib/python2.7/site-packages/boto/gs/resumable_upload_handler.pytget_tracker_uriscCsGd}|jr?||jkr?|j|jj|t|SdSdS(st Returns the upload ID for the resumable upload, or None if the upload has not yet started. s ?upload_id=N(R tindextlenR (Rtdelim((sM/opt/freeware/lib/python2.7/site-packages/boto/gs/resumable_upload_handler.pyt get_upload_ids !cCs5|jr1tjj|jr1tj|jndS(N(R R R.texiststunlink(R((sM/opt/freeware/lib/python2.7/site-packages/boto/gs/resumable_upload_handler.pyt_remove_tracker_files t*cCsd||fS(Ns bytes %s/%s((Rt range_spect length_spec((sM/opt/freeware/lib/python2.7/site-packages/boto/gs/resumable_upload_handler.pyt_build_content_range_headersc CsWi}|jd||dGot status %d from attempt to start resumable upload. AbortingtLocationsINo resumable tracker URI found in resumable initiation POST response (%s)N(ii(tbuckett connectionRUR R+RRR%tprovidertresumable_upload_headerRCtnametreadRItWAIT_BEFORE_RETRYRLRR&( RtkeyRARDt post_headerstkRVtbodyR ((sM/opt/freeware/lib/python2.7/site-packages/boto/gs/resumable_upload_handler.pyt_start_new_resumable_uploadsB     c  Cs|j|j} |rm|dkr<||j|d} n|dkrQd} nd} d} |||n|s|i} n |j} |r||kr|jd|} n |jd||df|} | | dystBotoR ic3s(|]}|j|jfVqdS(N(RtRm(RR(R(sM/opt/freeware/lib/python2.7/site-packages/boto/gs/resumable_upload_handler.pys sisResumable upload complete.NsCaught exception (%s)('R Rt isinstanceRtgetkeytsizeRR tSEEK_ENDttellR_R`RURtdictRtR RtgetintRRQR RRt generationtmetagenerationtdigestt local_hashesR9RtRETRYABLE_EXCEPTIONSt__repr__RRtEPIPERRRR(RRfRyRAR{R|RtCTRERURRkRR((RRsM/opt/freeware/lib/python2.7/site-packages/boto/gs/resumable_upload_handler.pyt send_file;sX%      "        ! (iiN(t__name__t __module__Rlthttplibt HTTPExceptionRRRtgaierrorRRRR RRR&RR2R6R9R=RGR[RjRRRRRQRR(((sM/opt/freeware/lib/python2.7/site-packages/boto/gs/resumable_upload_handler.pyR6s*         4 : ^ ^  (RRR RRMRRR)thashlibRtbotoRRtboto.connectionRtboto.exceptionRRRtboto.s3.keyfileRtobjectR(((sM/opt/freeware/lib/python2.7/site-packages/boto/gs/resumable_upload_handler.pyts