-=[ Mr. Bumblebee ]=-
_Indonesia_

Path : /usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/
File Upload :
Current File : //usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyc

ó
X`Oc@@sddZddlmZddlmZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
mZmZmZddlmZmZmZmZddlmZmZddlmZmZmZmZmZed	ƒd
ejfd„ƒYZ de!fd
„ƒYZ"dZ#dZ$defd„ƒYZ%d„Z&dS(sÁImplementation of Transport over ftp.

Written by Daniel Silverstone <dsilvers@digital-scurf.org> with serious
cargo-culting from the sftp transport and the http transport.

It provides the ftp:// and aftp:// protocols where ftp:// is passive ftp
and aftp:// is active ftp. Most people will want passive ftp for traversing
NAT and other firewalls, so it's best to use it unless you explicitly want
active, in which case aftp:// will be your friend.
i(tabsolute_import(tStringION(tconfigterrorstosutilsturlutils(tDEPRECATED_PARAMETERt
deprecated_intdeprecated_passedtwarn(tmuttertwarning(tAppendBasedFileStreamtConnectedTransportt
_file_streamst!register_urlparse_netloc_protocoltServertaftptFtpPathErrorcB@seZdZRS(s&FTP failed for path: %(path)s%(extra)s(t__name__t
__module__t__doc__(((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyR@st
FtpStatResultcB@seZd„ZRS(cC@swy"|j|ƒ|_tj|_WnNtjk
rr|jƒ}z|j|ƒtj	|_Wd|j|ƒXnXdS(N(
tsizetst_sizetstattS_IFREGtst_modetftplibt
error_permtpwdtcwdtS_IFDIR(tselftftabspathR((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyt__init__Fs
(RRR$(((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyRDsiitFtpTransportcB@sUeZdZd!d„Zd„ZejZd!d„Z	d„Z
d„Zd„Zd!e
d„Zd„Zd	d
„Zd!d	d„Zd!d„Zd!d
„Zd„Zd„Zd!d„Zd!d	d„Zd!d„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z!d„Z"d„Z#d„Z$d„Z%d „Z&RS("s.This is the transport agent for ftp:// access.cC@s†|jdƒp|jdƒs-t|ƒ‚ntt|ƒj|d|ƒd|_|jjdkrpt|_	n	t
|_	t|_dS(s-Set the base path where files will be stored.sftp://saftp://t_from_transporttftpRN(t
startswitht
ValueErrortsuperR%R$t_unqualified_schemet_parsed_urltschemetTruet	is_activetFalset_has_append(R!tbaseR&((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyR$^s		cC@sA|jƒ}|dkr=|jƒ\}}|j||ƒn|S(s/Return the ftplib.FTP instance for this object.N(t_get_connectiontNonet_create_connectiont_set_connection(R!t
connectiontcredentials((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyt_get_FTPns
cC@s€|dkr"|j|j}}n|\}}tjƒ}|dkrs|jd|jd|jdtj	ƒƒ}nt
d|j|j|d|jffƒy`|jƒ}|j
d|jd|jƒ|j||||ƒ|j|jƒ|jdƒWnqtjk
r8}tj|j|jdd	d
|ƒ‚n8tjk
ro}tjddt|ƒd
|ƒ‚nX|||ffS(
sáCreate a new connection with the provided credentials.

        :param credentials: The credentials needed to establish the connection.

        :return: The created connection and its associated credentials.

        The input credentials are only the password as it may have been
        entered interactively by the user and may be different from the one
        provided in base url at transport creation time.  The returned
        credentials are username, password.
        R'tporttdefaults$Constructing FTP instance against %rs********thostsTYPE ItmsgsUnable to connect tot
orig_errorsError setting up connection: %sN(R4t_usert	_passwordRtAuthenticationConfigtget_usert_hostt_porttgetpasstgetuserR
R/tconnection_classtconnectt_logintset_pasvtvoidcmdtsocketterrorRtSocketConnectionErrorRRtTransportErrortstr(R!R8tusertpasswordtauthR7te((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyR5zs0cC@s\|rB|dkrB|dkrB|jd|j|d|jƒ}n|jd|d|ƒdS(Nt	anonymousR'R:RQtpasswd(R4tget_passwordRCRDtlogin(R!R7RSRQRR((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyRI¢scC@s5|jƒ}|j|ƒ\}}|j||ƒdS(s<Create a new connection with the previously used credentialsN(t_get_credentialsR5R6(R!R8R7((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyt
_reconnect©scC@s)|jƒ}|dk	r%|jƒndS(N(R3R4tclose(R!R7((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyt
disconnect¯scC@s{t|ƒjƒ}|s't|ƒ}n|dt|ƒ7}d|ksÅd|ksÅd|ksÅd|ksÅd|ksÅd|ksÅd|ksÅ|jd	ƒrªd
|ksÅ|jd	ƒrÝd|krÝtj|d|ƒ‚nld
|krtj|d|ƒ‚nHd|kr%tj|d|ƒ‚n$d|krItj|d|ƒ‚ntd||ƒ|rt||d|ƒ‚n‚dS(s…Try to translate an ftplib exception to a bzrlib exception.

        :param err: The error to translate into a bzr error
        :param path: The path which had problems
        :param extra: Extra information which can be included
        :param unknown_exc: If None, we will just raise the original exception
                    otherwise we raise unknown_exc(path, extra=extra)
        s: sno such filescould not opensno such dirscould not create filesfile doesn't existsrnfr command failed.sfile/directory not founds550 sunable to rename toscan't find foldertextrasfile existssnot a directorysdirectory not emptys+unable to understand error for path: %s: %sN(	RPtlowerR(Rt
NoSuchFilet
FileExistst	PathErrortDirectoryNotEmptyR
(R!terrtpathR]tunknown_excts((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyt_translate_ftp_error´s0
cC@s©|j|ƒ}y@|jƒ}td||ƒ|j|ƒ}td|ƒtSWnStjk
r¤}dt|ƒjƒkrtd||ƒtStd||ƒt	SXdS(sDoes the target location exist?sFTP has check: %s => %ssFTP has: %ssis a directorysFTP has dir: %s: %ssFTP has not: %s: %sN(
t_remote_pathR9R
RR.RRRPR^R0(R!trelpathR#R"RfRT((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pythasæs
icC@s–yctd|j|ƒƒ|jƒ}tƒ}|jd|j|ƒ|jdƒ|jdƒ|SWn,tjk
rŸ}t	j
|j|ƒdt|ƒƒ‚nótj
k
r}|tkråt	jdd|j|ƒd|ƒ‚q’td	t|ƒƒ|jƒ|j||d
ƒSnytk
r‘}|tkrYt	jd|j|ƒd|ƒ‚q’tdƒtjtƒ|jƒ|j||d
ƒSnXd
S(sdGet the file at the given relative path.

        :param relpath: The relative path to the file
        :param retries: Number of retries after temporary failures so far
                        for this operation.

        We're meant to return a file-like object which bzr will
        then read from. For now we do this via the magic of StringIO
        sFTP get: %ssRETR i iR]R=s,FTP temporary error during GET %s. Aborting.R>s"FTP temporary error: %s. Retrying.is,FTP control connection closed during GET %s.s0FTP control connection closed. Trying to reopen.N(R
RhR9Rt
retrbinarytwritetseekRRRR_R#RPt
error_tempt_number_of_retriesRORRZtgettEOFErrorttimetsleept_sleep_between_retries(R!RitretriesR"tretRT((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyRpûs4
	#
'
	


cC@s¦|j|ƒ}d|tjƒtjƒtjddƒf}d}t|ddƒdkrp|}t|ƒ}n"dt	fd„ƒY}||ƒ}yÙt
d|ƒ|jƒ}	yX|	jd||ƒ|j
|||	ƒ|j||ƒ|dk	rþt|ƒS|jSWnatjtfk
ri}
td	||
fƒy|	j|ƒWntd
|ƒ|
‚nX‚nXWn4tjk
r¢}
|j|
|ddd
tjƒntjk
r%}
|tkrëtjd|j|ƒ|
fd|
ƒ‚q¢tdt|
ƒƒ|jƒ|j||||dƒn}tk
r¡|tkrctjd|j|ƒd|
ƒ‚q¢tdƒtj t!ƒ|jƒ|j||||dƒnXdS(s•Copy the file-like or string object into the location.

        :param relpath: Location to put the contents, relative to base.
        :param fp:       File-like or string object.
        :param retries: Number of retries after temporary failures so far
                        for this operation.

        TODO: jam 20051215 ftp as a protocol seems to support chmod, but
        ftplib does not
        s%s.tmp.%.9f.%d.%diiÿÿÿtreadtbyte_countercB@seZd„Zd„ZRS(cS@s||_d|_dS(Ni(tfpt
counted_bytes(R!Ry((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyR$9s	cS@s+|jj|ƒ}|jt|ƒ7_|S(N(RyRwRztlen(R!tcounttresult((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyRw<s(RRR$Rw(((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyRx8s	sFTP put: %ssSTOR s:Failure during ftp PUT of %s: %s. Deleting temporary file.s7Failed to delete temporary file on the server.
File: %sR]scould not storeRes0FTP temporary error during PUT %s: %s. Aborting.R>s"FTP temporary error: %s. Retrying.is,FTP control connection closed during PUT %s.s0FTP control connection closed. Trying to reopen.N("RhRrtostgetpidtrandomtrandintR4tgetattrRtobjectR
R9t
storbinaryt_rename_and_overwritet_setmodeR{RzRRnRqRtdeleteRRgRR_RoROR#RPRZtput_fileRsRt(R!RiRytmodeRuR#ttmp_abspathtbytesRxR"RT((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyRˆ"s`



"

	


cC@s¶|j|ƒ}yqtd|ƒ|jƒ}y|j|ƒWn0tjk
rn}|dd dkrhqo‚nX|j||ƒWn/tjk
r±}|j||dt	j
ƒnXdS(s%Create a directory at the given path.sFTP mkd: %siit250ReN(RhR
R9tmkdRterror_replyR†RRgRR`(R!RiR‰R#R"RT((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pytmkdirls
cC@s9|j|d|ƒt||ƒ}|t|j|ƒ<|S(s See Transport.open_write_stream.t(t	put_bytesRRR#(R!RiR‰R}((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pytopen_write_stream‚scC@sdS(s“See Transport.recommended_page_size().

        For FTP we suggest a large page size to reduce the overhead
        introduced by latency.
        i@ii((R!((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pytrecommended_page_size‰scC@so|j|ƒ}y*td|ƒ|jƒ}|j|ƒWn/tjk
rj}|j||dtjƒnXdS(s Delete the directory at rel_pathsFTP rmd: %sReN(	RhR
R9trmdRRRgRRa(R!trel_pathR#R"RT((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pytrmdir‘s
cC@s‘|jƒ}|j|ƒ}|j|ƒrH|jƒ}|j|ƒ}nd}|jrztd|ƒ|j|||ƒn|j|||ƒ|S(sQAppend the text in the file-like object into the final
        location.
        isFTP appe to %s(	RwRhRjR9RR1R
t_try_appendt_fallback_append(R!RiR"R‰ttextR#R'R}((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pytappend_file›s	
c
C@sjyy|j|ƒ}td||ƒ|jƒ}d|}|j|ƒ}|j|ƒ|jƒ|j||ƒ|jƒWnêtj	k
rñ}	t
|	ƒjdƒrÏtd|	ƒt
|_|j|||ƒqf|j|	|dddtjƒnutjk
re}	|tkr+tjd|d	|	ƒ‚qftd
t
|	ƒƒ|jƒ|j||||dƒnXdS(
s½Try repeatedly to append the given text to the file at relpath.

        This is a recursive function. On errors, it will be called until the
        number of retries is exceeded.
        sFTP appe (try %d) to %ssAPPE %ss502 s_FTP server does not support file appending natively. Performance may be severely degraded! (%s)R]serror appendingRes/FTP temporary error during APPEND %s. Aborting.R>s"FTP temporary error: %s. Retrying.iN(RhR
R9ttransfercmdtsendallR[R†tgetrespRRRPR(RR0R1R˜RgRR_RnRoRORZR—(
R!RiR™R‰RuR#R'tcmdtconnRT((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyR—¯s4


	

cC@sO|j|ƒ}|jdtjƒ|j|ƒ|jdƒ|j|||ƒS(Ni(RpRmR~tSEEK_ENDRlRˆ(R!RiR™R‰tremote((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyR˜Ós


cC@s©|r¥y[tdt|ƒ|j|ƒƒ|jƒ}dt|ƒ|j|ƒf}|j|ƒWq¥tjk
r¡}tdt|ƒ|j|ƒt|ƒƒq¥XndS(s€Set permissions on a path.

        Only set permissions if the FTP server supports the 'SITE CHMOD'
        extension.
        s/FTP site chmod: setting permissions to %s on %ssSITE CHMOD %s %ss-FTP Could not set permissions to %s on %s. %sN(	R
toctRhR9tsendcmdRRRRP(R!RiR‰R'RžRT((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyR†ÚscC@sM|j|ƒ}|j|ƒ}td||ƒ|jƒ}|j|||ƒS(NsFTP rename: %s => %s(RhR
R9t_rename(R!trel_fromtrel_totabs_fromtabs_toR"((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pytrenameòs
cC@sQy|j||ƒWn6tjtjfk
rL}|j||d|ƒnXdS(Ns: unable to rename to %r(R©RRnRRg(R!R§R¨R"RT((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyR¤ùs
cC@s”|j|ƒ}|j|ƒ}y3td||ƒ|jƒ}|j|||ƒWn<tjk
r}|j||dd|fdtjƒnXdS(s3Move the item at rel_from to the location at rel_tosFTP mv: %s => %sR]sunable to rename to %rReN(	RhR
R9R…RRRgRRa(R!R¥R¦R§R¨R"RT((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pytmoves
c@s8tj||d‡‡fd†d‡‡fd†ƒdS(sgDo a fancy rename on the remote server.

        Using the implementation provided by osutils.
        trename_funcc@sˆj||ˆƒS(N(R¤(tp1tp2(R"R!(sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyt<lambda>stunlink_funcc@sˆj|ˆƒS(N(t_delete(tp(R"R!(sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyR®sN(Rtfancy_rename(R!R§R¨R"((R"R!sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyR…
scC@s/|j|ƒ}|jƒ}|j||ƒdS(sDelete the item at relpathN(RhR9R°(R!RiR#R"((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyR‡scC@sWytd|ƒ|j|ƒWn2tjk
rR}|j||ddtjƒnXdS(Ns
FTP rm: %sserror deletingRe(R
R‡RRRgRR_(R!R#R"RT((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyR°s
cC@s|jS(s,See bzrlib.transport.Transport.external_url.(R2(R!((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pytexternal_url$scC@stS(sSee Transport.listable.(R.(R!((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pytlistable)sc	C@s>|j|ƒ}td|ƒ|jƒ}zy|j|ƒ}Wnvtjk
rl}|j||ddƒnKtjk
r¶}t|ƒj	ƒj
dƒr°tdt|ƒƒgS‚nXWd|jdƒX|r|dj
|ƒrg|D]}|t|ƒd	^qé}n|}g|D]!}|dkrt
j|ƒ^qS(
sSee Transport.list_dir.sFTP nlst: %sR]serror with list_dirs450 no files foundsDFTP Server returned "%s" for nlst. Assuming it means empty directoryNsTYPE Iiit.s..(Rµs..(RhR
R9tnlstRRRgRnRPR^R(RKR{Rtescape(	R!RitbasepathR"tpathsRTRdtentriestentry((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pytlist_dir-s*


*
cc@s¦tdƒt|jdƒƒ}x€|r¡|jdƒ}|j|ƒ}tj|jƒr™xCt|j|ƒƒD]$\}}|j||d|ƒqnWq"|Vq"WdS(sYSee Transport.iter_files_recursive.

        This is cargo-culted from the SFTP transportsFTP iter_files_recursiveRµit/N(	R
tlistR¼tpopRtS_ISDIRRt	enumeratetinsert(R!tqueueRitsttitbasename((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pytiter_files_recursivePs
	"cC@sl|j|ƒ}y*td|ƒ|jƒ}t||ƒSWn,tjk
rg}|j||ddƒnXdS(s'Return the stat information for a file.sFTP stat: %sR]s
error w/ statN(RhR
R9RRRRg(R!RiR#R"RT((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyR_s
cC@s dtfd„ƒY}||ƒS(sƒLock the given file for shared (read) access.
        :return: A lock object, which should be passed to Transport.unlock()
        t	BogusLockcB@seZd„Zd„ZRS(cS@s
||_dS(N(Rd(R!Rd((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyR$pscS@sdS(N((R!((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pytunlockrs(RRR$RÉ(((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyRÈos	(Rƒ(R!RiRÈ((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyt	lock_readiscC@s
|j|ƒS(s×Lock the given file for exclusive (write) access.
        WARNING: many transports do not support this, so trying avoid using it

        :return: A lock object, which should be passed to Transport.unlock()
        (RÊ(R!Ri((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyt
lock_writevsN('RRRR4R$R9RtFTPRGR5RIRZR\RRgRjRpRˆRR’R“R–RšR—R˜R†R©R¤RªR…R‡R°R³R´R¼RÇRRÊRË(((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyR%[sD	
	(			1	'J		
$				
							#		
	
cC@s ddlm}t|jfgS(s.Return the permutations to be used in testing.i(t
ftp_server(tbzrlib.testsRÍR%t
FTPTestServer(RÍ((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pytget_test_permutationss('Rt
__future__Rt	cStringIORRRER~R€RLRRrtbzrlibRRRRtbzrlib.symbol_versioningRRRR	tbzrlib.traceR
Rtbzrlib.transportRR
RRRRaRRƒRRoRtR%RÐ(((sA/usr/lib/python2.7/dist-packages/bzrlib/transport/ftp/__init__.pyt<module>s,""(	
ÿÿ&

Copyright © 2017 || Recoded By Mr.Bumblebee