G
Giampaolo Rodola'
Hi,
for an FTP server I wrote I'd need to group the FTP commands in one
table that defines the command itself, the syntax string, required
permission, whether it requires authorization, whether it takes
argument and whether there's a need to validate the path from the
argument.
The more obvious way I found to do that is something like this:
class CommandProperty:
def __init__(self, perm, auth_needed, arg_needed, check_path,
syntax):
self.perm = perm
self.auth_needed = auth_needed
self.arg_needed = arg_needed
self.check_path = check_path
self.syntax = syntax
ftp_cmds = {
"ABOR" : CommandProperty(perm=None, auth_needed=True,
arg_needed=False, check_path=False, syntax="ABOR (abort transfer)."),
"APPE" : CommandProperty(perm='a', auth_needed=True,
arg_needed=True, check_path=True, syntax="APPE <SP> file-name
(append data to an existent file)."),
"CDUP" : CommandProperty(perm='e',
auth_needed=True,arg_needed=False, check_path=False, syntax="CDUP (go
to parentdirectory)."),
...
...
...
}
....but I find it somewhat redundant and... "ugly".
I was wondering if there was some kind of data type which could better
fit such purpose or if someone could suggest me some other approach to
do this same thing. Maybe using a dictionary is not the better choice
here.
Thanks in advance
--- Giampaolo
http://code.google.com/p/pyftpdlib/
for an FTP server I wrote I'd need to group the FTP commands in one
table that defines the command itself, the syntax string, required
permission, whether it requires authorization, whether it takes
argument and whether there's a need to validate the path from the
argument.
The more obvious way I found to do that is something like this:
class CommandProperty:
def __init__(self, perm, auth_needed, arg_needed, check_path,
syntax):
self.perm = perm
self.auth_needed = auth_needed
self.arg_needed = arg_needed
self.check_path = check_path
self.syntax = syntax
ftp_cmds = {
"ABOR" : CommandProperty(perm=None, auth_needed=True,
arg_needed=False, check_path=False, syntax="ABOR (abort transfer)."),
"APPE" : CommandProperty(perm='a', auth_needed=True,
arg_needed=True, check_path=True, syntax="APPE <SP> file-name
(append data to an existent file)."),
"CDUP" : CommandProperty(perm='e',
auth_needed=True,arg_needed=False, check_path=False, syntax="CDUP (go
to parentdirectory)."),
...
...
...
}
....but I find it somewhat redundant and... "ugly".
I was wondering if there was some kind of data type which could better
fit such purpose or if someone could suggest me some other approach to
do this same thing. Maybe using a dictionary is not the better choice
here.
Thanks in advance
--- Giampaolo
http://code.google.com/p/pyftpdlib/