utils.py
branchtls-sprint
changeset 709 b21ee900c732
parent 708 b4728112625f
child 1016 26387b836099
equal deleted inserted replaced
708:b4728112625f 709:b21ee900c732
     4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     6 """
     6 """
     7 __docformat__ = "restructuredtext en"
     7 __docformat__ = "restructuredtext en"
     8 
     8 
       
     9 import locale
     9 from md5 import md5
    10 from md5 import md5
    10 from time import time
    11 from time import time
    11 from random import randint, seed
    12 from random import randint, seed
    12 
    13 
    13 # initialize random seed from current time
    14 # initialize random seed from current time
    39     date = begin
    40     date = begin
    40     while date <= end:
    41     while date <= end:
    41         if include is None or include(date): 
    42         if include is None or include(date): 
    42             yield date
    43             yield date
    43         date += incr
    44         date += incr
       
    45 
       
    46 def ustrftime(date, fmt='%Y-%m-%d'):
       
    47     """like strftime, but returns a unicode string instead of an encoded
       
    48     string which may be problematic with localized date.
       
    49     
       
    50     encoding is guessed by locale.getpreferredencoding()
       
    51     """
       
    52     # date format may depend on the locale
       
    53     encoding = locale.getpreferredencoding(do_setlocale=False) or 'UTF-8'
       
    54     return unicode(date.strftime(fmt), encoding)
    44 
    55 
    45 
    56 
    46 def dump_class(cls, clsname):
    57 def dump_class(cls, clsname):
    47     """create copy of a class by creating an empty class inheriting
    58     """create copy of a class by creating an empty class inheriting
    48     from the given cls.
    59     from the given cls.