Skip to content
Snippets Groups Projects
Commit f643f6bf authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

.

parent c71174e8
No related branches found
No related tags found
No related merge requests found
...@@ -5,7 +5,7 @@ import logging ...@@ -5,7 +5,7 @@ import logging
class _Required(object): class _Required(object):
pass """Only a placeholder to tell apart None default values from required fields"""
def nop(x): def nop(x):
return x return x
...@@ -16,6 +16,7 @@ __all__ = [ ...@@ -16,6 +16,7 @@ __all__ = [
] ]
class _Field(object): class _Field(object):
"""Base field object"""
def set(self, obj, elem): def set(self, obj, elem):
obj.__dict__[self.field_name] = self.find(elem) obj.__dict__[self.field_name] = self.find(elem)
...@@ -28,12 +29,20 @@ class _Field(object): ...@@ -28,12 +29,20 @@ class _Field(object):
class _ComputedField(_Field): class _ComputedField(_Field):
"""
There's no corresponding XML attribute name - value must
be computed from element
"""
def __init__(self, field_name, find_fun): def __init__(self, field_name, find_fun):
super(_ComputedField, self).__init__(field_name) super(_ComputedField, self).__init__(field_name)
self.find = find_fun self.find = find_fun
class _ValueField(_Field): class _ValueField(_Field):
"""
Can hide under a pick of different XML attribute names.
Has a type, can have a default value.
"""
def __init__(self, xml_names, field_name, field_type=nop, def __init__(self, xml_names, field_name, field_type=nop,
default=_Required): default=_Required):
if not isinstance(xml_names, tuple): if not isinstance(xml_names, tuple):
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment