def parse(self, file):
        '''
        Method the programmer should call when ready to parse a file.
        :param file: exact file path of the file to be processed
        :return: PieceTree object representing the file in memory
        '''
        parser = make_parser()
        self.clear()

        class Extractor(xml.sax.ContentHandler):

            def __init__(self, parent):
                self.parent = parent

            def startElement(self, name, attrs):
                attribs = {}
                for attrname in attrs.getNames():
                    attrvalue = attrs.get(attrname)
                    attribs[attrname] = attrvalue
                self.parent.StartTag(name, attribs)

            def characters(self, text):
                self.parent.NewData(text)

            def endElement(self, name):
                self.parent.EndTag(name)
        parser.setContentHandler(Extractor(self))
        # OFFLINE MODE
        parser.setFeature(handler.feature_external_ges, False)
        fob = open(file, 'r')
        parser.parse(fob)
        return self.piece
def parse ( self , file ) : parser = make_parser ( ) self . clear ( ) class Extractor ( xml . sax . ContentHandler ) : def __init__ ( self , parent ) : self . parent = parent def startElement ( self , name , attrs ) : attribs = { } for attrname in attrs . getNames ( ) : attrvalue = attrs . get ( attrname ) attribs [ attrname ] = attrvalue self . parent . StartTag ( name , attribs ) def characters ( self , text ) : self . parent . NewData ( text ) def endElement ( self , name ) : self . parent . EndTag ( name ) parser . setContentHandler ( Extractor ( self ) ) parser . setFeature ( handler . feature_external_ges , False ) fob = open ( file , 'r' ) parser . parse ( fob ) return self . piece
Method the programmer should call when ready to parse a file.
        :param file: exact file path of the file to be processed
        :return: PieceTree object representing the file in memory