'I turn an object into an AOT and return it.'

def jellyToAO(self, obj):

    objType = type(obj)
    self.stack.append(repr(obj))
    if (objType in _SIMPLE_BUILTINS):
        retval = obj
    elif (objType is types.MethodType):
        retval = InstanceMethod(_funcOfMethod(obj).__name__, reflect.qual(_classOfMethod(obj)), self.jellyToAO(_selfOfMethod(obj)))
    elif (objType is types.ModuleType):
        retval = Module(obj.__name__)
    elif (objType is _OldStyleClass):
        retval = Class(reflect.qual(obj))
    elif issubclass(objType, type):
        retval = Class(reflect.qual(obj))
    elif (objType is types.FunctionType):
        retval = Function(reflect.fullFuncName(obj))
    else:
        if (id(obj) in self.prepared):
            oldRef = self.prepared[id(obj)]
            if oldRef.refnum:
                key = oldRef.refnum
            else:
                self._ref_id = (self._ref_id + 1)
                key = self._ref_id
                oldRef.setRef(key)
            return Deref(key)
        retval = Ref()
        def _stateFrom(state):
            retval.setObj(Instance(reflect.qual(obj.__class__), self.jellyToAO(state)))
        self.prepareForRef(retval, obj)
        if (objType is list):
            retval.setObj([self.jellyToAO(o) for o in obj])
        elif (objType is tuple):
            retval.setObj(tuple(map(self.jellyToAO, obj)))
        elif (objType is dict):
            d = {}
            for (k, v) in obj.items():
                d[self.jellyToAO(k)] = self.jellyToAO(v)
            retval.setObj(d)
        elif (objType in copy_reg.dispatch_table):
            (unpickleFunc, state) = copy_reg.dispatch_table[objType](obj)
            retval.setObj(Copyreg(reflect.fullFuncName(unpickleFunc), self.jellyToAO(state)))
        elif hasattr(obj, '__getstate__'):
            _stateFrom(obj.__getstate__())
        elif hasattr(obj, '__dict__'):
            _stateFrom(obj.__dict__)
        else:
            raise TypeError(('Unsupported    type:    %s' % objType.__name__))
    del self.stack[(-1)]
    return retval
