Experimental, deprecated or non-standard converters

Deprecated Converters

Deprecated Converters

Warning

Since these converters may change or be removed at any time, don’t import this module, but copy and paste the functions you need in your application.

biryani.nonstandard.deprecatedbaseconv.N_(message)
biryani.nonstandard.deprecatedbaseconv.attribute(name)[source]

Return a converter that retrieves an existing attribute from an object.

This converter is non-standard, because:

  • It is a simple one-liner.
  • It needs an option to specify what to do when attribute doesn’t exist.
>>> class C(object):
...     pass
>>> conv.pipe(conv.make_dict_to_object(C), attribute('a'))(dict(a = 1, b = 2))
(1, None)
biryani.nonstandard.deprecatedbaseconv.mapping_value(key, default=None)[source]

Return a converter that retrieves an item value from a mapping.

This converter is non-standard, because:

  • It is a simple one-liner.
  • It needs an option to specify what to do when attribute doesn’t exist.
>>> mapping_value('a')(dict(a = 1, b = 2))
(1, None)
>>> mapping_value('c')(dict(a = 1, b = 2))
(None, None)
>>> mapping_value('c', u'Hello world!')(dict(a = 1, b = 2))
(u'Hello world!', None)
biryani.nonstandard.deprecatedbaseconv.sort(cmp=None, key=None, reverse=False)[source]

Return a converter that sorts an iterable.

This converter is non-standard, because:

  • It is a simple one-liner. Most of the times, conv.function(sorted) is sufficient.
>>> sort()([3, 2, 1])
([1, 2, 3], None)
>>> sort()(None)
(None, None)
biryani.nonstandard.deprecatedbaseconv.split(separator=None)[source]

Returns a converter that splits a string.

This converter is non-standard, because:

  • It is a simple one-liner.
>>> split()(u'a bc  def')
([u'a', u'bc', u'def'], None)
>>> split(u',')(u'a,bc,,def')
([u'a', u'bc', u'', u'def'], None)
>>> split()(None)
(None, None)
biryani.nonstandard.deprecatedbaseconv.strip(chars=None)[source]

Returns a converter that removes leading and trailing characters from string.

This converter is non-standard, because:

>>> strip()(u'   Hello world!   ')
(u'Hello world!', None)
>>> strip(u'+-!')(u'+-+Hello world!-+-')
(u'Hello world', None)
>>> strip()(None)
(None, None)
biryani.nonstandard.deprecatedbaseconv.test_match(regex, error='Invalid value format')[source]

Return a converter that accepts only values that match given (compiled) regular expression.

This converter is non-standard, because:

  • It is a simple one-liner.
  • The error message must always be given, so that error is explicit.
  • Often, knowing that there is a match is not sufficient and data must be extracted from match object.
>>> import re
>>> test_match(re.compile(u'OK$'))(u'OK')
(u'OK', None)
>>> test_match(re.compile(u'ok$'))(u'not OK')
(u'not OK', 'Invalid value format')

Experimental Converters

Experimental Converters

Warning

Since these converters may change at any time, don’t import this module, but copy and paste the functions you need in your application.

biryani.nonstandard.experimentalbaseconv.mapping_replace_sequence(keys, converter, sequence_constructor=<type 'list'>)[source]

Return a converter that extracts a sequence from a mapping, converts it and reinjects it into the mapping.

French Converters

French related Converters

biryani.frconv.expand_postal_routing(value, state=None)[source]

Replace abbreviations with their full name in a postal routing

Note

Postal routing must already be converted to uppercase ASCII.

>>> expand_postal_routing(u'ST NAZAIRE')
(u'SAINT NAZAIRE', None)
>>> expand_postal_routing(u'SAINT ETIENNE')
(u'SAINT ETIENNE', None)
>>> expand_postal_routing(u'STILL')
(u'STILL', None)
>>> expand_postal_routing(u'STES')
(u'SAINTES', None)
>>> expand_postal_routing(None)
(None, None)
biryani.frconv.input_to_depcom(*args, **kwargs)

Convert a string to aan INSEE commune code (aka depcom). Generate an error when depcom is not valid.

Note

To allow an invalid depcom without error, use input_to_lenient_depcom() instead.

>>> input_to_depcom(u'   75156   ')
(u'75156', None)
>>> input_to_depcom(u'   2A100   ')
(u'2A100', None)
>>> input_to_depcom(u'   2b100   ')
(u'2B100', None)
>>> input_to_depcom(u'   1234   ')
(u'01234', None)
>>> input_to_depcom(u'   123   ')
(u'123', u'INSEE code must contain only 5 digits or "A" or "B"')
>>> input_to_depcom(u'   123  456   ')
(u'123456', u'INSEE code must contain only 5 digits or "A" or "B"')
>>> input_to_depcom('   ')
(None, None)
>>> input_to_depcom(None)
(None, None)
biryani.frconv.input_to_lenient_depcom(*args, **kwargs)

Convert a string to an INSEE commune code (aka depcom). Don’t fail when depcom is not valid.

Note

To validate depcom, use input_to_depcom() instead.

>>> input_to_lenient_depcom(u'   75156   ')
(u'75156', None)
>>> input_to_lenient_depcom(u'   2A100   ')
(u'2A100', None)
>>> input_to_lenient_depcom(u'   2b100   ')
(u'2B100', None)
>>> input_to_lenient_depcom(u'   1234   ')
(u'01234', None)
>>> input_to_lenient_depcom(u'   123   ')
(u'123', None)
>>> input_to_lenient_depcom(u'   123  456   ')
(u'123456', None)
>>> input_to_lenient_depcom('   ')
(None, None)
>>> input_to_lenient_depcom(None)
(None, None)
biryani.frconv.input_to_lenient_postal_code(*args, **kwargs)

Convert a string to a postal code. Don’t fail when postal code is not valid.

Note

To validate postal code, use input_to_postal_code() instead.

>>> input_to_lenient_postal_code(u'   75014   ')
(u'75014', None)
>>> input_to_lenient_postal_code(u'   1234   ')
(u'01234', None)
>>> input_to_lenient_postal_code(u'   123   ')
(u'123', None)
>>> input_to_lenient_postal_code(u'   123  456   ')
(u'123456', None)
>>> input_to_lenient_postal_code('   ')
(None, None)
>>> input_to_lenient_postal_code(None)
(None, None)
biryani.frconv.input_to_phone(*args, **kwargs)

Convert a string to a phone number.

Warning

This converter is not stable and may change or be removed at any time. If you need it, you shouldn’t import it, but copy and paste its source code into your application.

>>> input_to_phone(u'   0123456789   ')
(u'+33 1 23 45 67 89', None)
>>> input_to_phone('   0123456789   ')
(u'+33 1 23 45 67 89', None)
biryani.frconv.input_to_postal_code(*args, **kwargs)

Convert a string to a postal code. Generate an error when postal code is not valid.

Note

To allow invalid postal codes without error, use input_to_lenient_postal_code() instead.

>>> input_to_postal_code(u'   75014   ')
(u'75014', None)
>>> input_to_postal_code(u'   1234   ')
(u'01234', None)
>>> input_to_postal_code(u'   123   ')
(u'123', u'Postal code must have 5 digits')
>>> input_to_postal_code(u'   123  456   ')
(u'123456', u'Postal code must have 5 digits')
>>> input_to_postal_code('   ')
(None, None)
>>> input_to_postal_code(None)
(None, None)
biryani.frconv.input_to_postal_distribution(*args, **kwargs)

Convert a string to a postal routing (aka locality, ie the part of the address after the postal code).

>>> input_to_postal_distribution(u'   75014  Paris')
((u'75014', u'PARIS'), None)
>>> input_to_postal_distribution(u'   75014 Paris  14   ')
((u'75014', u'PARIS 14'), None)
>>> input_to_postal_distribution(u'   42000 SAINT Etienne   ')
((u'42000', u'ST ETIENNE'), None)
>>> input_to_postal_distribution(u'   42000 SAINT Étienne   ')
((u'42000', u'ST ETIENNE'), None)
>>> input_to_postal_distribution(u'   44690 Saint-Fiacre-sur-Maine   ')
((u'44690', u'ST FIACRE SUR MAINE'), None)
>>> input_to_postal_distribution(u'88151 Thaon-les-vosges ced')
((u'88151', u'THAON LES VOSGES CEDEX'), None)
>>> input_to_postal_distribution(u'17100 Saintes')
((u'17100', u'SAINTES'), None)
>>> input_to_postal_distribution('   ')
(None, None)
>>> input_to_postal_distribution(None)
(None, None)
biryani.frconv.input_to_postal_routing(*args, **kwargs)

Convert a string to a postal routing (aka locality, ie the part of the address after the postal code).

>>> input_to_postal_routing(u'   Paris  14   ')
(u'PARIS 14', None)
>>> input_to_postal_routing(u'   Paris  xiv   ')
(u'PARIS XIV', None)
>>> input_to_postal_routing(u'   SAINT Etienne   ')
(u'ST ETIENNE', None)
>>> input_to_postal_routing(u'   SAINT Étienne   ')
(u'ST ETIENNE', None)
>>> input_to_postal_routing(u'   Saint-Fiacre-sur-Maine   ')
(u'ST FIACRE SUR MAINE', None)
>>> input_to_postal_routing(u'Thaon-les-vosges ced')
(u'THAON LES VOSGES CEDEX', None)
>>> input_to_postal_routing(u'Saintes')
(u'SAINTES', None)
>>> input_to_postal_routing('   ')
(None, None)
>>> input_to_postal_routing(None)
(None, None)
biryani.frconv.repair_postal_routing(value, state=None)[source]

Correct mispelled words in a postal routing.

Note

Postal routing must already be converted to uppercase ASCII.

Note

This converter doesn’t handle abbreviations. See shrink_postal_routing() or expand_postal_routing() to handle them.

>>> repair_postal_routing(u'SAINT NAZAIRE CED')
(u'SAINT NAZAIRE CEDEX', None)
>>> repair_postal_routing(u'ST NAZAIRE CED')
(u'ST NAZAIRE CEDEX', None)
>>> repair_postal_routing(None)
(None, None)
biryani.frconv.shrink_postal_routing(value, state=None)[source]

Replace words in a postal routing with their abbreviation.

Note

Postal routing must already be converted to uppercase ASCII.

>>> shrink_postal_routing(u'SAINT NAZAIRE')
(u'ST NAZAIRE', None)
>>> shrink_postal_routing(u'ST ETIENNE')
(u'ST ETIENNE', None)
>>> shrink_postal_routing(u'SAINTES')
(u'SAINTES', None)
>>> shrink_postal_routing(None)
(None, None)
biryani.frconv.split_postal_distribution(value, state=None)[source]

Extract french postal code and postal routing (aka locality) from a string

Note

Input value must already be converted to uppercase ASCII.

>>> split_postal_distribution(u'75014 PARIS')
((u'75014', u'PARIS'), None)
>>> split_postal_distribution(u'75014 PARIS 14')
((u'75014', u'PARIS 14'), None)
>>> split_postal_distribution(u'42000 ST ETIENNE')
((u'42000', u'ST ETIENNE'), None)
>>> split_postal_distribution(u'   44690 SAINT FIACRE SUR MAINE')
((u'44690', u'SAINT FIACRE SUR MAINE'), None)
>>> split_postal_distribution(u'88151 THAON LES VOSGES CED')
((u'88151', u'THAON LES VOSGES CED'), None)
>>> split_postal_distribution(u'17100 SAINTES')
((u'17100', u'SAINTES'), None)
>>> split_postal_distribution('   ')
(None, None)
>>> split_postal_distribution(None)
(None, None)
biryani.frconv.str_to_phone(value, state=None)[source]

Convert a clean string to a phone number.

Note

For a converter that doesn’t require a clean string, see input_to_phone().

Warning

This converter is not stable and may change or be removed at any time. If you need it, you shouldn’t import it, but copy and paste its source code into your application.

>>> str_to_phone(u'0123456789')
(u'+33 1 23 45 67 89', None)
>>> str_to_phone('0123456789')
(u'+33 1 23 45 67 89', None)

Table Of Contents

Previous topic

API

Next topic

Biryani Changelog

This Page