SlQc@sdZddlZddlZddlmZddlZddlmZddlmZddl m Z m Z ddl m Z ddlmZdd lmZdd lmZmZmZmZmZdd lmZdd lmZdd lmZmZmZddl m!Z!m"Z"m#Z#ddl$m%Z%ddlm&Z&m'Z'e j(de)ddZ*e#j+j,rvdZ-ne.Z-dej/fdYZ0dej1fdYZ2de j3fdYZ4de4fdYZ5de4fdYZ6de4fd YZ7d!e4fd"YZ8d#e8fd$YZ9d%e j3fd&YZ:d'e j3fd(YZ;d)ej1fd*YZ<d+e&j=fd,YZ>d-e j3fd.YZ?d/e j3fd0YZ@d1e j3fd2YZAd3e j3fd4YZBd5e j3fd6YZCd7e j3fd8YZDd9e j3fd:YZEd;e j3fd<YZFd=e j3fd>YZGd?e j3fd@YZHdAe j3fdBYZIdCfdDYZJdEe j3eJfdFYZKdGeLfdHYZMdIeLfdJYZNdKfdLYZOdMe j3eOfdNYZPdOfdPYZQdQfdRYZRdSe j3fdTYZSdUe j3fdVYZTdS(Ws FTP tests. iN(tStringIO(t implements(t verifyClass(tunittesttutil(tinsecureRandom(tIRealm(tbasic(treactorttasktprotocoltdeferterror(t IConsumer(tUnauthorizedLogin(tportaltcheckerst credentials(tfailuretfilepathtruntime(t proto_helpers(tftptloopbacktcategorytmessagesbFTPClient\.changeDirectory is deprecated in Twisted 8\.2 and newer\. Use FTPClient\.cwd instead\.sCannot run on WindowstDummycBs;eZdZdZdZdZdZdZRS(cCsg|_g|_dS(N(tlinestrawData(tself((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt__init__,s cCs|j|_dS(N(tfactorytf(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pytconnectionMade/scCs|jj|dS(N(Rtappend(Rtline((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt lineReceived1scCs|jj|dS(N(RR"(Rtdata((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pytrawDataReceived3scCsdS(N((RR#((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pytlineLengthExceeded5sN( t__name__t __module__tNonetlognameRR!R$R&R'(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR*s     t_BufferingProtocolcBs#eZdZdZdZRS(cCsd|_tj|_dS(Nt(tbufferR tDeferredtd(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR!;s cCs|j|7_dS(N(R.(RR%((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt dataReceived>scCs|jj|dS(N(R0tcallback(Rtreason((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pytconnectionLost@s(R(R)R!R1R4(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR,:s  tFTPServerTestCasecBsSeZdZejZdZdZddZ dddZ dZ dZ RS(sw Simple tests for an FTP server with the default settings. @ivar clientFactory: class used as ftp client. t anonymousc sj_tjjtjj_tjt j djdj}|j t j tjt j}d_d_|jjj|j |tjt jd|dj_tjdjdd }j|jjjtjfd }|j_|jj }t!j"tj#}|j$d |}fd }|j%|tj&|gS( Nt anonymousRoottuserHomes test-users test-passwordRt userAnonymousit interfaces 127.0.0.1csNj`|}|j_fd}j|jd|S(Ncs)jjdk r%jjjndS(N(tserverProtocolt transportR*tloseConnection((R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt cleanupServerqs(Rt buildProtocoltwrappedProtocolR;t addCleanupR2R*(taddrR R>(R?td1R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt_rememberProtocolInstanceks     cs#|_jjjjdS(N(tclientRAR<R=(RE(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt gotClient}s ('tmktempt directorytostmkdirRtFilePathtdirPathRtPortalRtFTPRealmtregisterCheckerRtAllowAnonymousAccessRt IAnonymoust'InMemoryUsernamePasswordDatabaseDontUsetusernametpasswordtaddUsertIUsernamePasswordt FTPFactoryR9RRt listenTCPRAt stopListeningR?R R/tgetHosttportR t ClientCreatort clientFactoryt connectTCPt addCallbackt gatherResults( Rtpt users_checkerR[RDtportNumt clientCreatortd2RF((R?RCRs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pytsetUpNs6         cs@|dkrtjd}nfd}|j|S(sAsserts that a sending an FTP command receives the expected response. Returns a Deferred. Optionally accepts a deferred to chain its actions to. cs1jj}fd}|j|S(Ncsj|dS(N(t assertEqual(t responseLines(texpectedResponseLinesR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt gotResponses(REtqueueStringCommandR_(tignoredR0Rj(tcommandRiR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt queueCommandsN(R*R tsucceedR_(RRmRit chainDeferredRn((RmRiRs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pytassertCommandResponses cso|dkrtjd}nfd}|j|j|tjfd}|j|S(NcsjjS(N(RERk(Rl(RmR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRnscs*dk r&j|jdndS(Ni(R*Rgtargs(t exception(texpectedResponseR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pytfaileds (R*R RoR_t assertFailureRt CommandFailed(RRmRtRpRnRu((RmRtRs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pytassertCommandFaileds  cCs.|jddg}|jddgd|S(NsUSER anonymouss8331 Guest login ok, type your email address as password.sPASS test@twistedmatrix.coms2230 Anonymous login ok, access restrictions apply.Rp(Rq(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt_anonymousLogins  cCsC|jd|jd|jg}|jd|jdgd|S(s4Authenticates the FTP client using the test account.sUSER %ss331 Password required for %s.sPASS %ss230 User logged in, proceedRp(RqRSRT(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt _userLogins   N( R(R)t__doc__RtFTPClientBasicR]R9RfR*RqRxRyRz(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR5Es  6   tFTPAnonymousTestCasecBseZdZdZdZRS(s Simple tests for an FTP server with different anonymous username. The new anonymous username used in this test case is "guest" tguestcCs.|jddg}|jddgd|S(s Tests whether the changing of the anonymous username is working or not. The FTP server should not comply about the need of password for the username 'guest', letting it login as anonymous asking just an email address as password. s USER guests8331 Guest login ok, type your email address as password.sPASS test@twistedmatrix.coms2230 Anonymous login ok, access restrictions apply.Rp(Rq(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_anonymousLogins  (R(R)R{R9R(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR}stBasicFTPServerTestCasecBseZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZejeZdZdZdZdZdZdZdZdZdZdZRS(c sddddddddd d g }d g}fd }fd }g}xP|D]H}jj|}j|tj|j|||j|qXWx=|D]5}jj|}|j|||j|qWtj|dt S(s When not logged in, most commands other than USER and PASS should get NOT_LOGGED_IN errors, but some can be called before USER and PASS. tCDUPtCWDtLISTtMODEtPASVtPWDtRETRtSTRUtSYSTtTYPEtFEATcs<|jd}j|djdd||dfdS(Niit530s'%s - Response didn't start with 530: %r(Rrt failUnlesst startswith(RsRmtfailureResponseLines(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pytcheckFailResponses cs1|d}j|jdd||fdS(NiRs %s - Response start with 530: %r(tfailIfR(tresultRm(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pytcheckPassResponses tfireOnOneErrback( RERkRvRRwR_R"R t DeferredListtTrue(RtloginRequiredCommandListtloginNotRequiredCommandListRRt deferredsRmtdeferred((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttestNotLoggedInReplys    cCs|jddgS(s@ Issuing PASS before USER should give an error. sPASS foos=503 Incorrect sequence of commands: USER required before PASS(Rx(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttestPASSBeforeUSERscCs|jddgS(sD Issuing USER without a username is a syntax error. tUSERs,500 Syntax error: USER requires an argument.(Rx(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttestNoParamsForUSERscCs+|jjd}|jddgd|S(sD Issuing PASS without a password is a syntax error. sUSER footPASSs,500 Syntax error: PASS requires an argument.Rp(RERkRx(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttestNoParamsForPASSs  cCs |jS(N(Ry(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttestAnonymousLoginscCs%|j}|jddgd|S(s; Issuing QUIT should return a 221 message. tQUITs 221 Goodbye.Rp(RyRq(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttestQuits   cCst|j_tj}|jjj|tj|j ddg}|j ddgd|}|j ddgd|}|S(NsUSER anonymouss$331 Password required for anonymous.sPASS test@twistedmatrix.coms!530 Sorry, Authentication failed.RpRs$530 Please login with USER and PASS.( tFalseRtallowAnonymousRRRRRORRVRqRx(RtdenyAlwaysCheckerR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttestAnonymousLoginDenieds         cCs%|j}|jddgd|S(s When an anonymous user attempts to edit the server-side filesystem, they will receive a 550 error with a descriptive message. s MKD newdirs:550 Anonymous users are forbidden to change the filesystemRp(RyRx(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_anonymousWriteDenied9s   cCs%|j}|jddgd|S(Nt GIBBERISHs'502 Command 'GIBBERISH' not implementedRp(RyRx(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttestUnknownCommandEs   cCs%|j}|jddgd|S(NsRETR foosE503 Incorrect sequence of commands: PORT or PASV required before RETRRp(RyRx(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttestRETRBeforePORTLs   cCs%|j}|jddgd|S(NsSTOR foosE503 Incorrect sequence of commands: PORT or PASV required before STORRp(RyRx(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttestSTORBeforePORTTs   cCsB|j}|jddgd||jddgd||S(NsMODE zs&504 Not implemented for parameter 'z'.RpsSTRU Is&504 Not implemented for parameter 'I'.(RyRx(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttestBadCommandArgs\s   cCs|jtjddtd}xXtdD]J}t|}d||((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_downloadFolders     csgj}jjdjjjdjjdd|fd}|j|S(sp NLST with no argument returns the directory listing for the current working directory. stest.txtRsNLST Rpcs7|d jd}|jjddg|dS(Nis Rstest.txt(RR$Rg(RR%(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR!s (RyRLRRRRR_(RR0R!((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_NLSTEmptys  cs;j}jdd|fd}|j|S(sH NLST on a non-existent file/directory returns nothing. sNLST nonexistent.txtRpcsjd|dS(NR-(Rg(R(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR!s(RyRR_(RR0R!((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_NLSTNonexistents c Cs|jddd fdS( ss NLST will receive Unicode filenames for IFTPShell.list, and will encode them using UTF-8. tNLSTu my resuméiiiR/R0s my resumé (iiiiisusersgroup(R.(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_NLSTUnicodes c Cs|jddd fdS( sJ NLST will just pass the non-Unicode data to lower level. RBs my resuméiiiR/R0s my resumé (iiiiisusersgroup(R.(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_NLSTNonASCIIBytess csQj}jjdjjdd|fd}|j|S(sN NLST on an existent file returns only the path to that file. stest.txts NLST test.txtRpcs*|d jd}jdg|dS(Nis stest.txt(RRg(RR%(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR!s(RyRLRRRR_(RR0R!((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_NLSTOnPathToFiles  N(R(R)R*RRRR#R'R.R1R2R:R?R@RARCRDRE(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRs   - 1  !  t#FTPServerPortDataConnectionTestCasecBs8eZdZddZdZdZdZRS(cCsg|_tj|S(N(t dataPortsRRf(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRfs cstjdtjffdY}tjd|dd}|jj|dtj d|j j }|j j |S(Nt DataFactorycseZeZfdZRS(cs/tjj||}tjdj||S(Ni(R t ServerFactoryR?Rt callLaterR2(RRBRa(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR? s(R(R)R,R R?((R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRH siR:s 127.0.0.1sPORT (R R/R RIRRXRGR"RtencodeHostPortRZR[RERk(RRlRHtdataPorttcmd((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRs cCs]g|jD]}tj|j^q }tjtj|}|j|tj|dtS(NR( RGR t maybeDeferredRYRttearDownR"RR(RR[tlR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyROs ( cs>j}d}|j|fd}|j|S(NcsStjdtjdd}|jj|j}|jfd|S(NiR:s 127.0.0.1csS(N((t_(Rc(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt(s(RRXR RRZR[RYR_(RlR[R0((Rcs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR,#s   cs#jdtjd|dgS(NsPORT s 127.0.0.1s425 Can't open data connection.(RxRRK(Rc(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt gotPortNum.s(RyR_(RR0R,RS((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttestPORTCannotConnects    cs}jjdjjjdjjjdjj}jdd|fd}|j|S(sv When Unix shell globbing is used with NLST only files matching the pattern will be returned. stest.txtsceva.txtsno.matchs NLST *.txtRpcs7|d jd}|jjddg|dS(Nis sceva.txtstest.txt(RR$Rg(RR%(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR!As (RLRRRyRR_(RR0R!((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_nlstGlobbing5s N(R(R)RfR*RRORTRU(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRFs     tDTPFactoryTestscBsMeZdZdZdZdZdZdZdZdZ RS(s& Tests for L{ftp.DTPFactory}. cCsStj|_dtfdY}||_tj|jd|j|_dS(sf Create a fake protocol interpreter and a L{ftp.DTPFactory} instance to test. tProtocolInterpretercBseZdZRS(N(R(R)R*R(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRWUsN( R tClockRRtprotocolInterpreterRt DTPFactoryR*R(RRW((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRfNs  cCsg}|j|jjtj}|j|j|jjd|jj d|j ||jj d|j ||j |jj dS(s L{ftp.DTPFactory.setTimeout} uses the reactor passed to its initializer to set up a timed event to time out the DTP setup after the specified number of seconds. iiiN( RvRRRtPortConnectionErrorR_R"t setTimeoutRtadvancet assertFalseRtcalls(RtfinishedR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_setTimeout]s  cCsE|jjd}|j|tj|j|jjdddS(s A L{ftp.DTPFactory} instance's C{buildProtocol} method can be used once to create a L{ftp.DTP} instance. N(RR?R*RRtDTPtassertIdentical(RR ((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_buildProtocolOnce{scCs9|jjd|jjd}|j|jjdS(s If a timeout has been set up using L{ftp.DTPFactory.setTimeout}, it is cancelled by L{ftp.DTPFactory.buildProtocol}. i N(RR\R?R*R^RR_(RR ((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_timeoutAfterConnectionscCs[|j|jjtj}|jjd|jjd|j|jj dd|S(s If L{ftp.DTPFactory.buildProtocol} is called after the timeout specified by L{ftp.DTPFactory.setTimeout} has elapsed, C{None} is returned. i N( RvRRRR[R\RR]RcR?R*(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_connectionAfterTimeouts cCsg}|j|jjtj}|j|j|jjd|j||jj dd|j ||j j d|S(s  L{ftp.DTPFactory.deferred} fails with L{PortConnectionError} when L{ftp.DTPFactory.clientConnectionFailed} is called. If the timeout specified with L{ftp.DTPFactory.setTimeout} expires after that, nothing additional happens. i N(RvRRRR[R_R"R\R^tclientConnectionFailedR*RRR](RR`R0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt!test_timeoutAfterConnectionFaileds  cCs[|j|jjtj}|jjd|jjd|jjdt j d|S(s If L{ftp.DTPFactory.clientConnectionFailed} is called after the timeout specified by L{ftp.DTPFactory.setTimeout} has elapsed, nothing beyond the normal timeout before happens. i RN( RvRRRR[R\RR]RgR*R t TimeoutError(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt!test_connectionFailedAfterTimeouts ( R(R)R{RfRaRdReRfRhRj(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRVJs    tDTPTestscBs eZdZdZdZRS(sx Tests for L{ftp.DTP}. The DTP instances in these tests are generated using DTPFactory.buildProtocol() cCsbtj|_dtfdY}||_tj|jd|j|_t j |_ dS(s Create a fake protocol interpreter, a L{ftp.DTPFactory} instance, and dummy transport to help with tests. RWcBseZdZRS(N(R(R)R*R(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRWsN( R RXRRRYRRZR*RRt StringTransportWithDisconnectionR<(RRW((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRfs  cCs\|jjd}|j|jd}|j||jj}|j|d|dS(sr L{ftp.DTP.sendLine} writes the line passed to it plus a line delimiter to its transport. s line contents N(RR?R*tmakeConnectionR<tsendLineRRg(RRt lineContenttdataSent((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_sendLineNewlines  (R(R)R{RfRq(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRks t PrintLinescBs eZdZdZdZRS(s)Helper class used by FTPFileListingTests.cCs ||_dS(N(t_lines(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRscCs9x%|jD]}|jj|dq W|jjdS(Ns (RsR<R7R=(RR#((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR!s(R(R)R{RR!(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRrs tMyFTPFileListProtocolcBseZdZdZRS(cCsg|_tjj|dS(N(totherRtFTPFileListProtocolR(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR s cCs|jj|dS(N(RuR"(RR#((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt unknownLines(R(R)RRw(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRt s tFTPFileListingTestscBsGeZdZdZdZdZdZdZdZRS(cs;ttjt|}|jfd|S(NcsjjfS(N(tfilesRu(RQ(tfileList(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRRs(RtRt loopbackAsyncRrR_(RRR0((Rzs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pytgetFilesForLiness cs.d}fd}j|gj|S(Ns<-rw-r--r-- 1 root other 531 Jan 29 03:26 READMEcs|\\}}j|dt|j|ddkdj|ddkdj|dd kdj|d d kdj|d d kdj|ddkdj|ddkdj|ddkdj|dddS(Nsunexpect unparsable lines: %stfiletypet-smisparsed fileitemtpermss rw-r--r--smisparsed permstownertrootR0RuR5itdates Jan 29 03:26tfilenametREADMEtnlinksismisparsed nlinkst linktargetsmisparsed linktarget(RtreprR(RRuR6(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pytchecks (R|R_(RR#R((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt testOneLines cs@d}d}d}fd}j|||gj|S(Ns7drw-r--r-- 2 root other 531 Jan 9 2003 As<lrw-r--r-- 1 root other 1 Jan 29 03:26 B -> Aswoohoo! cs|\\}}\}j|dkdj|ddkdj|ddkdj|d d kd j|d d kdj|ddkdj|ddkdj|ddkdj|ddkdj|ddj|ddkdj|ddkdj|d d kd j|d d kdj|ddkdj|ddkdj|dd kdj|ddkdj|ddkddS(!Ns woohoo! sincorrect other lineR}R0smisparsed fileitemRs rw-r--r--smisparsed permsRRsmisparsed ownerR0Rusmisparsed groupR5ismisparsed sizeRs Jan 9 2003smisparsed dateRtAsmisparsed filenameRismisparsed nlinksRsmisparsed linktargetRPis Jan 29 03:26tB(RR(Rtfile1tfile2Ru(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR.s((R|R_(Rtline1tline2tline3R((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttestVariantLines*s cs+fd}jddgj|S(NcsF|\}}j|dj|ddgkdt|dS(Nsunexpected file entriessABC s not a file sincorrect unparsable lines: %s(RRR(RRytothers(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRGs tABCs not a file(R|R_(RR((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttestUnknownLineFscs7d}d}fd}j||gj|S(se Will parse filenames and linktargets containing unescaped space characters. s9drw-r--r-- 2 root other 531 Jan 9 2003 A BsDlrw-r--r-- 1 root other 1 Jan 29 03:26 B A -> D C/A Bcst|\}}jg|djd|dddjd|dddjd|dd d dS( Nsunexpected others entriessA BiRsmisparsed filenamesB AisD C/A BRsmisparsed linktarget(Rg(RRyR(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRXs (R|R_(RRRR((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_filenameWithUnescapedSpaceMscs7d}d}fd}j||gj|S(sc Will parse filenames and linktargets containing escaped space characters. s:drw-r--r-- 2 root other 531 Jan 9 2003 A\ BsElrw-r--r-- 1 root other 1 Jan 29 03:26 B A -> D\ C/A Bcst|\}}jg|djd|dddjd|dddjd|dd d dS( Nsunexpected others entriessA BiRsmisparsed filenamesB AisD C/A BRsmisparsed linktarget(Rg(RRyR(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRms (R|R_(RRRR((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_filenameWithEscapedSpacebscsetjddtjffdY}fd}tj|}|j|S(Ns<-rw-r--r-- 1 root other 531 Jan 29 2003 README t PrintLinecseZfdZRS(cs!|jj|jjdS(N(R<R7R=(R(t exampleLine(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR!}s(R(R)R!((R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR|scs_jd}j|ddkdj|ddkdj|ddkddS( NiR5ismisparsed fileitemRs Jan 29 2003RR(RyR(RlR6(RzR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRs (RRvR tProtocolRR{R_(RRRR0((RRzRs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttestYearws  ( R(R)R|RRRRRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRxs      tFTPClientTestscBseZdZdZRS(cstj}d|_tjd|dd}|j|j|jj}ddddd|d ?|d @fd gfd |_ t j d d}tj tt j d d}|j d|}d}|j||j|t jS(NiR:s 127.0.0.1s1220 ready, dude (vsFTPd 1.0.0: beat me, break me)s 331 Please specify the password.s230 Login successful. Have fun.s200 Binary it is, then.s+227 Entering Passive Mode (127,0,0,1,%d,%d)iis550 Failed to open file.cs tS(N(Rr(RB(t responses(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRRstpassiveicSstj}|jd|S(Ns/file/that/doesnt/exist(R RR (RERa((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRFs (R RtnoisyRRXRARYRZR[R?RRR\R^R_RvRw(RR R[RcRERR0RF((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttestFailedRETRs&     cstj}tj}|j|||_|jdt}gfd}|j|ddl m }|j t j ||j|S(sl Test the ftp command errbacks when a connection lost happens during the operation. s some pathcsj|dS(N(R"R*(R(tm(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt_ebs i(tCONNECTION_LOST(RRRRlRmR RRRttwisted.internet.mainRR4RtFailureR(Rt ftpClientttrR0RR((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_errbacksUponDisconnects     (R(R)RR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRs tFTPClientTestCasecBseZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZege_dZege_dZege_dZdZ dZ!dZ"dZ#d Z$d!Z%d"Z&d#Z'd$Z(d%Z)d&Z*d'Z+d(Z,d)Z-d*Z.d+Z/d,Z0RS(-s, Test advanced FTP client commands. cCsDtj|_tj|_|jj|j|j|j_dS(sG Create a FTP client and connect it to fake transport. N(RRRERRlR<RmR (R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRfscCs|jjtjdS(s Deliver disconnection notification to the client so that it can perform any cleanup which may be required. N(RER4R tConnectionLost(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyROscCs|j|jjd|jjd|j|jjd|jj|jjd|j|jjd|jj|jjddS(s& Test the login part. R-s8331 Guest login ok, type your email address as password.sUSER anonymous s2230 Anonymous login ok, access restrictions apply.sTYPE I s200 Type set to I.N(RgR<RRER$tclear(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt _testLogins    cskfd}jjjj|}jjjdjjjjd|S(s Test the CDUP command. L{ftp.FTPClient.cdup} should return a Deferred which fires with a sequence of one element which is the string the server sent indicating that the command was executed successfully. (XXX - This is a bad API) csj|dddS(Nis&250 Requested File Action Completed OK(Rg(R(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pytcbCdupssCDUP s&250 Requested File Action Completed OK( RREtcdupR_RgR<RRR$(RRR0((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt test_CDUPs   cCsf|j|jj}|j|tj|j|jjd|jj |jj d|S(s Test L{ftp.FTPClient.cdup}'s handling of a failed CDUP command. When the CDUP command fails, the returned Deferred should errback with L{ftp.CommandFailed}. sCDUP s!550 ..: No such file or directory( RRERRvRRwRgR<RRR$(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_failedCDUPs  cs^fd}jjjj|}jjjdjjd|S(s Test the PWD command. L{ftp.FTPClient.pwd} should return a Deferred which fires with a sequence of one element which is a string representing the current working directory on the server. (XXX - This is a bad API) cs!jtj|dddS(Nis/bar/baz(RgRtparsePWDResponse(R(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pytcbPwdssPWD s257 "/bar/baz"(RREtpwdR_RgR<RR$(RRR0((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_PWD s  cCsY|j|jj}|j|tj|j|jjd|jj d|S(s Test a failure in PWD command. When the PWD command fails, the returned Deferred should errback with L{ftp.CommandFailed}. sPWD s'550 /bar/baz: No such file or directory( RRERRvRRwRgR<RR$(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_failedPWD!s  csafd}jjjdj|}jjjdjjd|S(s Test the CWD command. L{ftp.FTPClient.cwd} should return a Deferred which fires with a sequence of one element which is the string the server sent indicating that the command was executed successfully. (XXX - This is a bad API) csj|dddS(Nis&250 Requested File Action Completed OK(Rg(R(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pytcbCwd:ssbar/foos CWD bar/foo s&250 Requested File Action Completed OK(RREtcwdR_RgR<RR$(RRR0((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_CWD0s  cCs\|j|jjd}|j|tj|j|jjd|jj d|S(s Test a failure in CWD command. When the PWD command fails, the returned Deferred should errback with L{ftp.CommandFailed}. sbar/foos CWD bar/foo s&550 bar/foo: No such file or directory( RRERRvRRwRgR<RR$(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_failedCWDDs  csfd}fd}|j_jt}jjd|}|j||jjjdjj jj dt j ddfjjjdjj jj d |S( sN Test the RETR command in passive mode: get a file and verify its content. L{ftp.FTPClient.retrieveFile} should return a Deferred which fires with the protocol instance passed to it after the download has completed. (XXX - This API should be based on producers and consumers) csj|jdddS(NR4i(RgR.(RR(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pytcbRetr^scsj|dj|d|j||f}|jtjjjd|jdd|jt j t j ddS(Ns 127.0.0.1i90s4150 File status okay; about to open data connection.R4iR-( RgR?RmRtStringTransportRER$R1R4RRR tConnectionDone(RR[RR(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt cbConnectas tspamsPASV s227 Entering Passive Mode (%s).s 127.0.0.1i90s RETR spam s226 Transfer Complete.( REtconnectFactoryRR,R R_RgR<RRR$RRK(RRRRR0((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_passiveRETRSs       cstj_d}fd}|j_jt}jjd|}|j||jj j dt j ddfj j jjdjj j dj j jjd |S( s Test the RETR command in non-passive mode. Like L{test_passiveRETR} but in the configuration where the server establishes the data connection to the client, rather than the other way around. cSsldtjddf|_|jjtj|jjdd|jjt j t j ddS(NsPORT %ss 127.0.0.1i&R4iR-( RRKttextR RmRRR1R4RRR R(tportCmd((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt generatePorts  csj|jdddS(NR4i(RgR.(RR(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRsRs PORT %s s 127.0.0.1i&s 200 PORT OKs RETR spam s226 Transfer Complete.(RRERtgeneratePortCommandRR,R R_RgR<RRRKRR$(RRRRR0((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt test_RETRzs        csfd}|j_jt}jjd|}j|tjjj j dj j jj dtj ddfjj j dj j jj d|S( s Try to RETR an unexisting file. L{ftp.FTPClient.retrieveFile} should return a Deferred which errbacks with L{ftp.CommandFailed} if the server indicates the file cannot be transferred for some reason. cs{j|dj|d|j||f}|jtjjjd|jtj t j ddS(Ns 127.0.0.1i90s4150 File status okay; about to open data connection.R-( RgR?RmRRRER$R4RRR R(RR[RR(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRs RsPASV s227 Entering Passive Mode (%s).s 127.0.0.1i90s RETR spam s#550 spam: No such file or directory(RERRR,R RvRRwRgR<RRR$RK(RRRR0((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_failedRETRs      cst|j_gfd}||j_|jt}|jjd|}|j|jj dt j ddf|jj |jj d|j|jj d|jdj|jj|j|t j|S( s Try a RETR, but disconnect during the transfer. L{ftp.FTPClient.retrieveFile} should return a Deferred which errbacks with L{ftp.ConnectionLost) csidtjddf|_tj}|jj||j|_|jjddj|dS(NsPORT %ss 127.0.0.1i&R4i( RRKRRRlR RmR1R"(RR(RP(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRs   Rs PORT %s s 127.0.0.1i&s 200 PORT OKs RETR spam i(RRERRRR,R RgR<RRRKRR$tassert_R=RvR(RRRR0((RPs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt test_lostRETRs"       cstjfd}fd}fd}|j_jjjd\}}|j||j|jjj djj jj dt j ddfjjj d jj jj d tj||gS( s Test the STOR command: send a file and verify its content. L{ftp.FTPClient.storeFile} should return a two-tuple of Deferreds. The first of which should fire with a protocol instance when the data connection has been established and is responsible for sending the contents of the file. The second of which should fire when the upload has completed, the data connection has been closed, and the server has acknowledged receipt of the file. (XXX - storeFile should take a producer as an argument, instead, and only return a Deferred which fires when the upload has succeeded or failed). csQjjd|jjdd|j|jtjtj ddS(Ns4150 File status okay; about to open data connection.R4iR-( RER$R<R7tfinishR4RRR R(tsender(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pytcbStores   csjjdddS(NR4i(RgR(tign(RR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pytcbFinishscsFj|dj|d|j||f}|jdS(Ns 127.0.0.1i90(RgR?Rm(RR[RR(RR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRsRsPASV s227 Entering Passive Mode (%s).s 127.0.0.1i90s STOR spam s226 Transfer Complete.(RRRERRRR_RgR<RRR$RRKR R`(RRRRRCRe((RRs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_passiveSTORs"        cs tjfd}fd}|j_jjjd\}}|j|j|tj j j j dj j jjdtjddfj j j dj j jjd tj||gS( s Test a failure in the STOR command. If the server does not acknowledge successful receipt of the uploaded file, the second Deferred returned by L{ftp.FTPClient.storeFile} should errback with L{ftp.CommandFailed}. csQjjd|jjdd|j|jtjtj ddS(Ns4150 File status okay; about to open data connection.R4iR-( RER$R<R7RR4RRR R(R(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRs   csFj|dj|d|j||f}|jdS(Ns 127.0.0.1i90(RgR?Rm(RR[RR(RR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRsRsPASV s227 Entering Passive Mode (%s).s 127.0.0.1i90s STOR spam s.426 Transfer aborted. Data connection closed.(RRRERRRR_RvRRwRgR<RRR$RKR R`(RRRRCRe((RRs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_failedSTORs"        cstjtj_fd}fd}fd}|j_jjjd\}}|j||j|t j ||gS(s Test the STOR command in non-passive mode. Like L{test_passiveSTOR} but in the configuration where the server establishes the data connection to the client, rather than the other way around. cs-dtjdd|_|jjdS(NsPORT %ss 127.0.0.1i&(RRKRR Rm(R(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR>scsjjjdtjddfjjjjdjjjdjjjjd|jjdd|j |j t j t jd jjd dS( Ns PORT %s s 127.0.0.1i&s 200 PORT OKs STOR spam s4150 File status okay; about to open data connection.R4iR-s226 Transfer Complete.(RgR<RRRKRRER$R7RR4RRR R(R(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRBs    csjjdddS(NR4i(RgR(R(RR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRPsR( RRRRERRRRR_R R`(RRRRRCRe((RRs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt test_STOR4s      csfd}fd}|j_jtj}jjd|j||}jjj djj jj dtj ddfjjj djj d |S( s{ Test the LIST command. L{ftp.FTPClient.list} should return a Deferred which fires with a protocol instance which was passed to list after the command has succeeded. (XXX - This is a very unfortunate API; if my understanding is correct, the results are always at least line-oriented, so allowing a per-line parser function to be specified would make this simpler, but a default implementation should really be provided which knows how to deal with all the formats used in real servers, so application developers never have to care about this insanity. It would also be nice to either get back a Deferred of a list of filenames or to be able to consume the files as they are received (which the current API does allow, but in a somewhat inconvenient fashion) -exarkun) csWg|jD]}|d^q }dddg}|j|jj||dS(NRRRtbaz(RyR$Rg(RRzR tflstexpected(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pytcbListns    csj|dj|d|j||f}|jtjjjddddg}x|D]}|j|qnW|jt j t j ddS(Ns 127.0.0.1i90s4150 File status okay; about to open data connection.s8-rw-r--r-- 0 spam egg 100 Oct 10 2006 foo s8-rw-r--r-- 3 spam egg 100 Oct 10 2006 bar s8-rw-r--r-- 4 spam egg 100 Oct 10 2006 baz R-( RgR?RmRRRER$R1R4RRR R(RR[RRtsendingR(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRus   sfoo/barsPASV s227 Entering Passive Mode (%s).s 127.0.0.1i90sLIST foo/bar s226 Transfer Complete.( RERRRRvRR_RgR<RRR$RK(RRRRzR0((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_passiveLIST[s   !  cstj_fd}fd}|j_jtj}jjd|j||}j j j dtj ddfj j jjdj j j dj j jjd |S( s Test the LIST command in non-passive mode. Like L{test_passiveLIST} but in the configuration where the server establishes the data connection to the client, rather than the other way around. csdtjddf|_|jjtjjjddddg}x|D]}|jj |qXW|jj t j t jddS( NsPORT %ss 127.0.0.1i&s4150 File status okay; about to open data connection.s8-rw-r--r-- 0 spam egg 100 Oct 10 2006 foo s8-rw-r--r-- 3 spam egg 100 Oct 10 2006 bar s8-rw-r--r-- 4 spam egg 100 Oct 10 2006 baz R-(RRKRR RmRRRER$R1R4RRR R(RRR(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRs    csWg|jD]}|d^q }dddg}|j|jj||dS(NRRRR(RyR$Rg(RRzR RR(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRs    sfoo/bars PORT %s s 127.0.0.1i&s 200 PORT OKsLIST foo/bar s226 Transfer Complete.(RRERRRRRvRR_RgR<RRKRR$(RRRRzR0((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt test_LISTs    !  csfd}|j_jtj}jjd|}j|tjjj j dj j jj dtj ddfjj j djj d|S( s Test a failure in LIST command. L{ftp.FTPClient.list} should return a Deferred which fails with L{ftp.CommandFailed} if the server indicates the indicated path is invalid for some reason. cs{j|dj|d|j||f}|jtjjjd|jtj t j ddS(Ns 127.0.0.1i90s4150 File status okay; about to open data connection.R-( RgR?RmRRRER$R4RRR R(RR[RR(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRs sfoo/barsPASV s227 Entering Passive Mode (%s).s 127.0.0.1i90sLIST foo/bar s&550 foo/bar: No such file or directory(RERRRRvRRvRwRgR<RRR$RK(RRRzR0((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_failedLISTs     cstj_fd}fd}|j_jt}jjd|j||}jj j dt j ddfj j jjdjj j djjd |S( s Test the NLST command in non-passive mode. L{ftp.FTPClient.nlst} should return a Deferred which fires with a list of filenames when the list command has completed. csdtjddf|_|jjtjjjd|jj d|jj d|jj d|jj t j t jddS( NsPORT %ss 127.0.0.1i&s4150 File status okay; about to open data connection.sfoo sbar sbaz R-(RRKRR RmRRRER$R1R4RRR R(R(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRs  csF|jj}dddg}|j|jj||dS(NRRR(R.RR$Rg(RRRR(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRs   sfoo/bars PORT %s s 127.0.0.1i&s 200 PORT OKsNLST foo/bar s226 Transfer Complete.(RRERRRR,tnlstR_RgR<RRRKRR$(RRRtlstprotoR0((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt test_NLSTs     ! csfd}fd}|j_jt}jjd|j||}jjjdjj jj dt j ddfjjjdjj d |S( s Test the NLST command. Like L{test_passiveNLST} but in the configuration where the server establishes the data connection to the client, rather than the other way around. csF|jj}dddg}|j|jj||dS(NRRR(R.RR$Rg(RRRR(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR s   csj|dj|d|j||f}|jtjjjd|jd|jd|jd|jt j t j ddS(Ns 127.0.0.1i90s4150 File status okay; about to open data connection.sfoo sbar sbaz R-( RgR?RmRRRER$R1R4RRR R(RR[RR(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRs    sfoo/barsPASV s227 Entering Passive Mode (%s).s 127.0.0.1i90sNLST foo/bar s226 Transfer Complete.( RERRR,RR_RgR<RRR$RRK(RRRRR0((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_passiveNLSTs   !  cstjfd}|j_jt}jjd|}j|tj j j j dj j jjdtjddfj j j djjd|S( s Test a failure in NLST command. L{ftp.FTPClient.nlst} should return a Deferred which fails with L{ftp.CommandFailed} if the server indicates the indicated path is invalid for some reason. csuj|dj|d|j||f}|jjjd|jtjtj ddS(Ns 127.0.0.1i90s4150 File status okay; about to open data connection.R-( RgR?RmRER$R4RRR R(RR[RR(RR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR6s  sfoo/barsPASV s227 Entering Passive Mode (%s).s 127.0.0.1i90sNLST foo/bar s&550 foo/bar: No such file or directory(RRRERRR,RRvRRwRgR<RRR$RK(RRRR0((RRs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_failedNLST-s      cs?jjtdtfd}jjd|S(sw L{ftp.FTPClient.changeDirectory} is deprecated and the direct caller of it is warned of this. s]FTPClient.changeDirectory is deprecated in Twisted 8.2 and newer. Use FTPClient.cwd instead.csjjdS(Nt.(REtchangeDirectory((R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRRXss 250 success(Rt assertWarnstDeprecationWarningt__file__RER$(RR0((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_changeDirectoryDeprecatedMs csafd}jjjdj|}jjjdjjd|S(s Test the changeDirectory method. L{ftp.FTPClient.changeDirectory} should return a Deferred which fires with True if succeeded. csj|tdS(N(RgR(R(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pytcbCdgssbar/foos CWD bar/foo s&250 Requested File Action Completed OK(RRERR_RgR<RR$(RRR0((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_changeDirectory`s  cCs\|j|jjd}|j|tj|j|jjd|jj d|S(sx Test a failure in the changeDirectory method. The behaviour here is the same as a failed CWD. sbar/foos CWD bar/foo s&550 bar/foo: No such file or directory( RRERRvRRwRgR<RR$(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_failedChangeDirectoryrs  cCs\|j|jjd}|j|tj|j|jjd|jj d|S(s Test a strange failure in changeDirectory method. L{ftp.FTPClient.changeDirectory} is stricter than CWD as it checks code 250 for success. sbar/foos CWD bar/foo s252 I do what I want !( RRERRvRRwRgR<RR$(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt!test_strangeFailedChangeDirectorys  cCs|j|jjdd}|j|jjd|jjd}|jj||j|jjdd}|jj||j|j|g|gf|S(s L{ftp.FTPClient.rename} issues I{RNTO} and I{RNFR} commands and returns a L{Deferred} which fires when a file has successfully been renamed. s/spams/hams RNFR /spam s8350 Requested file action pending further information. s RNTO /ham s&250 Requested File Action Completed OK( RREtrenameRgR<RRR$R_(RR0t fromResponset toResponse((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_renameFromTos  cCsf|jd}d}|jj|||jjd|jjd|j|jjddS(s L{ftp.FTPClient.rename} issues I{RNTO} and I{RNFR} commands with paths escaped according to U{http://cr.yp.to/ftp/filesystem.html}. s /foo/ba r/bazs/qu uxs350 s250 s!RNFR /foo/bar/baz RNTO /quux N(RRERR$RgR<R(RtfromFilettoFile((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_renameFromToEscapesPathss  cCs|j|jjdd}|j|jjd|jj|jjd|j|jjd|j|t j S(s The L{Deferred} returned by L{ftp.FTPClient.rename} is errbacked with L{CommandFailed} if the I{RNFR} command receives an error response code (for example, because the file does not exist). s/spams/hams RNFR /spam s!550 Requested file unavailable. R-( RRERRgR<RRR$RvRRw(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt$test_renameFromToFailingOnFirstErrors  cCs|j|jjdd}|j|jjd|jj|jjd|j|jjd|jjd|j|t j S(s The L{Deferred} returned by L{ftp.FTPClient.rename} is errbacked with L{CommandFailed} if the I{RNTO} command receives an error response code (for example, because the destination directory does not exist). s/spams/hams RNFR /spam s8350 Requested file action pending further information. s RNTO /ham s!550 Requested file unavailable. ( RRERRgR<RRR$RvRRw(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt"test_renameFromToFailingOnRenameTos  cCs[|j|jjd}|j|jjd|jjd|j|jdgS(s L{ftp.FTPClient.makeDirectory} issues a I{MKD} command and returns a L{Deferred} which is called back with the server's response if the directory is created. s/spams MKD /spam s257 "/spam" created.(RREt makeDirectoryRgR<RR$R_(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_makeDirectorys  cCsI|j|jjd}|j|jjd|jjd|S(s L{ftp.FTPClient.makeDirectory} escapes the path name it sends according to U{http://cr.yp.to/ftp/filesystem.html}. s/sp ams MKD /spam s257 win(RRERRgR<RR$(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_makeDirectoryPathEscapes  cCsX|j|jjd}|j|jjd|jjd|j|tj S(s L{ftp.FTPClient.makeDirectory} returns a L{Deferred} which is errbacked with L{CommandFailed} if the server returns an error response code. s/spams MKD /spam s550 PERMISSION DENIED( RRERRgR<RR$RvRRw(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_failedMakeDirectorys  cs^fd}jjjj|}jjjdjjd|S(s Test the getDirectory method. L{ftp.FTPClient.getDirectory} should return a Deferred which fires with the current directory on the server. It wraps PWD command. csj|ddS(Ns/bar/baz(Rg(R(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pytcbGet ssPWD s257 "/bar/baz"(RREt getDirectoryR_RgR<RR$(RRR0((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_getDirectory s  cCsY|j|jj}|j|tj|j|jjd|jj d|S(sj Test a failure in getDirectory method. The behaviour should be the same as PWD. sPWD s'550 /bar/baz: No such file or directory( RRERRvRRwRgR<RR$(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_failedGetDirectory s  cCsY|j|jj}|j|tj|j|jjd|jj d|S(s Test a different failure in getDirectory method. The response should be quoted to be parsed, so it returns an error otherwise. sPWD s 257 /bar/baz( RRERRvRRwRgR<RR$(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_anotherFailedGetDirectory( s  cCsa|j|jjd}|j|jjdd}|jj||j|j|gS(s L{ftp.FTPClient.removeFile} sends a I{DELE} command to the server for the indicated file and returns a Deferred which fires after the server sends a 250 response code. s /tmp/testsDELE /tmp/test s*250 Requested file action okay, completed.(RREt removeFileRgR<RR$R_(RR0tresponse((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_removeFile7 s  cs}jjjd}jjjddjjj|tj }|j fd|S(s If the server returns a response code other than 250 in response to a I{DELE} sent by L{ftp.FTPClient.removeFile}, the L{Deferred} returned by C{removeFile} is errbacked with a L{Failure} wrapping a L{CommandFailed}. s /tmp/testsDELE /tmp/test s,501 Syntax error in parameters or arguments.csj|jgfS(N(RgRr(texc(RR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRRR s( RRERRgR<RR$RvRRwR_(RR0((RRs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_failedRemoveFileE s csdjjjd}djjj|tj}|jfd|S(s If the server returns a response line which cannot be parsed, the L{Deferred} returned by L{ftp.FTPClient.removeFile} is errbacked with a L{BadResponse} containing the response. s /tmp/tests765 blah blah blahcsj|jgfS(N(RgRr(R(RR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRRa s(RRERR$RvRt BadResponseR_(RR0((RRs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt!test_unparsableRemoveFileResponseV s cCsK|j|jjd}ddg}t|jj||j|jS(s If the server returns multiple response lines, the L{Deferred} returned by L{ftp.FTPClient.removeFile} is still fired with a true value if the ultimate response code is 250. s /tmp/tests250-perhaps a progress reports250 okay(RRERRR$R_R(RR0R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt test_multilineRemoveFileResponsee s   cCsa|j|jjd}|j|jjdd}|jj||j|j|gS(s L{ftp.FTPClient.removeDirectory} sends a I{RMD} command to the server for the indicated directory and returns a Deferred which fires after the server sends a 250 response code. s /tmp/testsRMD /tmp/test s*250 Requested file action okay, completed.(RREtremoveDirectoryRgR<RR$R_(RR0R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_removeDirectorys s  cs}jjjd}jjjddjjj|tj }|j fd|S(s  If the server returns a response code other than 250 in response to a I{RMD} sent by L{ftp.FTPClient.removeDirectory}, the L{Deferred} returned by C{removeDirectory} is errbacked with a L{Failure} wrapping a L{CommandFailed}. s /tmp/testsRMD /tmp/test s,501 Syntax error in parameters or arguments.csj|jgfS(N(RgRr(R(RR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRR s( RRERRgR<RR$RvRRwR_(RR0((RRs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_failedRemoveDirectory s csdjjjd}djjj|tj}|jfd|S(s If the server returns a response line which cannot be parsed, the L{Deferred} returned by L{ftp.FTPClient.removeDirectory} is errbacked with a L{BadResponse} containing the response. s /tmp/tests765 blah blah blahcsj|jgfS(N(RgRr(R(RR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRR s(RRERR$RvRRR_(RR0((RRs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt&test_unparsableRemoveDirectoryResponse s cCsK|j|jjd}ddg}t|jj||j|jS(s If the server returns multiple response lines, the L{Deferred} returned by L{ftp.FTPClient.removeDirectory} is still fired with a true value if the ultimate response code is 250. s /tmp/tests250-perhaps a progress reports250 okay(RRERRR$R_R(RR0R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt%test_multilineRemoveDirectoryResponse s   (1R(R)R{RfRORRRRRRRRRRRRRRRRRRRRRRt_changeDirectorySuppressiontsuppressRRRRRRRRRRRRRRRRRRRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRs`         ' # " / & ' 7 -  ' (                     tFTPClientBasicTestscBs5eZdZdZdZdZdZRS(cCs3tj}|jd|jdg|jdS(Ns220 Imaginary FTP.(RR|R$Rgtgreeting(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt testGreeting s  cCs3tj}|jd|jdg|jdS(Ns220 (RR|R$RgR (RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttestResponseWithNoMessage s  cCsEtj}tj|_|jd|jd}g}|j|j|j |j |jd|j g||jd|j g||jd|j g||jd|j g||jd|j g||jd|j g||jd |j ddddddd g|d dS( Ns220 Imaginary FTP.tBLAHs210-First line.s123-Second line.sJust some text.tHiR-t321s 210 Done.i( RR|RRR<R$RkR_R"RRRg(RRRR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttestMultilineResponse s8         cCstj}tj|_|jd|jdd|jd|jj |jj |jd|jd|jj dS(sO Passing None as the password avoids sending the PASS command. s220 Welcome to Imaginary FTP.tbobs USER bob s200 Hello bob.R-N( RR|RRR<R$t queueLoginR*RgRR(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_noPasswordGiven s    cCstj}tj|_|jd|jdd|jd|jj|jj |jd|jd|jjdS(sQ Receiving a 230 response to USER prevents PASS from being sent. s220 Welcome to Imaginary FTP.Rtsecrets USER bob s#230 Hello bob. No password needed.R-N( RR|RRR<R$RRgRR(RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_noPasswordNeeded s    (R(R)R R RRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR s    0 t PathHandlingcBseZdZRS(c Cs@xddgfddgfdgfddddgfddddgfddgfd dgfgD](\}}|jtjg||qdWxdddgfd ddgfd dgfd dgfd dddgfddddgfdddgfdddgfgD]+\}}|jtjdg||qWx`dgfddgfddgfdddgfgD](\}}|jtjg||quWxZdgfddgfddddgfgD]+\}}|jtjdg||qWxdgfdgfddgfdgfddgfddgfdddgfdddgfd dgfd!dgfd"gfd#gfg D]+\}}|jtjdg||qWxEddd$d%d&d'd(d)d*g D]"}|jtjtjg|qWx6d+d,d-gD]%}|jtjtjdg|qWdS(.NRs/at/sa/b/cRtcs/a/b/cs/a/sa/sb/s/bs/b/sb/csb/c/s/b/cs/b/c/s//s//asa//sa//bs//bsb//cs..s../sa/..R4s/a/..s/a/b/..s/a/b/../s /a/b/../cs /a/b/../c/s /a/b/../../cs /a/b/../../c/s/a/b/../../c/..s/a/b/../../c/../sa/../..sa/../../s/..s/../s/a/../..s /a/../../s /a/b/../../..s../..s../../s ../a/../..(RgRt toSegmentsRt InvalidPath(Rtinptoutp((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttestNormalizer sZ      #      "#         #   (R(R)R(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR stIsGlobbingExpressionTestscBs)eZdZdZdZdZRS(s; Tests for _isGlobbingExpression utility function. cCsC|jtj|jtjg|jtjddS(s^ _isGlobbingExpression will return False for None, or empty segments. N(R^Rt_isGlobbingExpressionR*(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt&test_isGlobbingExpressionEmptySegmentsZ scCs<|jtjddg|jtjddgdS(s _isGlobbingExpression will return False for plain segments. Also, it only checks the last segment part (filename) and will not check the path name. Rtexprs*.txtN(R^RR(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_isGlobbingExpressionNoGlobd scCsX|jtjddg|jtjddg|jtjddgdS(s _isGlobbingExpression will return True for segments which contains globbing characters in the last segment part (filename). Rs*.txts [a-b].txtsfil?.txtN(RRR(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_isGlobbingExpressionGlobo s(R(R)R{RR!R"(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRU s tBaseFTPRealmTestscBs2eZdZdZdZdZdZRS(s Tests for L{ftp.BaseFTPRealm}, a base class to help define L{IFTPShell} realms with different user home directory policies. cCs|jtttjdS(s; L{ftp.BaseFTPRealm} implements L{IRealm}. N(RRRRt BaseFTPRealm(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_interface scstj|jgdtjffdY}||j}|jddtj\}}}|j|tj |j |j dS(s L{ftp.BaseFTPRealm} calls its C{getHomeDirectory} method with the avatarId being requested to determine the home directory for that avatar. t TestRealmcseZfdZRS(csj|S(N(R"(RtavatarId(tavatarsR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pytgetHomeDirectory s (R(R)R)((R(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR& ssalice@example.comN( RRKRGRR$t requestAvatarR*t IFTPShellRtFTPShellRgtfilesystemRoot(RR&trealmtifacetavatartlogout((R(Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_getHomeDirectory s"cCsr|j}tj|}|jtjdtj\}}}|j|tj |j |j t j |dS(sy L{ftp.BaseFTPRealm} returns an L{ftp.FTPAnonymousShell} instance for anonymous avatar requests. N(RGRR$R*Rt ANONYMOUSR*R+RRRgR-RRK(RR6R.R/R0R1((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_anonymous s  cCs2tj|j}|jt|jtdS(s L{ftp.BaseFTPRealm.getHomeDirectory} should be overridden by a subclass and raises L{NotImplementedError} if it is not. N(RR$RGRtNotImplementedErrorR)R(RR.((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_notImplemented s(R(R)R{R%R2R4R6(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR#z s    tFTPRealmTestCasecBs eZdZdZdZRS(s$ Tests for L{ftp.FTPRealm}. cCsSd}tj|j|}|jd}|jtj|jd|dS(s L{ftp.FTPRealm} accepts an extra directory to its initializer and treats the avatarId passed to L{ftp.FTPRealm.getHomeDirectory} as a single path segment to construct a child of that directory. s /path/to/homesalice@example.comN(RRNRGR)RgRRKR(RtbaseR.thome((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR2 s cCsAtj|j}|jd}|jtjd|dS(s If no extra directory is passed to L{ftp.FTPRealm}, it uses C{"/home"} as the base directory containing all user home directories. salice@example.coms/home/alice@example.comN(RRNRGR)RgRRK(RR.R9((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_defaultHomeDirectory s(R(R)R{R2R:(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR7 s tSystemFTPRealmTestscBs&eZdZeZdZdZRS(s* Tests for L{ftp.SystemFTPRealm}. cCsktj}ddl}|j|j}tj|j}|j|}|j |t j |dS(s L{ftp.SystemFTPRealm.getHomeDirectory} treats the avatarId passed to it as a username in the underlying platform and returns that account's home directory. iN( tgetpasstgetuserRtgetpwnamtpw_dirRtSystemFTPRealmRGR)RgRRK(RR/RRR.R9((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR2 s   cCsDtdjd}tj|j}|jt|j|dS(s L{ftp.SystemFTPRealm.getHomeDirectory} raises L{UnauthorizedLogin} when passed a username which has no corresponding home directory in the system's accounts database. ithexN(RtencodeRR@RGRRR)(RR/R.((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_noSuchUser s(R(R)R{t nonPOSIXSkiptskipR2RC(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR; s tErrnoToFailureTestCasecBsMeZdZdZdZdZdZdZdZdZ RS(s9 Tests for L{ftp.errnoToFailure} errno checking. cCs(tjtjd}|j|tjS(sS C{errno.ENOENT} should be translated to L{ftp.FileNotFoundError}. R(RterrnoToFailureterrnotENOENTRvtFileNotFoundError(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt test_notFound scCs(tjtjd}|j|tjS(sV C{errno.EPERM} should be translated to L{ftp.PermissionDeniedError}. R(RRGRHtEPERMRvtPermissionDeniedError(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_permissionDenied scCs(tjtjd}|j|tjS(sW C{errno.EACCES} should be translated to L{ftp.PermissionDeniedError}. R(RRGRHtEACCESRvRM(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_accessDenied scCs(tjtjd}|j|tjS(sW C{errno.ENOTDIR} should be translated to L{ftp.IsNotADirectoryError}. R(RRGRHtENOTDIRRvtIsNotADirectoryError(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_notDirectory scCs(tjtjd}|j|tjS(sQ C{errno.EEXIST} should be translated to L{ftp.FileExistsError}. R(RRGRHtEEXISTRvtFileExistsError(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_fileExists scCs(tjtjd}|j|tjS(sS C{errno.EISDIR} should be translated to L{ftp.IsADirectoryError}. R(RRGRHtEISDIRRvR(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_isDirectory scCs=ytdWn&tjdd}|j|tSXdS(s If an unknown errno is passed to L{ftp.errnoToFailure}, it should let the originating exception pass through. RiRN(RRRGRv(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_passThrough( s ( R(R)R{RKRNRPRSRVRXRY(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRF s      tAnonymousFTPShellTestCasecBseZdZdZRS(s* Test anynomous shell properties. cCs5tjd}|jd}|j|tj|S(st Check that L{ftp.FTPAnonymousShell} returns an error when trying to open it in write mode. R-R(sfoo(RRRRvRM(RRR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_anonymousWrite: s(R(R)R{R[(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRZ5 stIFTPShellTestsMixincBsCeZdZdZdZdZddZdZdZdZ d Z d Z d Z d Z d ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ d Z!d!Z"d"Z#d#Z$RS($s7 Generic tests for the C{IFTPShell} interface. cCs tdS(s  Test if the directory exists at C{path}. @param path: the relative path to check. @type path: C{str}. @return: C{True} if C{path} exists and is a directory, C{False} if it's not the case @rtype: C{bool} N(R5(RR"((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pytdirectoryExistsK s cCs tdS(s Create a directory in C{path}. @param path: the relative path of the directory to create, with one segment. @type path: C{str} N(R5(RR"((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRY scCs tdS(s Test if the file exists at C{path}. @param path: the relative path to check. @type path: C{str}. @return: C{True} if C{path} exists and is a file, C{False} if it's not the case. @rtype: C{bool} N(R5(RR"((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt fileExistsd s R-cCs tdS(s Create a file named C{path} with some content. @param path: the relative path of the file to create, without directory. @type path: C{str} @param fileContent: the content of the file. @type fileContent: C{str} N(R5(RR"t fileContent((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt createFiler s cCs=|j|jd|jd|j|jddS(s C{directoryExists} should report correctly about directory existence, and C{createDirectory} should create a directory detectable by C{directoryExists}. RN(R^R]RR(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_createDirectory s cCs=|j|jd|jd|j|jddS(s C{fileExists} should report correctly about file existence, and C{createFile} should create a file detectable by C{fileExists}. sfile.txtN(R^R^R`R(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_createFile s cs.jjd}fd}|j|S(sI Create a directory and check it ends in the filesystem. RcsjjddS(NR(RR](R(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pytcb s(sfoo(RRR_(RR0Rc((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR scCs2|jd|jjd}|j|tjS(sm Creating a directory that already exists should fail with a C{ftp.FileExistsError}. R(sfoo(RRRRvRRU(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_makeDirectoryError s cs;jdjjd}fd}|j|S(sW Try to remove a directory and check it's removed from the filesystem. RcsjjddS(NR(R^R](R(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRc s(sbar(RRRR_(RR0Rc((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR s cCs2|jd|jjd}|j|tjS(sn removeDirectory should not work in file and fail with a C{ftp.IsNotADirectoryError}. sfile.txt(sfile.txt(R`RRRvRRR(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_removeDirectoryOnFile s cCs%|jjd}|j|tjS(sl Removing directory that doesn't exist should fail with a C{ftp.FileNotFoundError}. R(sbar(RRRvRRJ(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_removeNotExistingDirectory scs?jdjjd}fd}|j||S(sR Try to remove a file and check it's removed from the filesystem. sfile.txtcsjjddS(Nsfile.txt(R^R^(R(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRc s(sfile.txt(R`RRR_(RR0Rc((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR s   cCs2|jd|jjd}|j|tjS(s: removeFile should not work on directory. tned(Rg(RRRRvRR(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_removeFileOnDirectory s cCs%|jjd}|j|tjS(sl Try to remove a non existent file, and check it raises a L{ftp.FileNotFoundError}. R(sfoo(RRRvRRJ(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_removeNotExistingFile scsHjdjdjjd}fd}|j|S(s6 Check the output of the list method. Rgsfile.txtRcs0|jj|dgfdgfgdS(Nsfile.txtRg(R$Rg(RP(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRc s  (R(RR`RRR_(RR0Rc((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt test_list s   csKjdjdjjdd}fd}|j|S( s< Check the output of list with asked stats. Rgsfile.txtRR5t permissionscs|jjt|dj|dddj|dddjt|dddjt|ddddS(Niisfile.txtiRg(R$RgR(RP(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRc s  (R(ssizeRk(RR`RRR_(RR0Rc((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_listWithStat s    cCs2|jd|jjdd}|j|tS(sP Querying an invalid stat should result to a C{AttributeError}. RgRR5t whateverstat(R(ssizeRm(RRRRvtAttributeError(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_listWithInvalidStat s cs;jdjjd}fd}|j|S(s@ Check the output of the list method on a file. sfile.txtcs'|jj|dgfgdS(Nsfile.txt(R$Rg(RP(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRc s  (sfile.txt(R`RRR_(RR0Rc((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt test_listFile s cCs%|jjd}|j|tjS(sm list on a directory that doesn't exist should fail with a L{ftp.FileNotFoundError}. R(sfoo(RRRvRRJ(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_listNotExistingDirectory scCs#|jd|jjd}|S(s+ Try to access a resource. Rg(sned(RRtaccess(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt test_access% s cCs%|jjd}|j|tjS(sF access should fail on a resource that doesn't exist. R(sfoo(RRrRvRRJ(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_accessNotFound. scs?jdjjd}fd}|j||S(sY Check that openForReading returns an object providing C{ftp.IReadFile}. sfile.txtcsjtjj|dS(N(RRt IReadFilet providedBy(R(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRc< s(sfile.txt(R`RR R_(RR0Rc((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_openForReading6 s   cCs%|jjd}|j|tjS(sr openForReading should fail with a C{ftp.FileNotFoundError} on a file that doesn't exist. Rg(sned(RR RvRRJ(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_openForReadingNotFoundB scCs2|jd|jjd}|j|tjS(s> openForReading should not work on directory. Rg(sned(RRR RvRR(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_openForReadingOnDirectoryK s csDjjd}fd}fd|j||S(sZ Check that openForWriting returns an object providing C{ftp.IWriteFile}. Rcs,jtjj||jjS(N(RRt IWriteFileRvRR_(R(tcb2R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pytcb1Y scsjtj|dS(N(RR Rv(R(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR{\ s(sfoo(RRR_(RR0R|((R{Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_openForWritingT s  cCs2|jd|jjd}|j|tjS(sd openForWriting should not be able to open a directory that already exists. Rg(sned(RRRRvRR(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt$test_openForWritingExistingDirectoryb s cCs2|jd|jjd}|j|tjS(s openForWring should fail with a L{ftp.FileNotFoundError} if you specify a file in a directory that doesn't exist. Rgt idonotexistR(snedRsfoo(RRRRvRRJ(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt)test_openForWritingInNotExistingDirectoryl s csNdjdjjdd}fd}|j||S(s@ Check the output of the stat method on a file. swobble sfile.txtR5RHcs/j|dtj|ddS(Nii(RgRR^(R(R_R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRc} s(sfile.txt(ssizes directory(R`RtstatR_(RR0Rc((R_Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt test_statFilev s  csBjdjjdd}fd}|j||S(sE Check the output of the stat method on a directory. RgR5RHcsj|ddS(Ni(R(R(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRc s(sned(ssizes directory(RRRR_(RR0Rc((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_statDirectory s   csBjdjjdd}fd}|j||S(s3 Check the owner and groups stats. RgRR0csjt|ddS(Ni(RgR(R(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRc s(sned(sownersgroup(RRRR_(RR0Rc((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_statOwnerGroup s   cCs(|jjdd}|j|tjS(sf stat should fail with L{ftp.FileNotFoundError} on a file that doesn't exist. RR5RH(sfoo(ssizes directory(RRRvRRJ(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_statNotExisting scCs2|jd|jjdd}|j|tS(sP Querying an invalid stat should result to a C{AttributeError}. RgR5Rm(sned(ssizes whateverstat(RRRRvRn(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_invalidStat s cs>jdjjdd}fd}|j|S(s, Try to rename a directory. RgRcs0jjdjjddS(NRRg(RR]R^(R(R(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRc s(sned(sfoo(RRRR_(RR0Rc((Rs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt test_rename s cCs(|jjdd}|j|tjS(sl Renaming a directory that doesn't exist should fail with L{ftp.FileNotFoundError}. RR(sfoo(sbar(RRRvRRJ(RR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyttest_renameNotExisting s(%R(R)R{R]RR^R`RaRbRRdRReRfRRhRiRjRlRoRpRqRsRtRwRxRyR}R~RRRRRRRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR\F sF         tFTPShellTestCasecBs>eZdZdZdZdZdZddZRS(s/ Tests for the C{ftp.FTPShell} object. cCs>tj|j|_|jjtj|j|_dS(sB Create a root directory and instantiate a shell. N(RRKRGRRRR,R(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRf s cCs|jj|jS(s: Test if the directory exists at C{path}. (RRtisdir(RR"((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR] scCs|jj|jS(s0 Create a directory in C{path}. (RRR(RR"((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR scCs|jj|jS(s5 Test if the file exists at C{path}. (RRtisfile(RR"((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR^ sR-cCs|jj|j|S(s@ Create a file named C{path} with some content. (RRt setContent(RR"R_((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR` s(R(R)R{RfR]RR^R`(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR s    t TestConsumercBs9eZdZeedZdZdZdZ RS(s A simple consumer for tests. It only works with non-streaming producers. @ivar producer: an object providing L{twisted.internet.interfaces.IPullProducer}. cCs8|jdkstg|_||_|jjdS(sc Simple register of producer, checks that no register has happened before. N(tproducerR*RR.tresumeProducing(RRt streaming((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pytregisterProducer s  cCs"|jdk std|_dS(sN Unregister the producer, it should be done after a register. N(RR*R(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pytunregisterProducer scCs!|jj||jjdS(s) Save the data received. N(R.R"RR(RR%((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR7 sN( R(R)R{RR R*RRRR7(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR s   t TestProducercBs eZdZdZdZRS(s A dumb producer. cCs||_||_dS(s @param toProduce: data to write @type toProduce: C{str} @param consumer: the consumer of data. @type consumer: C{IConsumer} N(t toProduceR(RRR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR s cCs|jj|jdS(s+ Send the data to consume. N(RR7R(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pytstart& s(R(R)R{RR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR s tIReadWriteTestsMixincBs;eZdZdZdZdZdZdZRS(sJ Generic tests for the C{IReadFile} and C{IWriteFile} interfaces. cCs tdS(sY Return an object providing C{IReadFile}, ready to send data C{content}. N(R5(Rtcontent((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt getFileReader3 scCs tdS(sR Return an object providing C{IWriteFile}, ready to receive data. N(R5(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt getFileWriter: scCs tdS(s6 Return the content of the file used. N(R5(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pytgetFileContentA scsLdtfd}fdjj|S(s Test L{ftp.IReadFile}: the implementation should have a send method returning a C{Deferred} which fires when all the data has been sent to the consumer, and the data should be correctly send to the consumer. swobble cs|jjS(N(RR_(treader(tcbSendR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRP scs jdjjdS(NR-(RgRR.(R(RRR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRR s(RRR_(RR((RRRRs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt test_readH s  csLdfd}fdfdjj|S(s Test L{ftp.IWriteFile}: the implementation should have a receive method returning a C{Deferred} which fires with a consumer ready to receive data to be written. It should also have a close() method that returns a Deferred. selbbow cs|jj|S(N(RR_(twriter(t cbReceive(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR_ scsFt|}|jdt|j|j|jjS(N(RRR*RRRR8R_(RRR(tcbCloseR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRa s   csjjdS(N(RgR(Rl(RR(s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRg s(RR_(RR((RRRRs9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt test_writeW s (R(R)R{RRRRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR. s     tFTPReadWriteTestCasecBs2eZdZdZdZdZdZRS(s Tests for C{ftp._FileReader} and C{ftp._FileWriter}, the objects returned by the shell in C{openForReading}/C{openForWriting}. cCsGtj|j|_|jjtj|j|_d|_dS(s5 Create a temporary file used later. sfile.txtN( RRKRGRRRR,RR(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRfs s cCs2|jj|jj||jj|jfS(sV Return a C{ftp._FileReader} instance with a file opened for reading. (RRRRRR (RR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR} scCs|jj|jfS(sV Return a C{ftp._FileWriter} instance with a file opened for writing. (RRR(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR scCs|jj|jjS(s; Return the content of the temporary file. (RRRt getContent(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR s(R(R)R{RfRRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyRm s   tCloseTestWritercBs-eZeejeZdZdZRS(cCs+t|_tj|j}tj|S(N(RRRt FileConsumerR Ro(Rtfc((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR s cCst|_|jS(N(Rt closeStartedR0(R((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR8 s ( R(R)RRRzRRRR8(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR s  tCloseTestShellcBseZdZRS(cCstj|jS(N(R RoR(Rtsegs((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR s(R(R)R(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR st FTPCloseTestcBseZdZdZRS(s.Tests that the server invokes IWriteFile.closecCsetj}dg|_t|_t|j_tj|jj_ tj |_ d|j _ |jttj}tj||_ ||_|jdg}|jd}|j|j|j|jjjd|jd|j|jjjd|jd|j|jjjd|j||jjj jd|j||S( stConfirm that FTP uploads (i.e. ftp_STOR) correctly call and wait upon the IWriteFile object's close() methodRR"sclose() called earlyssome data heresreason is ignoredsclose() not calledsallow close() to finishN(RtFTPtworkingDirectoryRRRRR R/R0RWRR*ttimeOutRmRRbRZRtftp_STORR_R"R^RR1R4RR2(RR tdit stor_doneR0((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR s0           (R(R)R{R(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR stFTPResponseCodeTestscBseZdZdZRS(s4 Tests relating directly to response codes. cCsttj}t}xttjD]q\}}t|tr+|jr+|j||d||f|j ||d||f|j |q+q+WdS(s All of the response code globals (for example C{RESTART_MARKER_REPLY} or C{USR_NAME_OK_NEED_PASS}) have unique values and are present in the C{RESPONSE} dictionary. s0Code %r with value %r missing from RESPONSE dictsDuplicate code %r with value %rN( tsetRtRESPONSEtvarstitemst isinstanceRtisupperRt assertNotIntadd(Rt allValuest seenValuestkeyR((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyt test_unique s (R(R)R{R(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyR s(UR{RIRHRR<tzope.interfaceRtzope.interface.verifyRt twisted.trialRRttwisted.python.randbytesRttwisted.cred.portalRttwisted.protocolsRttwisted.internetRR R R R ttwisted.internet.interfacesR ttwisted.cred.errorRt twisted.credRRRttwisted.pythonRRRt twisted.testRRRRRRtplatformt isWindowsRDR*t LineReceiverRRR,tTestCaseR5R}RRRRFRVRkRrRvRtRxRRRRRR#R7R;RFRZR\RRRRRRRRRR(((s9/usr/lib/python2.7/dist-packages/twisted/test/test_ftp.pyts|   (    tp2I*  y6m8%7&B+'?' &