)Ej RdZddlmZddlmZmZmZddlmZm Z m Z m Z ddl Z ddl Z ddlZddlZddlZdZejdZdZeejedd d ed d ed ddeZGddeZdZdZdZdZdS)z*xmlWriter.py -- Simple XML authoring class) annotations)BinaryIOCallableTextIO)byteordstrjointobytestostrNz z fontTools.ttx? )  ii)iiceZdZedddfd#dZdZdZd$dZd%dZdZ d&dZ dZ d'dZ dZ dZdZdZdZdZd Zd!Zd"ZdS)( XMLWriterNutf_8 fileOrPath*str | os.PathLike[str] | BinaryIO | TextIO indentwhitestridlefuncCallable[[], None] | Noneencoding newlinestr str | bytesreturnNonec|dddddkrtd|dkr tj}|t |dsTt |ttj fstd||_ t|d|_ d |_nd|_ ||_ d |_ |j d t |_n6#t$r)|j dt$|_YnwxYw|||_|%|tj|_n|||_d |_g|_d |_||_d |_|d|dS)N-_utf8z!Only UTF-8 encoding is supported.writez]fileOrPath must be a file path (str or PathLike) if it isn't an object with a `write` method.wbTFrz&)lowerreplace Exceptionsysstdouthasattr isinstancerosPathLike TypeErrorfilenameopenfile _closeStreamr%r totyper rlinesepr indentlevelstack needindentr idlecounter _writerawnewline)selfrrrrrs JC:\PYTHON\MyICR_Suite\python\Lib\site-packages\fontTools/misc/xmlWriter.py__init__zXMLWriter.__init__s >>   # #C , , 4 4S" = = G G?@@ @   J 4z7++ &j3 *<== s'DMZ..DI $D   DM"DI %D   IOOC !DKK   IOOB   DKKK  ;;{33  "kk"*55DOO"kk*55DO    ?@@@ s&D0D87D8c|SNr?s r@ __enter__zXMLWriter.__enter__Os r'c.|dSrC)close)r?exception_typeexception_value tracebacks r@__exit__zXMLWriter.__exit__Rs r'c|jrCt|jttjfrJ|jdSdSrC)r6r/r5rr0r1rHrEs r@rHzXMLWriter.closeUsN   !$)c2;-?@@ @ @@ IOO       r'TcN|t||dS)z Writes text.indentNr=escape)r?stringrPs r@r%zXMLWriter.writeZs$ vf~~f55555r'c<|d|zdzdS)zWrites text in a CDATA section.z N)r=r?rSs r@ writecdatazXMLWriter.writecdata^s$ {V+e344444r'FcN|t||dS)zWrites a bytes() sequence into the XML, escaping non-ASCII bytes. When this is read in xmlReader, the original bytes can be recovered by encoding to 'latin-1'.)stripN)r= escape8bit)r?datarXs r@ write8bitzXMLWriter.write8bitbs( z$''u55555r'cN|t|ddS)z Writes text without indentation.FrONrQrUs r@write_noindentzXMLWriter.write_noindentis$ vf~~e44444r'c|r5|jr.|j|j|jzd|_||d}|r|}|j|dS)z Writes bytes, possibly indented.rr)rN)r;r5r%r9rr7rX)r?rZrPrXss r@r=zXMLWriter._writerawms}  do IOOD,t/?? @ @ @DO KKwK / /   A r'c|j|jd|_|j}|dzs|j||dz|_dS)Nr(d)r5r%rr;r<r)r?r<s r@r>zXMLWriter.newlinewsZ (((& S  T]%> MMOOO&?r'c&t|}|d}|d|dz|ddD].}||d|z/|ddS)Nrz)rRsplitr=r>)r?rZlineslines r@commentzXMLWriter.commentsd|| 4   wq)***!""I + +D LLNNN NN7T> * * * * vr'cZ|j|i|}d||d}||dS)N)stringifyattrsr=r?_TAG_argskwargsattrdatarZs r@ simpletagzXMLWriter.simpletagsC&4&777!E888, tr'c|j|i|}d||d}|||j||dS)Nrh>)rir=r:appendrPrjs r@begintagzXMLWriter.begintagsd&4&777 5(((+ t %    r'c|jr|jd|ks Jd|jd=|d|z}||dS)Nznonmatching endtagz)r:dedentr=)r?rkrZs r@endtagzXMLWriter.endtags`zKdjn5557K555 JrN  tr'c:d}|dz}d}tdt||D]r}t||||z}d}d}td||D]} ||z|| | |zz}d}|||sdS)Nrr" )rangelenhexStrr=r>) r?rZ linelength hexlinelength chunksizeihexlinerewhitejs r@dumphexzXMLWriter.dumphexs "Q  q#d))Z00  AT!a*n"4566GDE1mY77  e|ga!i-.?&@@ NN4 LLNNNN  r'c$|jdz|_dS)Nr(r9rEs r@rPzXMLWriter.indents+a/r'c>|jdksJ|jdz |_dS)Nrr(rrEs r@rvzXMLWriter.dedents,!####+a/r'c6|r&|rJt|}n"|rt|dksJ|d}ndSd}|D]I\}}t|tt fst |}|d|dt |dz}J|S)Nr(rr"r|z="")sorteditemsr~r/bytesr escapeattr)r?rlrm attributesrZattrvalues r@rizXMLWriter.stringifyattrss  OO8 //JJ  t99>>>>aJJ2% A AKD%eeS\22 #E 4j.?.?.?.?@@DD r') rrrrrrrrrrrr)rr)T)F)TF)__name__ __module__ __qualname__INDENTrArFrLrHr%rVr[r]r=r>rfrorsrwrrPrvrirDr'r@rrsO".2"& 00000d 66665556666555+++    000000r'rct|d}|dd}|dd}|dd}|dd }|t}||krgd }t |}t ||kr"t |d |d d dz}t d|t|S)zQEscape characters not allowed in `XML 1.0 `_.r&z&rhz<rqz> z Nr(ruz...zEIllegal XML character(s) found; replacing offending string %r with %r) r r* translateILLEGAL_XML_CHARSreprr~TTX_LOGwarning REPLACEMENT)rZnewDatamaxLenpreviews r@rRrRs w  D <<W % %D <<V $ $D <<V $ $D <<g & &Dnn.//G$t** t99v  4=))!B$/%7G S     Nr'cPt|}|dd}|S)Nrz")rRr*)rZs r@rrs% $<z&#;)ordr)cns r@ escapecharzescape8bit..escapecharsH FF >>>>c>>>>>aunnH$q''>C' 'r'zlatin-1)rmapdecode)rZrs r@rYrYs7((( 3z4;;y#9#9:: ; ;;r'ctj}d}|D].}t|}|||dz dzz||dzz}/|S)Nr")rS hexdigitsr)r_hrrrs r@rrsTA A // AJJ 16S.! !Aa#gJ . Hr') __doc__ __future__rtypingrrrfontTools.misc.textToolsrrr r r,r0rSlogging itertoolsr getLoggerrrdictfromkeyschainr}robjectrrRrrYrrDr'r@rs00""""""----------EEEEEEEEEEEE   ' O , , MMIO dD dD ff   bbbbbbbbJ, < < <     r'