ó 2škSc@srdZddlZddlZddlmZddlmZmZmZm Z m Z m Z ddddgZ ej d ƒZej d ƒZdefd „ƒYZd efd „ƒYZeedƒrãdejfd„ƒYZnd„Zdefd„ƒYZy ddlmZmZmZWn-ek rQddlmZmZmZnXe sneZe jdƒndS(sž markupsafe ~~~~~~~~~~ Implements a Markup string. :copyright: (c) 2010 by Armin Ronacher. :license: BSD, see LICENSE for more details. iÿÿÿÿN(tMapping(t text_typet string_typest int_typestunichrt iteritemstPY2tMarkupt soft_unicodetescapet escape_silents(|<[^>]*>)s &([^;]+);cBs|eZdZd)Zdd*dd„Zd„Zd„Zd„Zd„Z e Z d„Z d „Z d „Z ej je _d „Zejje_d „Zejje_d „Zejje_d„Zd„Zed„ƒZd„Zx!d+D]Zeeƒeƒe>> Markup("Hello World!") Markup(u'Hello World!') >>> class Foo(object): ... def __html__(self): ... return 'foo' ... >>> Markup(Foo()) Markup(u'foo') If you want object passed being always treated as unsafe you can use the :meth:`escape` classmethod to create a :class:`Markup` object: >>> Markup.escape("Hello World!") Markup(u'Hello <em>World</em>!') Operations on a markup string are markup aware which means that all arguments are passed through the :func:`escape` function: >>> em = Markup("%s") >>> em % "foo & bar" Markup(u'foo & bar') >>> strong = Markup("%(text)s") >>> strong % {'text': 'hacker here'} Markup(u'<blink>hacker here</blink>') >>> Markup("Hello ") + "" Markup(u'Hello <foo>') utstrictcCsPt|dƒr|jƒ}n|dkr:tj||ƒStj||||ƒS(Nt__html__(thasattrR tNoneRt__new__(tclstbasetencodingterrors((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyRFs  cCs|S(N((tself((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyR MscCsJt|tƒst|dƒrF|jtt|ƒj|j|ƒƒƒStS(NR ( t isinstanceRR t __class__tsuperRt__add__R tNotImplemented(Rtother((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyRPs(cCs8t|dƒst|tƒr4|j|ƒj|ƒStS(NR (R RRR RR(RR((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyt__radd__UscCs,t|tƒr(|jtj||ƒƒStS(N(RRRRt__mul__R(Rtnum((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyRZscsYt|tƒr.t‡fd†|Dƒƒ}nt|ˆjƒ}ˆjtjˆ|ƒƒS(Nc3s!|]}t|ˆjƒVqdS(N(t_MarkupEscapeHelperR (t.0tx(R(s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pys bs(RttupleRR RRt__mod__(Rtarg((Rs=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyR"`scCsd|jjtj|ƒfS(Ns%s(%s)(Rt__name__Rt__repr__(R((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyR%gs cCs%|jtj|t|j|ƒƒƒS(N(RRtjointmapR (Rtseq((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyR&mscOs%tt|jtj|||ŽƒƒS(N(tlistR'RRtsplit(Rtargstkwargs((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyR*qscOs%tt|jtj|||ŽƒƒS(N(R)R'RRtrsplit(RR+R,((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyR-uscOs%tt|jtj|||ŽƒƒS(N(R)R'RRt splitlines(RR+R,((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyR.yscs5ddlm‰‡fd†}tj|t|ƒƒS(sÖUnescape markup again into an text_type string. This also resolves known HTML4 and XHTML entities: >>> Markup("Main » About").unescape() u'Main \xbb About' iÿÿÿÿ(t HTML_ENTITIEScs|jdƒ}|ˆkr)tˆ|ƒSyN|d dkrStt|ddƒƒS|jdƒrvtt|dƒƒSWntk rŠnXdS( Niis#xs#Xit#u(s#xs#X(tgroupRtintt startswitht ValueError(tmtname(R/(s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyt handle_match†s  (tmarkupsafe._constantsR/t _entity_retsubR(RR7((R/s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pytunescape~s cCs1djtjd|ƒjƒƒ}t|ƒjƒS(sUnescape markup into an text_type string and strip all tags. This also resolves known HTML4 and XHTML entities. Whitespace is normalized to one: >>> Markup("Main » About").striptags() u'Main \xbb About' u t(R&t _striptags_reR:R*RR;(Rtstripped((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyt striptags”s!cCs)t|ƒ}|j|k r%||ƒS|S(s²Escape the string. Works like :func:`escape` with the difference that for subclasses of :class:`Markup` this function would return the correct subclass. (R R(Rtstrv((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyR Ÿs  cs:tt|ƒ‰‡fd†}ˆj|_ˆj|_|S(NcsStt|ƒt|ƒ|jƒ}t|t|ƒ|jƒ|jˆ|||ŽƒS(N(t_escape_argspecR)t enumerateR RR(RR+R,(torig(s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pytfunc¬s!(tgetattrRR$t__doc__(R6RE((RDs=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pytmake_simple_escaping_wrapperªs   t __getitem__t capitalizettitletlowertuppertreplacetljusttrjusttlstriptrstriptcentertstript translatet expandtabstswapcasetzfillt partitioncCs+tt|jtj||j|ƒƒƒƒS(N(R!R'RRRYR (Rtsep((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyRY¼s cCs+tt|jtj||j|ƒƒƒƒS(N(R!R'RRt rpartitionR (RRZ((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyR[¿s tformatcOsO|d|d}}t|jƒ}t||ƒ}|j|j|||ƒƒS(Nii(tEscapeFormatterR t_MagicFormatMappingRtvformat(R+R,Rt formatter((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyR\ÅscCs|rtdƒ‚n|S(Ns,Unsupported format specification for Markup.(R4(Rt format_spec((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyt__html_format__Ëst __getslice__(N(s __getitem__s capitalizestitleslowersuppersreplacesljustsrjustslstripsrstripscentersstrips translates expandtabssswapcaseszfill(R$t __module__RGt __slots__RRR RRRt__rmul__R"R%R&RR*R-R.R;R?t classmethodR RHtmethodtlocalsR RYR[R\RbRc(((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyRsH*                  R^cBs2eZdZd„Zd„Zd„Zd„ZRS(sÍThis class implements a dummy wrapper to fix a bug in the Python standard library for string formatting. See http://bugs.python.org/issue13598 for information about why this is necessary. cCs||_||_d|_dS(Ni(t_argst_kwargst _last_index(RR+R,((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyt__init__às  cCsa|dkrV|j}|jd7_y|j|SWntk rFnXt|ƒ}n|j|S(NR<i(RlRjt LookupErrortstrRk(Rtkeytidx((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyRIås   cCs t|jƒS(N(titerRk(R((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyt__iter__ðscCs t|jƒS(N(tlenRk(R((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyt__len__ós(R$RdRGRmRIRsRu(((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyR^Øs   R\R]cBseZd„Zd„ZRS(cCs ||_dS(N(R (RR ((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyRmúscCst|dƒr!|j|ƒ}nKt|dƒrT|rEtdƒ‚n|jƒ}ntjj|||ƒ}t|j|ƒƒS(NRbR sSNo format specification allowed when formatting an object with its __html__ method.( R RbR4R tstringt Formattert format_fieldRR (RtvalueRaRA((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyRxýs(R$RdRmRx(((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyR]øs cCsLxE|D]=\}}t|dƒs1t|tƒr||ƒ||scCst|j|jƒƒS(N(RR Rz(R@((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyR|scCst|jt|jƒƒƒS(N(RoR treprRz(R@((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyR|scCs t|jƒS(N(R2Rz(R@((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyR|scCs t|jƒS(N(tfloatRz(R@((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyR|s( R$RdRGRmRIt __unicode__t__str__R%t__int__t __float__(((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyRs     (R R Rtsoft_str( RGtreRvt collectionsRtmarkupsafe._compatRRRRRRt__all__tcompileR=R9RR^R RwR]RBtobjectRtmarkupsafe._speedupsR R Rt ImportErrortmarkupsafe._nativeRƒtappend(((s=/usr/local/lib/python2.7/site-packages/markupsafe/__init__.pyt s(  .¿