]> granicus.if.org Git - python/commitdiff
Allow classes from other modules to be specified at startup. For example,
authorSkip Montanaro <skip@pobox.com>
Sat, 26 Jun 2004 19:18:49 +0000 (19:18 +0000)
committerSkip Montanaro <skip@pobox.com>
Sat, 26 Jun 2004 19:18:49 +0000 (19:18 +0000)
using the postfixproxy module from Spambayes you might start smtpd up like

    smtpd.py -c spambayes.postfixproxy.SpambayesProxy :8025 :8026

Lib/smtpd.py

index 2d52f0fd84c932f49a8a67bb41a722728ec5977d..6f46c97ed9930593426f903eb8de0595d05e1137 100755 (executable)
@@ -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: