parameters: (self, xml_file=None)
docstring: Given a well formed XML file (xml_file), read it and turn it into
          a big string.
docstring_summary: Given a well formed XML file (xml_file), read it and turn it into
          a big string.
docstring_tokens: Given a well formed XML file ( xml_file ) read it and turn it into a big string .
function: def __init__(self, xml_file=None):
          """
          Given a well formed XML file (xml_file), read it and turn it into
          a big string.
          """
          self.__root = None
          self.__include_serializable_files = []
          self.__include_enum_files = []
          self.__include_array_files = []
          self.__include_header_files = []
          #
          self.__config = ConfigManager.ConfigManager.getInstance()
          #
          self.__port = None
          self.__args = []
          self.__enum_list_items = []
          self.__modifier = None
          #
          if os.path.isfile(xml_file) == False:
              str = "ERROR: Could not find specified XML file %s." % xml_file
              raise OSError(str)
          fd = open(xml_file)
          xml_file = os.path.basename(xml_file)
          self.__xml_filename = xml_file
          #
  
          xml_parser = etree.XMLParser(remove_comments=True)
          element_tree = etree.parse(fd, parser=xml_parser)
          fd.close()  # Close the file, which is only used for the parsing above
  
          # Validate against schema
          relax_file_handler = open(ROOTDIR + self.__config.get("schema", "interface"))
          relax_parsed = etree.parse(relax_file_handler)
          relax_file_handler.close()
          relax_compiled = etree.RelaxNG(relax_parsed)
  
          # 2/3 conversion
          if not relax_compiled.validate(element_tree):
              raise FprimeRngXmlValidationException(relax_compiled.error_log)
  
          interface = element_tree.getroot()
          if interface.tag != "interface":
              PRINT.info("%s is not an interface file" % xml_file)
              sys.exit(-1)
  
          print("Parsing Interface %s" % interface.attrib["name"])
  
          if "namespace" in interface.attrib:
              namespace_name = interface.attrib["namespace"]
          else:
              namespace_name = None
  
          self.__port = Interface(namespace_name, interface.attrib["name"])
  
          for interface_tag in interface:
              if interface_tag.tag == "comment":
                  self.__port.set_comment(interface_tag.text.strip())
              elif interface_tag.tag == "include_header":
                  self.__include_header_files.append(interface_tag.text)
              elif interface_tag.tag == "import_serializable_type":
                  self.__include_serializable_files.append(interface_tag.text)
              elif interface_tag.tag == "import_enum_type":
                  self.__include_enum_files.append(interface_tag.text)
              elif interface_tag.tag == "import_array_type":
                  self.__include_array_files.append(interface_tag.text)
              elif interface_tag.tag == "args":
                  for arg in interface_tag:
                      if arg.tag != "arg":
                          PRINT.info(
                              "%s: Invalid tag %s in interface args definition"
                              % (xml_file, arg.tag)
                          )
                          sys.exit(-1)
                      n = arg.attrib["name"]
                      t = arg.attrib["type"]
                      if "pass_by" in list(arg.attrib.keys()):
                          p = arg.attrib["pass_by"]
                      else:
                          p = None
                      if t == "string" or t == "buffer":
                          if not "size" in list(arg.attrib.keys()):
                              PRINT.info(
                                  "%s: arg %s string must specify size tag"
                                  % (xml_file, arg.tag)
                              )
                              sys.exit(-1)
                          else:
                              s = arg.attrib["size"]
                      else:
                          s = None
                      arg_obj = Arg(n, t, p, s, None)
                      for arg_tag in arg:
                          # only valid tag in command args is comment
                          if arg_tag.tag == "comment":
                              arg_obj.set_comment(arg_tag.text)
                          elif arg_tag.tag == "enum" and t == "ENUM":
                              en = arg_tag.attrib["name"]
                              enum_members = []
                              for mem in arg_tag:
                                  mn = mem.attrib["name"]
                                  if "value" in list(mem.attrib.keys()):
                                      v = mem.attrib["value"]
                                  else:
                                      v = None
                                  if "comment" in list(mem.attrib.keys()):
                                      mc = mem.attrib["comment"].strip()
                                  else:
                                      mc = None
                                  enum_members.append((mn, v, mc))
                              arg_obj.set_type(((t, en), enum_members))
                          else:
                              PRINT.info(
                                  "%s: Invalid argument tag %s in port %s argument %s"
                                  % (xml_file, arg_tag.tag, interface_tag.tag, n)
                              )
                              sys.exit(-1)
  
                      self.__args.append(arg_obj)
  
              elif interface_tag.tag == "return":
                  t = interface_tag.attrib["type"]
                  if "pass_by" in list(interface_tag.attrib.keys()):
                      m = interface_tag.attrib["pass_by"]
                  else:
                      m = "value"
                  for enum_tag in interface_tag:
                      # The only tags would be enumeration declarations
                      if enum_tag.tag == "enum" and t == "ENUM":
                          en = enum_tag.attrib["name"]
                          enum_members = []
                          for mem in enum_tag:
                              mn = mem.attrib["name"]
                              if "value" in list(mem.attrib.keys()):
                                  v = mem.attrib["value"]
                              else:
                                  v = None
                              if "comment" in list(mem.attrib.keys()):
                                  mc = mem.attrib["comment"].strip()
                              else:
                                  mc = None
                              enum_members.append((mn, v, mc))
                          t = ((t, en), enum_members)
                      else:
                          PRINT.info(
                              "%s: Invalid port return value tag %s"
                              % (xml_file, enum_tag.tag)
                          )
                          sys.exit(-1)
  
                  self.__port.set_return(t, m)
function_tokens: def __init__ ( self , xml_file = None ) : self . __root = None self . __include_serializable_files = [ ] self . __include_enum_files = [ ] self . __include_array_files = [ ] self . __include_header_files = [ ] # self . __config = ConfigManager . ConfigManager . getInstance ( ) # self . __port = None self . __args = [ ] self . __enum_list_items = [ ] self . __modifier = None # if os . path . isfile ( xml_file ) == False : str = "ERROR: Could not find specified XML file %s." % xml_file raise OSError ( str ) fd = open ( xml_file ) xml_file = os . path . basename ( xml_file ) self . __xml_filename = xml_file # xml_parser = etree . XMLParser ( remove_comments = True ) element_tree = etree . parse ( fd , parser = xml_parser ) fd . close ( ) # Close the file, which is only used for the parsing above # Validate against schema relax_file_handler = open ( ROOTDIR + self . __config . get ( "schema" , "interface" ) ) relax_parsed = etree . parse ( relax_file_handler ) relax_file_handler . close ( ) relax_compiled = etree . RelaxNG ( relax_parsed ) # 2/3 conversion if not relax_compiled . validate ( element_tree ) : raise FprimeRngXmlValidationException ( relax_compiled . error_log ) interface = element_tree . getroot ( ) if interface . tag != "interface" : PRINT . info ( "%s is not an interface file" % xml_file ) sys . exit ( - 1 ) print ( "Parsing Interface %s" % interface . attrib [ "name" ] ) if "namespace" in interface . attrib : namespace_name = interface . attrib [ "namespace" ] else : namespace_name = None self . __port = Interface ( namespace_name , interface . attrib [ "name" ] ) for interface_tag in interface : if interface_tag . tag == "comment" : self . __port . set_comment ( interface_tag . text . strip ( ) ) elif interface_tag . tag == "include_header" : self . __include_header_files . append ( interface_tag . text ) elif interface_tag . tag == "import_serializable_type" : self . __include_serializable_files . append ( interface_tag . text ) elif interface_tag . tag == "import_enum_type" : self . __include_enum_files . append ( interface_tag . text ) elif interface_tag . tag == "import_array_type" : self . __include_array_files . append ( interface_tag . text ) elif interface_tag . tag == "args" : for arg in interface_tag : if arg . tag != "arg" : PRINT . info ( "%s: Invalid tag %s in interface args definition" % ( xml_file , arg . tag ) ) sys . exit ( - 1 ) n = arg . attrib [ "name" ] t = arg . attrib [ "type" ] if "pass_by" in list ( arg . attrib . keys ( ) ) : p = arg . attrib [ "pass_by" ] else : p = None if t == "string" or t == "buffer" : if not "size" in list ( arg . attrib . keys ( ) ) : PRINT . info ( "%s: arg %s string must specify size tag" % ( xml_file , arg . tag ) ) sys . exit ( - 1 ) else : s = arg . attrib [ "size" ] else : s = None arg_obj = Arg ( n , t , p , s , None ) for arg_tag in arg : # only valid tag in command args is comment if arg_tag . tag == "comment" : arg_obj . set_comment ( arg_tag . text ) elif arg_tag . tag == "enum" and t == "ENUM" : en = arg_tag . attrib [ "name" ] enum_members = [ ] for mem in arg_tag : mn = mem . attrib [ "name" ] if "value" in list ( mem . attrib . keys ( ) ) : v = mem . attrib [ "value" ] else : v = None if "comment" in list ( mem . attrib . keys ( ) ) : mc = mem . attrib [ "comment" ] . strip ( ) else : mc = None enum_members . append ( ( mn , v , mc ) ) arg_obj . set_type ( ( ( t , en ) , enum_members ) ) else : PRINT . info ( "%s: Invalid argument tag %s in port %s argument %s" % ( xml_file , arg_tag . tag , interface_tag . tag , n ) ) sys . exit ( - 1 ) self . __args . append ( arg_obj ) elif interface_tag . tag == "return" : t = interface_tag . attrib [ "type" ] if "pass_by" in list ( interface_tag . attrib . keys ( ) ) : m = interface_tag . attrib [ "pass_by" ] else : m = "value" for enum_tag in interface_tag : # The only tags would be enumeration declarations if enum_tag . tag == "enum" and t == "ENUM" : en = enum_tag . attrib [ "name" ] enum_members = [ ] for mem in enum_tag : mn = mem . attrib [ "name" ] if "value" in list ( mem . attrib . keys ( ) ) : v = mem . attrib [ "value" ] else : v = None if "comment" in list ( mem . attrib . keys ( ) ) : mc = mem . attrib [ "comment" ] . strip ( ) else : mc = None enum_members . append ( ( mn , v , mc ) ) t = ( ( t , en ) , enum_members ) else : PRINT . info ( "%s: Invalid port return value tag %s" % ( xml_file , enum_tag . tag ) ) sys . exit ( - 1 ) self . __port . set_return ( t , m )