Commits

savemu  committed 2c46ae5

fix unicode validation error

  • Participants
  • Parent commits 53e8a08

Comments (0)

Files changed (2)

File timedelta/helpers.py

     # This is the format we sometimes get from Postgres.
     d = re.match(r'((?P<days>\d+) days )?(?P<hours>\d+):'
                  r'(?P<minutes>\d+)(:(?P<seconds>\d+))?',
-                 str(string))
+                 unicode(string))
     if d: 
         d = d.groupdict(0)
     else:
                      r'((?P<hours>((\d*\.\d+)|\d+))\W*h(ou)?r(s)?(,)?\W*)?'
                      r'((?P<minutes>((\d*\.\d+)|\d+))\W*m(in(ute)?)?(s)?(,)?\W*)?'
                      r'((?P<seconds>((\d*\.\d+)|\d+))\W*s(ec(ond)?(s)?)?)?\W*$',
-                     str(string))
+                     unicode(string))
         if not d:
             raise TypeError("'%s' is not a valid time interval" % string)
         d = d.groupdict()

File timedelta/tests.py

         datetime.timedelta(7)
         >>> t.clean('2 weeks, 2 days')
         datetime.timedelta(16)
+        >>> t.clean(u'2 we\xe8k, 2 days')
+        Traceback (most recent call last):
+        ValidationError: [u'Enter a valid time span: e.g. "3 days, 4 hours, 2 minutes"']
         """
 
 class TimedeltaHelpersTest(TestCase):