changeset 33:9b10c81ffd0f

merge
author Bernhard Herzog <bh@intevation.de>
date Thu, 15 Mar 2007 11:49:17 +0100
parents b1235080e694 (current diff) 47d69e5d8ace (diff)
children 1fefedfb77df
files
diffstat 1 files changed, 22 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/treepkg/status.py	Thu Mar 15 11:48:13 2007 +0100
+++ b/treepkg/status.py	Thu Mar 15 11:49:17 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)