morepath.converter – Convert URL variables

Convert path variables and URL parameters to Python objects.

This module contains functionality that can convert traject and URL parameters (?foo=3) into Python values (ints, date, etc) that are passed into model factories that are configured using the morepath.App.path() and morepath.App.mount() directives. The inverse conversion back from Python value to string also needs to be provided to support link generation.

morepath.Converter is exported to the public API.

See also morepath.directive.ConverterRegistry

class morepath.converter.ParameterFactory(parameters, converters, required, extra=False)

Convert URL parameters.

Given expected URL parameters, converters for them and required parameters, create a dictionary of converted URL parameters with Python values.

  • parameters – dictionary of parameter names -> default values.
  • converters – dictionary of parameter names -> converters.
  • required – dictionary of parameter names -> required booleans.
  • extra – should extra unknown parameters be included?

Convert URL parameters to Python dictionary with values.

class morepath.converter.ListConverter(converter)

How to decode from list of strings to list of objects and back.

Used morepath.converter.ConverterRegistry to handle lists of repeated names in parameters.

Used for decoding/encoding URL parameters and path variables.

Create new converter.

Parameters:converter – the converter to use for list entries

Decode list of strings into list of Python values.

Parameters:strings – list of strings
Returns:list of Python values

Encode list of Python values into list of strings

Parameters:values – list of Python values.
Returns:List of strings.

True is a given value is the missing value.

morepath.converter.IDENTITY_CONVERTER = <morepath.converter.Converter object>

Converter that has no effect.

String becomes string.