Properties Subpackage¶
This subpackage deal with XML tags of diverse data type. It contains classes to handle tags whose data type are: boolean, datetime, numeric and text.
Classes
- class nometa.properties.Property¶
Abstract class for dealing with xml nodes/tags
- abstract _set_node_value(node: _Element) None¶
Hook method to set the tag’s value
- Parameters:
node (etree._Element) – the node corresponding this XML tag
- abstract static from_element(tname: str, elem: _Element) Property¶
Read an _Element and returns the corresponding property object
- Parameters:
tname (str) – the official tag name in XML documents
elem (etree._Element) – a valid etree._Element instance
- Raises:
TypeError –
- Returns:
an instance of Property or its subclasses
- Return type:
- property tname: str¶
Get the official tag name of this property
- to_element(elem: _Element) None¶
Write the value of this property to elem parameter
- Parameters:
elem (etree._Element) – the target xml tree node
- Raises:
TypeError –
- class nometa.properties.boolean.BooleanProperty(tname: str)¶
Deal with boolean values. It can be used with any xml-tag data type, the assignment of value is determined as:
For these string values ‘false’,’no’,’not’,’n’,’0’ and ‘’, it puts False. For any other value, it puts True.
For any numeric representation >= ‘1.0’, it puts True. Otherwise, False.
- __init__(tname: str) None¶
Constructor
- Parameters:
tname – tag name in the XML file. Eg: dc:title
- Raises:
TypeError –
- static from_element(tname: str, elem: _Element) Property¶
Read an _Element and returns the corresponding property object
- Parameters:
tname (str) – the official tag name in XML documents
elem (etree._Element) – a valid etree._Element instance
- Raises:
TypeError –
- Returns:
an instance of Property or its subclasses
- Return type:
- property value: bool | None¶
Get the value of this property
- class nometa.properties.datetime.DatetimeProperty(tname: str)¶
Deal with UTC-ISO formatted dates. It must be used only with ISO formatted dates, and always writes UTC time.
- __init__(tname: str) None¶
Constructor
- Parameters:
tname – tag name in the XML file. Eg: dc:title
- Raises:
TypeError –
- static from_element(tname: str, elem: _Element) Property¶
Read an _Element and returns the corresponding property object
- Parameters:
tname (str) – the official tag name in XML documents
elem (etree._Element) – a valid etree._Element instance
- Raises:
TypeError –
- Returns:
an instance of Property or its subclasses
- Return type:
- property value: datetime | None¶
Get a datetime instance in UTC
- class nometa.properties.numeric.NumericProperty(tname: str)¶
Deal with numeric (integer or float) values. It must be used only in float or integer xml elements.
- __init__(tname: str) None¶
Constructor
- Parameters:
tname – tag name in the XML file. Eg: dc:title
- Raises:
TypeError –
- static from_element(tname: str, elem: _Element) Property¶
Read an _Element and returns the corresponding property object
- Parameters:
tname (str) – the official tag name in XML documents
elem (etree._Element) – a valid etree._Element instance
- Raises:
TypeError –
- Returns:
an instance of Property or its subclasses
- Return type:
- property value: int | float | None¶
Get the value of this property
- class nometa.properties.text.TextProperty(tname: str)¶
Deal with string values. It reads and keeps all element value as string.
- __init__(tname: str) None¶
Constructor
- Parameters:
tname – tag name in the XML file. Eg: dc:title
- Raises:
TypeError –
- static from_element(tname: str, elem: _Element) Property¶
Read an _Element and returns the corresponding property object
- Parameters:
tname (str) – the official tag name in XML documents
elem (etree._Element) – a valid etree._Element instance
- Raises:
TypeError –
- Returns:
an instance of Property or its subclasses
- Return type:
- property value: str | None¶
Get the string value of a property