-=[ Mr. Bumblebee ]=-
_Indonesia_

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


:Nc@@s;dZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
mZmZmZddlmZmZmZmZmZmZddlmZddlmZmZddlmZmZm Z m!Z!ej"d	d
de#dd
yddl$Z$Wne%k
rgZ&ee&nUXddl'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.ddl/m0Z0ddl1m2Z2e3e$ddddfZ4e4dddfkZ5de6fdYZ7de6fdYZ8de!fdYZ9dZ:dS(s6Implementation of Transport over SFTP, using paramiko.i(tabsolute_importN(tconfigtdebugterrorsturlutils(t
FileExistst
NoSuchFiletTransportErrort	LockErrort	PathErrortParamikoNotPresent(tfancy_rename(tmuttertwarning(tFileFileStreamt
_file_streamstsshtConnectedTransporttignores$integer argument expected, got floattcategorytmodulesparamiko.message(tSFTP_FLAG_WRITEtSFTP_FLAG_CREATEtSFTP_FLAG_EXCLtSFTP_FLAG_TRUNCtSFTP_OKt
CMD_HANDLEtCMD_OPEN(tSFTPAttributes(tSFTPFilet__version_info__iitSFTPLockcB@s2eZdZddddgZdZdZRS(sThis fakes a lock in a remote location.

    A present lock is indicated just by the existence of a file.  This
    doesn't work well on all transports and they are only used in
    deprecated storage formats.
    tpatht	lock_patht	lock_filet	transportcC@s~d|_||_|d|_||_y(|j|j}|j||_Wn'tk
rytd|jfnXdS(Ns.write-locksFile %r already locked(	tNoneR"R R!R#t_remote_patht_sftp_open_exclusiveRR(tselfR R#tabspath((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyt__init__ds		
	
cC@sU|js
dS|jjd|_y|jj|jWntfk
rPnXdS(N(R"tcloseR$R#tdeleteR!R(R'((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pytunlockps	
	(t__name__t
__module__t__doc__t	__slots__R)R,(((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyRZs	t_SFTPReadvHelpercB@s/eZdZdZdZdZdZRS(s;A class to help with managing the state of a readv request.icC@s%t||_||_||_dS(s4Create a new readv helper.

        :param original_offsets: The original requests given by the caller of
            readv()
        :param relpath: The name of the file (if known)
        :param _report_activity: A Transport._report_activity bound method,
            to be called as data arrives.
        N(tlisttoriginal_offsetstrelpatht_report_activity(R'R3R4R5((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyR)s		cC@st|j}ttj|dddd}g}xl|D]d}|j}|j}xI|dkrt||j}|j	||f||8}||7}qXWq=Wdt
jkrtd|j
t|t|t|n|S(s
Break up the offsets into individual requests over sftp.

        The SFTP spec only requires implementers to support 32kB requests. We
        could try something larger (openssh supports 64kB), but then we have to
        handle requests that fail.
        So instead, we just break up our maximum chunks into 32kB chunks, and
        asyncronously requests them.
        Newer versions of paramiko would do the chunking for us, but we want to
        start processing results right away, so we do it ourselves.
        tlimititfudge_factortsftps8SFTP.readv(%s) %s offsets => %s coalesced => %s requests(tsortedR3R2Rt_coalesce_offsetststarttlengthtmint_max_request_sizetappendRtdebug_flagsRR4tlen(R'tsorted_offsetst	coalescedtrequeststc_offsetR;tsizet	next_size((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyt
_get_requestss"
		
cc@s|j}t|j}|j\}}d	}d	}g}d}	g}
tj|j|tjd	}xtj	||D]
\\}}
}|d	krt
d	k	rtj|j
||
t|qnt||
kr	tj|j
||
t|n|j|
d|d	kr=|g}|
}	|}nl||krc|j||	|
7}	nF|	dkrdj|}|
j||fn|}|g}|
}	||
}||kr||	krdj|}|2d}xb||krH|||	krH||||!}||7}||7}||fV|j\}}qW|t|krjg}d}	q||}|g}t|}	qqW|j|	rdj|}|2|
j||fn|
rdtjkrtdttd|
nxtrtj|
|f}|t|
krY|
|d|krY|
|d| }nP|dkr|d8}||
|d}|
|d}||||!}nd}t||krtd|t|fn||fV|j\}}qWnd	S(
sRequest the data from the remote machine, yielding the results.

        :param fp: A Paramiko SFTPFile object that supports readv.
        :return: Yield the data requested by the original readv caller, one by
            one.
        itreadtR8s*SFTP readv left with %d out-of-order bytescS@st|dS(Ni(RA(tx((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyt<lambda>sisBWe must have miscalulated. We expected %d bytes, but only found %dN(RHtiterR3tnextR$t	itertoolstchaintreadvtrepeattizipt
cur_coalescedRtShortReadvErrorR4RAR5R?tjoinR*RR@RtsumtmaptTruetbisecttbisect_lefttAssertionError(R'tfpRDtoffset_itert
cur_offsettcur_sizetinput_starttlast_endt
buffered_datatbuffered_lentdata_chunkstdata_streamR;R<tdatatbufferedtbuffered_offsettcur_datatidxt
sub_offset((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pytrequest_and_yield_offsetss%		

	


	
	
		&
(R-R.R/R>R)RHRm(((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyR1|s
	
	$t
SFTPTransportcB@seZdZeZdZdZdZdZd)dZ
dZdZdZ
d	Zd
ZdZdZd
Zd)dZd)dZd)ed)dZd)ed)dZd)ed)dZdZd)dZd)dZd)dZdedZd)dZdZ dZ!dZ"dZ#dZ$dZ%d Z&d!Z'd"Z(d#Z)d$Z*d%Z+d&Z,d)d'Z-d(Z.RS(*s)Transport implementation for SFTP access.ii icC@sJ|jj|j}|jdr1|d}n|dkrFd}n|S(s{Return the path to be passed along the sftp protocol for relpath.

        :param relpath: is a urlencoded string.
        s/~/is/~RJ(t_parsed_urltcloneR t
startswith(R'R4tremote_path((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyR%Os
	cC@s|dkr|jj}n|}tj}|jj}|dkrutj}|jd|jj	|jj
}n|j|jj||jj	|jj
}|||ffS(sCreate 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 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.
        RN(R$RotpasswordRt_get_ssh_vendortuserRtAuthenticationConfigtget_userthosttporttconnect_sftp(R'tcredentialsRstvendorRutautht
connection((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyt_create_connectionascC@s)|j}|dk	r%|jndS(N(t_get_connectionR$R*(R'R~((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyt
disconnect{scC@sA|j}|dkr=|j\}}|j||n|S(s(Ensures that a connection is establishedN(RR$Rt_set_connection(R'R~R{((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyt	_get_sftps
cC@sMy4|jj|j||jddtSWntk
rHtSXdS(s1
        Does the target location exist?
        iRIN(RtstatR%R5RYtIOErrortFalse(R'R4((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pythass
cC@sy`|j|}|jj|dd}|jr[t|dddk	r[|jn|SWn8ttj	fk
r}|j
||ddtjnXdS(shGet the file at the given relative path.

        :param relpath: The relative path to the file
        tmodetrbtprefetchs: error retrievingtfailure_excN(
R%Rtfilet_do_prefetchtgetattrR$RRtparamikotSSHExceptiont_translate_io_exceptionRt	ReadError(R'R4R tfte((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pytgets!
cC@sK|j|}z*|j}|jt|d|SWd|jXdS(NRI(RRIR5RAR*(R'R4Rtbytes((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyt	get_bytesscC@s|s
dSy|j|}|jj|dd}t|dd}|rb|j|||Sdtjkrtdt	|n|j
|||SWn/ttj
fk
r}|j||dnXdS(sSee Transport.readv()NRRRQR8sseek and read %s offsetss: error retrieving(R%RRRR$t_sftp_readvRR@RRAt_seek_and_readRRRR(R'R4toffsetsR R]RQR((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyt_readvscC@sdS(sSee Transport.recommended_page_size().

        For SFTP we suggest a large page size to reduce the overhead
        introduced by latency.
        i@ii((R'((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pytrecommended_page_sizescC@s"t|||j}|j|S(sUse the readv() member of fp to do async readv.

        Then read them using paramiko.readv(). paramiko.readv()
        does not support ranges > 64K, so it caps the request size, and
        just reads until it gets all the stuff it wants.
        (R1R5Rm(R'R]RR4thelper((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyRscC@s%|j|}|j||d|S(s
        Copy the file-like object into the location.

        :param relpath: Location to put the contents, relative to base.
        :param f:       File-like object.
        :param mode: The final mode for the file
        R(R%t_put(R'R4RRt
final_path((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pytput_filesc
C@s[d|tjtjtjddf}|j|d|}t}yy#|jt|j	||}Wn,t
tjfk
r}|j
||nX|dk	r|jj||n|jt}|j|||SWnltk
rV}ddl}	t|	jy*|s,|jn|jj|Wn
|nXnXdS(sBHelper function so both put() and copy_abspaths can reuse the codes%s.tmp.%.9f.%d.%diiRN(ttimetostgetpidtrandomtrandintR&Rt
set_pipelinedRYt_pumpRRRRR$RtchmodR*t_rename_and_overwritet	Exceptiont	tracebackRt
format_exctremove(
R'R(RRttmp_abspathtfouttclosedR<RR((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyRs4



c@sj|fd}|s8|dSy|Wn:tk
rtjj}j|||nXdS(Nc@sd}zy6jjdd}|jt|Wn/tjtfk
rp}j|dnXdk	rjj	nWd|dk	r|j
nXdS(s3Try to open the target file, raise error on failureRtwbs: unable to openN(R$RRRRYRRRRRR*(RR(R(RR'twriter(s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyt_open_and_write_files
(R%RRR tdirnamet_mkdir(R'R4RRtcreate_parent_dirtdir_modeRt
parent_dir((R(RR'Rs9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyt_put_non_atomic_helpers
c	@s8fd}j||d|d|d|dS(sCopy the file-like object into the target location.

        This function is not strictly safe to use. It is only meant to
        be used when you already know that the target does not exist.
        It is not safe, because it will open and truncate the remote
        file. So there may be a time when the file has invalid contents.

        :param relpath: The remote location to put the contents.
        :param f:       File-like object.
        :param mode:    Possible access permissions for new file.
                        None means do not set remote permissions.
        :param create_parent_dir: If we cannot create the target file because
                        the parent directory does not exist, go ahead and
                        create it, and then try again.
        c@sj|dS(N(R(R(RR'(s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyRNsRRRN(R(R'R4RRRRR((RR's9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pytput_file_non_atomic<sc	@s5fd}|j||d|d|d|dS(Nc@s|jdS(N(twrite(R(R(s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyRWsRRR(R(R'R4RRRRR((Rs9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pytput_bytes_non_atomicTscc@st|jd}x|r|jd}|j|}tj|jrxCt|j|D]$\}}|j||d|qdWq|VqWdS(s7Walk the relative paths of all files in this transport.t.it/N(R2tlist_dirtpopRtS_ISDIRtst_modet	enumeratetinsert(R'tqueueR4tsttitbasename((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pytiter_files_recursive]s	"cC@s|dkrd}n|}y|jt|d|jj|||jdd|dk	r|jj|}|d@}||jd@kr|jd@rtd|d|fn|jj|d|qnWn5t	j
tfk
r}|j||dd	t
nXdS(
NiRiRIisAbout to chmod %s over sftp, which will result in its suid or sgid bits being cleared.  If you want to preserve those bits, change your  environment on the server to use umask 0%03o.Rs: unable to mkdirR(R$R5RARtmkdirtlstatRR
RRRRRR(R'R(Rt
local_modeRR((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyRjs$	

#cC@s |j|j|d|dS(s%Create a directory at the given path.RN(RR%(R'R4R((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyRscC@s|j|d||j|}d}y,|jj|dd}|jtWn/tjt	fk
r}|j
||dnX|t|j|<t
|||S(s See Transport.open_write_stream.RJRRs: unable to openN(RR%R$RRRRYRRRRRR(R(R'R4RR(thandleR((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pytopen_write_streamsRJcC@s|j||dtt|dddk	rQ|jdksL|jdkrht|t||n|jdks|jdjdrt|t||n|jdkr||t||n|jdjd	st|d
dt	j
kr tj|t|n|jdkr>tj
ntd|jnt|d
ddk	r|td
|j	n|dS(sTranslate a paramiko or IOError into a friendlier exception.

        :param e: The original exception
        :param path: The path in question when the error is raised
        :param more_info: Extra information that can be included,
                          such as what was going on
        :param failure_exc: Paramiko has the super fun ability to raise completely
                           opaque errors that just set "e.args = ('Failure',)" with
                           no more information.
                           If this parameter is set, it defines the exception
                           to raise in these cases.
        t
raise_generictargssNo such file or directorysNo such filesmkdir failedissyserr: File existstFailuresDirectory not empty: terrnosOperation unsupportedsRaising exception with args %ssRaising exception with errno %sN(sNo such file or directory(sNo such file(smkdir failed(R(sOperation unsupported(t_translate_errorRRR$RRtstrRqRRt	ENOTEMPTYRtDirectoryNotEmptytTransportNotPossibleR(R'RR t	more_infoR((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyRs&cC@syp|j|}|jj|d}|dk	rO|jj||n|j}|j|||SWn/ttj	fk
r}|j
||dnXdS(sZ
        Append the text in the file-like object into the final
        location.
        tabs: unable to appendN(R%RRR$RttellRRRRR(R'R4RRR RtresultR((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pytappend_filescC@sfy,|jj|j||j|Wn3ttjfk
ra}|j||d|nXdS(s"Rename without special overwritings: unable to rename to %rN(RtrenameR%RRRR(R'trel_fromtrel_toR((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyRscC@siy/|j}t||d|jd|jWn3ttjfk
rd}|j||d|nXdS(sgDo a fancy rename on the remote server.

        Using the implementation provided by osutils.
        trename_functunlink_funcs: unable to rename to %rN(RRRRRRRR(R'tabs_fromtabs_toR8R((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyRs	cC@s2|j|}|j|}|j||dS(s3Move the item at rel_from to the location at rel_toN(R%R(R'RRt	path_fromtpath_to((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pytmovescC@s\|j|}y|jj|Wn/ttjfk
rW}|j||dnXdS(sDelete the item at relpaths: unable to deleteN(R%RRRRRR(R'R4R R((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyR+s
cC@s|jS(s,See bzrlib.transport.Transport.external_url.(tbase(R'((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pytexternal_urlscC@stS(s+Return True if this store supports listing.(RY(R'((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pytlistablescC@s|j|}y8|jj|}|jttt|dWn/ttj	fk
rx}|j
||dnXg|D]}tj|^qS(sC
        Return a list of all files at the given location.
        RIs: failed to list_dir(
R%RtlistdirR5RWRXRARRRRRtescape(R'R4R tentriesRtentry((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyRs#cC@s\|j|}y|jj|SWn/ttjfk
rW}|j||dnXdS(sSee Transport.rmdir.s: failed to rmdirN(R%RtrmdirRRRR(R'R4R R((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyRs
cC@s\|j|}y|jj|SWn/ttjfk
rW}|j||dnXdS(s'Return the stat information for a file.s: unable to statN(R%RRRRRR(R'R4R R((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyRs
cC@s\|j|}y|jj|SWn/ttjfk
rW}|j||dnXdS(sSee Transport.readlink.s: unable to readlinkN(R%RtreadlinkRRRR(R'R4R R((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyR&s
cC@syJ|j}|j||}t|krItd||f|nWn3ttjfk
r}|j||d|nXdS(sSee Transport.symlink.s"%r: unable to create symlink to %rs : unable to create symlink to %rN(RtsymlinkRRRRRR(R'tsourcet	link_nametconntsftp_retvalR((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyR.s
cC@s dtfdY}||S(s
        Lock the given file for shared (read) access.
        :return: A lock object, which has an unlock() member function
        t	BogusLockcB@seZdZdZRS(cS@s
||_dS(N(R (R'R ((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyR)CscS@sdS(N((R'((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyR,Es(R-R.R)R,(((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyRBs	(tobject(R'R4R((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyt	lock_read<scC@s
t||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 has an unlock() member function
        (R(R'R4((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyt
lock_writeIsc
C@s|jj|}t}|dk	r6||_nttBtBtB}yh|jj	t
|||\}}|tkrtdn|j
}t|j|ddSWn5tjtfk
r}	|j|	|ddtnXdS(sOpen a remote path exclusively.

        SFTP supports O_EXCL (SFTP_FLAG_EXCL), which fails if
        the file already exists. However it does not expose this
        at the higher level of SFTPClient.open(), so we have to
        sneak away with it.

        WARNING: This breaks the SFTPClient abstraction, so it
        could easily break against an updated version of paramiko.

        :param abspath: The remote absolute path where the file should be opened
        :param mode: The mode permissions bits for the new file
        sExpected an SFTP handleRis: unable to openRN(Rt_adjust_cwdRR$RRRRRt_requestRRRt
get_stringRRRRRR(
R'R(RR tattrtomodetttmsgRR((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyR&Vs	$cC@stjdkrtStSdS(Ntwin32(tsystplatformRRY(R'((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyt_can_roundtrip_unix_modebitsysN(/R-R.R/t_default_do_prefetchRt_max_readv_combinet_bytes_to_read_before_seekR>R%R$RRRRRRRRRRRRRRRRRRRR	RRRRRR+RRRRRRRRRR&R(((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyRn:s`							
			
1*	
&													
	
#cC@s8ddlm}t|jft|jft|jfgS(s.Return the permutations to be used in testing.i(t	stub_sftp(tbzrlib.testsRRntSFTPAbsoluteServertSFTPHomeDirServertSFTPSiblingAbsoluteServer(R((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pytget_test_permutationss(;R/t
__future__RRZRRORRRRRtwarningstbzrlibRRRRt
bzrlib.errorsRRRRR	R
tbzrlib.osutilsRtbzrlib.traceRR
tbzrlib.transportRRRRtfilterwarningstDeprecationWarningRtImportErrorRt
paramiko.sftpRRRRRRRtparamiko.sftp_attrRtparamiko.sftp_fileRRt_paramiko_versionRRRR1RnR(((s9/usr/lib/python2.7/dist-packages/bzrlib/transport/sftp.pyt<module>sD	"."	4"I

Copyright © 2017 || Recoded By Mr.Bumblebee