Module eoxserver.core.util.multiparttools

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.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)
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.

Utilities

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

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

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

Extract boundary string from mutipart Content-Type string.

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

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