/usr/lib/python3/dist-packages/twisted/protocols/__pycache__
Edit: /usr/lib/python3/dist-packages/twisted/protocols/__pycache__/ftp.cpython-310.pyc (100484B)
o
b @ s d Z ddlZddlZddlZddlZddlZddlZz
ddlZddlZW n
e y1 d ZZY nw ddl
mZmZ ddl
mZ ddlmZmZmZmZ ddlmZmZmZmZmZ ddlmZmZ ddlmZmZm Z d Z!d
Z"dZ#dZ$d
Z%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3dZ4dZ5dZ6dZ7d Z8d!Z9d"Z:d#Z;d$Z
d'Z?d(Z@d)ZAd*ZBd+ZCd,ZDd-ZEd.ZFd/ZGd0ZHd1ZId2ZJd3ZKd4ZLd5ZMd6ZNd7ZOd8ZPd9ZQd:ZRd;ZSdZVd?ZWd@ZXdAZYdBZZi e!dCe"dDe#dEe$dFe%dGe&dHe'dIe(dJe)dKe*dLdMge+dNe,dOe-dPe.dQe0dRe/dSe1dTi e2dUe3dVe4dWe5dXe6dYe7dZe8d[e9d\e:d]e;d^edae?dbe@dceAddeBdei eCdfeDdgeEdheFdieGdjeHdkeIdleJdmeKdneLdoeMdpeNdqeOdrePdseQdteRdueSdveTdweVdxeWdyeUdzeXd{eYd|eZd}iZ[G d~d de\Z]dd Z^dd Z_e`dZadddZbG dd de\ZcG dd decZdG dd decZeG dd decZfG dd decZgG dd decZhG dd decZiG dd decZjG dd decZkG dd decZlG dd decZmG dd de\ZnG dd de\ZoG dd decZpG dd decZqdd Zrg dZseejtG dd dejuZvG dd dejwZxG dd dZyeejtG dd dZzG dd dej{Z|G dd dej{ej}Z~G dd dejZG dd deZG dd deZG dd deZdd ZdddZeeG dd dZeeG ddĄ dăZG ddƄ deZeeG ddȄ dȃZeejG ddʄ dʃZG dd̄ deZG dd΄ deZG ddЄ denZG dd҄ denZG ddԄ denZG ddք denZG dd denZG ddڄ dڃZG dd܄ dejuZG ddބ dejtZeeG dd dejuZdd Zdd Zdd ZG dd dejZG dd dej{ZG dd dejwZG dd deZG dd dej{Zdd ZdS )z
An FTP protocol implementation
N) Interfaceimplementer) copyright)checkerscredentialserrorportal)deferr
interfacesprotocolreactor)basicpolicies)failurefilepathlog100120125150z200.1z200.2z200.3202z211.1z211.2212213214215z220.1z220.2z221.1z221.2225z226.1z226.2227229z230.1z230.2250z257.1z257.2z331.1z331.2332350z421.1z421.2425426450451452500501z502.1z502.2503504z530.1z530.2532z550.1z550.2z550.3z550.4z550.5z550.6z550.7551552553z110 MARK yyyy-mmmmz120 service ready in %s minutesz3125 Data connection already open, starting transferz4150 File status okay; about to open data connection.z200 Command OKz200 Type set to %s.z200 PORT OKz5202 Command not implemented, superfluous at this sitez211 System status replyz
211-Features:z211 Endz212 %sz213 %sz214 help: %sz215 UNIX Type: L8z220 %sz220 Service readyz&221 Service closing control connectionz221 Goodbye.z1225 data connection open, no transfer in progressz226 Abort successfulz226 Transfer Complete.z227 Entering Passive Mode (%s).z,229 Entering Extended Passive Mode (|||%s|).z230 User logged in, proceedz2230 Anonymous login ok, access restrictions apply.z&250 Requested File Action Completed OKz257 "%s"z257 "%s" createdz331 Password required for %s.z8331 Guest login ok, type your email address as password.z332 Need account for login.z6350 Requested file action pending further information.z6421 Service not available, closing control connection.z9421 Too many users right now, try again in a few minutes.z425 Can't open data connection.z.426 Transfer aborted. Data connection closed.z/450 Requested action aborted. File unavailable.z8451 Requested action aborted. Local error in processing.z3452 Requested action aborted. Insufficient storage.z500 Syntax error: %sz#501 syntax error in argument(s) %s.z 502 Command '%s' not implementedz 502 Option '%s' not implemented.z&503 Incorrect sequence of commands: %sz'504 Not implemented for parameter '%s'.z$530 Please login with USER and PASS.z!530 Sorry, Authentication failed.z%532 Need an account for storing filesz"550 %s: No such file or directory.z550 %s: Permission denied.z:550 Anonymous users are forbidden to change the filesystemz%550 Cannot rmd, %s is not a directoryz550 %s: File existsz550 %s: is a directoryz"550 Requested action not taken: %sz551 Page type unknownzC552 Requested file action aborted, exceeded file storage allocationz5553 Requested action not taken, file name not allowedc @ s e Zd ZdZdS )InvalidPathzL
Internal exception used to signify an error during parsing a path.
N)__name__
__module____qualname____doc__ r3 r3 7/usr/lib/python3/dist-packages/twisted/protocols/ftp.pyr. s r. c C s | drg }n| dd }|dD ]-}|dks|dkrq|dkr.|r)| qt| |d|v s6d|v r;t| ||| q|S )zn
Normalize a path, as represented by a list of strings each
representing one segment of the path.
/N. .. )
startswithsplitpopr. append)cwdpathsegssr3 r3 r4
toSegments s
rB c C s | t jkrtt|S | t jks| t jkrtt|S | t jkr)tt |S | t j
kr5tt|S | t jkrAtt
|S t S )z?
Map C{OSError} and C{IOError} to standard FTP errors.
)errnoENOENTr failFileNotFoundErrorEACCESEPERMPermissionDeniedErrorENOTDIRIsNotADirectoryErrorEEXISTFileExistsErrorEISDIRIsADirectoryError)er? r3 r3 r4 errnoToFailure s
rQ TESTc C s8 | sdS | d }t |}td|d}||krdS dS )a
Helper for checking if a FTPShell `segments` contains a wildcard Unix
expression.
Only filename globbing is supported.
This means that wildcards can only be presents in the last element of
`segments`.
@type segments: C{list}
@param segments: List of path elements as used by the FTP server protocol.
@rtype: Boolean
@return: True if `segments` contains a globbing expression.
FrR T)fnmatch translate_testTranslationreplace)segments
globCandidateglobTranslationsnonGlobTranslationsr3 r3 r4 _isGlobbingExpression s
r] c @ e Zd ZdZdd Zdd ZdS )FTPCmdErrorz-
Generic exception for FTP commands.
c G s t j| g|R || _d S N) Exception__init__errorMessage)selfmsgr3 r3 r4 rb s
zFTPCmdError.__init__c C s t | j | j S )zA
Generate a FTP response message for this error.
)RESPONSE errorCoderc rd r3 r3 r4 response s zFTPCmdError.responseN)r/ r0 r1 r2 rb ri r3 r3 r3 r4 r_
s r_ c @ e Zd ZdZeZdS )rF zH
Raised when trying to access a non existent file or directory.
N)r/ r0 r1 r2 FILE_NOT_FOUNDrg r3 r3 r3 r4 rF rF c @ rj )AnonUserDeniedErrorz[
Raised when an anonymous user issues a command that will alter the
filesystem
N)r/ r0 r1 r2 ANON_USER_DENIEDrg r3 r3 r3 r4 rm " rm c @ rj )rI z[
Raised when access is attempted to a resource to which access is
not allowed.
N)r/ r0 r1 r2 PERMISSION_DENIEDrg r3 r3 r3 r4 rI + ro rI c @ rj )rK zE
Raised when RMD is called on a path that isn't a directory.
N)r/ r0 r1 r2 IS_NOT_A_DIRrg r3 r3 r3 r4 rK 4 rl rK c @ rj )rM zA
Raised when attempted to override an existing resource.
N)r/ r0 r1 r2 FILE_EXISTSrg r3 r3 r3 r4 rM < rl rM c @ rj )rO zC
Raised when DELE is called on a path that is a directory.
N)r/ r0 r1 r2 IS_A_DIRrg r3 r3 r3 r4 rO D rl rO c @ rj )CmdSyntaxErrorz0
Raised when a command syntax is wrong.
N)r/ r0 r1 r2
SYNTAX_ERRrg r3 r3 r3 r4 rt L rl rt c @ rj )CmdArgSyntaxErrorz^
Raised when a command is called with wrong value or a wrong number of
arguments.
N)r/ r0 r1 r2 SYNTAX_ERR_IN_ARGSrg r3 r3 r3 r4 rv T ro rv c @ rj )CmdNotImplementedErrorzF
Raised when an unimplemented command is given to the server.
N)r/ r0 r1 r2 CMD_NOT_IMPLMNTDrg r3 r3 r3 r4 rx ] rl rx c @ rj )CmdNotImplementedForArgErrorze
Raised when the handling of a parameter for a command is not implemented by
the server.
N)r/ r0 r1 r2 CMD_NOT_IMPLMNTD_FOR_PARAMrg r3 r3 r3 r4 rz e ro rz c @ e Zd ZdS )FTPErrorNr/ r0 r1 r3 r3 r3 r4 r} n r} c @ r| )PortConnectionErrorNr~ r3 r3 r3 r4 r r r r c @ rj )BadCmdSequenceErrorzS
Raised when a client sends a series of commands in an illogical sequence.
N)r/ r0 r1 r2 BAD_CMD_SEQrg r3 r3 r3 r4 r v rl r c @ rj )AuthorizationErrorz2
Raised when client authentication fails.
N)r/ r0 r1 r2 AUTH_FAILURErg r3 r3 r3 r4 r ~ rl r c G s t jdt| dd d S )NzdebugDeferred(): %sTdebug)r re str)rd _r3 r3 r4
debugDeferred s r )
NJanFebMarAprMayJunJulAugSepOctNovDecc @ s e Zd ZdZdZdZdZdZdd Zdd Z dd Z
d
d Zdd
Zdd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! ZdS )"DTPFNlatin-1c C s d| _ | jjd g | _d S NT)isConnectedfactorydeferredcallback_bufferrh r3 r3 r4 connectionMade s
zDTP.connectionMadec C s$ d| _ | jd ur| jd d S d S NF)r _onConnLostr rd reasonr3 r3 r4 connectionLost s
zDTP.connectionLostc C s | j |d dS )zv
Send a line to data channel.
@param line: The line to be sent.
@type line: L{bytes}
s
N transportwriterd liner3 r3 r4 sendLine s zDTP.sendLinec C sZ dd } d}
|
|rdpd| ||dd |dd || t|d | j}|| S ) a
Helper method to format one entry's info into a text entry like:
'drwxrwxrwx 0 user group 0 Jan 01 1970 filename.txt'
@param name: C{bytes} name of the entry (file or directory or link)
@param size: C{int} size of the entry
@param directory: evals to C{bool} - whether the entry is a directory
@param permissions: L{twisted.python.filepath.Permissions} object
representing that entry's permissions
@param hardlinks: C{int} number of hardlinks
@param modified: C{float} - entry's last modified time in seconds
since the epoch
@param owner: C{str} username of the owner
@param group: C{str} group name of the owner
@return: C{str} in the requisite format
c S sB t }t| j | j| j| j| jd}|j| jkrd| S d| S )N)monthdayyearhourminutez%(month)s %(day)02d %(year)5dz+%(month)s %(day)02d %(hour)02d:%(minute)02d)timegmtime_monthstm_montm_mdaytm_yeartm_hourtm_min)mtimenowinfor3 r3 r4
formatDate s z.DTP._formatOneListResponse..formatDatezY%(directory)s%(permissions)s%(hardlinks)4d %(owner)-9s %(group)-9s %(size)15d %(date)12s d-N ) directorypermissions hardlinksownergroupsizedate) shorthandr r encode _encoding)rd namer r r r modifiedr r r formatre r3 r3 r4 _formatOneListResponse s
zDTP._formatOneListResponsec C s | | j|g|R d S r` )r r )rd r ri r3 r3 r4 sendListResponse s zDTP.sendListResponsec C s | j ||S r` r registerProducerrd producer streamingr3 r3 r4 r zDTP.registerProducerc C s | j | j d S r` )r unregisterProducerloseConnectionrh r3 r3 r4 r s
zDTP.unregisterProducerc C s | j r | j|S td)NzCrap damn crap damn crap damn)r r r ra rd datar3 r3 r4 r s z DTP.writec C s2 z | j | W d S ty | j Y d S w r` )_consr
BaseExceptionr errbackrd bytesr3 r3 r4
_conswrite s
zDTP._conswritec C s( | j d ur| | d S | j| d S r` )r r r r= r r3 r3 r4 dataReceived s
zDTP.dataReceivedc C s | j d | _ | `|S r` )r r r rd ignoredr3 r3 r4 _unregConsumer
s
zDTP._unregConsumerc C s| | j d u sJ || _ | j | d | jD ]}| | qd | _| jr1t | _}|| j |S | j
d | _ td S r )r r r r r r Deferredr addBothr r succeed)rd conschunkr r3 r3 r4 registerConsumer s
zDTP.registerConsumerc C | j d S r` )r resumeProducingrh r3 r3 r4 r # r zDTP.resumeProducingc C r r` )r pauseProducingrh r3 r3 r4 r & r zDTP.pauseProducingc C r r` )r
stopProducingrh r3 r3 r4 r ) r zDTP.stopProducing)r/ r0 r1 r r r r r r r r r r r r r r r r r r r r r3 r3 r3 r4 r s* 6r c @ sd e Zd ZdZe Ze Ze ZeZdZ dddZ
dd Zdd Zd
d Z
dd
Zdd Zdd ZdS )
DTPFactorya
Client factory for I{data transfer process} protocols.
@ivar peerCheck: perform checks to make sure the ftp-pi's peer is the same
as the dtp's
@ivar pi: a reference to this factory's protocol interpreter
@ivar _state: Indicates the current state of the DTPFactory. Initially,
this is L{_IN_PROGRESS}. If the connection fails or times out, it is
L{_FAILED}. If the connection succeeds before the timeout, it is
L{_FINISHED}.
@cvar _IN_PROGRESS: Token to signal that connection is active.
@type _IN_PROGRESS: L{object}.
@cvar _FAILED: Token to signal that connection has failed.
@type _FAILED: L{object}.
@cvar _FINISHED: Token to signal that connection was successfully closed.
@type _FINISHED: L{object}.
FNc C s: || _ || _t | _d| _|du rddlm} || _dS )z
Constructor
@param pi: this factory's protocol interpreter
@param peerHost: if peerCheck is True, this is the tuple that the
generated instance will use to perform security checks
Nr r ) pipeerHostr r r delayedCalltwisted.internetr _reactor)rd r r r r3 r3 r4 rb N s
zDTPFactory.__init__c C sN t jddd | j| jurd S | j| _| t }| |_| j|_|| j_ |S )NDTPFactory.buildProtocolTr )
r re _state_IN_PROGRESS _FINISHED
cancelTimeoutr r r dtpInstancerd addrpr3 r3 r4
buildProtocol_ s r c C s t jddd | d S )NzdtpFactory.stopFactoryTr )r re r rh r3 r3 r4 stopFactorym s zDTPFactory.stopFactoryc C sF t d | j| jur
d S | j| _| j}d | _|tt d d S )Nz$timed out waiting for DTP connectionzDTPFactory timeout)
r re r r _FAILEDr r r r TimeoutError)rd r r3 r3 r4 timeoutFactoryq s
zDTPFactory.timeoutFactoryc C s8 | j d ur| j rtjddd | j d S d S d S )Nzcancelling DTP timeoutTr )r activer re cancelrh r3 r3 r4 r { s zDTPFactory.cancelTimeoutc C s$ t d| | j|| j| _d S )Nz'DTPFactory.setTimeout set to %s seconds)r re r callLaterr r )rd secondsr3 r3 r4
setTimeout s zDTPFactory.setTimeoutc C s6 | j | jurd S | j| _ | j}d | _|t| d S r` )r r r r r r )rd connectorr r r3 r3 r4 clientConnectionFailed s z!DTPFactory.clientConnectionFailed)NN)r/ r0 r1 r2 objectr r r r peerCheckrb r r r r r r r3 r3 r3 r4 r - s
r c @ s e Zd Zdd Zdd ZdS )ASCIIConsumerWrapperc C sP || _ |j| _|j| _tjdksttjdksJ dtjdkr&|j| _d S d S )N
rT z6Unsupported platform (yea right like this even exists))r r r oslineseplenr )rd r r3 r3 r4 rb s
zASCIIConsumerWrapper.__init__c C s | j |tjdS )Nr
)r r rX r r r r3 r3 r4 r s zASCIIConsumerWrapper.writeN)r/ r0 r1 rb r r3 r3 r3 r4 r s r c @ s0 e Zd ZdZdd Zdd Zdd Zdd Zd
S )FileConsumerz
A consumer for FTP input that writes data to a file.
@ivar fObj: a file object opened for writing, used to write data received.
@type fObj: C{file}
c C
|| _ d S r` )fObjrd r r3 r3 r4 rb
zFileConsumer.__init__c C s || _ |sJ d S r` )r r r3 r3 r4 r zFileConsumer.registerProducerc C s d | _ | j d S r` )r r closerh r3 r3 r4 r s zFileConsumer.unregisterProducerc C | j | d S r` )r r r r3 r3 r4 r zFileConsumer.writeN)r/ r0 r1 r2 rb r r r r3 r3 r3 r4 r s r c @ e Zd ZdZdZdd ZdS )FTPOverflowProtocolz:FTP mini-protocol for when there are too many connections.r c C s$ | tt | j | j d S r` )r rf TOO_MANY_CONNECTIONSr r r r rh r3 r3 r4 r s z"FTPOverflowProtocol.connectionMadeN)r/ r0 r1 r2 r r r3 r3 r3 r4 r s r c s e Zd ZdZdZed\ZZZZ dZ
dZdZdZ
dZdZdZddgZg d Zed
dZejZdZd
d Z fddZdd Zdd Zdd Zdd Zdd Zdd Zdd Z dd Z!d!d" Z"d#d$ Z#d%d&