diff options
author | Skip Montanaro <skip@pobox.com> | 2004-06-26 19:18:49 (GMT) |
---|---|---|
committer | Skip Montanaro <skip@pobox.com> | 2004-06-26 19:18:49 (GMT) |
commit | 90e01539409c01649fab95122b61c023784d9a51 (patch) | |
tree | 702de2fe94e7a04ec453414419e98f7dfdf7d81f | |
parent | 616f4f61bae92b5733b346552d6b522ad1409937 (diff) | |
download | cpython-90e01539409c01649fab95122b61c023784d9a51.zip cpython-90e01539409c01649fab95122b61c023784d9a51.tar.gz cpython-90e01539409c01649fab95122b61c023784d9a51.tar.bz2 |
Allow classes from other modules to be specified at startup. For example,
using the postfixproxy module from Spambayes you might start smtpd up like
smtpd.py -c spambayes.postfixproxy.SpambayesProxy :8025 :8026
-rwxr-xr-x | Lib/smtpd.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/Lib/smtpd.py b/Lib/smtpd.py index 2d52f0f..6f46c97 100755 --- a/Lib/smtpd.py +++ b/Lib/smtpd.py @@ -533,8 +533,15 @@ if __name__ == '__main__': print >> sys.stderr, \ 'Cannot setuid "nobody"; try running with -n option.' sys.exit(1) - import __main__ - class_ = getattr(__main__, options.classname) + classname = options.classname + if "." in classname: + lastdot = classname.rfind(".") + mod = __import__(classname[:lastdot], globals(), locals(), [""]) + classname = classname[lastdot+1:] + else: + import __main__ as mod + print mod.__name__, dir(mod) + class_ = getattr(mod, classname) proxy = class_((options.localhost, options.localport), (options.remotehost, options.remoteport)) try: |