Package konval :: Module impl
[hide private]
[frames] | no frames]

Module impl

source code

Internal implementation utilities and details.

This module contains various odds and ends to make development easier. None of code within should be relied upon as it is subject to change at a whim.

Functions [hide private]
 
make_list(x)
If this isn't a list, make it one.
source code
 
make_canonical(value)
Clean-up minor string variants to a single form.
source code
Variables [hide private]
  __package__ = 'konval'
Function Details [hide private]

make_list(x)

source code 

If this isn't a list, make it one.

Syntactic sugar for allowing method calls to be single elements or lists of elements.

For example:

>>> make_list (1)
[1]
>>> make_list ('1')
['1']
>>> make_list ([1, 2])
[1, 2]
>>> make_list ((1, 2))
(1, 2)
Parameters:
  • x (list, tuple, other) - a sequence, or a single element to be placed in a sequence
Returns:
Either the original a parameter if a sequence, or the parameter placed in a list.

make_canonical(value)

source code 

Clean-up minor string variants to a single form.

This is syntactic sugar for mapping minor string variants (mostly whitespace and punctuation flourishes, as you expect in user input or free text) to a single canonical from. This consists of trimming flanking spaces, making the string uppercase, and collapsing all internal spaces / hyphens / underscores to a single underscore.

For example:

>>> make_canonical ('abc')
'ABC'
>>> make_canonical ('  CD-EF  ')
'CD_EF'
>>> make_canonical ('H-IJ- _K')
'H_IJ_K'
Parameters:
  • value (string) - the string to be sanitized
Returns:
The parameter cleaned up