human
Complete this python program:
def import_phantom_module(xml_file):
assistant
#Here is the Python code you requested.

    """Insert a fake Python module to sys.modules, based on a XML file.
    The XML file is expected to conform to Pydocweb DTD. The fake
    module will contain dummy objects, which guarantee the following:
    - Docstrings are correct.
    - Class inheritance relationships are correct (if present in XML).
    - Function argspec is *NOT* correct (even if present in XML).
    Instead, the function signature is prepended to the function docstring.
    - Class attributes are *NOT* correct; instead, they are dummy objects.
    Parameters
    xml_file : str
    Name of an XML file to read
    """
    import lxml.etree as etree
    object_cache = {}
    tree = etree.parse(xml_file)
    root = tree.getroot()
    all_nodes = dict([(n.attrib['id'], n) for n in root])
    def _get_bases(node, recurse=False):
        bases = [x.attrib['ref'] for x in node.findall('base')]
        if recurse:
            j = 0
            while True:
                try:
                    b = bases[j]
                except IndexError:
                    break
                if (b in all_nodes):
                    bases.extend(_get_bases(all_nodes[b]))
                j += 1
        return bases
    type_index = ['module', 'class', 'callable', 'object']
    def base_cmp(a, b):
        x = cmp(type_index.index(a.tag), type_index.index(b.tag))
        if (x != 0):
            return x
        if ((a.tag == 'class') and (b.tag == 'class')):
            a_bases = _get_bases(a, recurse=True)
            b_bases = _get_bases(b, recurse=True)
            x = cmp(len(a_bases), len(b_bases))
            if (x != 0):
                return x
            if (a.attrib['id'] in b_bases):
                return (-1)
            if (b.attrib['id'] in a_bases):
                return 1
        return cmp(a.attrib['id'].count('.'), b.attrib['id'].count('.'))
    nodes = root.getchildren()
    nodes.sort(base_cmp)
    for node in nodes:
        name = node.attrib['id']
        doc = ((node.text or '').decode('string-escape') + '\n')
        if (doc == '\n'):
            doc = ''
        parent = name
        while True:
            parent = '.'.join(parent.split('.')[:(-1)])
            if (not parent):
                break
            if (parent in object_cache):
                break
            obj = imp.new_module(parent)
            object_cache[parent] = obj
            sys.modules[parent] = obj
        if (node.tag == 'module'):
            obj = imp.new_module(name)
            obj.__doc__ = doc
            sys.modules[name] = obj
        elif (node.tag == 'class'):
            bases = [object_cache[b] for b in _get_bases(node)...