spambayes/spambayes OptionsClass.py,1.26,1.27

"Tony Meyer" <[email protected]>
Newsgroups gmane.mail.spam.spambayes.cvs
Message-ID <[email protected]>
Update of /cvsroot/spambayes/spambayes/spambayes
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18352/spambayes

Modified Files:
	OptionsClass.py 
Log Message:
Speed up a couple of things.

Allow an OptionClass object to set and restore from a particular point.

Index: OptionsClass.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/spambayes/OptionsClass.py,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** OptionsClass.py	16 Jan 2005 22:20:21 -0000	1.26
--- OptionsClass.py	16 Mar 2005 03:37:11 -0000	1.27
***************
*** 208,222 ****
          s = str(value)
          i = 0
!         vals = ()
          while True:
              m = r.search(s[i:])
              if m is None:
                  break
!             vals += (m.group(),)
              delimiter = s[i:i + m.start()]
              if self.delimiter is None and delimiter != "":
                  self.delimiter = delimiter
              i += m.end()
!         return vals
  
      def as_nice_string(self, section=None):
--- 208,222 ----
          s = str(value)
          i = 0
!         vals = []
          while True:
              m = r.search(s[i:])
              if m is None:
                  break
!             vals.append(m.group())
              delimiter = s[i:i + m.start()]
              if self.delimiter is None and delimiter != "":
                  self.delimiter = delimiter
              i += m.end()
!         return tuple(vals)
  
      def as_nice_string(self, section=None):
***************
*** 399,402 ****
--- 399,403 ----
          self.verbose = None
          self._options = {}
+         self.restore_point = {}
          self.conversion_table = {} # set by creator if they need it.
      #
***************
*** 519,523 ****
  
      def load_defaults(self, defaults):
!         '''Load default values (stored in this module).'''
          for section, opts in defaults.items():
              for opt in opts:
--- 520,524 ----
  
      def load_defaults(self, defaults):
!         '''Load default values (stored in Options.py).'''
          for section, opts in defaults.items():
              for opt in opts:
***************
*** 537,540 ****
--- 538,563 ----
                  self._options[section, o.name] = o
  
+     def set_restore_point(self):
+         '''Remember what the option values are right now, to
+         be able to go back to them, via revert_to_restore_point().
+ 
+         Any existing restore point is wiped.  Restore points do
+         not persist over sessions.
+         '''
+         self.restore_point = {}
+         for key, opt_obj in self._options.iteritems():
+             self.restore_point[key] = opt_obj.get()
+ 
+     def revert_to_restore_point(self):
+         '''Restore option values to their values when set_restore_point()
+         was last called.
+ 
+         If set_restore_point() has not been called, then this has no
+         effect.  If new options have been added since set_restore_point,
+         their values are not effected.
+         '''
+         for key, value in self.restore_point.iteritems():
+             self._options[key].set(value)
+ 
      def merge_files(self, file_list):
          for f in file_list:
***************
*** 802,810 ****
  #   where number represents the number of CHAR8 octets
  # but this is too complex for us at the moment.
! IMAP_ASTRING = ""
  for i in range(1, 128):
      if not chr(i) in ['"', '\\', '\n', '\r']:
!         IMAP_ASTRING += chr(i)
! IMAP_ASTRING = r"\"?\\?[" + re.escape(IMAP_ASTRING) + r"]+\"?"
  
  # Similarly, each option must specify whether it should be reset to
--- 825,833 ----
  #   where number represents the number of CHAR8 octets
  # but this is too complex for us at the moment.
! IMAP_ASTRING = []
  for i in range(1, 128):
      if not chr(i) in ['"', '\\', '\n', '\r']:
!         IMAP_ASTRING.append(chr(i))
! IMAP_ASTRING = r"\"?[" + re.escape(''.join(IMAP_ASTRING)) + r"]+\"?"
  
  # Similarly, each option must specify whether it should be reset to
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.