def encode(obj):
    """Encode simple Python types into a binary string."""
    try:
        return encoder[type(obj)](obj)
    except KeyError, e:
        raise EncodeError, "Type not supported. (%s)" % e
Encode simple Python types into a binary string.
recipes/Python/415503_safer_serializatisimple/recipe-415503.py