eoxserver.core.util package

Submodules

eoxserver.core.util.functools module

total_ordering and force_total_ordering are class decorators for Python 2.6 & Python 3.

They provides all the rich comparison methods on a class by defining any one of ‘__lt__’, ‘__gt__’, ‘__le__’, ‘__ge__’.

total_ordering fills in all unimplemented rich comparison methods, assuming at least one is implemented. __lt__ is taken as the base comparison method on which the others are built, but if that is not available it will be constructed from the first one found.

force_total_ordering does the same, but having taken a comparison method as the base it fills in all the others - this overwrites additional comparison methods that may be implemented, guaranteeing consistent comparison semantics.

from total_ordering import total_ordering

@total_ordering
class Something(object):
    def __init__(self, value):
        self.value = value
    def __lt__(self, other):
        return self.value < other.value

It also works with Python 2.5, but you need to do the wrapping yourself:

from total_ordering import total_ordering

class Something(object):
    def __init__(self, value):
        self.value = value
    def __lt__(self, other):
        return self.value < other.value

total_ordering(Something)

It would be easy to modify for it to work as a class decorator for Python 3.X and a metaclass for Python 2.X.

eoxserver.core.util.functools.force_total_ordering(cls)
eoxserver.core.util.functools.total_ordering(cls)

eoxserver.core.util.geotools module

eoxserver.core.util.importtools module

This module contains utilities to easily import hierarchies of packages and modules.

eoxserver.core.util.importtools.easy_import(module_path)

Utility function to import one or more modules via a given module path. The last component of the module path can also be a ‘*’ or a ‘**’ character string which imports all submodules of the package either recursively (with ‘**’) or not (with ‘*’).

Parameters:module_path – a typical python module path in the dotted notation. wildcards can be appeded at the last level.
eoxserver.core.util.importtools.import_modules(base_module_path)

Helper function to import all direct submodules within a package. This function is not recursive.

Parameters:base_module_path – the base module path in the dotted notation.
eoxserver.core.util.importtools.import_recursive(base_module_path)

Helper function to recursively import all submodules and packages.

Parameters:base_module_path – the base module path in the dotted notation.
eoxserver.core.util.importtools.import_string(dotted_path)

Import a dotted module path and return the attribute/class designated by the last name in the path. Raise ImportError if the import failed.

eoxserver.core.util.iteratortools module

This module is an extension of the iteratortools module and provides additional helpers.

eoxserver.core.util.iteratortools.pairwise(iterable)

s -> (s0,s1), (s2,s3), (s4, s5), …

eoxserver.core.util.iteratortools.pairwise_iterative(iterable)

s -> (s0,s1), (s1,s2), (s2, s3), …

eoxserver.core.util.multiparttools module

This module contains implementation of MIME multipart packing and unpacking utilities.

The main benefit of the utilities over other methods of mutipart handling is that the functions of this module do not manipulate the input data buffers and especially avoid any unnecessary data copying.

eoxserver.core.util.multiparttools.capitalize(header_name)

Capitalize header field name. Eg., ‘content-type’ is capilalized to ‘Content-Type’.

Deprecated since version 0.4.

eoxserver.core.util.multiparttools.capitalize_header(key)

Returns a capitalized version of the header line such as ‘content-type’ -> ‘Content-Type’.

eoxserver.core.util.multiparttools.getMimeType(content_type)

Extract MIME-type from Content-Type string and convert it to lower-case.

Deprecated since version 0.4.

eoxserver.core.util.multiparttools.getMultipartBoundary(content_type)

Extract boundary string from mutipart Content-Type string.

Deprecated since version 0.4.

eoxserver.core.util.multiparttools.get_substring(data, boundary, offset, end)

Retrieves the substring of data until the next boundary from a given offset to a until end.

eoxserver.core.util.multiparttools.iterate(data, offset=0, end=None, headers=None)

Efficient generator function to iterate over a single- or multipart message. I yields tuples in the shape (headers, data), where headers is a dict and data a buffer object, referencing the subset of the original content. In case of multipart messages, the multipart headers are yielded beforehand, with an empty string as data.

The offset parameter specifies the offset index to the start of the data. This is mostly used in the recursive call. The same applies to the end parameter.

The headers parameter specifies that the header section of the response was already read, and the headers are now entailed in the given dict. If this parameter is omitted, the headers are read from the stream.

eoxserver.core.util.multiparttools.mpPack(parts, boundary)

Low-level memory-friendly MIME multipart packing.

Note: The data payload is passed untouched and no transport encoding of the payload is performed.

Inputs:

  • parts - list of part-tuples, each tuple shall have two elements
    the header list and (string) payload. The header itsels should be a sequence of key-value pairs (tuples).
  • boundary - boundary string

Ouput:

  • list of strings (which can be directly passsed as a Django response content)

Deprecated since version 0.4.

eoxserver.core.util.multiparttools.mpUnpack(cbuffer, boundary, capitalize=False)

Low-level memory-friendly MIME multipart unpacking.

Note: The payload of the multipart package data is neither modified nor copied. No decoding of the transport encoded payload is performed.

Note: The subroutine does not unpack any nested mutipart content.

Inputs:

  • cbuffer - character buffer (string) containing the the header list and (string) payload. The header itsels should be a sequence of key-value pairs (tuples).
  • boundary - boundary string
  • capitalize - by default the header keys are converted to lower-case (e.g., ‘content-type’). To capitalize the names (e.g., ‘Content-Type’) set this option to true.

Output:

  • list of parts - each part is a tuple of the header dictionary, payload cbuffer offset and payload size.

Deprecated since version 0.4.

eoxserver.core.util.multiparttools.parse_parametrized_option(string)

Parses a parametrized options string like ‘base;option=value;otheroption=othervalue’.

Returns:the base string and a dict with all parameters

eoxserver.core.util.perftools module

class eoxserver.core.util.perftools.DurationMeasurement(name, logger, level)

Bases: object

duration
eoxserver.core.util.perftools.log_duration(name, logger=None, level=10)

Convenience function to log the duration of a specific event.

Parameters:
  • name – The name of the event.
  • logger – The logger to use.
  • level – The log level to log the final message to.

eoxserver.core.util.rect module

This module contains definition of the auxiliary 2D bounding box class.

class eoxserver.core.util.rect.Rect

Bases: tuple

Named tuple to describe areas in a 2D array like in images. The tuple is always in the form (offset_x, offset_y, size_x, size_y).

Parameters:
  • offset_x – the x offset of the origin
  • offset_y – the y offset of the origin
  • size_x – thy x size of the rect
  • size_y – thy y size of the rect
  • upper_x – thy upper x offset of the rect (mutually exclusive with size_x)
  • upper_y – thy upper y offset of the rect (mutually exclusive with size_y)
area
envelope(other)

Returns the envelope of two Rect, i.e., a smallest rectange contaning the input rectangles.

intersection(other)

Returns the intersection of two Rect, i.e., a largest common rectanle contained by the input rectangles.

intersects(other)

Tests whether two Rect overlap (True) or not (False).

offset
offset_x
offset_y
size
size_x
size_y
translated(tup)

Returns a new Rect shifted by the given offset.

upper
upper_x
upper_y

eoxserver.core.util.timetools module

eoxserver.core.util.timetools.isoformat(dt)

Formats a datetime object to an ISO string. Timezone naive datetimes are are treated as UTC Zulu. UTC Zulu is expressed with the proper “Z” ending and not with the “+00:00” offset declaration.

Parameters:dt – the datetime.datetime to encode
Returns:an encoded string
eoxserver.core.util.timetools.parse_duration(value)

Parses an ISO 8601 duration string into a python timedelta object. Raises a ValueError if a conversion was not possible.

eoxserver.core.util.timetools.parse_iso8601(value, tzinfo=None)

Parses an ISO 8601 date or datetime string to a python date or datetime. Raises a ValueError if a conversion was not possible. The returned datetime is always considered time-zone aware and defaulting to the given timezone tzinfo or UTC Zulu if none was specified.

If the optional module dateutil is installed, it is used in preference over the dateparse functions.

Parameters:
  • value – the string value to be parsed
  • tzinfo – an optional tzinfo object that is used when the input string is not timezone aware
Returns:

a datetime.datetime

eoxserver.core.util.xmltools module

This module contains utils for XML encoding, decoding and printing.

class eoxserver.core.util.xmltools.NameSpace(uri, prefix=None, schema_location=None)

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 eoxserver.core.util.xmltools.NameSpaceMap(*namespaces)

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 eoxserver.core.decoders.xml.Decoder subclasses.

Parameters:namespaces – a list of NameSpace objects.
add(namespace)
schema_locations
class eoxserver.core.util.xmltools.XMLEncoder

Bases: object

Base class for XML encoders using lxml.etree. This class does not actually provide any helpers for encoding XML in a tree structure (this is already done in lxml.etree), but adds tree to string serialization and automatic handling of schema locations.

content_type
get_schema_locations()

Interface method. Returns a dict mapping namespace URIs to a network locations.

serialize(tree, pretty_print=True, encoding='iso-8859-1')

Serialize a tree to an XML string. Also adds the schemaLocations attribute to the root node.

eoxserver.core.util.xmltools.add_cdata(element, cdata)
eoxserver.core.util.xmltools.parse(obj)

Helper function to parse XML either directly from a string, or fall back to whatever lxml.etree.parse parses. Returns None if it could not parse any XML.

Module contents