def get_memory()

in libraries/botbuilder-dialogs/botbuilder/dialogs/memory/scopes/dialog_context_memory_scope.py [0:0]


    def get_memory(self, dialog_context: "DialogContext") -> object:
        """
        Gets the backing memory for this scope.
        <param name="dc">The <see cref="DialogContext"/> object for this turn.</param>
        <returns>Memory for the scope.</returns>
        """
        if not dialog_context:
            raise TypeError(f"Expecting: DialogContext, but received None")

        # TODO: make sure that every object in the dict is serializable
        memory = {}
        stack = list([])
        current_dc = dialog_context

        # go to leaf node
        while current_dc.child:
            current_dc = current_dc.child

        while current_dc:
            # (PORTERS NOTE: javascript stack is reversed with top of stack on end)
            for item in current_dc.stack:
                # filter out ActionScope items because they are internal bookkeeping.
                if not item.id.startswith("ActionScope["):
                    stack.append(item.id)

            current_dc = current_dc.parent

        # top of stack is stack[0].
        memory[self.STACK] = stack
        memory[self.ACTIVE_DIALOG] = (
            dialog_context.active_dialog.id if dialog_context.active_dialog else None
        )
        memory[self.PARENT] = (
            dialog_context.parent.active_dialog.id
            if dialog_context.parent and dialog_context.parent.active_dialog
            else None
        )
        return memory