Author: mtredinnick
Date: 2009-03-01 02:13:38 -0600 (Sun, 01 Mar 2009)
New Revision: 9936

Modified:
   django/trunk/django/core/cache/__init__.py
   django/trunk/django/db/backends/creation.py
Log:
Changed the way cache specifiers are parsed.

Allows us to reuse the same code in multiple places, avoiding new and
interesting bugs (the testing framework had a DIY version that was slightly
wrong, for example). Fixed #9833.

Modified: django/trunk/django/core/cache/__init__.py
===================================================================
--- django/trunk/django/core/cache/__init__.py  2009-03-01 07:33:45 UTC (rev 
9935)
+++ django/trunk/django/core/cache/__init__.py  2009-03-01 08:13:38 UTC (rev 
9936)
@@ -31,7 +31,12 @@
     'dummy': 'dummy',
 }
 
-def get_cache(backend_uri):
+def parse_backend_uri(backend_uri):
+    """
+    Converts the "backend_uri" into a cache scheme ('db', 'memcached', etc), a
+    host and any extra params that are required for the backend. Returns a
+    (scheme, host, params) tuple.
+    """
     if backend_uri.find(':') == -1:
         raise InvalidCacheBackendError, "Backend URI must start with scheme://"
     scheme, rest = backend_uri.split(':', 1)
@@ -48,6 +53,10 @@
     if host.endswith('/'):
         host = host[:-1]
 
+    return scheme, host, params
+
+def get_cache(backend_uri):
+    scheme, host, params = parse_backend_uri(backend_uri)
     if scheme in BACKENDS:
         module = __import__('django.core.cache.backends.%s' % 
BACKENDS[scheme], {}, {}, [''])
     else:

Modified: django/trunk/django/db/backends/creation.py
===================================================================
--- django/trunk/django/db/backends/creation.py 2009-03-01 07:33:45 UTC (rev 
9935)
+++ django/trunk/django/db/backends/creation.py 2009-03-01 08:13:38 UTC (rev 
9936)
@@ -312,11 +312,12 @@
         self.connection.close()
         settings.DATABASE_NAME = test_database_name
         settings.DATABASE_SUPPORTS_TRANSACTIONS = self._rollback_works()
-        
+
         call_command('syncdb', verbosity=verbosity, interactive=False)
 
         if settings.CACHE_BACKEND.startswith('db://'):
-            cache_name = settings.CACHE_BACKEND[len('db://'):]
+            from django.core.cache import parse_backend_uri
+            _, cache_name, _ = parse_backend_uri(settings.CACHE_BACKEND)
             call_command('createcachetable', cache_name)
 
         # Get a cursor (even though we don't need one yet). This has
@@ -363,7 +364,7 @@
                 sys.exit(1)
 
         return test_database_name
-    
+
     def _rollback_works(self):
         cursor = self.connection.cursor()
         cursor.execute('CREATE TABLE ROLLBACK_TEST (X INT)')
@@ -375,7 +376,7 @@
         cursor.execute('DROP TABLE ROLLBACK_TEST')
         self.connection._commit()
         return count == 0
-        
+
     def destroy_test_db(self, old_database_name, verbosity=1):
         """
         Destroy a test database, prompting the user for confirmation if the


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---


Reply via email to