Ñò /èêJc @sÃdZdZddkZddkZd„ZddddfZd „Zddd„ƒYZyddkZ ddk Z Wne j on4Xde i i ifd„ƒYZddd„ƒYZdS(sñ dsml - generate and parse DSMLv1 data (see http://www.oasis-open.org/committees/dsml/) See http://www.python-ldap.org/ for details. $Id: dsml.py,v 1.13 2009/07/14 10:44:13 stroeder Exp $ Python compability note: Tested with Python 2.0+. s2.3.9iÿÿÿÿNcCs%h}x|D]}d||. indent String used for indentiation of next nested level. N(t _output_fileRtmapR tlowert _base64_attrst _dsml_commentt_indent(tselftft base64_attrst dsml_commenttindent((s*/usr/lib64/python2.6/site-packages/dsml.pyt__init__)s  cCsT|io|iiti|ƒƒSyt|dƒWntj odSXdSdS(Nsutf-8ii(Rthas_keyR Rtunicodet UnicodeError(Rt attr_typet attr_value((s*/usr/lib64/python2.6/site-packages/dsml.pyt_needs_base64_encoding<s cCsŒ|iididddd|igƒƒ|ioR|iid|iƒ|iid|i|ifƒ|iid|iƒnd S( s Write the header s s&sDs1s%s s%s N(RtwritetjoinRR(R((s*/usr/lib64/python2.6/site-packages/dsml.pyt writeHeaderGs  cCs+|iid|iƒ|iidƒdS(s Write the footer s%s s N(RR$R(R((s*/usr/lib64/python2.6/site-packages/dsml.pyt writeFooterWscCs|i||ƒS(N(t writeRecord(Rtdntentry((s*/usr/lib64/python2.6/site-packages/dsml.pytunparse^sc Cs|iid|idt|ƒfƒ|id|idgƒƒ}|iid|idƒx/|D]'}|iid|id|fƒqgW|iid |idƒ|iƒ}y|idƒ|idƒWntj onX|iƒxû|D]ó}|iid |id|fƒx®||D]¢}|i ||ƒ}|ot i |ƒ}n t|ƒ}|iid |idd |fƒ|iid |id|fƒ|iid|idfƒq1W|iid|idƒqÿW|iid|idƒdS(s„ dn string-representation of distinguished name entry dictionary holding the LDAP entry {attr:data} s%s it objectclasst objectClasss%s is$%s%s is%s s%s s%s s encoding="base64"s%s%s is%s s%s s%s N( RR$RRtgettkeystremovet ValueErrortsortR#tbase64t encodestring( RR)R*t objectclassestoct attr_typesR!tattr_value_itemtneeds_base64_encoding((s*/usr/lib64/python2.6/site-packages/dsml.pyR(asJ %   !         (t__name__t __module__RR#R&R'R+R((((s*/usr/lib64/python2.6/site-packages/dsml.pyR's    t DSMLv1HandlercBsDeZdZd„Zd„Zd„Zd„Zd„Zd„ZRS(s* Content handler class for DSMLv1 cCs#||_tiiii|ƒdS(N(t_parser_instancetxmltsaxthandlertContentHandlerR(Rtparser_instance((s*/usr/lib64/python2.6/site-packages/dsml.pyR©s cCsdS(N((R((s*/usr/lib64/python2.6/site-packages/dsml.pyt startDocument­scCsdS(N((R((s*/usr/lib64/python2.6/site-packages/dsml.pyt endDocument°scCs |d}|djonî|djo d|_nÔ|djo|d|_h|_n­|djo#|did ƒ|_g|_n}|d jo.d |_|id d ƒiƒd j|_ nB|djo g|_ n(|djo d |_ nt d|‚dS(Nitdsmlsdirectory-entriesiR*R)tattrtnamesutf-8tvalueRtencodingR3R,soc-valuesUnknown tag %s( t_parsing_entriest_dnt_entrytencodet _attr_typet _attr_valuest _attr_valueR.Rt_base64_encodingt_object_classest _oc_valueR1(Rtraw_nametattrsRG((s*/usr/lib64/python2.6/site-packages/dsml.pyt startElement³s&           %    cCsz|d}|djon\|djo d|_nB|djo)|ii|i|iƒ|`|`n |djo#|i|i|i<|`|`nÜ|djoa|ioti |i i ƒƒ}n|i i ƒi dƒ}|ii |ƒ~|` |`nn|d jo|i|id <|`nG|d jo,|ii |ii ƒi dƒƒ|`ntd |‚dS( NiREsdirectory-entriesiR*RFRHsutf-8R,R-soc-valuesUnknown tag %s(RJR=thandleRKRLRORNRQR3t decodestringRPtstripRMtappendRRRSR1(RRTRGR"((s*/usr/lib64/python2.6/site-packages/dsml.pyt endElementÌs8              " cCsR|iidƒo|i||_n(|iidƒo|i||_ndS(NRSRP(t__dict__RRSRP(Rtch((s*/usr/lib64/python2.6/site-packages/dsml.pyt charactersïs ( R:R;t__doc__RRCRDRVR[R^(((s*/usr/lib64/python2.6/site-packages/dsml.pyR<¤s     #t DSMLParsercBs/eZdZddd„Zd„Zd„ZRS(sô Base class for a DSMLv1 parser. Applications should sub-class this class and override method handle() to implement something meaningful. Public class attributes: records_read Counter for records processed so far icCs”||_||_ttti|pgƒƒ|_d|_d|_ t i i ƒ|_ |i it i iidƒ||ƒ}|i i|ƒdS(sa Parameters: input_file File-object to read the DSMLv1 input from ignored_attr_types Attributes with these attribute type names will be ignored. max_entries If non-zero specifies the maximum number of entries to be read from f. line_sep String used as line separator iN(NN(t _input_filet _max_entriesRRR Rt_ignored_attr_typesRt_current_recordt records_readR>R?t make_parsert_parsert setFeatureR@tfeature_namespacestsetContentHandler(Rt input_filetContentHandlerClasstignored_attr_typest max_entriestcontent_handler((s*/usr/lib64/python2.6/site-packages/dsml.pyRs  "   cOs*ddk}|i|ƒ|i|ƒdS(s Process a single content DSMLv1 record. This method should be implemented by applications using DSMLParser. iÿÿÿÿN(tpprint(RtargstkwargsRp((s*/usr/lib64/python2.6/site-packages/dsml.pyRWs  cCs|ii|iƒdS(s5 Continously read and parse DSML records N(RgtparseRa(R((s*/usr/lib64/python2.6/site-packages/dsml.pyRs(sN(R:R;R_RRRWRs(((s*/usr/lib64/python2.6/site-packages/dsml.pyR`øs   (Rs&(Rs<(Rs"(Rs'(((R_t __version__R R3RR RRtxml.saxR>txml.sax.handlert ImportErrorR?R@RAR<R`(((s*/usr/lib64/python2.6/site-packages/dsml.pyt s   tT