libearth.codecs — Common codecs

This module provides commonly used codecs to parse RSS-related standard formats.

class libearth.codecs.Boolean(true='true', false='false', default_value=None)

Codec to interpret boolean representation in strings e.g. 'true', 'no', and encode bool values back to string.

Parameters:
  • true (str, tuple) – text to parse as True. 'true' by default
  • false (str, tuple) – text to parse as False. 'false' by default
  • default_value (bool) – default value when it cannot be parsed
class libearth.codecs.Enum(values)

Codec that accepts only predefined fixed types of values:

gender = Enum(['male', 'female'])

Actually it doesn’t any encoding nor decoding, but it simply validates all values from XML and Python both.

Note that values have to consist of only strings.

Parameters:values (collections.Iterable) – any iterable that yields all possible values
class libearth.codecs.Integer

Codec to encode and decode integer numbers.

class libearth.codecs.Rfc3339(prefer_utc=False)

Codec to store datetime.datetime values to RFC 3339 format.

Parameters:prefer_utc (bool) – normalize all timezones to UTC. False by default
PATTERN = <_sre.SRE_Pattern object at 0x1a98430>

(re.RegexObject) The regular expression pattern that matches to valid RFC 3339 date time string.

class libearth.codecs.Rfc822(microseconds=False)

Codec to encode/decode datetime.datetime values to/from RFC 822 format.

Parameters:microseconds (bool) – whether to preserve and parse microseconds as well. False by default since it’s not standard compliant

New in version 0.3.0: Added microseconds option.