[Spambayes-checkins] spambayes pop3proxy.py,1.37,1.38

Richie Hindle richiehindle at users.sourceforge.net
Tue Jan 21 10:25:18 EST 2003


Update of /cvsroot/spambayes/spambayes
In directory sc8-pr-cvs1:/tmp/cvs-serv20431

Modified Files:
	pop3proxy.py 
Log Message:
You can now specify the local address to listen on, as well as the port.
Thanks for Tony Lownds for the patch.
I now use a neater mechanism for loading the HTML resources.
Thanks to Mike Fletcher for the code.


Index: pop3proxy.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/pop3proxy.py,v
retrieving revision 1.37
retrieving revision 1.38
diff -C2 -d -r1.37 -r1.38
*** pop3proxy.py	20 Jan 2003 20:23:30 -0000	1.37
--- pop3proxy.py	21 Jan 2003 18:25:15 -0000	1.38
***************
*** 345,350 ****
          proxyArgs = (serverName, serverPort)
          Dibbler.Listener.__init__(self, proxyPort, BayesProxy, proxyArgs)
!         print 'Listener on port %d is proxying %s:%d' % \
!                (proxyPort, serverName, serverPort)
  
  
--- 345,350 ----
          proxyArgs = (serverName, serverPort)
          Dibbler.Listener.__init__(self, proxyPort, BayesProxy, proxyArgs)
!         print 'Listener on port %s is proxying %s:%d' % \
!                (_addressPortStr(proxyPort), serverName, serverPort)
  
  
***************
*** 536,542 ****
      from spambayes.resources import ui_html
      images = {}
!     for imageName in IMAGES:
!         exec "from spambayes.resources import %s_gif" % imageName
!         exec "images[imageName] = %s_gif.data" % imageName
      return ui_html.data, images
  
--- 536,543 ----
      from spambayes.resources import ui_html
      images = {}
!     for baseName in IMAGES:
!         moduleName = '%s.%s_gif' % ('spambayes.resources', baseName)
!         module = __import__(moduleName, {}, {}, ('spambayes', 'resources'))
!         images[baseName] = module.data
      return ui_html.data, images
  
***************
*** 1067,1071 ****
          if options.pop3proxy_ports:
              splitPorts = options.pop3proxy_ports.split(',')
!             self.proxyPorts = map(int, map(string.strip, splitPorts))
  
          if len(self.servers) != len(self.proxyPorts):
--- 1068,1072 ----
          if options.pop3proxy_ports:
              splitPorts = options.pop3proxy_ports.split(',')
!             self.proxyPorts = map(_addressAndPort, splitPorts)
  
          if len(self.servers) != len(self.proxyPorts):
***************
*** 1098,1102 ****
          serverStrings = ["%s:%s" % (s, p) for s, p in self.servers]
          self.serversString = ', '.join(serverStrings)
!         self.proxyPortsString = ', '.join(map(str, self.proxyPorts))
  
      def createWorkers(self):
--- 1099,1103 ----
          serverStrings = ["%s:%s" % (s, p) for s, p in self.servers]
          self.serversString = ', '.join(serverStrings)
!         self.proxyPortsString = ', '.join(map(_addressPortStr, self.proxyPorts))
  
      def createWorkers(self):
***************
*** 1157,1160 ****
--- 1158,1180 ----
              self.hamCorpus.addObserver(self.hamTrainer)
  
+ 
+ # Option-parsing helper functions
+ def _addressAndPort(s):
+    """Decode a string representing a port to bind to, with optional address."""
+    s = s.strip()
+    if ':' in s:
+      addr, port = s.split(':')
+      return addr, int(port)
+    else:
+      return '', int(s)
+ 
+ def _addressPortStr((addr, port)):
+   """Encode a string representing a port to bind to, with optional address."""
+   if not addr:
+     return str(port)
+   else:
+     return '%s:%d' % (addr, port)
+ 
+ 
  state = State()
  proxyListeners = []
***************
*** 1431,1435 ****
              options.pop3proxy_persistent_storage_file = arg
          elif opt == '-l':
!             state.proxyPorts = [int(arg)]
          elif opt == '-u':
              state.uiPort = int(arg)
--- 1451,1455 ----
              options.pop3proxy_persistent_storage_file = arg
          elif opt == '-l':
!             state.proxyPorts = [_addressAndPort(arg)]
          elif opt == '-u':
              state.uiPort = int(arg)





More information about the Spambayes-checkins mailing list