[Spambayes-checkins] spambayes/Outlook2000 manager.py,1.65,1.66

Mark Hammond mhammond at users.sourceforge.net
Sun Jul 20 19:55:16 EDT 2003


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

Modified Files:
	manager.py 
Log Message:
Work better with a unicode data directory.


Index: manager.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/Outlook2000/manager.py,v
retrieving revision 1.65
retrieving revision 1.66
diff -C2 -d -r1.65 -r1.66
*** manager.py	20 Jul 2003 13:31:13 -0000	1.65
--- manager.py	21 Jul 2003 01:55:13 -0000	1.66
***************
*** 21,24 ****
--- 21,32 ----
      True, False = 1, 0
  
+ # Notes on Unicode directory names
+ # You will have much more success with extended characters in
+ # directory names using Python 2.3.
+ try:
+     filesystem_encoding = sys.getfilesystemencoding()
+ except AttributeError:
+     filesystem_encoding = "mbcs"
+ 
  # Work out our "application directory", which is
  # the directory of our main .py/.dll/.exe file we
***************
*** 73,77 ****
          "'spambayes.Options' was imported too early"
      global bayes_classifier, bayes_tokenize, bayes_storage
!     os.environ["BAYESCUSTOMIZE"] = ini_filename
      from spambayes import classifier
      from spambayes.tokenizer import tokenize
--- 81,86 ----
          "'spambayes.Options' was imported too early"
      global bayes_classifier, bayes_tokenize, bayes_storage
!     # ini_filename is Unicode, but environ not unicode aware
!     os.environ["BAYESCUSTOMIZE"] = ini_filename.encode(filesystem_encoding)
      from spambayes import classifier
      from spambayes.tokenizer import tokenize
***************
*** 157,166 ****
      db_extension = ".db"
      def open_bayes(self):
!         return bayes_storage.DBDictClassifier(self.bayes_filename)
      def close_bayes(self, bayes):
          bayes.db.close()
          bayes.dbm.close()
      def open_mdb(self):
!         return bsddb.hashopen(self.mdb_filename)
      def new_mdb(self):
          try:
--- 166,178 ----
      db_extension = ".db"
      def open_bayes(self):
!         # bsddb doesn't handle unicode filenames yet :(
!         fname = self.bayes_filename.encode(filesystem_encoding)
!         return bayes_storage.DBDictClassifier(fname)
      def close_bayes(self, bayes):
          bayes.db.close()
          bayes.dbm.close()
      def open_mdb(self):
!         fname = self.mdb_filename.encode(filesystem_encoding)
!         return bsddb.hashopen(fname)
      def new_mdb(self):
          try:
***************
*** 201,204 ****
--- 213,225 ----
          value = self.config.general.data_directory
          if value:
+             # until I know otherwise, config files are ASCII - but our
+             # file system is unicode to some degree.
+             # (do config files support encodings at all?)
+             # Assume the file system encoding for file names!
+             try:
+                 value = value.decode(filesystem_encoding)
+             except AttributeError: # May already be Unicode
+                 pass
+             assert type(value) == type(u''), "%r should be a unicode" % value
              try:
                  if not os.path.isdir(value):
***************
*** 216,220 ****
          else:
              self.data_directory = self.windows_data_directory
!             
          # Now we have the data directory, migrate anything needed, and load
          # any config from it.
--- 237,241 ----
          else:
              self.data_directory = self.windows_data_directory
! 
          # Now we have the data directory, migrate anything needed, and load
          # any config from it.
***************
*** 418,427 ****
              # file-not-found handled gracefully by storage.
              bayes = self.db_manager.open_bayes()
!             print "Loaded bayes database from '%s'" % (self.db_manager.bayes_filename,)
          except:
              self.ReportFatalStartupError("Failed to load bayes database")
          try:
              message_db = self.db_manager.open_mdb()
!             print "Loaded message database from '%s'" % (self.db_manager.mdb_filename,)
          except IOError:
              pass
--- 439,450 ----
              # file-not-found handled gracefully by storage.
              bayes = self.db_manager.open_bayes()
!             fname = self.db_manager.bayes_filename.encode("mbcs", "replace")
!             print "Loaded bayes database from '%s'" % (fname,)
          except:
              self.ReportFatalStartupError("Failed to load bayes database")
          try:
              message_db = self.db_manager.open_mdb()
!             fname = self.db_manager.mdb_filename.encode("mbcs", "replace")
!             print "Loaded message database from '%s'" % (fname,)
          except IOError:
              pass
***************
*** 601,605 ****
  
      def SaveConfig(self):
!         print "Saving configuration ->", self.config_filename
          assert self.config and self.options, "Have no config to save!"
          if self.verbose > 1:
--- 624,628 ----
  
      def SaveConfig(self):
!         print "Saving configuration ->", self.config_filename.encode("mbcs", "replace")
          assert self.config and self.options, "Have no config to save!"
          if self.verbose > 1:





More information about the Spambayes-checkins mailing list