Ñò (sPMc@sedZddkZddkZddkZddklZddklZlZddk l Z ddk l Z ddk Z ddkZyddklZWnddklZnXeid eiƒZd „Zd „Zd „Zeid eiƒZd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z!d„Z"dd„Z$dS(sÌ Reconstitute an entry document from the output of the Universal Feed Parser. The main entry point is called 'reconstitute'. Input parameters are: results: this is the entire hash table return by the UFP entry: this is the entry in the hash that you want reconstituted The value returned is an XML DOM. Every effort is made to convert everything to unicode, and text fields into either plain text or well formed XHTML. Todo: * extension elements iÿÿÿÿN(tescape(tminidomtNode(t html5parser(tdom(tmd5(tnews [- -]cCs|pdSt|tƒo0y|idƒ}WqL|idƒ}qLXntit|ƒ}|i}|i|ƒ}|i|i |ƒƒ|i|ƒ|S(sC utility function to create a child element with the specified textNsutf-8s iso-8859-1( t isinstancetstrtdecodetillegal_xml_charstsubt invalidatet ownerDocumentt createElementt appendChildtcreateTextNode(tparenttnametvaluetxdoctxelement((s@/home/sa3ruby/intertwingly.net/code/venus/planet/reconstitute.pytcreateTextElements  cCs)ddtt|idƒƒƒddS(s replace invalid characters u�t000iiiüÿÿÿ(thextordtgroup(tc((s@/home/sa3ruby/intertwingly.net/code/venus/planet/reconstitute.pyR -scCsR|idƒ}|idƒott|ddƒƒ}ntt|ƒƒ}|S(s4 convert numeric character references to characters itxi(Rt startswithtunichrtint(R((s@/home/sa3ruby/intertwingly.net/code/venus/planet/reconstitute.pytncr2c2s s\W+cCs]y.tid|idƒƒiƒidƒ}Wntid|ƒiƒ}nX|idƒS(s generate a css id from a name t-sutf-8(tnonalphaR R tlowertencodetstrip(R((s@/home/sa3ruby/intertwingly.net/code/venus/planet/reconstitute.pytcssid<s .cCsc|idƒo;|io1|i}t|dƒo|iƒd}qDnú|idƒo|io |i}nÓ|idƒo1|io'|iidt|iƒi ƒ}n’|idƒo1|i o'|i idt|i ƒi ƒ}nQ|idƒo<|i o2|i didt|i di ƒi ƒ}nd S|ot|d|ƒn|S( s% copy or compute an id for the entry tidtvaluesitlinkttitlet/tsummarytcontentN(thas_keyR'thasattrR(R)R*t title_detailtbaseRt hexdigestR,tsummary_detailR-RR(txentrytentrytentry_id((s@/home/sa3ruby/intertwingly.net/code/venus/planet/reconstitute.pyR'Ds&    !cCs||idƒpDg|d<|idƒo&|dihdd6|id6ƒqTn|i}x|dD] }d|iƒjoqhn|idƒ}|id|idƒƒ|idƒo|id|idƒƒn|idƒo |id|idd ƒƒn|idƒo|id|idƒƒn|idƒo|id|idƒƒn|i |ƒqhWd S( s copy links to the entry tlinksR)t alternatetrelthrefttypeR*tlengthN( R.tappendR)R tkeysRt setAttributetgettNoneR(R4R5RR)txlink((s@/home/sa3ruby/intertwingly.net/code/venus/planet/reconstitute.pyR7\s( *   cCse|pdStid|ƒ}t|||ƒ}titiƒ|ƒ}|id|idƒƒdS(s/ insert a date-formated element into the entry Ns%Y-%m-%dT%H:%M:%SZs planet:formatsutf-8(ttimetstrftimeRtconfigt date_formatR?R (R4Rtparsedt formattedtxdate((s@/home/sa3ruby/intertwingly.net/code/venus/planet/reconstitute.pytdateqs cCsË|iidƒ}|idƒ p |i odS|id|idƒƒ|idƒo'|io|id|idƒƒn|idƒo'|io|id|idƒƒn|i|ƒdS(Ntcategoryttermtschemetlabel( R RR.RLR?R@RMRNR(R4ttagtxtag((s@/home/sa3ruby/intertwingly.net/code/venus/planet/reconstitute.pyRKyscCs³|pdS|i}|i|ƒ}|iddƒot|d|idƒƒn|i|idƒƒt|d|iddƒƒt|d|iddƒƒ|i|ƒdS(s. insert an author-like element into the entry NRtemailturiR:(R RR@RARR(R4RtdetailRtxauthor((s@/home/sa3ruby/intertwingly.net/code/venus/planet/reconstitute.pytauthorƒs c Cs| p |i odSd}d}|i}|i|ƒ}t|itƒo|iidƒ|_n|idƒ p|ii ƒi dƒdjo!t |iƒ|d%ssutf-8R;thtmliRs text/htmltxhtmlittreetencodingtbodytdivtlanguagesxml:lang((RRAR RRtunicodeR$R.R;R#tfindRRt parseStringtdocumentElementR?Rt HTMLParserRt TreeBuildertparset childNodestnodeTypeRt ELEMENT_NODEtnodeNamet normalizetlent firstChildt TEXT_NODER tsearchtdataRR R R RR@R\( R4RRStbozoRmtxdivRtxcontenttparserRVRZR[((s@/home/sa3ruby/intertwingly.net/code/venus/planet/reconstitute.pyR-“sf 0!      +cCs‡| p| odSt|dd d|ƒ}|id dƒt|dd d|ƒ}|id dƒ|i|ƒ|i|ƒdS( s$ insert geo location into the entry Ns%s:%stgeotlats%fsxmlns:%ss(http://www.w3.org/2003/01/geo/wgs84_pos#tlong(sgeoslats xmlns:geo(sgeoslongs xmlns:geo(RR?R(R4RtRstxlattxlong((s@/home/sa3ruby/intertwingly.net/code/venus/planet/reconstitute.pytlocationÍs c Csè|i}t|d|id|idd ƒƒƒt|d|idd ƒƒt|d|idd ƒƒ|idƒ o3|idƒo#t|d|iidd ƒƒnx'|idgƒD]}t||ƒqÀWt|d|id hƒƒx*|id gƒD]}t|d |ƒqW|id ƒ o`|idƒoPh|idƒd6g|d <|id ƒo|id ƒ|d dd s xmlns:planetR\sxml:langR*R0R,R3R-iRR€Rƒt publishedtpublished_parseds dc_date.takens%s:%stdct date_Takens%ssxmlns:%ss http://purl.org/dc/elements/1.1/R{t feedburnertorigLinks%s_%stwhereR;t coordinatestPointitBoxt LineStringtPolygontgeo_lattgeo_longt georss_points[,\s]t georss_linet georss_circlet georss_boxiitgeorss_polygonR|RR‰RUR}R~R‘RŠR't planet_idN(sdcs date_Takensxmlns:dc(s feedburnerR™(%RR_R`R?tplanettxmlnsR.R\tfeedR'R7RnR*RRR-R@RARJt entry_updatedRCRRRKR#t namespacesRwtfloattretsplitRURŽRt __class__tcopyR‘tversion(RªR5RR4RnR—ROtnsRt xoriglinkRšR;R›R|R~tsrcRt src_authorR((s@/home/sa3ruby/intertwingly.net/code/venus/planet/reconstitute.pyt reconstitutes°    &%&  # '(8(((L(  $  cCs`|df|df|dff}x8|D]0\}}|i|ƒo||o ||Sq(W|S(NR„R•(R.(RªR5tdefaulttchkstnodetfield((s@/home/sa3ruby/intertwingly.net/code/venus/planet/reconstitute.pyR«ks    (%t__doc__R®RCtsgmllibtxml.sax.saxutilsRtxml.domRRthtml5libRthtml5lib.treebuildersRR¨REthashlibRRtcompiletUNICODER RR R R"R&R'R7RJRKRUR-RwR‘R·RAR«(((s@/home/sa3ruby/intertwingly.net/code/venus/planet/reconstitute.pyts4$         : ( j