[Zodb-checkins] SVN: ZODB/branches/3.8/src/ZODB/ Fixed numerous windows issues

Jim Fulton jim at zope.com
Thu Sep 18 18:07:55 EDT 2008


Log message for revision 91239:
  Fixed numerous windows issues

Changed:
  U   ZODB/branches/3.8/src/ZODB/blob.py
  U   ZODB/branches/3.8/src/ZODB/tests/blob_packing.txt
  U   ZODB/branches/3.8/src/ZODB/tests/blob_transaction.txt
  U   ZODB/branches/3.8/src/ZODB/tests/testblob.py

-=-
Modified: ZODB/branches/3.8/src/ZODB/blob.py
===================================================================
--- ZODB/branches/3.8/src/ZODB/blob.py	2008-09-18 20:03:13 UTC (rev 91238)
+++ ZODB/branches/3.8/src/ZODB/blob.py	2008-09-18 22:07:54 UTC (rev 91239)
@@ -298,7 +298,7 @@
     # want to perform blob storage differently.
 
     def __init__(self, base_dir, layout_name='automatic'):
-        self.base_dir = os.path.normpath(base_dir) + '/'
+        self.base_dir = os.path.normpath(base_dir) + os.path.sep
         self.temp_dir = os.path.join(base_dir, 'tmp')
 
         if layout_name == 'automatic':
@@ -488,8 +488,8 @@
 
     """
 
-    blob_path_pattern = r'^' + (r'0x[0-9a-f]{1,2}/*'*8) + r'$'
-    blob_path_pattern = re.compile(blob_path_pattern)
+    blob_path_pattern = re.compile(
+        r'(0x[0-9a-f]{1,2}\%s){7,7}0x[0-9a-f]{1,2}$' % os.path.sep)
 
     def oid_to_path(self, oid):
         directories = []
@@ -497,12 +497,12 @@
         # first
         for byte in str(oid):
             directories.append('0x%s' % binascii.hexlify(byte))
-        return '/'.join(directories)
+        return os.path.sep.join(directories)
 
     def path_to_oid(self, path):
         if self.blob_path_pattern.match(path) is None:
             raise ValueError("Not a valid OID path: `%s`" % path)
-        path = path.split('/')
+        path = path.split(os.path.sep)
         # Each path segment stores a byte in hex representation. Turn it into
         # an int and then get the character for our byte string.
         oid = ''.join(binascii.unhexlify(byte[2:]) for byte in path)

Modified: ZODB/branches/3.8/src/ZODB/tests/blob_packing.txt
===================================================================
--- ZODB/branches/3.8/src/ZODB/tests/blob_packing.txt	2008-09-18 20:03:13 UTC (rev 91238)
+++ ZODB/branches/3.8/src/ZODB/tests/blob_packing.txt	2008-09-18 22:07:54 UTC (rev 91239)
@@ -146,7 +146,7 @@
 
 Clean up our blob directory and database:
 
-    >>> shutil.rmtree(blob_dir)
+    >>> rmtree(blob_dir)
     >>> base_storage.close()
     >>> os.unlink(storagefile)
     >>> os.unlink(storagefile+".index")
@@ -273,4 +273,4 @@
 
 Clean up our blob directory:
 
-    >>> shutil.rmtree(blob_dir)
+    >>> rmtree(blob_dir)

Modified: ZODB/branches/3.8/src/ZODB/tests/blob_transaction.txt
===================================================================
--- ZODB/branches/3.8/src/ZODB/tests/blob_transaction.txt	2008-09-18 20:03:13 UTC (rev 91238)
+++ ZODB/branches/3.8/src/ZODB/tests/blob_transaction.txt	2008-09-18 22:07:54 UTC (rev 91239)
@@ -381,6 +381,5 @@
     >>> tm1.abort()
     >>> tm2.abort()
     >>> database.close()
-    >>> import shutil
-    >>> shutil.rmtree(blob_dir)
-    >>> shutil.rmtree(blob_dir2)
+    >>> rmtree(blob_dir)
+    >>> rmtree(blob_dir2)

Modified: ZODB/branches/3.8/src/ZODB/tests/testblob.py
===================================================================
--- ZODB/branches/3.8/src/ZODB/tests/testblob.py	2008-09-18 20:03:13 UTC (rev 91238)
+++ ZODB/branches/3.8/src/ZODB/tests/testblob.py	2008-09-18 22:07:54 UTC (rev 91239)
@@ -12,7 +12,7 @@
 #
 ##############################################################################
 
-import base64, os, re, shutil, tempfile, unittest
+import base64, os, re, shutil, stat, sys, tempfile, unittest
 import time
 from zope.testing import doctest, renormalizing
 import ZODB.tests.util
@@ -473,6 +473,11 @@
 
     """
 
+# On windows, we can't create secure blob directories, at least not
+# with APIs in the standard library, so there's no point in testing
+# this.
+if sys.platform == 'win32':
+    del secure_blob_directory
 
 def loadblob_tmpstore():
     """
@@ -520,14 +525,27 @@
 
     >>> database.close()
     >>> import shutil
-    >>> shutil.rmtree(blob_dir)
+    >>> rmtree(blob_dir)
 
     >>> os.unlink(storagefile)
     >>> os.unlink(storagefile+".index")
     >>> os.unlink(storagefile+".tmp")
 """
 
+def setUp(test):
+    ZODB.tests.util.setUp(test)
+    def rmtree(path):
+        for path, dirs, files in os.walk(path, False):
+            for fname in files:
+                fname = os.path.join(path, fname)
+                os.chmod(fname, stat.S_IWUSR)
+                os.remove(fname)
+            for dname in dirs:
+                dname = os.path.join(path, dname)
+                os.rmdir(dname)
 
+    test.globs['rmtree'] = rmtree
+
 def test_suite():
     suite = unittest.TestSuite()
     suite.addTest(unittest.makeSuite(ZODBBlobConfigTest))
@@ -536,22 +554,26 @@
         "blob_packing.txt", "blob_importexport.txt", "blob_consume.txt",
         "blob_tempdir.txt",
         optionflags=doctest.ELLIPSIS,
-        setUp=ZODB.tests.util.setUp,
+        setUp=setUp,
         tearDown=ZODB.tests.util.tearDown,
         ))
     suite.addTest(doctest.DocFileSuite(
         "blob_layout.txt",
         optionflags=doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE,
-        setUp=ZODB.tests.util.setUp,
+        setUp=setUp,
         tearDown=ZODB.tests.util.tearDown,
         checker = renormalizing.RENormalizing([
-            (re.compile(r'[%(sep)s]' % dict(sep=os.path.sep)), '/'),
+            (re.compile(r'\%(sep)s' % dict(sep=os.path.sep)), '/'),
             (re.compile(r'\S+/((old|bushy|lawn)/\S+/foo[23456]?)'), r'\1'),
             ]),
         ))
     suite.addTest(doctest.DocTestSuite(
-        setUp=ZODB.tests.util.setUp,
+        setUp=setUp,
         tearDown=ZODB.tests.util.tearDown,
+        checker = renormalizing.RENormalizing([
+            (re.compile(r'\%(sep)s\%(sep)s' % dict(sep=os.path.sep)), '/'),
+            (re.compile(r'\%(sep)s' % dict(sep=os.path.sep)), '/'),
+            ]),
         ))
     suite.addTest(unittest.makeSuite(BlobUndoTests))
 



More information about the Zodb-checkins mailing list