[Tutor] What on earth is happening here ???

Lipska TheCat lipskathekat at yahoo.co.uk
Wed Jul 25 17:11:58 CEST 2012


Pythoners

I have a class
The point of this class is to provide an uncluttered interface
to Document Creation


from xml.dom.minidom import getDOMImplementation

class NpDOMDocumentFactory:
    
    """A DOM Document Factory convenience class"""  

    

    # make these private "by convention"
    __DOMImplementation = getDOMImplementation()
    __defaultNamespaceUri = "http://nuldomain.com/"
    __defaultQualifiedName = "root"
    __defaultDoctype = __DOMImplementation.createDocumentType("HTML", 
                                                            "-//W3C//DTD HTML 4.01//EN", 
                                                            "http://www.w3.org/TR/html4/strict.dtd")
    #params required for the createDocument method on DOMImplementation    
    #DOMImplementation.createDocument(namespaceUri, qualifiedName, doctype)
        
    #get a default document with the root element initialised to <root>
    def getDOMDocument(self):
        print("no args")
        return self.__DOMImplementation.createDocument(None, "root", None)

    #allow a user to specify the namespaceUri node name
    def getDOMDocument(self, namespaceUri=__defaultNamespaceUri):
        return self.__DOMImplementation.createDocument(namespaceUri, "root", None) 


    #allow a user to specify the namespaceUri and a qualifiedName
    def getDOMDocument(self, namespaceUri=__defaultNamespaceUri, qualifiedName=__defaultQualifiedName):
        return self.__DOMImplementation.createDocument(namespaceUri, qualifiedName, None) 

    
    #allow a user to specify the namespaceUri, a qualifiedName and a doctype
    def getDOMDocument(self, namespaceUri=__defaultNamespaceUri, qualifiedName=__defaultQualifiedName, docType=__defaultDoctype):
        print("3 args")
        return self.__DOMImplementation.createDocument(namespaceUri, qualifiedName, docType) 



#end NpDOMDocumentFactory

factory = NpDOMDocumentFactory()

print(factory.getDOMDocument().toxml())

when I pass this to python I get the following

lipska at ubuntu:~/python/dev/classes/com/nuldomain/xml$ python3.2 NpDOMDocumentFactory.py
3 args
<?xml version="1.0" ?><!DOCTYPE HTML  PUBLIC '-//W3C//DTD HTML 4.01//EN'  'http://www.w3.org/TR/html4/strict.dtd'><root/>

I have absolutely no idea why a method that requires three arguments is being called when I intend the "no args" method to be called

I'm not asking for a critique of my code and I realise that something spooky
is going on with the doctype stuff I just need to understand why the 3 arg method is being called instead of the 

0 arg method as expected

Can someone enlighten me ... please, thanks


Lipska


More information about the Tutor mailing list