webexteamssdk/models/immutable.py
def _serialize(cls, data):
        """Serialize data to an frozen tuple."""
        if hasattr(data, "__hash__") and callable(data.__hash__):
            # If the data is already hashable (should be immutable) return it
            return data
        elif isinstance(data, list):
            # Freeze the elements of the list and return as a tuple
            return tuple((cls._serialize(item) for item in data))
        elif isinstance(data, dict):
            # Freeze the elements of the dictionary, sort them, and return
            # them as a list of tuples
            key_value_tuples = [
                (key, cls._serialize(value))
                for key, value in data.items()
            ]
            key_value_tuples.sort()
            return tuple(key_value_tuples)
        else:
            raise TypeError(
                "Unable to freeze {} data type.".format(type(data))
            )
def _serialize(cls, data):
        if hasattr(data, "__hash__") and callable(data.__hash__):
            # If the data is already hashable (should be immutable) return it
            return data
        elif isinstance(data, list):
            # Freeze the elements of the list and return as a tuple
            return tuple((cls._serialize(item) for item in data))
        elif isinstance(data, dict):
            # Freeze the elements of the dictionary, sort them, and return
            # them as a list of tuples
            key_value_tuples = [
                (key, cls._serialize(value))
                for key, value in data.items()
            ]
            key_value_tuples.sort()
            return tuple(key_value_tuples)
        else:
            raise TypeError(
                "Unable to freeze {} data type.".format(type(data))
            )
def _serialize ( cls , data ) : if hasattr ( data , "__hash__" ) and callable ( data . __hash__ ) : # If the data is already hashable (should be immutable) return it return data elif isinstance ( data , list ) : # Freeze the elements of the list and return as a tuple return tuple ( ( cls . _serialize ( item ) for item in data ) ) elif isinstance ( data , dict ) : # Freeze the elements of the dictionary, sort them, and return # them as a list of tuples key_value_tuples = [ ( key , cls . _serialize ( value ) ) for key , value in data . items ( ) ] key_value_tuples . sort ( ) return tuple ( key_value_tuples ) else : raise TypeError ( "Unable to freeze {} data type." . format ( type ( data ) ) )
Serialize data to an frozen tuple.
Serialize data to an frozen tuple .