utils.py
branch3.5
changeset 3146 cfc4344023f2
parent 3101 e75ab3635f07
child 3155 14e30e2520d7
equal deleted inserted replaced
3145:9b28545de60d 3146:cfc4344023f2
     9 
     9 
    10 from logilab.mtconverter import xml_escape
    10 from logilab.mtconverter import xml_escape
    11 
    11 
    12 import locale
    12 import locale
    13 from md5 import md5
    13 from md5 import md5
       
    14 import sys
    14 from datetime import datetime, timedelta, date
    15 from datetime import datetime, timedelta, date
    15 from time import time, mktime
    16 from time import time, mktime
    16 from random import randint, seed
    17 from random import randint, seed
    17 from calendar import monthrange
    18 from calendar import monthrange
    18 
    19 
   101     """
   102     """
   102     # date format may depend on the locale
   103     # date format may depend on the locale
   103     encoding = locale.getpreferredencoding(do_setlocale=False) or 'UTF-8'
   104     encoding = locale.getpreferredencoding(do_setlocale=False) or 'UTF-8'
   104     return unicode(date.strftime(str(fmt)), encoding)
   105     return unicode(date.strftime(str(fmt)), encoding)
   105 
   106 
   106 def make_uid(key):
   107 
   107     """forge a unique identifier"""
   108 if sys.version_info[:2] < (2, 5):
   108     msg = str(key) + "%.10f" % time() + str(randint(0, 1000000))
   109     def make_uid(key):
   109     return md5(msg).hexdigest()
   110         """forge a unique identifier
   110 
   111         not that unique on win32"""
       
   112         msg = str(key) + "%.10f" % time() + str(randint(0, 1000000))
       
   113         return md5(msg).hexdigest()
       
   114 else:
       
   115     from uuid import uuid4
       
   116     def make_uid(key):
       
   117         return key + str(uuid4())
   111 
   118 
   112 def dump_class(cls, clsname):
   119 def dump_class(cls, clsname):
   113     """create copy of a class by creating an empty class inheriting
   120     """create copy of a class by creating an empty class inheriting
   114     from the given cls.
   121     from the given cls.
   115 
   122