MyCapytain.common.metadata¶
-
class
MyCapytain.common.metadata.
Metadata
(keys=None)[source]¶ Bases:
future.types.newobject.newobject
A metadatum aggregation object provided to centralize metadata
Parameters: key (List.<basestring>) – A metadata field name Variables: metadata – Dictionary of metadatum -
__getitem__
(key)[source]¶ Add a quick access system through getitem on the instance
Parameters: key (basestring, int, tuple) – Index key representing a set of metadatum
Returns: An element of children whose index is key
Raises: KeyError If key is not registered or recognized
Example: >>> a = Metadata() >>> m1 = Metadatum(name="title", [("lat", "Amores"), ("fre", "Les Amours")]) >>> m2 = Metadatum(name="author", [("lat", "Ovidius"), ("fre", "Ovide")]) >>> a[("title", "author")] = (m1, m2)
>>> a["title"] == m1 >>> a[0] == m1 >>> a[("title", "author")] == (m1, m2)
-
__setitem__
(key, value)[source]¶ Set a new metadata field
Parameters: - key (basestring, tuple) – Name of metadatum field
- value (Metadatum) – Metadum dictionary
Returns: An element of children whose index is key
Raises: TypeError if key is not basestring or tuple of basestring
Raises: ValueError if key and value are list and are not the same size
Example: >>> a = Metadata()
>>> a["title"] = Metadatum(name="title", [("lat", "Amores"), ("fre", "Les Amours")]) >>> print(a["title"]["lat"]) # Amores
>>> a[("title", "author")] = ( >>> Metadatum(name="title", [("lat", "Amores"), ("fre", "Les Amours")]), >>> Metadatum(name="author", [("lat", "Ovidius"), ("fre", "Ovide")]) >>> ) >>> print(a["title"]["lat"], a["author"]["fre"]) # Amores, Ovide
-
__iter__
()[source]¶ Iter method of Metadata
Example: >>> a = Metadata(("title", "desc", "author")) >>> for key, value in a: >>> print(key, value) # Print ("title", "<Metadatum object>") then ("desc", "<Metadatum object>")...
-
__len__
()[source]¶ Returns the number of Metadatum registered in the object
Return type: Returns: Number of metadatum objects
Example: >>> a = Metadata(("title", "description", "author")) >>> print(len(a)) # 3
-
__add__
(other)[source]¶ Merge Metadata objects together
Parameters: other (Metadata) – Metadata object to merge with the current one
Returns: The merge result of both metadata object
Return type: Example: >>> a = Metadata(name="label") >>> b = Metadata(name="title") >>> a + b == Metadata(name=["label", "title"])
-
-
class
MyCapytain.common.metadata.
Metadatum
(name, children=None)[source]¶ Bases:
future.types.newobject.newobject
Metadatum object represent a single field of metadata
Parameters: - name (basestring) – Name of the field
- children (List) – List of tuples, where first element is the key, and second the value
Example: >>> a = Metadatum(name="label", [("lat", "Amores"), ("fre", "Les Amours")]) >>> print(a["lat"]) # == "Amores"
-
__getitem__
(key)[source]¶ Add an iterable access method
Int typed key access to the n th registered key in the instance. If string based key does not exist, see for a default.
Parameters: key (basestring, tuple, int) – Key of wished value
Returns: An element of children whose index is key
Raises: KeyError if key is unknown (when using Int based key or when default is not set)
Example: >>> a = Metadatum(name="label", [("lat", "Amores"), ("fre", "Les Amours")]) >>> print(a["lat"]) # Amores >>> print(a[("lat", "fre")]) # Amores, Les Amours >>> print(a[0]) # Amores >>> print(a["dut"]) # Amores
-
__setitem__
(key, value)[source]¶ Register index key and value for the instance
Parameters: - key (basestring, list, tuple) – Index key(s) for the metadata
- value (basestring, list, tuple) – Values for the metadata
Returns: An element of children whose index is key
Raises: TypeError if key is not basestring or tuple of basestring
Raises: ValueError if key and value are list and are not the same size
Example: >>> a = Metadatum(name="label")
>>> a["eng"] = "Illiad" >>> print(a["eng"]) # Illiad
>>> a[("fre", "grc")] = ("Illiade", "Ἰλιάς") >>> print(a["fre"], a["grc"]) # Illiade, Ἰλιάς
>>> a[("ger", "dut")] = "Iliade" >>> print(a["ger"], a["dut"]) # Iliade, Iliade
-
__iter__
()[source]¶ Iter method of Metadatum
Example: >>> a = Metadata(name="label", [("lat", "Amores"), ("fre", "Les Amours")]) >>> for key, value in a: >>> print(key, value) # Print ("lat", "Amores") and then ("fre", "Les Amours")
-
setDefault
(key)[source]¶ Set a default key when a field does not exist
Parameters: key (basestring) – An existing key of the instance
Returns: Default key
Raises: ValueError If key is not registered
Example: >>> a = Metadatum(name="label", [("lat", "Amores"), ("fre", "Les Amours")]) >>> a.setDefault("fre") >>> print(a["eng"]) # == "Les Amours"