Repository navigation
Expand file tree
/
Copy pathreturn_code.py
More file actions
329 lines (238 loc) · 12.1 KB
/
Copy pathreturn_code.py
File metadata and controls
329 lines (238 loc) · 12.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# -*- coding: utf-8 -*-
# mypy: disable-error-code=assignment
# pylint: disable=line-too-long,consider-using-f-string
"""FTP Server Return Code
============================
.. module:: pcapkit.const.ftp.return_code
This module contains the constant enumeration for **FTP Server Return Code**,
which is automatically generated from :class:`pcapkit.vendor.ftp.return_code.ReturnCode`.
"""
from typing import TYPE_CHECKING
from aenum import IntEnum
from pcapkit.corekit.enum import EnumRegistry
if TYPE_CHECKING:
from typing import Optional, Type
__all__ = ['ReturnCode']
#: Grouping information.
INFO = {
'0': 'Syntax',
'1': 'Information',
'2': 'Connections',
'3': 'Authentication and accounting',
'4': 'Unspecified', # [RFC 959]
'5': 'File system',
} # type: dict[str, str]
class ResponseKind(EnumRegistry, IntEnum):
"""Response kind; whether the response is good, bad or incomplete."""
PositivePreliminary = 1
PositiveCompletion = 2
PositiveIntermediate = 3
TransientNegativeCompletion = 4
PermanentNegativeCompletion = 5
Protected = 6
@classmethod
def _missing_(cls, value: 'int') -> 'ResponseKind':
"""Lookup function used when value is not found.
Args:
value: Value to lookup.
"""
if isinstance(value, int) and 0 <= value <= 9:
#: Unknown
return cls._unregistered_member(value, 'Unknown')
return super()._missing_(value)
class GroupingInformation(EnumRegistry, IntEnum):
"""Grouping information."""
Syntax = 0
Information = 1
Connections = 2
AuthenticationAccounting = 3
Unspecified = 4
FileSystem = 5
@classmethod
def _missing_(cls, value: 'int') -> 'GroupingInformation':
"""Lookup function used when value is not found.
Args:
value: Value to lookup.
"""
if isinstance(value, int) and 0 <= value <= 9:
#: Unknown
return cls._unregistered_member(value, 'Unknown')
return super()._missing_(value)
class ReturnCode(EnumRegistry, IntEnum):
"""[ReturnCode] FTP Server Return Code"""
if TYPE_CHECKING:
#: Description of the return code.
description: 'Optional[str]'
#: Response kind.
kind: 'ResponseKind'
#: Grouping information.
group: 'GroupingInformation'
def __new__(cls, value: 'int', description: 'Optional[str]' = None) -> 'Type[ReturnCode]':
obj = int.__new__(cls, value)
obj._value_ = value
code = '%03d' % value
obj.description = description
obj.kind = ResponseKind(int(code[0]))
obj.group = GroupingInformation(int(code[1]))
return obj
def __repr__(self) -> 'str':
return f'<{self.__class__.__name__} [{self._value_}]>'
def __str__(self) -> 'str':
return "[%s] %s" % (self._value_, self.description)
#: Restart marker replay. In this case, the text is exact and not left to the
#: particular implementation; it must read: MARK yyyy = mmmm where yyyy is
#: User-process data stream marker, and mmmm server's equivalent marker (note
#: the spaces between markers and "=").
CODE_110: 'ReturnCode' = 110, 'Restart marker replay.'
#: Service ready in nnn minutes.
CODE_120: 'ReturnCode' = 120, 'Service ready in nnn minutes.'
#: Data connection already open; transfer starting.
CODE_125: 'ReturnCode' = 125, 'Data connection already open; transfer starting.'
#: File status okay; about to open data connection.
CODE_150: 'ReturnCode' = 150, 'File status okay; about to open data connection.'
#: Command not implemented, superfluous at this site.
CODE_202: 'ReturnCode' = 202, 'Command not implemented, superfluous at this site.'
#: System status, or system help reply.
CODE_211: 'ReturnCode' = 211, 'System status, or system help reply.'
#: Directory status.
CODE_212: 'ReturnCode' = 212, 'Directory status.'
#: File status.
CODE_213: 'ReturnCode' = 213, 'File status.'
#: Help message. Explains how to use the server or the meaning of a particular
#: non-standard command. This reply is useful only to the human user.
CODE_214: 'ReturnCode' = 214, 'Help message.'
#: NAME system type. Where NAME is an official system name from the registry
#: kept by IANA.
CODE_215: 'ReturnCode' = 215, 'NAME system type.'
#: Service ready for new user.
CODE_220: 'ReturnCode' = 220, 'Service ready for new user.'
#: Service closing control connection. Logged out if appropriate.
CODE_221: 'ReturnCode' = 221, 'Service closing control connection.'
#: Data connection open; no transfer in progress.
CODE_225: 'ReturnCode' = 225, 'Data connection open; no transfer in progress.'
#: Closing data connection. Requested file action successful (for example, file
#: transfer or file abort).
CODE_226: 'ReturnCode' = 226, 'Closing data connection.'
#: Entering Passive Mode (h1,h2,h3,h4,p1,p2).
CODE_227: 'ReturnCode' = 227, 'Entering Passive Mode.'
#: Entering Long Passive Mode (long address, port).
CODE_228: 'ReturnCode' = 228, 'Entering Long Passive Mode.'
#: Entering Extended Passive Mode ( |||port| ).
CODE_229: 'ReturnCode' = 229, 'Entering Extended Passive Mode.'
#: User logged in, proceed.
CODE_230: 'ReturnCode' = 230, 'User logged in, proceed.'
#: User logged in, authorized by security data exchange.
CODE_232: 'ReturnCode' = 232, 'User logged in, authorized by security data exchange.'
#: Server accepts the security mechanism specified by the client; no security
#: data needs to be exchanged.
CODE_234: 'ReturnCode' = 234, 'Server accepts the security mechanism specified by the client; no security data needs to be exchanged.'
#: Server accepts the security data given by the client; no further security
#: data needs to be exchanged.
CODE_235: 'ReturnCode' = 235, 'Server accepts the security data given by the client; no further security data needs to be exchanged.'
#: Requested file action was okay, completed.
CODE_250: 'ReturnCode' = 250, 'Requested file action was okay, completed.'
#: User name okay, password needed.
CODE_331: 'ReturnCode' = 331, 'User name okay, password needed.'
#: No need account for login.
CODE_332: 'ReturnCode' = 332, 'No need account for login.'
#: Server accepts the security mechanism specified by the client; some security
#: data needs to be exchanged.
CODE_334: 'ReturnCode' = 334, 'Server accepts the security mechanism specified by the client; some security data needs to be exchanged.'
#: Server accepts the security data given by the client; more security data
#: needs to be exchanged.
CODE_335: 'ReturnCode' = 335, 'Server accepts the security data given by the client; more security data needs to be exchanged.'
#: Username okay, password okay. Challenge is ". . . . ".
CODE_336: 'ReturnCode' = 336, 'Username okay, password okay.'
#: Service NOT available, closing control connection. This may be a reply to
#: any command if the service knows it must shut down.
CODE_421: 'ReturnCode' = 421, 'Service NOT available, closing control connection.'
#: Can't open data connection.
CODE_425: 'ReturnCode' = 425, "Can't open data connection."
#: Connection closed; transfer aborted.
CODE_426: 'ReturnCode' = 426, 'Connection closed; transfer aborted.'
#: Invalid username or password
CODE_430: 'ReturnCode' = 430, 'Invalid username or password.'
#: Need some unavailable resource to process security.
CODE_431: 'ReturnCode' = 431, 'Need some unavailable resource to process security.'
#: Requested host unavailable.
CODE_434: 'ReturnCode' = 434, 'Requested host unavailable.'
#: Requested file action not taken. File unavailable (e.g., file busy).
CODE_450: 'ReturnCode' = 450, 'Requested file action not taken.'
#: Requested action aborted. Local error in processing.
CODE_451: 'ReturnCode' = 451, 'Requested action aborted.'
#: Requested action not taken. Insufficient storage space in system.
CODE_452: 'ReturnCode' = 452, 'Requested action not taken.'
#: Syntax error in parameters or arguments.
CODE_501: 'ReturnCode' = 501, 'Syntax error in parameters or arguments.'
#: Command not implemented.
CODE_502: 'ReturnCode' = 502, 'Command not implemented.'
#: Bad sequence of commands.
CODE_503: 'ReturnCode' = 503, 'Bad sequence of commands.'
#: Command not implemented for that parameter.
CODE_504: 'ReturnCode' = 504, 'Command not implemented for that parameter.'
#: Not logged in.
CODE_530: 'ReturnCode' = 530, 'Not logged in.'
#: Need account for storing files.
CODE_532: 'ReturnCode' = 532, 'Need account for storing files.'
#: Command protection level denied for policy reasons.
CODE_533: 'ReturnCode' = 533, 'Command protection level denied for policy reasons.'
#: Request denied for policy reasons.
CODE_534: 'ReturnCode' = 534, 'Request denied for policy reasons.'
#: Failed security check.
CODE_535: 'ReturnCode' = 535, 'Failed security check.'
#: Data protection level not supported by security mechanism.
CODE_536: 'ReturnCode' = 536, 'Data protection level not supported by security mechanism.'
#: Command protection level not supported by security mechanism.
CODE_537: 'ReturnCode' = 537, 'Command protection level not supported by security mechanism.'
#: Requested action not taken. File unavailable (e.g., file not found, no
#: access).
CODE_550: 'ReturnCode' = 550, 'Requested action not taken.'
#: Requested action aborted. Page type unknown.
CODE_551: 'ReturnCode' = 551, 'Requested action aborted.'
#: Requested file action aborted. Exceeded storage allocation (for current
#: directory or dataset).
CODE_552: 'ReturnCode' = 552, 'Requested file action aborted.'
#: Requested action not taken. File name not allowed.
CODE_553: 'ReturnCode' = 553, 'Requested action not taken.'
#: Integrity protected reply.
CODE_631: 'ReturnCode' = 631, 'Integrity protected reply.'
#: Confidentiality and integrity protected reply.
CODE_632: 'ReturnCode' = 632, 'Confidentiality and integrity protected reply.'
#: Confidentiality protected reply.
CODE_633: 'ReturnCode' = 633, 'Confidentiality protected reply.'
@classmethod
def _unregistered_member(cls, value: 'int', name: 'str') -> 'ReturnCode':
"""Build a member absent from this registry's own lookup tables.
Reconstructs :attr:`description`, :attr:`kind` and :attr:`group` the
same way :meth:`__new__` would, rather than leaving them unset --
:meth:`~pcapkit.corekit.enum.EnumRegistry._unregistered_member`
bypasses :meth:`__new__` entirely (it calls :class:`int`'s directly),
so those three attributes would otherwise be missing from the result
and :meth:`__str__`/:meth:`__repr__` would raise on it.
Args:
value: Value to get enum item.
name: Bare label for the unregistered member, per the ranged
mint/unmint criterion.
"""
obj = super()._unregistered_member(value, name)
code = '%03d' % value
obj.description = None
obj.kind = ResponseKind(int(code[0]))
obj.group = GroupingInformation(int(code[1]))
return obj
@classmethod
def _missing_(cls, value: 'int') -> 'ReturnCode':
"""Lookup function used when value is not found.
A reply code is three digits (:rfc:`959#section-4.2`), so every value
from 0 to 999 can arrive on the wire: one within the registry's range
resolves to ``Unassigned``, any other to ``Unknown``.
Args:
value: Value to get enum item.
"""
if not (isinstance(value, int) and 0 <= value <= 999):
raise ValueError('%r is not a valid %s' % (value, cls.__name__))
if isinstance(value, int) and 100 <= value <= 659:
#: Unassigned
return cls._unregistered_member(value, 'Unassigned')
#: Unknown
return cls._unregistered_member(value, 'Unknown')