ows package

class ows.Version(major: int, minor: int, patch: int = None)[source]

Bases: object

classmethod from_str(value: str)[source]
patch = None

Subpackages

Submodules

ows.decoder module

This module provides base functionality for any other decoder class.

class ows.decoder.BaseDecoder[source]

Bases: object

collect_params()[source]

Collect all parameters. This will collect all values which are computed using properties.

create_object(params: dict)[source]

Create the associated object for that decoder using the passed parameters.

decode()[source]

Collect all decoder parameters and construct the object.

map_params(params)[source]

Map parameters, if necessary. Default implementation is a no-op.

object_class = None
class ows.decoder.BaseParameter(type=None, num=1, default=<class 'ows.decoder.NO_DEFAULT'>, default_factory=None)[source]

Bases: property

Abstract base class for XML, KVP or any other kind of parameter.

fget(decoder)[source]

Property getter function.

locator
select(decoder)[source]

Interface method.

class ows.decoder.Choice(*choices)[source]

Bases: object

Tries all given choices until one does return something.

class ows.decoder.Concatenate(*choices, **kwargs)[source]

Bases: object

Helper to concatenate the results of all sub-parameters to one.

exception ows.decoder.DecodingException(message, locator=None)[source]

Bases: Exception

Base Exception class to be thrown whenever a decoding failed.

class ows.decoder.Exclusive(*choices)[source]

Bases: object

For mutual exclusive Parameters.

exception ows.decoder.ExclusiveException(message, locator=None)[source]

Bases: ows.decoder.DecodingException

exception ows.decoder.InvalidParameterException(message, locator=None)[source]

Bases: ows.decoder.DecodingException

code = 'InvalidParameterValue'
exception ows.decoder.MissingParameterException(locator)[source]

Bases: ows.decoder.DecodingException

Exception to be thrown, when a decoder could not read one parameter, where exactly one was required.

code = 'MissingParameterValue'
exception ows.decoder.MissingParameterMultipleException(locator)[source]

Bases: ows.decoder.DecodingException

Exception to be thrown, when a decoder could not read at least one parameter, where one ore more were required.

code = 'MissingParameterValue'
class ows.decoder.NO_DEFAULT[source]

Bases: object

exception ows.decoder.NoChoiceResultException(message, locator=None)[source]

Bases: ows.decoder.DecodingException

exception ows.decoder.WrongMultiplicityException(locator, expected, result)[source]

Bases: ows.decoder.DecodingException

Decoding Exception to be thrown when the multiplicity of a parameter did not match the expected count.

code = 'InvalidParameterValue'
ows.decoder.boolean(raw)[source]

Functor to convert “true”/”false” to a boolean.

class ows.decoder.enum(values, case_sensitive=True)[source]

Bases: object

Helper for parameters that are expected to be in a certain enumeration. A ValueError is raised if not.

class ows.decoder.fixed(value, case_sensitive=True)[source]

Bases: object

Helper for parameters that are expected to be have a fixed value and raises a ValueError if not.

ows.decoder.lower(value)[source]

Functor to return a lower-case string.

ows.decoder.strip(value)[source]

Functor to return a whitespace stripped string.

ows.decoder.to_dict(decoder, dict_class=<class 'dict'>)[source]

Utility function to get a dictionary representation of the given decoder. This function invokes all decoder parameters and sets the dictionary fields accordingly

class ows.decoder.typelist(typ=None, separator=' ')[source]

Bases: object

Helper for XMLDecoder schemas that expect a string that represents a list of a type separated by some separator.

ows.decoder.upper(value)[source]

Functor to return a upper-case string.

class ows.decoder.value_range(min, max, type=<class 'float'>)[source]

Bases: object

Helper to assert that a given parameter is within a specified range.

ows.exceptions module

exception ows.exceptions.HTTPMethodNotAllowedError(msg, allowed_methods)[source]

Bases: Exception

This exception is raised in case of a HTTP requires with unsupported HTTP method. This exception should always lead to the 405 Method not allowed HTTP error.

The constructor takes two arguments, the error message mgs and the list of the accepted HTTP methods allowed_methods.

exception ows.exceptions.InvalidRequestException(msg, code=None, locator=None)[source]

Bases: Exception

This exception indicates that the request was invalid and an exception report shall be returned to the client.

The constructor takes three arguments, namely msg, the error message, code, the error code, and locator, which is needed in OWS exception reports for indicating which part of the request produced the error.

How exactly the exception reports are constructed is not defined by the exception, but by exception handlers.

exception ows.exceptions.OperationNotSupportedException(message, operation=None)[source]

Bases: Exception

Exception to be thrown when some operations are not supported or disabled.

code = 'OperationNotSupported'
locator
exception ows.exceptions.ServiceNotSupportedException(service)[source]

Bases: ows.exceptions.OperationNotSupportedException

Exception to be thrown when a specific OWS service is not enabled.

exception ows.exceptions.VersionNegotiationException[source]

Bases: Exception

This exception indicates that version negotiation fails. Such errors can happen with OWS 2.0 compliant “new-style” version negotation.

code = 'VersionNegotiationFailed'
exception ows.exceptions.VersionNotSupportedException(service, version)[source]

Bases: Exception

Exception to be thrown when a specific OWS service version is not supported.

code = 'InvalidParameterValue'

ows.kvp module

This module contains facilities to help decoding KVP strings.

class ows.kvp.Decoder(params)[source]

Bases: ows.decoder.BaseDecoder

Base class for KVP decoders.

Parameters:params – an instance of either dict, django.http.QueryDict or basestring (which will be parsed using cgi.parse_qs())

Decoders should be used as such:

from ows import kvp, 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 ows.kvp.DecoderMetaclass(name, bases, dct)[source]

Bases: type

Metaclass for KVP Decoders to allow easy parameter declaration.

class ows.kvp.MultiParameter(selector, num=1, default=None, locator=None)[source]

Bases: ows.kvp.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)[source]

Interface method.

class ows.kvp.Parameter(key=None, type=None, num=1, default=<class 'ows.decoder.NO_DEFAULT'>, default_factory=None, locator=None)[source]

Bases: ows.decoder.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
  • default_factory – the default value factory
  • locator – override the locator in case of exceptions
key = None
locator
select(decoder, decoder_class=None)[source]

Interface method.

ows.registry module

class ows.registry.Registry[source]

Bases: object

get_kvp_decoder(service, version, request)[source]
get_xml_decoder(tag_name, namespace=None)[source]
register_kvp_decoder(service, version, request)[source]

Decorator function to register a KVP decoder.

register_kvp_encoder(object_class)[source]

Decorator function to register a KVP encoder.

register_xml_decoder(tag_name, namespace=None)[source]

Decorator function to register an XML decoder.

register_xml_encoder(object_class)[source]

Decorator function to register an XML encoder.

ows.test module

ows.test.assert_elements_equal(elem_a, elem_b, path='/')[source]
ows.test.assert_xml_equal(xml_a: str, xml_b: str)[source]
ows.test.strip_common_attribs(attrib)[source]
ows.test.strip_elements(elements)[source]

ows.test_util module

ows.util module

class ows.util.Result(value: Any, content_type: str = None)[source]

Bases: object

content_type = None
classmethod from_etree(tree: lxml.etree._ElementTree, content_type='application/xml', **kwargs)[source]
classmethod from_kvp(params: Union[Dict[KT, VT], Sequence[Tuple[str, str]]], content_type='application/x-www-form-urlencoded')[source]
class ows.util.Version(major: int, minor: int, patch: int = None)[source]

Bases: object

classmethod from_str(value: str)[source]
patch = None
ows.util.duration(td: datetime.timedelta) → str[source]

Encode a timedelta as an ISO 8601 duration string.

ows.util.isoformat(temporal: Union[datetime.datetime, datetime.date, ows.util.month, ows.util.year], zulu=True) → str[source]

Formats a datetime, date, month or year object to an ISO string. Timezone naive datetimes are treated as UTC Zulu. UTC Zulu is expressed with the proper ‘Z’ ending and not with the ‘+00:00’ offset declaration.

Parameters:
  • temporal – the datetime.datetime, datetime.date, month, or year to encode
  • zulu – whether an offset of zero shall be abbreviated with Z
Returns:

an encoded string

class ows.util.month(year: int, month: int)[source]

Bases: object

isoformat() → str[source]
max = month(year=9999, month=12)
min = month(year=1, month=1)
replace(year: int, month: int) → ows.util.month[source]
ows.util.parse_temporal(value: str) → Union[datetime.datetime, datetime.date, ows.util.month, ows.util.year][source]

Parses a temporal value to either a datetime, date, month or year construct. Valid values are either

ows.util.temporal_bounds(temporal: Union[datetime.datetime, datetime.date, ows.util.month, ows.util.year]) → Tuple[datetime.datetime, datetime.datetime][source]

Calculates the effective temporal bounds of the passed temporal value.

ows.util.to_int(d, key, default_to_zero=False, default=None, required=True)[source]

Pull a value from the dict and convert to int

Parameters:
  • default_to_zero – If the value is None or empty, treat it as zero
  • default – If the value is missing in the dict use this default
class ows.util.year(year: int)[source]

Bases: object

isoformat() → str[source]
max = year(year=9999)
min = year(year=1)
replace(year: int) → ows.util.year[source]

ows.xml module

This module contains facilities to help decoding XML structures.

class ows.xml.Decoder(tree)[source]

Bases: ows.decoder.BaseDecoder

Base class for XML Decoders.

param params:an instance of either lxml.etree.ElementTree, or basestring (which will be parsed using lxml.etree.fromstring())

Decoders should be used as such:

from ows import xml, 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 ows.xml.ElementMaker[source]

Bases: lxml.builder.ElementMaker

Subclass of the original ElementMaker that automatically filters out None values in sub-elements and attributes.

class ows.xml.NameSpace(uri: str, prefix=None, schema_location=None)[source]

Bases: object

Helper object to ease the dealing with namespaces in both encoding and decoding.

Parameters:
  • uri – the namespace URI
  • prefix – the namespace prefix
  • schema_location – the schema location of this namespace
prefix
schema_location
uri
class ows.xml.NameSpaceMap(*namespaces)[source]

Bases: dict

Helper object to ease the setup and management of namespace collections in both encoding and decoding. Can (and should) be passed as namespaces attribute in ows.xml.Decoder subclasses.

Parameters:namespaces – a list of NameSpace objects.
add(namespace)[source]
schema_locations
class ows.xml.Parameter(selector, type=None, num=1, default=<class 'ows.decoder.NO_DEFAULT'>, default_factory=None, namespaces=None, locator=None)[source]

Bases: ows.decoder.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
locator
select(decoder)[source]

Interface method.