[Spambayes-checkins] spambayes/scripts sb_server.py,1.46,1.47

Tony Meyer anadelonbrin at users.sourceforge.net
Sat Nov 26 06:12:58 CET 2005


Update of /cvsroot/spambayes/spambayes/scripts
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4914/scripts

Modified Files:
	sb_server.py 
Log Message:
More handling of Python 2.4's stupid asyncore error handling.

Add ability to use a different asyncore map.

Fix closing of ssl sockets.

Let callers change the name of the mutex.

Fix message database code to match new, corrected, style.

Index: sb_server.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/scripts/sb_server.py,v
retrieving revision 1.46
retrieving revision 1.47
diff -C2 -d -r1.46 -r1.47
*** sb_server.py	22 Apr 2005 07:15:08 -0000	1.46
--- sb_server.py	26 Nov 2005 05:12:49 -0000	1.47
***************
*** 144,150 ****
      synchronously, because that would block the process."""
  
!     def __init__(self, serverName, serverPort, lineCallback, ssl=False):
!         Dibbler.BrighterAsyncChat.__init__(self)
          self.lineCallback = lineCallback
          self.request = ''
          self.set_terminator('\r\n')
--- 144,152 ----
      synchronously, because that would block the process."""
  
!     def __init__(self, serverName, serverPort, lineCallback, ssl=False,
!                  map=None):
!         Dibbler.BrighterAsyncChat.__init__(self, map=map)
          self.lineCallback = lineCallback
+         self.handled_exception = False
          self.request = ''
          self.set_terminator('\r\n')
***************
*** 201,204 ****
--- 203,213 ----
          return self.ssl_socket.write(data)
  
+     def handle_expt(self):
+         # Python 2.4's system of continuously pumping error messages
+         # is stupid.  Print an error once, and then ignore.
+         if not self.handled_exception:
+             print >> sys.stderr, "Unhandled exception in ServerLineReader"
+             self.handled_exception = True
+ 
      def recv_ssl(self, buffer_size):
          try:
***************
*** 231,235 ****
          self.close()
          try:
!             del self.ssl_socket, self.socket
          except AttributeError:
              pass
--- 240,244 ----
          self.close()
          try:
!             del self.ssl_socket
          except AttributeError:
              pass
***************
*** 249,253 ****
      """
  
!     def __init__(self, clientSocket, serverName, serverPort, ssl=False):
          Dibbler.BrighterAsyncChat.__init__(self, clientSocket)
          self.request = ''
--- 258,263 ----
      """
  
!     def __init__(self, clientSocket, serverName, serverPort,
!                  ssl=False, map=Dibbler._defaultContext._map):
          Dibbler.BrighterAsyncChat.__init__(self, clientSocket)
          self.request = ''
***************
*** 268,272 ****
  
          self.serverSocket = ServerLineReader(serverName, serverPort,
!                                              self.onServerLine, ssl)
  
      def onIncomingConnection(self, clientSocket):
--- 278,282 ----
  
          self.serverSocket = ServerLineReader(serverName, serverPort,
!                                              self.onServerLine, ssl, map)
  
      def onIncomingConnection(self, clientSocket):
***************
*** 530,534 ****
          """Adds the judgement header based on the raw headers and body
          of the message."""
!         # Previous, we used '\n\r?\n' to detect the end of the headers in
          # case of broken emails that don't use the proper line separators,
          # and if we couldn't find it, then we assumed that the response was
--- 540,544 ----
          """Adds the judgement header based on the raw headers and body
          of the message."""
!         # Previously, we used '\n\r?\n' to detect the end of the headers in
          # case of broken emails that don't use the proper line separators,
          # and if we couldn't find it, then we assumed that the response was
***************
*** 653,659 ****
  # multiple servers starting at once.  Platform specific as no reasonable
  # cross-platform solution exists (however, an old trick is to use a
! # directory for a mutex, as a "create/test" atomic API generally exists.
  # Will return a handle to be later closed, or may throw AlreadyRunningException
! def open_platform_mutex():
      if sys.platform.startswith("win"):
          try:
--- 663,669 ----
  # multiple servers starting at once.  Platform specific as no reasonable
  # cross-platform solution exists (however, an old trick is to use a
! # directory for a mutex, as a "create/test" atomic API generally exists).
  # Will return a handle to be later closed, or may throw AlreadyRunningException
! def open_platform_mutex(mutex_name="SpamBayesServer"):
      if sys.platform.startswith("win"):
          try:
***************
*** 670,674 ****
              # "SpamBayesServer" mutex, if for no better reason than so
              # an installer can check if we are running
-             mutex_name = "SpamBayesServer"
              try:
                  hmutex = win32event.CreateMutex(None, True, mutex_name)
--- 680,683 ----
***************
*** 889,895 ****
              map(storage.ensureDir, [sc, hc, uc])
              if self.gzipCache:
!                 factory = GzipFileMessageFactory(self.mdb)
              else:
!                 factory = FileMessageFactory(self.mdb)
              age = options["Storage", "cache_expiry_days"]*24*60*60
              self.spamCorpus = ExpiryFileCorpus(age, factory, sc,
--- 898,904 ----
              map(storage.ensureDir, [sc, hc, uc])
              if self.gzipCache:
!                 factory = GzipFileMessageFactory()
              else:
!                 factory = FileMessageFactory()
              age = options["Storage", "cache_expiry_days"]*24*60*60
              self.spamCorpus = ExpiryFileCorpus(age, factory, sc,



More information about the Spambayes-checkins mailing list