eoxserver.core.decoders package¶
Submodules¶
eoxserver.core.decoders.base module¶
This module provides base functionality for any other decoder class.
eoxserver.core.decoders.config module¶
This module contains facilities to help decoding configuration files.
It relies on the ConfigParser
module for actually reading the file.
- class eoxserver.core.decoders.config.Option(key=None, type=None, separator=None, required=False, default=None, section=None, doc=None)¶
Bases:
property
The
Option
is used as aproperty
forReader
subclasses.- Parameters:
key – the lookup key; defaults to the property name of the
Reader
.type – the type to parse the raw value; by default the raw string is returned
separator – the separator for list options; by default no list is assumed
required – if
True
raise an error if the option does not existdefault – the default value
section – override the section for this option
- check(reader)¶
- fget(reader)¶
- class eoxserver.core.decoders.config.Reader(config)¶
Bases:
object
Base class for config readers.
- Parameters:
config – an instance of
ConfigParser.RawConfigParser
Readers should be used as such:
from ConfigParser import RawConfigParser try: from cStringIO import StringIO except ImportError: from io import StringIO from textwrap import dedent from eoxserver.core.decoders import config class ExampleReader(config.Reader): section = "example_section" string_opt = config.Option() string_list_opt = config.Option(separator=",") integer_opt = config.Option(type=int) section = "other_section" mandatory_opt = config.Option(required=True) optional_opt = config.Option(default="some_default") special_section_opt = config.Option(section="special_section") f = StringIO(dedent(''' [example_section] string_opt = mystring string_list_opt = my,string,list integer_opt = 123456 [other_section] mandatory_opt = mandatory_value # optional_opt = no value [special_section] special_section_opt = special_value ''')) parser = RawConfigParser() parser.readfp(f) reader = ExampleReader(parser) print reader.string_opt print reader.string_list_opt print reader.integer_opt print reader.mandatory_opt print reader.optional_opt ...
eoxserver.core.decoders.kvp module¶
This module contains facilities to help decoding KVP strings.
- class eoxserver.core.decoders.kvp.Decoder(params)¶
Bases:
object
Base class for KVP decoders.
- Parameters:
params – an instance of either
dict
,django.http.QueryDict
orbasestring
(which will be parsed usingcgi.parse_qs()
)
Decoders should be used as such:
from eoxserver.core.decoders import kvp from eoxserver.core.decoders import typelist class ExampleDecoder(kvp.Decoder): mandatory_param = kvp.Parameter(num=1) list_param = kvp.Parameter(type=typelist(separator=",")) multiple_param = kvp.Parameter("multi", num="+") optional_param = kvp.Parameter(num="?", default="default_value") decoder = ExampleDecoder( "mandatory_param=value" "&list_param=a,b,c" "&multi=a&multi=b&multi=c" ) print decoder.mandatory_param print decoder.list_param print decoder.multiple_param print decoder.optional_param
- class eoxserver.core.decoders.kvp.DecoderMetaclass(name, bases, dct)¶
Bases:
type
Metaclass for KVP Decoders to allow easy parameter declaration.
- class eoxserver.core.decoders.kvp.MultiParameter(selector, num=1, default=None, locator=None)¶
Bases:
Parameter
Class for selecting different KVP parameters at once.
- Parameters:
selector – a function to determine if a key is used for the multi parameter selection
num – defines how many times the key can be present; use any numeric value to set it to a fixed count, “*” for any number, “?” for zero or one time or “+” for one or more times
default – the default value
locator – override the locator in case of exceptions
- select(decoder)¶
Interface method.
- class eoxserver.core.decoders.kvp.Parameter(key=None, type=None, num=1, default=None, locator=None)¶
Bases:
BaseParameter
Parameter for KVP values.
- Parameters:
key – the lookup key; defaults to the property name of the
Decoder
type – the type to parse the raw value; by default the raw string is returned
num – defines how many times the key can be present; use any numeric value to set it to a fixed count, “*” for any number, “?” for zero or one time or “+” for one or more times
default – the default value
locator – override the locator in case of exceptions
- key = None¶
- property locator¶
- select(decoder, decoder_class=None)¶
Interface method.
eoxserver.core.decoders.xml module¶
This module contains facilities to help decoding XML structures.
- class eoxserver.core.decoders.xml.Decoder(tree)¶
Bases:
object
Base class for XML Decoders.
- param params:
an instance of either
lxml.etree.ElementTree
, orbasestring
(which will be parsed usinglxml.etree.fromstring()
)
Decoders should be used as such:
from eoxserver.core.decoders import xml from eoxserver.core.decoders import typelist class ExampleDecoder(xml.Decoder): namespaces = {"myns": "http://myns.org"} single = xml.Parameter("myns:single/text()", num=1) items = xml.Parameter("myns:collection/myns:item/text()", num="+") attr_a = xml.Parameter("myns:object/@attrA", num="?") attr_b = xml.Parameter("myns:object/@attrB", num="?", default="x") decoder = ExampleDecoder(''' <myns:root xmlns:myns="http://myns.org"> <myns:single>value</myns:single> <myns:collection> <myns:item>a</myns:item> <myns:item>b</myns:item> <myns:item>c</myns:item> </myns:collection> <myns:object attrA="value"/> </myns:root> ''') print decoder.single print decoder.items print decoder.attr_a print decoder.attr_b
- namespaces = {}¶
- class eoxserver.core.decoders.xml.Parameter(selector, type=None, num=1, default=None, namespaces=None, locator=None)¶
Bases:
BaseParameter
Parameter for XML values.
- Parameters:
selector – the node selector; if a string is passed it is interpreted as an XPath expression, a callable will be called with the root of the element tree and shall yield any number of node
type – the type to parse the raw value; by default the raw string is returned
num – defines how many times the key can be present; use any numeric value to set it to a fixed count, “*” for any number, “?” for zero or one time or “+” for one or more times
default – the default value
namespaces – any namespace necessary for the XPath expression; defaults to the
Decoder
namespaces.locator – override the locator in case of exceptions
- property locator¶
- select(decoder)¶
Interface method.
Module contents¶
- class eoxserver.core.decoders.Choice(*choices)¶
Bases:
object
Tries all given choices until one does return something.
- class eoxserver.core.decoders.Concatenate(*choices, **kwargs)¶
Bases:
object
Helper to concatenate the results of all sub-parameters to one.
- exception eoxserver.core.decoders.DecodingException(message, locator=None)¶
Bases:
Exception
Base Exception class to be thrown whenever a decoding failed.
- exception eoxserver.core.decoders.ExclusiveException(message, locator=None)¶
Bases:
DecodingException
- exception eoxserver.core.decoders.InvalidParameterException(message, locator=None)¶
Bases:
DecodingException
- code = 'InvalidParameterValue'¶
- exception eoxserver.core.decoders.MissingParameterException(locator)¶
Bases:
DecodingException
Exception to be thrown, when a decoder could not read one parameter, where exactly one was required.
- code = 'MissingParameterValue'¶
- exception eoxserver.core.decoders.MissingParameterMultipleException(locator)¶
Bases:
DecodingException
Exception to be thrown, when a decoder could not read at least one parameter, where one ore more were required.
- code = 'MissingParameterValue'¶
- exception eoxserver.core.decoders.NoChoiceResultException(message, locator=None)¶
Bases:
DecodingException
- exception eoxserver.core.decoders.WrongMultiplicityException(locator, expected, result)¶
Bases:
DecodingException
Decoding Exception to be thrown when the multiplicity of a parameter did not match the expected count.
- code = 'InvalidParameterValue'¶
- eoxserver.core.decoders.boolean(raw)¶
Functor to convert “true”/”false” to a boolean.
- class eoxserver.core.decoders.enum(values, case_sensitive=True, error_class=<class 'ValueError'>)¶
Bases:
object
Helper for parameters that are expected to be in a certain enumeration. A ValueError is raised if not.
- class eoxserver.core.decoders.fixed(value, case_sensitive=True)¶
Bases:
object
Helper for parameters that are expected to be have a fixed value and raises a ValueError if not.
- eoxserver.core.decoders.lower(value)¶
Functor to return a lower-case string.
- eoxserver.core.decoders.strip(value)¶
Functor to return a whitespace stripped string.
- eoxserver.core.decoders.to_dict(decoder, dict_class=<class 'dict'>)¶
Utility function to get a dictionary representation of the given decoder. This function invokes all decoder parameters and sets the dictionary fields accordingly
- class eoxserver.core.decoders.typelist(typ=None, separator=' ')¶
Bases:
object
Helper for XMLDecoder schemas that expect a string that represents a list of a type separated by some separator.
- eoxserver.core.decoders.upper(value)¶
Functor to return a upper-case string.