(self, iterable, **kwargs)
This update is a bit different from the usual dict update method. It works recursively and will parse a
        variety of Python containers, creating menus as necessary.

        Keys of corresponding MenuItems in the Menu dictionary are the title of those MenuItems at the time of parsing.
This update is a bit different from the usual dict update method. It works recursively and will parse a
        variety of Python containers, creating menus as necessary.
This update is a bit different from the usual dict update method . It works recursively and will parse a variety of Python containers creating menus as necessary .
def update(self, iterable, **kwargs):
        """
        This update is a bit different from the usual dict update method. It works recursively and will parse a
        variety of Python containers, creating menus as necessary.

        Keys of corresponding MenuItems in the Menu dictionary are the title of those MenuItems at the time of parsing.
        """
        def parse_menu(iterable, menu, depth):
            if isinstance(iterable, MenuItem):
                menu.add(iterable)
                return

            for n, ele in enumerate(iterable.iteritems() if isinstance(iterable, Mapping) else iterable):

                # for mappings we recurse but don't drop down a level in the menu
                if not isinstance(ele, MenuItem) and isinstance(ele, Mapping):
                    parse_menu(ele, menu, depth)

                # any iterables other than strings and MenuItems
                elif not isinstance(ele, (basestring, MenuItem)) and isinstance(ele, Iterable):
                    try:
                        menuitem, submenu = ele
                    except TypeError:
                        raise ValueError('menu iterable element #{} at depth {} has length {}; must be a single '
                                         'menu item or a pair consisting of a menu item and its '
                                         'submenu'.format(n, depth, len(tuple(ele))))
                    menuitem = MenuItem(menuitem)
                    menu.add(menuitem)
                    parse_menu(submenu, menuitem, depth+1)

                # menu item / could be visual separator where ele is None or separator
                else:
                    menu.add(ele)
        parse_menu(iterable, self, 0)
        parse_menu(kwargs, self, 0)
def update ( self , iterable , * * kwargs ) : def parse_menu ( iterable , menu , depth ) : if isinstance ( iterable , MenuItem ) : menu . add ( iterable ) return for n , ele in enumerate ( iterable . iteritems ( ) if isinstance ( iterable , Mapping ) else iterable ) : # for mappings we recurse but don't drop down a level in the menu if not isinstance ( ele , MenuItem ) and isinstance ( ele , Mapping ) : parse_menu ( ele , menu , depth ) # any iterables other than strings and MenuItems elif not isinstance ( ele , ( basestring , MenuItem ) ) and isinstance ( ele , Iterable ) : try : menuitem , submenu = ele except TypeError : raise ValueError ( 'menu iterable element #{} at depth {} has length {}; must be a single ' 'menu item or a pair consisting of a menu item and its ' 'submenu' . format ( n , depth , len ( tuple ( ele ) ) ) ) menuitem = MenuItem ( menuitem ) menu . add ( menuitem ) parse_menu ( submenu , menuitem , depth + 1 ) # menu item / could be visual separator where ele is None or separator else : menu . add ( ele ) parse_menu ( iterable , self , 0 ) parse_menu ( kwargs , self , 0 )