]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Add __str__ to DateTimePattern (#515)
authorStefane Fermigier <sf@fermigier.com>
Thu, 3 Aug 2017 18:22:46 +0000 (20:22 +0200)
committerAarni Koskela <akx@iki.fi>
Thu, 3 Aug 2017 18:22:46 +0000 (21:22 +0300)
Fixes #514

babel/dates.py

index c84ca48652df30ce66727867396b106cefac21f6..75e53a1d77a090c085b6d1cf4c82411229eaa0da 100644 (file)
@@ -27,8 +27,7 @@ from bisect import bisect_right
 
 from babel.core import default_locale, get_global, Locale
 from babel.util import UTC, LOCALTZ
-from babel._compat import string_types, integer_types, number_types
-
+from babel._compat import string_types, integer_types, number_types, PY2
 
 # "If a given short metazone form is known NOT to be understood in a given
 #  locale and the parent locale has this value such that it would normally
@@ -1218,6 +1217,12 @@ class DateTimePattern(object):
     def __unicode__(self):
         return self.pattern
 
+    def __str__(self):
+        pat = self.pattern
+        if PY2:
+            pat = pat.encode('utf-8')
+        return pat
+
     def __mod__(self, other):
         if type(other) is not DateTimeFormat:
             return NotImplemented