changeset 31:47d69e5d8ace

merge
author Bernhard Herzog <bh@intevation.de>
date Thu, 15 Mar 2007 11:42:03 +0100
parents beec3ed6e0df (diff) 22192fad1f79 (current diff)
children 9b10c81ffd0f
files treepkg/status.py
diffstat 1 files changed, 22 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/treepkg/status.py	Wed Mar 14 21:49:05 2007 +0100
+++ b/treepkg/status.py	Thu Mar 15 11:42:03 2007 +0100
@@ -15,33 +15,41 @@
 # special object to indicate no default value
 nodefault = object()
 
-def serialize_datetime(d):
-    return d.strftime("%Y-%m-%d %H:%M:%S")
-
-def deserialize_datetime(s):
-    return datetime.datetime(*time.strptime(s.strip(), "%Y-%m-%d %H:%M:%S")[:6])
-
 
 class FieldDesc(object):
 
-    def __init__(self, serialize, deserialize, default=nodefault):
-        self.serialize = serialize
-        self.deserialize = deserialize
+    def __init__(self, default=nodefault):
         self.default = default
 
     def has_default(self):
         return self.default is not nodefault
 
+    def serialize(self, value):
+        raise NotImplementedError
+
+    def deserialize(self, string):
+        raise NotImplementedError
+
+
 class StringFieldDesc(FieldDesc):
 
-    def __init__(self, **kw):
-        super(StringFieldDesc, self).__init__(str, lambda s: s.strip(), **kw)
+    def serialize(self, value):
+        return str(value)
+
+    def deserialize(self, value):
+        return value.strip()
+
 
 class DateFieldDesc(FieldDesc):
 
-    def __init__(self, **kw):
-        super(DateFieldDesc, self).__init__(serialize_datetime,
-                                            deserialize_datetime, **kw)
+    date_format = "%Y-%m-%d %H:%M:%S"
+
+    def serialize(self, value):
+        return value.strftime(self.date_format)
+
+    def deserialize(self, string):
+        return datetime.datetime(*time.strptime(string.strip(),
+                                                self.date_format)[:6])
 
 
 class Status(object):
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)