summaryrefslogtreecommitdiff
path: root/morphlib/morph3.py
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2013-08-07 13:53:36 +0000
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2013-08-14 16:32:04 +0000
commit4bea99229dfa1ee7bffeefc4d194c34eb4752509 (patch)
treed892c903716268bc555a7a27b8cd4924c4b5297a /morphlib/morph3.py
parent5d95df761c8335711f27e9ab062c0a20ddd332b1 (diff)
downloadmorph-4bea99229dfa1ee7bffeefc4d194c34eb4752509.tar.gz
Add new morphology abstraction and morphology loading/saving
The old code is somewhat weird. The new code is meant to be cleaner and more straightforward to understand and to use. For example, the old code has setting of defaults in both the Morphology and MorphologyFactory classes. The new code has a minimally simple Morphology class, and has all the logic to validate and set defaults in the MorphologyLoader class. Further, the new code makes it possible to load an invalid morphology, which will be useful later.
Diffstat (limited to 'morphlib/morph3.py')
-rw-r--r--morphlib/morph3.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/morphlib/morph3.py b/morphlib/morph3.py
new file mode 100644
index 00000000..477cac1a
--- /dev/null
+++ b/morphlib/morph3.py
@@ -0,0 +1,45 @@
+# Copyright (C) 2013 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# =*= License: GPL-2 =*=
+
+
+import UserDict
+
+
+class Morphology(UserDict.IterableUserDict):
+
+ '''A container for a morphology, plus its metadata.
+
+ A morphology is, basically, a dict. This class acts as that dict,
+ plus stores additional metadata about the morphology, such as where
+ it came from, and the ref that was used for it. It also has a dirty
+ attribute, to indicate whether the morphology has had changes done
+ to it, but does not itself set that attribute: the caller has to
+ maintain the flag themselves.
+
+ This class does NO validation of the data, nor does it parse the
+ morphology text, or produce a textual form of itself. For those
+ things, see MorphologyLoader.
+
+ '''
+
+ def __init__(self, *args, **kwargs):
+ UserDict.IterableUserDict.__init__(self, *args, **kwargs)
+ self.repo_url = None
+ self.ref = None
+ self.filename = None
+ self.dirty = None
+