app/django/db/backends/util.py
changeset 323 ff1a9aa48cfd
parent 54 03e267d67478
equal deleted inserted replaced
322:6641e941ef1e 323:ff1a9aa48cfd
     1 import datetime
     1 import datetime
     2 import md5
       
     3 from time import time
     2 from time import time
       
     3 
       
     4 from django.utils.hashcompat import md5_constructor
     4 
     5 
     5 try:
     6 try:
     6     import decimal
     7     import decimal
     7 except ImportError:
     8 except ImportError:
     8     from django.utils import _decimal as decimal    # for Python 2.3
     9     from django.utils import _decimal as decimal    # for Python 2.3
   112     """Shortens a string to a repeatable mangled version with the given length.
   113     """Shortens a string to a repeatable mangled version with the given length.
   113     """
   114     """
   114     if length is None or len(name) <= length:
   115     if length is None or len(name) <= length:
   115         return name
   116         return name
   116 
   117 
   117     hash = md5.md5(name).hexdigest()[:4]
   118     hash = md5_constructor(name).hexdigest()[:4]
   118 
   119 
   119     return '%s%s' % (name[:length-4], hash)
   120     return '%s%s' % (name[:length-4], hash)
       
   121 
       
   122 def format_number(value, max_digits, decimal_places):
       
   123     """
       
   124     Formats a number into a string with the requisite number of digits and
       
   125     decimal places.
       
   126     """
       
   127     return u"%.*f" % (decimal_places, value)