This function locates the output file name in the node's role attribute and returns it. It also handles two error cases, returning None if the node has no role attribute or if the role attribute doesn't start with "outFile:".
# - - - f i n d F i l e N a m e - - -
def findFileName ( node ):
"""Find the output file name from the node's role attribute.
[ node is a programlisting DOM Element with a role
attribute ->
return file-referenced(node) ]
"""
|
The .getAttribute() method comes from the DOM interface. It returns the attribute with the given name, or an empty string if there is no such attribute.
#-- 1 --
# [ if node has a role attribute ->
# attr := that attribute
# else -> return None ]
attr = node.getAttribute ( ROLE_ATTR )
if attr == "":
return None
|
Now that we have the attribute value, we check to see that it's properly formed. If so, we return the part after the prefix. If it's badly formed, we return None.
#-- 2 --
# [ if attr starts with ROLE_PREFIX ->
# retern the rest of attr
# else -> return None ]
if attr.startswith(ROLE_PREFIX):
return attr[len(ROLE_PREFIX):]
else:
return None
|