[Spambayes-checkins] spambayes/scripts sb_imapfilter.py, 1.30.4.2, 1.30.4.3

Tony Meyer anadelonbrin at users.sourceforge.net
Thu Jan 13 22:42:45 CET 2005


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

Modified Files:
      Tag: release_1_0-branch
	sb_imapfilter.py 
Log Message:
Backport attempt at fix for MemoryError problems with OS X.

Index: sb_imapfilter.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/scripts/sb_imapfilter.py,v
retrieving revision 1.30.4.2
retrieving revision 1.30.4.3
diff -C2 -d -r1.30.4.2 -r1.30.4.3
*** sb_imapfilter.py	9 Nov 2004 22:48:41 -0000	1.30.4.2
--- sb_imapfilter.py	13 Jan 2005 21:42:42 -0000	1.30.4.3
***************
*** 215,218 ****
--- 215,226 ----
          self.logged_in = False
  
+         # We override the base read so that we only read a certain amount
+         # of data at a time.  OS X and Python has problems with getting 
+         # large amounts of memory at a time, so maybe this will be a way we
+         # can work around that (I don't know, and don't have a mac to test,
+         # but we need to try something).
+         self._read = self.read
+         self.read = self.safe_read
+ 
      def login(self, username, pwd):
          try:
***************
*** 325,328 ****
--- 333,351 ----
          return None
  
+     # Maximum amount of data that will be read at any one time.
+     MAXIMUM_SAFE_READ = 4096
+     def safe_read(self, size):
+         """Read data from remote, but in manageable sizes."""
+         data = []
+         while size > 0:
+             if size < self.MAXIMUM_SAFE_READ:
+                 to_collect = size
+             else:
+                 to_collect = self.MAXIMUM_SAFE_READ
+             data.append(self._read(to_collect))
+             size -= self.MAXIMUM_SAFE_READ
+         return "".join(data)
+ 
+ 
  class IMAPMessage(message.SBHeaderMessage):
      def __init__(self):



More information about the Spambayes-checkins mailing list