[Spambayes-checkins] spambayes/spambayes Options.py, 1.41, 1.42 UserInterface.py, 1.6, 1.7

Tony Meyer anadelonbrin at users.sourceforge.net
Thu Apr 24 20:29:18 EDT 2003


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

Modified Files:
	Options.py UserInterface.py 
Log Message:
Fix Options convert and unconvert functions.

Fix valid characters for imap username and password.

Improve behaviour of convert_config_file script.

A few extra comments here and there.

Check that spam/unsure/filter folders exist in imap before filtering,
likewise with training.

Index: Options.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/spambayes/Options.py,v
retrieving revision 1.41
retrieving revision 1.42
diff -C2 -d -r1.41 -r1.42
*** Options.py	24 Apr 2003 07:43:46 -0000	1.41
--- Options.py	25 Apr 2003 02:29:16 -0000	1.42
***************
*** 32,35 ****
--- 32,37 ----
   o Find a regex expert to come up with *good* patterns for domains,
     email addresses, and so forth.
+  o str(Option) should really call Option.unconvert since this is what
+    it does.  Try putting that in and running all the tests.
   o [See also the __issues__ string.]
   o Suggestions?
***************
*** 112,115 ****
--- 114,127 ----
  IMAP_FOLDER = r"[^,]+"
  
+ # IMAP's astring should also be valid in the form:
+ #   "{" number "}" CRLF *CHAR8
+ #   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
  # this value on a "reset to defaults" command.  Most should, but with some
***************
*** 886,890 ****
       on the same server, please see the comments regarding the server
       value.""",
!      r"[\w]+", DO_NOT_RESTORE),
  
      ("password", "Password", (),
--- 898,902 ----
       on the same server, please see the comments regarding the server
       value.""",
!      IMAP_ASTRING, DO_NOT_RESTORE),
  
      ("password", "Password", (),
***************
*** 896,900 ****
       blank and use the -p command line option to imapfilter.py and you will
       be prompted for your password.""",
!      r"[\w]+", DO_NOT_RESTORE),
  
      ("expunge", "Purge//Expunge", False,
--- 908,912 ----
       blank and use the -p command line option to imapfilter.py and you will
       be prompted for your password.""",
!      IMAP_ASTRING, DO_NOT_RESTORE),
  
      ("expunge", "Purge//Expunge", False,
***************
*** 938,941 ****
--- 950,954 ----
          self.restore = restore
          self.value = None
+         self.delimiter = None
  
      def display_name(self):
***************
*** 1061,1064 ****
--- 1074,1081 ----
      def convert(self, value):
          '''Convert value from a string to the appropriate type.'''
+         svt = type(self.value)
+         if svt == type(value):
+             # already the correct type
+             return value
          if self.is_boolean():
              if str(value) == "True" or value == 1:
***************
*** 1067,1081 ****
                  return False
              raise TypeError, self.name + " must be True or False"
!         svt = type(self.value)
!         if svt == type(value):
              # already the correct type
              return value
!         if svt == types.IntType:
              return locale.atoi(value)
!         if svt == types.FloatType:
              return locale.atof(value)
!         if svt in types.StringTypes and svt in types.StringTypes:
!             return value
!         raise TypeError, self.name + " has an invalid type."
  
      def unconvert(self):
--- 1084,1117 ----
                  return False
              raise TypeError, self.name + " must be True or False"
!         if self.multiple_values_allowed():
!             # This will fall apart if the allowed_value is a tuple,
!             # but not a homogenous one...
!             if type(self.allowed_values) in types.StringTypes:
!                 vals = list(self._split_values(value))
!             else:
!                 vals = value.split()
!             if len(self.default_value) > 0:
!                 to_type = type(self.default_value[0])
!             else:
!                 to_type = types.StringType
!             for i in range(0, len(vals)):
!                 vals[i] = self._convert(vals[i], to_type)
!             return tuple(vals)
!         else:
!             return self._convert(value, svt)
!         raise TypeError, self.name + " has an invalid type."
! 
!     def _convert(self, value, to_type):
!         '''Convert an int, float or string to the specified type.'''
!         if to_type == type(value):
              # already the correct type
              return value
!         if to_type == types.IntType:
              return locale.atoi(value)
!         if to_type == types.FloatType:
              return locale.atof(value)
!         if to_type in types.StringTypes:
!             return str(value)
!         raise TypeError, "Invalid type."
  
      def unconvert(self):
***************
*** 1091,1102 ****
                  return "False"
          if type(self.value) == types.TupleType:
              # We need to separate out the items
-             # We use a character that is invalid as the separator
-             # so that it will reparse correctly
              strval = ""
!             # XXX fix this
!             sep = ' '
              for v in self.value:
!                 strval += v + sep
              strval = strval[:-1] # trailing seperator
          else:
--- 1127,1171 ----
                  return "False"
          if type(self.value) == types.TupleType:
+             if len(self.value) == 0:
+                 return ""
+             if len(self.value) == 1:
+                 v = self.value[0]
+                 if type(v) == types.FloatType:
+                     return locale.str(self.value[0])
+                 return str(v)
              # We need to separate out the items
              strval = ""
!             # We use a character that is invalid as the separator
!             # so that it will reparse correctly.  We could try all
!             # characters, but we make do with this set of commonly
!             # used ones - note that the first one that works will
!             # be used.  Perhaps a nicer solution than this would be
!             # to specifiy a valid delimiter for all options that
!             # can have multiple values.  Note that we have None at
!             # the end so that this will crash and die if none of
!             # the separators works <wink>
!             if self.delimiter is None:
!                 if type(self.allowed_values) == types.TupleType:
!                     self.delimiter = ' '
!                 else:
!                     v0 = self.value[0]
!                     v1 = self.value[1]
!                     for sep in [' ', ',', ':', ';', '/', '\\', None]:
!                         # we know at this point that len(self.value) is at
!                         # least two, because len==0 and len==1 were dealt
!                         # with as special cases
!                         test_str = v0 + sep + v1
!                         test_tuple = self._split_values(test_str)
!                         if test_tuple[0] == v0 and test_tuple[1] == v1 and \
!                            len(test_tuple) == 2:
!                             break
!                     # cache this so we don't always need to do the above
!                     self.delimiter = sep
              for v in self.value:
!                 if type(v) == types.FloatType:
!                     v = locale.str(v)
!                 else:
!                     v = str(v)
!                 strval += v + self.delimiter
              strval = strval[:-1] # trailing seperator
          else:

Index: UserInterface.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/spambayes/UserInterface.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** UserInterface.py	24 Apr 2003 07:43:48 -0000	1.6
--- UserInterface.py	25 Apr 2003 02:29:16 -0000	1.7
***************
*** 38,46 ****
   o Save the stats (num classified, etc.) between sessions.
   o "Reload database" button.
!  o Checkboxes need a default value (i.e. what to set the option as
!    when no boxes are checked).  This needs to be thought about and
!    then implemented.  add_id is an example of what it does at the
!    moment.
! 
   o Suggestions?
  
--- 38,43 ----
   o Save the stats (num classified, etc.) between sessions.
   o "Reload database" button.
!  o Displaying options should be done with the locale format function
!    rather than str().
   o Suggestions?
  





More information about the Spambayes-checkins mailing list