Exemplo n.º 1
0
    def __getstate__ ( self ):
        state = super( NumericContext, self ).__getstate__()

        # Save non-transient traits (Traits 2.1 will do this for us):
        for k in HasTraits.get( self, transient = True ):
            if k in state:
                del state[ k ]

        # Filter out any unpickleable data from the context dictionary:
        if 'context_data' in state:
            state[ 'context_data' ] = state[ 'context_data' ].copy()
            for k, v in state[ 'context_data' ].items():
                if isinstance( v, NonPickleable ):
                    del state[ 'context_data' ][k]

        # Return the saveable state:
        state[ '__numeric_context_version__' ] = 1

        return state