Next / Previous / Contents / TCC Help System / NM Tech homepage

4.7. addName(): Add one name to the name table

This function takes care of building the Python equivalent of each XML name and making sure there is an entry for that pair in nameTable.

pyrang
def addName(nameTable, args, name, suffix):
    """Add one element or attribute name to nameTable.

      [ (nameTable is a dictionary) and
        (args is an Args object) and
        (name is an XML element or attribute name as a string) and
        (suffix is a string) ->
          nameTable  :=  nameTable with an entry added with
              (args.prefix + (name, uppercased and with each "-"
              replaced by "_") + "_" + suffix) as the key, and
              name as the corresponding value ]
    """

First, we form the Python equivalent of name. See Section 4.8, “pythonizeName(): Sanitize an XML name for Python use”.

pyrang
    #-- 1
    # [ pyName  :=  name, convert to str, uppercased, and with
    #       hyphens converted to underbars, and "_" inserted
    #       at each lowercase->uppercase transition ]
    pyName = pythonizeName(name)

The key consists of pyName, prefixed with args.prefix, with an underbar and the suffix argument appended.

pyrang
    #-- 2
    # [ key  :=  args.prefix + pyName + "_" + suffix ]
    key = "{0}{1}_{2}".format(args.prefix, pyName, suffix)

Now we are ready to add the new entry to the table.

pyrang
    #-- 3
    # [ nameTable  :=  nameTable with an entry whose key=key and
    #       whose value=name ]
    nameTable[key] = name