a _q\'@s6dZddlZddlZddlmZddlmZddlmZddlmZddlmZdd lm Z dd lm Z d Z gd Z e d Ze dZGddde ZGdddeZee drGdddejZddZGdddeZzddlmZmZmZWn(eyddlmZmZmZYn0es2eZe ddS)z markupsafe ~~~~~~~~~~ Implements an escape function and a Markup string to replace HTML special characters with safe representations. :copyright: 2010 Pallets :license: BSD-3-Clause N) int_types) iteritems)Mapping)PY2) string_types) text_type)unichrz1.1.1)Markup soft_unicodeescape escape_silentz(|<[^>]*>)z &([^& ;]+);cseZdZdZdZd.ddZdd Zfd d Zd d ZddZ e Z ddZ ddZ ddZ ej je _ddZejje_ddZejje_ddZejje_ddZddZed d!Zd"d#Zd$D]Zeeee<qd%d&Zd'd(Zd)d*Zd+d,Zeed-r ed-Z[[ZS)/r aA string that is ready to be safely inserted into an HTML or XML document, either because it was escaped or because it was marked safe. Passing an object to the constructor converts it to text and wraps it to mark it safe without escaping. To escape the text, use the :meth:`escape` class method instead. >>> Markup('Hello, World!') Markup('Hello, World!') >>> Markup(42) Markup('42') >>> Markup.escape('Hello, World!') Markup('Hello <em>World</em>!') This implements the ``__html__()`` interface that some frameworks use. Passing an object that implements ``__html__()`` will wrap the output of that method, marking it safe. >>> class Foo: ... def __html__(self): ... return 'foo' ... >>> Markup(Foo()) Markup('foo') This is a subclass of the text type (``str`` in Python 3, ``unicode`` in Python 2). It has the same methods as that type, but all methods escape their arguments and return a ``Markup`` instance. >>> Markup('%s') % 'foo & bar' Markup('foo & bar') >>> Markup('Hello ') + '' Markup('Hello <foo>') NstrictcCs6t|dr|}|dur&t||St||||SN__html__)hasattrrr__new__)clsbaseencodingerrorsrr9/usr/lib64/python3.9/site-packages/markupsafe/__init__.pyrFs   zMarkup.__new__cCs|SNrselfrrrrMszMarkup.__html__cs4t|tst|dr0|tt|||StSr) isinstancerr __class__superr __add__r NotImplementedrotherrrrr PszMarkup.__add__cCs(t|dst|tr$|||StSr)rrrr r r!r"rrr__radd__UszMarkup.__radd__cCs t|tr|t||StSr)rrrr__mul__r!)rZnumrrrr&Zs zMarkup.__mul__cs@t|tr"tfdd|D}n t|j}t|S)Nc3s|]}t|jVqdSr)_MarkupEscapeHelperr ).0xrrr cz!Markup.__mod__..)rtupler'r rr__mod__)rargrrrr-as  zMarkup.__mod__cCsd|jjt|fS)Nz%s(%s))r__name__r__repr__rrrrr0hszMarkup.__repr__cCs|t|t|j|Sr)rrjoinmapr )rseqrrrr1ksz Markup.joincOs$tt|jtj|g|Ri|Sr)listr2rrsplitrargskwargsrrrr5psz Markup.splitcOs$tt|jtj|g|Ri|Sr)r4r2rrrsplitr6rrrr9usz Markup.rsplitcOs$tt|jtj|g|Ri|Sr)r4r2rr splitlinesr6rrrr:zszMarkup.splitlinescs(ddlmfdd}t|t|S)uConvert escaped markup back into a text string. This replaces HTML entities with the characters they represent. >>> Markup('Main » About').unescape() 'Main » About' r HTML_ENTITIEScs|d}|vrt|SzL|dddvrHtt|dddWS|drhtt|ddWSWnty|Yn0|S)Nr)z#xz#X#)groupr int startswith ValueError)mnamer;rr handle_matchs    z%Markup.unescape..handle_match)Z _constantsr< _entity_resubr)rrFrr;runescapes  zMarkup.unescapecCs"dtd|}t|S)u:meth:`unescape` the markup, remove tags, and normalize whitespace to single spaces. >>> Markup('Main » About').striptags() 'Main » About'  r)r1 _striptags_rerHr5r rI)rstrippedrrr striptagsszMarkup.striptagscCst|}|j|ur||S|S)ztEscape a string. Calls :func:`escape` and ensures that for subclasses the correct type is returned. )r r)rsrvrrrr s z Markup.escapecs*tt|fdd}j|_j|_|S)NcsDtt|t||j}t|t||j||g|Ri|Sr)_escape_argspecr4 enumerater rrr6Zorigrrfuncsz1Markup.make_simple_escaping_wrapper..func)getattrrr/__doc__)rErSrrRrmake_simple_escaping_wrappers   z#Markup.make_simple_escaping_wrapper) __getitem__ capitalizetitlelowerupperreplaceljustrjustlstriprstripcenterstrip translate expandtabsswapcasezfillc Cstt|jt|||Sr)r,r2rr partitionr rseprrrrgszMarkup.partitionc Cstt|jt|||Sr)r,r2rr rpartitionr rhrrrrjszMarkup.rpartitioncOs(t|j}t||}|||||Sr)EscapeFormatterr _MagicFormatMappingrZvformat)rr7r8 formatterrrrformats  z Markup.formatcCs|r td|S)Nz,Unsupported format specification for Markup.)rC)r format_specrrr__html_format__szMarkup.__html_format__ __getslice__)rNr) r/ __module__ __qualname__rU __slots__rrr r%r&__rmul__r-r0r1rr5r9r:rIrM classmethodr rVmethodlocalsrgrjrnrprrq __classcell__rrr$rr s@$          r c@s0eZdZdZddZddZddZdd Zd S) rlzThis 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)Nr)_args_kwargs _last_indexr6rrr__init__sz_MagicFormatMapping.__init__cCsN|dkrD|j}|jd7_z |j|WSty:Yn0t|}|j|S)Nrr)r|rz LookupErrorstrr{)rkeyidxrrrrWs  z_MagicFormatMapping.__getitem__cCs t|jSr)iterr{rrrr__iter__sz_MagicFormatMapping.__iter__cCs t|jSr)lenr{rrrr__len__sz_MagicFormatMapping.__len__N)r/rrrsrUr}rWrrrrrrrls  rlrnc@seZdZddZddZdS)rkcCs ||_dSr)r )rr rrrr}szEscapeFormatter.__init__cCsdt|dr||}n@t|drB|r8td|t||}ntj||t |}t | |S)NrprzFormat specifier {0} given, but {1} does not define __html_format__. A class that defines __html__ must define __html_format__ to work with format specifiers.) rrprCrntyperstring Formatter format_fieldrr )rvaluerorOrrrrs    zEscapeFormatter.format_fieldN)r/rrrsr}rrrrrrksrkcCs2|D](\}}t|ds t|tr||||<q|S)z,Helper for various string-wrapped functions.r)rrr)objiterabler rrrrrrPs rPc@sDeZdZdZddZddZddZeZdd Zd d Z d d Z dS)r'zHelper for Markup.__mod__cCs||_||_dSr)rr )rrr rrrr}(sz_MarkupEscapeHelper.__init__cCst|j||jSr)r'rr )ritemrrrrW,sz_MarkupEscapeHelper.__getitem__cCst||jSr)rr rrrrr__str__/sz_MarkupEscapeHelper.__str__cCst|t|jSr)rr reprrrrrrr04sz_MarkupEscapeHelper.__repr__cCs t|jSr)rArrrrr__int__7sz_MarkupEscapeHelper.__int__cCs t|jSr)floatrrrrr __float__:sz_MarkupEscapeHelper.__float__N) r/rrrsrUr}rWrZ __unicode__r0rrrrrrr'%sr')r r r soft_str) rUrerZ_compatrrrrrrr __version____all__compilerKrGr rlrrrkrPobjectr'Z _speedupsr r r ImportErrorZ_nativerappendrrrrs6          E