(file, allNames=False, extraData=False, disarm=False, force=False)
return xmlDoc
Example of XML output:
    <PDFiD ErrorOccured="False" ErrorMessage="" Filename="test.pdf" Header="%PDF-1.1" IsPDF="True" Version="0.0.4" Entropy="4.28">
            <Keywords>
                    <Keyword Count="7" HexcodeCount="0" Name="obj"/>
                    <Keyword Count="7" HexcodeCount="0" Name="endobj"/>
                    <Keyword Count="1" HexcodeCount="0" Name="stream"/>
                    <Keyword Count="1" HexcodeCount="0" Name="endstream"/>
                    <Keyword Count="1" HexcodeCount="0" Name="xref"/>
                    <Keyword Count="1" HexcodeCount="0" Name="trailer"/>
                    <Keyword Count="1" HexcodeCount="0" Name="startxref"/>
                    <Keyword Count="1" HexcodeCount="0" Name="/Page"/>
                    <Keyword Count="0" HexcodeCount="0" Name="/Encrypt"/>
                    <Keyword Count="1" HexcodeCount="0" Name="/JS"/>
                    <Keyword Count="1" HexcodeCount="0" Name="/JavaScript"/>
                    <Keyword Count="0" HexcodeCount="0" Name="/AA"/>
                    <Keyword Count="1" HexcodeCount="0" Name="/OpenAction"/>
                    <Keyword Count="0" HexcodeCount="0" Name="/JBIG2Decode"/>
            </Keywords>
            <Dates>
                    <Date Value="D:20090128132916+01'00" Name="/ModDate"/>
            </Dates>
    </PDFiD>
Example of XML output:
    <PDFiD ErrorOccured="False" ErrorMessage="" Filename="test.pdf" Header="%PDF-1.1" IsPDF="True" Version="0.0.4" Entropy="4.28">
            <Keywords>
                    <Keyword Count="7" HexcodeCount="0" Name="obj"/>
                    <Keyword Count="7" HexcodeCount="0" Name="endobj"/>
                    <Keyword Count="1" HexcodeCount="0" Name="stream"/>
                    <Keyword Count="1" HexcodeCount="0" Name="endstream"/>
                    <Keyword Count="1" HexcodeCount="0" Name="xref"/>
                    <Keyword Count="1" HexcodeCount="0" Name="trailer"/>
                    <Keyword Count="1" HexcodeCount="0" Name="startxref"/>
                    <Keyword Count="1" HexcodeCount="0" Name="/Page"/>
                    <Keyword Count="0" HexcodeCount="0" Name="/Encrypt"/>
                    <Keyword Count="1" HexcodeCount="0" Name="/JS"/>
                    <Keyword Count="1" HexcodeCount="0" Name="/JavaScript"/>
                    <Keyword Count="0" HexcodeCount="0" Name="/AA"/>
                    <Keyword Count="1" HexcodeCount="0" Name="/OpenAction"/>
                    <Keyword Count="0" HexcodeCount="0" Name="/JBIG2Decode"/>
            </Keywords>
            <Dates>
                    <Date Value="D:20090128132916+01'00" Name="/ModDate"/>
            </Dates>
    </PDFiD>
Example of XML output : <PDFiD ErrorOccured = False ErrorMessage = Filename = test . pdf Header = %PDF - 1 . 1 IsPDF = True Version = 0 . 0 . 4 Entropy = 4 . 28 > <Keywords > <Keyword Count = 7 HexcodeCount = 0 Name = obj / > <Keyword Count = 7 HexcodeCount = 0 Name = endobj / > <Keyword Count = 1 HexcodeCount = 0 Name = stream / > <Keyword Count = 1 HexcodeCount = 0 Name = endstream / > <Keyword Count = 1 HexcodeCount = 0 Name = xref / > <Keyword Count = 1 HexcodeCount = 0 Name = trailer / > <Keyword Count = 1 HexcodeCount = 0 Name = startxref / > <Keyword Count = 1 HexcodeCount = 0 Name = / Page / > <Keyword Count = 0 HexcodeCount = 0 Name = / Encrypt / > <Keyword Count = 1 HexcodeCount = 0 Name = / JS / > <Keyword Count = 1 HexcodeCount = 0 Name = / JavaScript / > <Keyword Count = 0 HexcodeCount = 0 Name = / AA / > <Keyword Count = 1 HexcodeCount = 0 Name = / OpenAction / > <Keyword Count = 0 HexcodeCount = 0 Name = / JBIG2Decode / > < / Keywords > <Dates > <Date Value = D : 20090128132916 + 01 00 Name = / ModDate / > < / Dates > < / PDFiD >
def PDFiD(file, allNames=False, extraData=False, disarm=False, force=False):
    """Example of XML output:
    <PDFiD ErrorOccured="False" ErrorMessage="" Filename="test.pdf" Header="%PDF-1.1" IsPDF="True" Version="0.0.4" Entropy="4.28">
            <Keywords>
                    <Keyword Count="7" HexcodeCount="0" Name="obj"/>
                    <Keyword Count="7" HexcodeCount="0" Name="endobj"/>
                    <Keyword Count="1" HexcodeCount="0" Name="stream"/>
                    <Keyword Count="1" HexcodeCount="0" Name="endstream"/>
                    <Keyword Count="1" HexcodeCount="0" Name="xref"/>
                    <Keyword Count="1" HexcodeCount="0" Name="trailer"/>
                    <Keyword Count="1" HexcodeCount="0" Name="startxref"/>
                    <Keyword Count="1" HexcodeCount="0" Name="/Page"/>
                    <Keyword Count="0" HexcodeCount="0" Name="/Encrypt"/>
                    <Keyword Count="1" HexcodeCount="0" Name="/JS"/>
                    <Keyword Count="1" HexcodeCount="0" Name="/JavaScript"/>
                    <Keyword Count="0" HexcodeCount="0" Name="/AA"/>
                    <Keyword Count="1" HexcodeCount="0" Name="/OpenAction"/>
                    <Keyword Count="0" HexcodeCount="0" Name="/JBIG2Decode"/>
            </Keywords>
            <Dates>
                    <Date Value="D:20090128132916+01'00" Name="/ModDate"/>
            </Dates>
    </PDFiD>
    """

    word = ''
    wordExact = []
    hexcode = False
    lastName = ''
    insideStream = False
    keywords = ('obj',
                'endobj',
                'stream',
                'endstream',
                'xref',
                'trailer',
                'startxref',
                '/Page',
                '/Encrypt',
                '/ObjStm',
                '/JS',
                '/JavaScript',
                '/AA',
                '/OpenAction',
                '/AcroForm',
                '/JBIG2Decode',
                '/RichMedia',
                '/Launch',
                '/EmbeddedFile',
                '/XFA',
               )
    words = {}
    dates = []
    for keyword in keywords:
        words[keyword] = [0, 0]
    slash = ''
    xmlDoc = xml.dom.minidom.getDOMImplementation().createDocument(None, 'PDFiD', None)
    XMLAddAttribute(xmlDoc, 'Version', __version__)
    XMLAddAttribute(xmlDoc, 'Filename', file)
    attErrorOccured = XMLAddAttribute(xmlDoc, 'ErrorOccured', 'False')
    attErrorMessage = XMLAddAttribute(xmlDoc, 'ErrorMessage', '')

    oPDFDate = None
    oEntropy = None
    oPDFEOF = None
    oCVE_2009_3459 = cCVE_2009_3459()
    try:
        attIsPDF = xmlDoc.createAttribute('IsPDF')
        xmlDoc.documentElement.setAttributeNode(attIsPDF)
        oBinaryFile = cBinaryFile(file)
        if extraData:
            oPDFDate = cPDFDate()
            oEntropy = cEntropy()
            oPDFEOF = cPDFEOF()
        (bytesHeader, pdfHeader) = FindPDFHeaderRelaxed(oBinaryFile)
        if disarm:
            (pathfile, extension) = os.path.splitext(file)
            fOut = open(pathfile + '.disarmed' + extension, 'wb')
            for byteHeader in bytesHeader:
                fOut.write(C2BIP3(chr(byteHeader)))
        else:
            fOut = None
        if oEntropy != None:
            for byteHeader in bytesHeader:
                oEntropy.add(byteHeader, insideStream)
        if pdfHeader == None and not force:
            attIsPDF.nodeValue = 'False'
            return xmlDoc
        else:
            if pdfHeader == None:
                attIsPDF.nodeValue = 'False'
                pdfHeader = ''
            else:
                attIsPDF.nodeValue = 'True'
            att = xmlDoc.createAttribute('Header')
            att.nodeValue = repr(pdfHeader[0:10]).strip("'")
            xmlDoc.documentElement.setAttributeNode(att)
        byte = oBinaryFile.byte()
        while byte != None:
            char = chr(byte)
            charUpper = char.upper()
            if charUpper >= 'A' and charUpper <= 'Z' or charUpper >= '0' and charUpper <= '9':
                word += char
                wordExact.append(char)
            elif slash == '/' and char == '#':
                d1 = oBinaryFile.byte()
                if d1 != None:
                    d2 = oBinaryFile.byte()
                    if d2 != None and (chr(d1) >= '0' and chr(d1) <= '9' or chr(d1).upper() >= 'A' and chr(d1).upper() <= 'F') and (chr(d2) >= '0' and chr(d2) <= '9' or chr(d2).upper() >= 'A' and chr(d2).upper() <= 'F'):
                        word += chr(int(chr(d1) + chr(d2), 16))
                        wordExact.append(int(chr(d1) + chr(d2), 16))
                        hexcode = True
                        if oEntropy != None:
                            oEntropy.add(d1, insideStream)
                            oEntropy.add(d2, insideStream)
                        if oPDFEOF != None:
                            oPDFEOF.parse(d1)
                            oPDFEOF.parse(d2)
                    else:
                        oBinaryFile.unget(d2)
                        oBinaryFile.unget(d1)
                        (word, wordExact, hexcode, lastName, insideStream) = UpdateWords(word, wordExact, slash, words, hexcode, allNames, lastName, insideStream, oEntropy, fOut)
                        if disarm:
                            fOut.write(C2BIP3(char))
                else:
                    oBinaryFile.unget(d1)
                    (word, wordExact, hexcode, lastName, insideStream) = UpdateWords(word, wordExact, slash, words, hexcode, allNames, lastName, insideStream, oEntropy, fOut)
                    if disarm:
                        fOut.write(C2BIP3(char))
            else:
                oCVE_2009_3459.Check(lastName, word)

                (word, wordExact, hexcode, lastName, insideStream) = UpdateWords(word, wordExact, slash, words, hexcode, allNames, lastName, insideStream, oEntropy, fOut)
                if char == '/':
                    slash = '/'
                else:
                    slash = ''
                if disarm:
                    fOut.write(C2BIP3(char))

            if oPDFDate != None and oPDFDate.parse(char) != None:
                dates.append([oPDFDate.date, lastName])

            if oEntropy != None:
                oEntropy.add(byte, insideStream)

            if oPDFEOF != None:
                oPDFEOF.parse(char)

            byte = oBinaryFile.byte()
        (word, wordExact, hexcode, lastName, insideStream) = UpdateWords(word, wordExact, slash, words, hexcode, allNames, lastName, insideStream, oEntropy, fOut)

        # check to see if file ended with %%EOF.  If so, we can reset charsAfterLastEOF and add one to EOF count.  This is never performed in
        # the parse function because it never gets called due to hitting the end of file.
        if byte == None and oPDFEOF != None:
            if oPDFEOF.token == '%%EOF':
                oPDFEOF.cntEOFs += 1
                oPDFEOF.cntCharsAfterLastEOF = 0
                oPDFEOF.token = ''

    except SystemExit:
        sys.exit()
    except:
        attErrorOccured.nodeValue = 'True'
        attErrorMessage.nodeValue = traceback.format_exc()

    if disarm:
        fOut.close()

    attEntropyAll = xmlDoc.createAttribute('TotalEntropy')
    xmlDoc.documentElement.setAttributeNode(attEntropyAll)
    attCountAll = xmlDoc.createAttribute('TotalCount')
    xmlDoc.documentElement.setAttributeNode(attCountAll)
    attEntropyStream = xmlDoc.createAttribute('StreamEntropy')
    xmlDoc.documentElement.setAttributeNode(attEntropyStream)
    attCountStream = xmlDoc.createAttribute('StreamCount')
    xmlDoc.documentElement.setAttributeNode(attCountStream)
    attEntropyNonStream = xmlDoc.createAttribute('NonStreamEntropy')
    xmlDoc.documentElement.setAttributeNode(attEntropyNonStream)
    attCountNonStream = xmlDoc.createAttribute('NonStreamCount')
    xmlDoc.documentElement.setAttributeNode(attCountNonStream)
    if oEntropy != None:
        (countAll, entropyAll , countStream, entropyStream, countNonStream, entropyNonStream) = oEntropy.calc()
        attEntropyAll.nodeValue = '%f' % entropyAll
        attCountAll.nodeValue = '%d' % countAll
        attEntropyStream.nodeValue = '%f' % entropyStream
        attCountStream.nodeValue = '%d' % countStream
        attEntropyNonStream.nodeValue = '%f' % entropyNonStream
        attCountNonStream.nodeValue = '%d' % countNonStream
    else:
        attEntropyAll.nodeValue = ''
        attCountAll.nodeValue = ''
        attEntropyStream.nodeValue = ''
        attCountStream.nodeValue = ''
        attEntropyNonStream.nodeValue = ''
        attCountNonStream.nodeValue = ''
    attCountEOF = xmlDoc.createAttribute('CountEOF')
    xmlDoc.documentElement.setAttributeNode(attCountEOF)
    attCountCharsAfterLastEOF = xmlDoc.createAttribute('CountCharsAfterLastEOF')
    xmlDoc.documentElement.setAttributeNode(attCountCharsAfterLastEOF)
    if oPDFEOF != None:
        attCountEOF.nodeValue = '%d' % oPDFEOF.cntEOFs
        attCountCharsAfterLastEOF.nodeValue = '%d' % oPDFEOF.cntCharsAfterLastEOF
    else:
        attCountEOF.nodeValue = ''
        attCountCharsAfterLastEOF.nodeValue = ''

    eleKeywords = xmlDoc.createElement('Keywords')
    xmlDoc.documentElement.appendChild(eleKeywords)
    for keyword in keywords:
        eleKeyword = xmlDoc.createElement('Keyword')
        eleKeywords.appendChild(eleKeyword)
        att = xmlDoc.createAttribute('Name')
        att.nodeValue = keyword
        eleKeyword.setAttributeNode(att)
        att = xmlDoc.createAttribute('Count')
        att.nodeValue = str(words[keyword][0])
        eleKeyword.setAttributeNode(att)
        att = xmlDoc.createAttribute('HexcodeCount')
        att.nodeValue = str(words[keyword][1])
        eleKeyword.setAttributeNode(att)
    eleKeyword = xmlDoc.createElement('Keyword')
    eleKeywords.appendChild(eleKeyword)
    att = xmlDoc.createAttribute('Name')
    att.nodeValue = '/Colors > 2^24'
    eleKeyword.setAttributeNode(att)
    att = xmlDoc.createAttribute('Count')
    att.nodeValue = str(oCVE_2009_3459.count)
    eleKeyword.setAttributeNode(att)
    att = xmlDoc.createAttribute('HexcodeCount')
    att.nodeValue = str(0)
    eleKeyword.setAttributeNode(att)
    if allNames:
        keys = sorted(words.keys())
        for word in keys:
            if not word in keywords:
                eleKeyword = xmlDoc.createElement('Keyword')
                eleKeywords.appendChild(eleKeyword)
                att = xmlDoc.createAttribute('Name')
                att.nodeValue = word
                eleKeyword.setAttributeNode(att)
                att = xmlDoc.createAttribute('Count')
                att.nodeValue = str(words[word][0])
                eleKeyword.setAttributeNode(att)
                att = xmlDoc.createAttribute('HexcodeCount')
                att.nodeValue = str(words[word][1])
                eleKeyword.setAttributeNode(att)
    eleDates = xmlDoc.createElement('Dates')
    xmlDoc.documentElement.appendChild(eleDates)
    dates.sort(key=lambda x: x[0])
    for date in dates:
        eleDate = xmlDoc.createElement('Date')
        eleDates.appendChild(eleDate)
        att = xmlDoc.createAttribute('Value')
        att.nodeValue = date[0]
        eleDate.setAttributeNode(att)
        att = xmlDoc.createAttribute('Name')
        att.nodeValue = date[1]
        eleDate.setAttributeNode(att)
    return xmlDoc
def PDFiD ( file , allNames = False , extraData = False , disarm = False , force = False ) : word = '' wordExact = [ ] hexcode = False lastName = '' insideStream = False keywords = ( 'obj' , 'endobj' , 'stream' , 'endstream' , 'xref' , 'trailer' , 'startxref' , '/Page' , '/Encrypt' , '/ObjStm' , '/JS' , '/JavaScript' , '/AA' , '/OpenAction' , '/AcroForm' , '/JBIG2Decode' , '/RichMedia' , '/Launch' , '/EmbeddedFile' , '/XFA' , ) words = { } dates = [ ] for keyword in keywords : words [ keyword ] = [ 0 , 0 ] slash = '' xmlDoc = xml . dom . minidom . getDOMImplementation ( ) . createDocument ( None , 'PDFiD' , None ) XMLAddAttribute ( xmlDoc , 'Version' , __version__ ) XMLAddAttribute ( xmlDoc , 'Filename' , file ) attErrorOccured = XMLAddAttribute ( xmlDoc , 'ErrorOccured' , 'False' ) attErrorMessage = XMLAddAttribute ( xmlDoc , 'ErrorMessage' , '' ) oPDFDate = None oEntropy = None oPDFEOF = None oCVE_2009_3459 = cCVE_2009_3459 ( ) try : attIsPDF = xmlDoc . createAttribute ( 'IsPDF' ) xmlDoc . documentElement . setAttributeNode ( attIsPDF ) oBinaryFile = cBinaryFile ( file ) if extraData : oPDFDate = cPDFDate ( ) oEntropy = cEntropy ( ) oPDFEOF = cPDFEOF ( ) ( bytesHeader , pdfHeader ) = FindPDFHeaderRelaxed ( oBinaryFile ) if disarm : ( pathfile , extension ) = os . path . splitext ( file ) fOut = open ( pathfile + '.disarmed' + extension , 'wb' ) for byteHeader in bytesHeader : fOut . write ( C2BIP3 ( chr ( byteHeader ) ) ) else : fOut = None if oEntropy != None : for byteHeader in bytesHeader : oEntropy . add ( byteHeader , insideStream ) if pdfHeader == None and not force : attIsPDF . nodeValue = 'False' return xmlDoc else : if pdfHeader == None : attIsPDF . nodeValue = 'False' pdfHeader = '' else : attIsPDF . nodeValue = 'True' att = xmlDoc . createAttribute ( 'Header' ) att . nodeValue = repr ( pdfHeader [ 0 : 10 ] ) . strip ( "'" ) xmlDoc . documentElement . setAttributeNode ( att ) byte = oBinaryFile . byte ( ) while byte != None : char = chr ( byte ) charUpper = char . upper ( ) if charUpper >= 'A' and charUpper <= 'Z' or charUpper >= '0' and charUpper <= '9' : word += char wordExact . append ( char ) elif slash == '/' and char == '#' : d1 = oBinaryFile . byte ( ) if d1 != None : d2 = oBinaryFile . byte ( ) if d2 != None and ( chr ( d1 ) >= '0' and chr ( d1 ) <= '9' or chr ( d1 ) . upper ( ) >= 'A' and chr ( d1 ) . upper ( ) <= 'F' ) and ( chr ( d2 ) >= '0' and chr ( d2 ) <= '9' or chr ( d2 ) . upper ( ) >= 'A' and chr ( d2 ) . upper ( ) <= 'F' ) : word += chr ( int ( chr ( d1 ) + chr ( d2 ) , 16 ) ) wordExact . append ( int ( chr ( d1 ) + chr ( d2 ) , 16 ) ) hexcode = True if oEntropy != None : oEntropy . add ( d1 , insideStream ) oEntropy . add ( d2 , insideStream ) if oPDFEOF != None : oPDFEOF . parse ( d1 ) oPDFEOF . parse ( d2 ) else : oBinaryFile . unget ( d2 ) oBinaryFile . unget ( d1 ) ( word , wordExact , hexcode , lastName , insideStream ) = UpdateWords ( word , wordExact , slash , words , hexcode , allNames , lastName , insideStream , oEntropy , fOut ) if disarm : fOut . write ( C2BIP3 ( char ) ) else : oBinaryFile . unget ( d1 ) ( word , wordExact , hexcode , lastName , insideStream ) = UpdateWords ( word , wordExact , slash , words , hexcode , allNames , lastName , insideStream , oEntropy , fOut ) if disarm : fOut . write ( C2BIP3 ( char ) ) else : oCVE_2009_3459 . Check ( lastName , word ) ( word , wordExact , hexcode , lastName , insideStream ) = UpdateWords ( word , wordExact , slash , words , hexcode , allNames , lastName , insideStream , oEntropy , fOut ) if char == '/' : slash = '/' else : slash = '' if disarm : fOut . write ( C2BIP3 ( char ) ) if oPDFDate != None and oPDFDate . parse ( char ) != None : dates . append ( [ oPDFDate . date , lastName ] ) if oEntropy != None : oEntropy . add ( byte , insideStream ) if oPDFEOF != None : oPDFEOF . parse ( char ) byte = oBinaryFile . byte ( ) ( word , wordExact , hexcode , lastName , insideStream ) = UpdateWords ( word , wordExact , slash , words , hexcode , allNames , lastName , insideStream , oEntropy , fOut ) # check to see if file ended with %%EOF.  If so, we can reset charsAfterLastEOF and add one to EOF count.  This is never performed in # the parse function because it never gets called due to hitting the end of file. if byte == None and oPDFEOF != None : if oPDFEOF . token == '%%EOF' : oPDFEOF . cntEOFs += 1 oPDFEOF . cntCharsAfterLastEOF = 0 oPDFEOF . token = '' except SystemExit : sys . exit ( ) except : attErrorOccured . nodeValue = 'True' attErrorMessage . nodeValue = traceback . format_exc ( ) if disarm : fOut . close ( ) attEntropyAll = xmlDoc . createAttribute ( 'TotalEntropy' ) xmlDoc . documentElement . setAttributeNode ( attEntropyAll ) attCountAll = xmlDoc . createAttribute ( 'TotalCount' ) xmlDoc . documentElement . setAttributeNode ( attCountAll ) attEntropyStream = xmlDoc . createAttribute ( 'StreamEntropy' ) xmlDoc . documentElement . setAttributeNode ( attEntropyStream ) attCountStream = xmlDoc . createAttribute ( 'StreamCount' ) xmlDoc . documentElement . setAttributeNode ( attCountStream ) attEntropyNonStream = xmlDoc . createAttribute ( 'NonStreamEntropy' ) xmlDoc . documentElement . setAttributeNode ( attEntropyNonStream ) attCountNonStream = xmlDoc . createAttribute ( 'NonStreamCount' ) xmlDoc . documentElement . setAttributeNode ( attCountNonStream ) if oEntropy != None : ( countAll , entropyAll , countStream , entropyStream , countNonStream , entropyNonStream ) = oEntropy . calc ( ) attEntropyAll . nodeValue = '%f' % entropyAll attCountAll . nodeValue = '%d' % countAll attEntropyStream . nodeValue = '%f' % entropyStream attCountStream . nodeValue = '%d' % countStream attEntropyNonStream . nodeValue = '%f' % entropyNonStream attCountNonStream . nodeValue = '%d' % countNonStream else : attEntropyAll . nodeValue = '' attCountAll . nodeValue = '' attEntropyStream . nodeValue = '' attCountStream . nodeValue = '' attEntropyNonStream . nodeValue = '' attCountNonStream . nodeValue = '' attCountEOF = xmlDoc . createAttribute ( 'CountEOF' ) xmlDoc . documentElement . setAttributeNode ( attCountEOF ) attCountCharsAfterLastEOF = xmlDoc . createAttribute ( 'CountCharsAfterLastEOF' ) xmlDoc . documentElement . setAttributeNode ( attCountCharsAfterLastEOF ) if oPDFEOF != None : attCountEOF . nodeValue = '%d' % oPDFEOF . cntEOFs attCountCharsAfterLastEOF . nodeValue = '%d' % oPDFEOF . cntCharsAfterLastEOF else : attCountEOF . nodeValue = '' attCountCharsAfterLastEOF . nodeValue = '' eleKeywords = xmlDoc . createElement ( 'Keywords' ) xmlDoc . documentElement . appendChild ( eleKeywords ) for keyword in keywords : eleKeyword = xmlDoc . createElement ( 'Keyword' ) eleKeywords . appendChild ( eleKeyword ) att = xmlDoc . createAttribute ( 'Name' ) att . nodeValue = keyword eleKeyword . setAttributeNode ( att ) att = xmlDoc . createAttribute ( 'Count' ) att . nodeValue = str ( words [ keyword ] [ 0 ] ) eleKeyword . setAttributeNode ( att ) att = xmlDoc . createAttribute ( 'HexcodeCount' ) att . nodeValue = str ( words [ keyword ] [ 1 ] ) eleKeyword . setAttributeNode ( att ) eleKeyword = xmlDoc . createElement ( 'Keyword' ) eleKeywords . appendChild ( eleKeyword ) att = xmlDoc . createAttribute ( 'Name' ) att . nodeValue = '/Colors > 2^24' eleKeyword . setAttributeNode ( att ) att = xmlDoc . createAttribute ( 'Count' ) att . nodeValue = str ( oCVE_2009_3459 . count ) eleKeyword . setAttributeNode ( att ) att = xmlDoc . createAttribute ( 'HexcodeCount' ) att . nodeValue = str ( 0 ) eleKeyword . setAttributeNode ( att ) if allNames : keys = sorted ( words . keys ( ) ) for word in keys : if not word in keywords : eleKeyword = xmlDoc . createElement ( 'Keyword' ) eleKeywords . appendChild ( eleKeyword ) att = xmlDoc . createAttribute ( 'Name' ) att . nodeValue = word eleKeyword . setAttributeNode ( att ) att = xmlDoc . createAttribute ( 'Count' ) att . nodeValue = str ( words [ word ] [ 0 ] ) eleKeyword . setAttributeNode ( att ) att = xmlDoc . createAttribute ( 'HexcodeCount' ) att . nodeValue = str ( words [ word ] [ 1 ] ) eleKeyword . setAttributeNode ( att ) eleDates = xmlDoc . createElement ( 'Dates' ) xmlDoc . documentElement . appendChild ( eleDates ) dates . sort ( key = lambda x : x [ 0 ] ) for date in dates : eleDate = xmlDoc . createElement ( 'Date' ) eleDates . appendChild ( eleDate ) att = xmlDoc . createAttribute ( 'Value' ) att . nodeValue = date [ 0 ] eleDate . setAttributeNode ( att ) att = xmlDoc . createAttribute ( 'Name' ) att . nodeValue = date [ 1 ] eleDate . setAttributeNode ( att ) return xmlDoc