web/lib/django/core/files/storage.py
changeset 29 cc9b7e14412b
parent 0 0d40e90630ef
--- a/web/lib/django/core/files/storage.py	Wed May 19 17:43:59 2010 +0200
+++ b/web/lib/django/core/files/storage.py	Tue May 25 02:43:45 2010 +0200
@@ -1,12 +1,13 @@
 import os
 import errno
 import urlparse
+import itertools
 
 from django.conf import settings
 from django.core.exceptions import ImproperlyConfigured, SuspiciousOperation
 from django.core.files import locks, File
 from django.core.files.move import file_move_safe
-from django.utils.encoding import force_unicode, smart_str
+from django.utils.encoding import force_unicode
 from django.utils.functional import LazyObject
 from django.utils.importlib import import_module
 from django.utils.text import get_valid_filename
@@ -65,13 +66,14 @@
         """
         dir_name, file_name = os.path.split(name)
         file_root, file_ext = os.path.splitext(file_name)
-        # If the filename already exists, keep adding an underscore (before the
-        # file extension, if one exists) to the filename until the generated
+        # If the filename already exists, add an underscore and a number (before
+        # the file extension, if one exists) to the filename until the generated
         # filename doesn't exist.
+        count = itertools.count(1)
         while self.exists(name):
-            file_root += '_'
             # file_ext includes the dot.
-            name = os.path.join(dir_name, file_root + file_ext)
+            name = os.path.join(dir_name, "%s_%s%s" % (file_root, count.next(), file_ext))
+
         return name
 
     def path(self, name):
@@ -118,10 +120,6 @@
         """
         raise NotImplementedError()
 
-    # Needed by django.utils.functional.LazyObject (via DefaultStorage).
-    def get_all_members(self):
-        return self.__members__
-
 class FileSystemStorage(Storage):
     """
     Standard filesystem storage
@@ -212,7 +210,7 @@
             path = safe_join(self.location, name)
         except ValueError:
             raise SuspiciousOperation("Attempted access to '%s' denied." % name)
-        return smart_str(os.path.normpath(path))
+        return os.path.normpath(path)
 
     def size(self, name):
         return os.path.getsize(self.path(name))