]> git.ipfire.org Git - thirdparty/python-drafthorse.git/commitdiff
Compat for Python 3.5
authorRaphael Michel <mail@raphaelmichel.de>
Tue, 16 Oct 2018 05:18:57 +0000 (07:18 +0200)
committerRaphael Michel <mail@raphaelmichel.de>
Tue, 16 Oct 2018 05:19:08 +0000 (07:19 +0200)
drafthorse/models/elements.py
setup.py

index f70f234cd3511b464ca58b3cde1b3cb23235d099..6525fa2a57388dd94b901c5306c063fe0e41adb8 100644 (file)
@@ -255,7 +255,10 @@ class DateTimeElement(StringElement):
             if self.format == '102':
                 node.text = self.value.strftime("%Y%m%d")
             elif self.format == '616':
-                node.text = self.value.strftime("%G%V")
+                if sys.version_info < (3, 6):
+                    node.text = '{}{}'.format(self.value.isocalendar()[0], self.value.isocalendar()[1])
+                else:
+                    node.text = self.value.strftime("%G%V")
             node.attrib['format'] = self.format
             t.append(node)
         return t
@@ -269,7 +272,12 @@ class DateTimeElement(StringElement):
         if self.format == '102':
             self.value = datetime.strptime(root[0].text, '%Y%m%d').date()
         elif self.format == '616':
-            self.value = datetime.strptime(root[0].text + '1', '%G%V%u').date()
+            if sys.version_info < (3, 6):
+                from isoweek import Week
+                w = Week(int(root[0].text[:4]), int(root[0].text[4:]))
+                self.value = w.monday()
+            else:
+                self.value = datetime.strptime(root[0].text + '1', '%G%V%u').date()
         else:
             raise TypeError("Date format %s cannot be parsed" % root[0].attrib['format'])
         return self
index 17178f3b6e5a30d8ff6ae72cddcc77f47aff128a..0dbf14ca2cb7a21554ac333975ce11191d047eca 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -1,3 +1,5 @@
+import sys
+
 from codecs import open
 from os import path
 
@@ -35,8 +37,8 @@ setup(
 
     keywords='xml banking sepa',
     install_requires=[
-        'lxml'
-    ],
+                         'lxml'
+                     ] + (['isoweek'] if sys.version_info < (3, 6) else []),
 
     packages=find_packages(include=['sepadd', 'sepadd.*']),
 )