docs: def generate_module(spec, out):
      """
      Given an AMQP spec parsed into an xml.etree.ElemenTree,
      and a file-like 'out' object to write to, generate
      the skeleton of a Python module.
  
      """
      #
      # HACK THE SPEC so that 'access' is handled by 'channel' instead of 'connection'
      #
      for amqp_class in spec.findall('class'):
          if amqp_class.attrib['name'] == 'access':
              amqp_class.attrib['handler'] = 'channel'
  
      #
      # Build up some helper dictionaries
      #
      for domain in spec.findall('domain'):
          domains[domain.attrib['name']] = domain.attrib['type']
  
      for amqp_class in spec.findall('class'):
          for amqp_method in amqp_class.findall('method'):
              method_name_map[(amqp_class.attrib['name'], amqp_method.attrib['name'])] = \
                  (
                      amqp_class.attrib['index'],
                      amqp_method.attrib['index'],
                      amqp_class.attrib['handler'].capitalize() + '.' +
                          _fixup_method_name(amqp_class, amqp_method),
                  )
  
      #### Actually generate output
  
      for amqp_class in spec.findall('class'):
          if amqp_class.attrib['handler'] == amqp_class.attrib['name']:
              generate_class(spec, amqp_class, out)
  
      out.write('_METHOD_MAP = {\n')
      for amqp_class in spec.findall('class'):
          print amqp_class.attrib
  #        for chassis in amqp_class.findall('chassis'):
  #            print '  ', chassis.attrib
          for amqp_method in amqp_class.findall('method'):
  #            print '  ', amqp_method.attrib
  #            for chassis in amqp_method.findall('chassis'):
  #                print '      ', chassis.attrib
              chassis = [x.attrib['name'] for x in amqp_method.findall('chassis')]
              if 'client' in chassis:
                  out.write("    (%s, %s): (%s, %s._%s),\n" % (
                      amqp_class.attrib['index'],
                      amqp_method.attrib['index'],
                      amqp_class.attrib['handler'].capitalize(),
                      amqp_class.attrib['handler'].capitalize(),
                      _fixup_method_name(amqp_class, amqp_method)))
      out.write('}\n\n')
  
      out.write('_METHOD_NAME_MAP = {\n')
      for amqp_class in spec.findall('class'):
          for amqp_method in amqp_class.findall('method'):
              out.write("    (%s, %s): '%s.%s',\n" % (
                  amqp_class.attrib['index'],
                  amqp_method.attrib['index'],
                  amqp_class.attrib['handler'].capitalize(),
                  _fixup_method_name(amqp_class, amqp_method)))
      out.write('}\n')