o d@s~dZddlZddlZddlmZddlZddlZddlZddl m Z dZ Gdddej j ZGd d d Zdd efd d ZdS)z( Implementation for HTTP upload method. N)HTTPConnection) dputhelperzutf-8c@s eZdZdZddZddZdS)PromptingPasswordMgrz Password manager that prompts at the terminal. Custom HTTP password manager that prompts for a password using getpass() if required, and mangles the saved URL so that only one password is prompted for. cCstjj|||_dSN)urllibrequestHTTPPasswordMgr__init__username)selfr r $/usr/share/dput/dput/methods/http.pyr s zPromptingPasswordMgr.__init__cCsV||d}tjj|||}|dkr|Std|}||||j||j|fS)Nr)NNz Password for %s:) reduce_urirrr find_user_passwordgetpass add_passwordr )r realmauthuriauthinfopasswordr r rr$s z'PromptingPasswordMgr.find_user_passwordN)__name__ __module__ __qualname____doc__r rr r r rrs rc@s@eZdZdZddZddZddZdd Zd d Zd d Z dS)AuthHandlerHackAroundz! Fake request and parent object. cCsVi|_||_||_g|_i|_tjjtjjfD]}||}| ||j |qdSr) headersurl resp_headers authhandlerstimeoutrrHTTPBasicAuthHandlerHTTPDigestAuthHandler add_parentappend)r rrpwmanauthhandler_classahr r rr 4s zAuthHandlerHackAround.__init__cC||j|<dSrrr kvr r r add_headerEz AuthHandlerHackAround.add_headercCr(rr)r*r r radd_unredirected_headerHr.z-AuthHandlerHackAround.add_unredirected_headercCs|jSr)r)r r r r get_full_urlKsz"AuthHandlerHackAround.get_full_urlcOsdSrr )r argskeywordsr r ropenOszAuthHandlerHackAround.openc CsZ|jD] }z ||ddd|jWqty#}zWYd}~qd}~ww|jr*|jS|jS)N)rhttp_error_401r ValueErrorr)r r'er r rget_auth_headersSs  z&AuthHandlerHackAround.get_auth_headersN) rrrrr r-r/r0r3r8r r r rr1s rhttpc Cs|dvrtjdtd|dsd|}|ds!|d7}|dd} i} t|} | rR| d} tj | \} }tj d|tj zt | j }Wntygtjd| tdYnwt| d }|rytj||tj|d }||}d |||f}|rtj d |||}|jd |dd|dd| D] \}}|||q|dd|dt||d}||kr|d}|||t|7}||ks|d}|}|jdkr|jdkrtj d| d=nQ|jdkr| stj dt||j| } n8|jdkr"tj d|j n tj d|j|j f|!t"}|rE|rEtj dj#|dtd|| s0dSdS) z Upload the files via WebDAV. )r9httpsz,Wrong protocol for upload http[s].py method /Nrz Uploading %s: z%Determining size of file '%s' failed rb)ptype progressfsizez %s://%s%szD: HTTP-PUT to URL: %s PUTT)skip_accept_encodingz User-Agentdput ConnectionclosezContent-Lengthii,zdone. r4zneed authentication. zFUpload failed as unauthorized: %s Maybe wrong username or password? zUpload failed: %d %s zD: Response body: {body} )body)$sysstderrwriteexit startswithendswithrospathsplitstdoutflushstatst_size Exceptionr3rFileWithProgress putrequest putheaderitemsstr endheadersreadsendlenrE getresponsestatusrmsgr8reasondecodeMESSAGE_BODY_ENCODINGformat)fqdnloginincomingfiles_to_uploaddebugdummyprogressprotocolconnection_classunprocessed_files_to_upload auth_headersr% file_pathfile_directory file_namer@furl_pathrconnr+r,possres response_bodyr r rupload^s                   r|)rr http.clientr9rrOrIurllib.requestrhelperrrerr rrr|r r r rs  /