Commits

Flavio Curella committed 315ae00

added py3k support.

Comments (0)

Files changed (6)

         "timedelta",
         "timedelta.templatetags",
     ],
+    install_requires = [
+        "six",
+    ],
     package_data = {'timedelta': ['VERSION']},
     classifiers = [
         'Programming Language :: Python',

timedelta/__init__.py

 __version__ = open(os.path.join(os.path.dirname(__file__), "VERSION")).read().strip()
 
 try:
-    from fields import TimedeltaField
-    from helpers import (
+    from .fields import TimedeltaField
+    from .helpers import (
         divide, multiply, modulo, 
         parse, nice_repr, 
         percentage, decimal_percentage,

timedelta/fields.py

 
 from collections import defaultdict
 import datetime
+import six
 
-from helpers import parse
-from forms import TimedeltaFormField
+from .helpers import parse
+from .forms import TimedeltaFormField
 
 # TODO: Figure out why django admin thinks fields of this type have changed every time an object is saved.
 
     def get_prep_value(self, value):
         if self.null and value == "":
             return None
-        if (value is None) or isinstance(value, (str, unicode)):
+        if (value is None) or isinstance(value, six.string_types):
             return value
         return str(value).replace(',', '')
         

timedelta/forms.py

 import datetime
 from collections import defaultdict
 
-from widgets import TimedeltaWidget
-from helpers import parse
+from .widgets import TimedeltaWidget
+from .helpers import parse
 
 class TimedeltaFormField(forms.Field):
     default_error_messages = {

timedelta/helpers.py

 import datetime
 from decimal import Decimal
 
+import six
+
 def nice_repr(timedelta, display="long", sep=", "):
     """
     Turns a datetime.timedelta object into a nice string repr.
     # and from serialization
     d = re.match(r'^((?P<days>\d+) days?,? )?(?P<hours>\d+):'
                  r'(?P<minutes>\d+)(:(?P<seconds>\d+(\.\d+)?))?$',
-                 unicode(string))
+                 six.text_type(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*$',
-                     unicode(string))
+                     six.text_type(string))
         if not d:
             raise TypeError("'%s' is not a valid time interval" % string)
         d = d.groupdict(0)

timedelta/widgets.py

 from django import forms
 import datetime
+import six
 
-from helpers import nice_repr, parse
+from .helpers import nice_repr, parse
 
 class TimedeltaWidget(forms.TextInput):
     def __init__(self, *args, **kwargs):
     def render(self, name, value, attrs=None):
         if value is None:
             value = ""
-        elif isinstance(value, (str, unicode)):
+        elif isinstance(value, six.string_types):
             pass
         else:
             if isinstance(value, int):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.