+
    DfjF                    *   R t ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RI	H
t
 ^ RIHt ^ RIHtHtHtHtHtHtHtHtHtHtHtHt ^ RIHtHt ^ R	IHt ^ R
IH t  ^ RI!H"t"H#t#H$t$H%t%H&t&H't' ^ RI(H)t)H*t*H+t+ ^ RI,H-t-H.t. ]! R4      t/]t0 ]]1]2]&]"]$]%]]0R3,          ]]0,          ]]0RR3,          ]#]]0,          ]]]0,          ]3]03,          ]-3,          t4 R't5R R lt6R R lt7R R lt8R R lt9R R lt:R(R R llt;R R lt<R R  lt=R! R" lt>R# R$ lt?R% R& lt@R# ))zu
Context-free flattener/serializer for rendering Python objects, possibly
complex or arbitrarily nested, as strings.
)annotations)iscoroutine)BytesIO)exc_info)
extract_tb)GeneratorType)AnyCallable	Coroutine	GeneratorListMappingOptionalSequenceTupleTypeVarUnioncast)DeferredensureDeferred)nativeString)Failure)CDATACharRefCommentTagslotvoidElements)FlattenerErrorUnfilledSlotUnsupportedType)IRenderableIRequestT.Nc                    V ^8  d   QhRRRR/#    datazUnion[bytes, str]returnbytes )formats   "6/usr/lib/python3/dist-packages/twisted/web/_flatten.py__annotate__r-   G   s      ,      c                    \        V \        4      '       d   V P                  R4      p V P                  RR4      P                  RR4      P                  RR4      p V # )a{  
Escape some character or UTF-8 byte data for inclusion in an HTML or XML
document, by replacing metacharacters (C{&<>}) with their entity
equivalents (C{&amp;&lt;&gt;}).

This is used as an input to L{_flattenElement}'s C{dataEscaper} parameter.

@param data: The string to escape.

@return: The quoted form of C{data}.  If C{data} is L{str}, return a utf-8
    encoded string.
utf-8   &s   &amp;   <s   &lt;   >s   &gt;
isinstancestrencodereplacer'   s   &r,   escapeForContentr:   G   sN     ${{7#<<h'//g>FFtWUDKr.   c                    V ^8  d   QhRRRR/# r%   r*   )r+   s   "r,   r-   r-   Z   s      '8 U r.   c                T    \        V \        4      '       d   V P                  R4      # V # )a  
Escape some character or UTF-8 byte data for inclusion in the top level of
an attribute.  L{attributeEscapingDoneOutside} actually passes the data
through unchanged, because L{writeWithAttributeEscaping} handles the
quoting of the text within attributes outside the generator returned by
L{_flattenElement}; this is used as the C{dataEscaper} argument to that
L{_flattenElement} call so that that generator does not redundantly escape
its text output.

@param data: The string to escape.

@return: The string, unchanged, except for encoding.
r0   )r5   r6   r7   r9   s   &r,   attributeEscapingDoneOutsider=   Z   s%     ${{7##Kr.   c                    V ^8  d   QhRRRR/# )r&   writeCallable[[bytes], object]r(   zCallable[[bytes], None]r*   )r+   s   "r,   r-   r-   m   s     , ,$,,r.   c                   a  R V 3R llpV# )a  
Decorate a C{write} callable so that all output written is properly quoted
for inclusion within an XML attribute value.

If a L{Tag <twisted.web.template.Tag>} C{x} is flattened within the context
of the contents of another L{Tag <twisted.web.template.Tag>} C{y}, the
metacharacters (C{<>&"}) delimiting C{x} should be passed through
unchanged, but the textual content of C{x} should still be quoted, as
usual.  For example: C{<y><x>&amp;</x></y>}.  That is the default behavior
of L{_flattenElement} when L{escapeForContent} is passed as the
C{dataEscaper}.

However, when a L{Tag <twisted.web.template.Tag>} C{x} is flattened within
the context of an I{attribute} of another L{Tag <twisted.web.template.Tag>}
C{y}, then the metacharacters delimiting C{x} should be quoted so that it
can be parsed from the attribute's value.  In the DOM itself, this is not a
valid thing to do, but given that renderers and slots may be freely moved
around in a L{twisted.web.template} template, it is a condition which may
arise in a document and must be handled in a way which produces valid
output.  So, for example, you should be able to get C{<y attr="&lt;x /&gt;"
/>}.  This should also be true for other XML/HTML meta-constructs such as
comments and CDATA, so if you were to serialize a L{comment
<twisted.web.template.Comment>} in an attribute you should get C{<y
attr="&lt;-- comment --&gt;" />}.  Therefore in order to capture these
meta-characters, flattening is done with C{write} callable that is wrapped
with L{writeWithAttributeEscaping}.

The final case, and hopefully the much more common one as compared to
serializing L{Tag <twisted.web.template.Tag>} and arbitrary L{IRenderable}
objects within an attribute, is to serialize a simple string, and those
should be passed through for L{writeWithAttributeEscaping} to quote
without applying a second, redundant level of quoting.

@param write: A callable which will be invoked with the escaped L{bytes}.

@return: A callable that writes data with escaping.
c                    V ^8  d   QhRRRR/# )r&   r'   r)   r(   Noner*   )r+   s   "r,   r-   0writeWithAttributeEscaping.<locals>.__annotate__   s     ? ?U ?t ?r.   c                J   < S! \        V 4      P                  R R4      4       R# )   "s   &quot;N)r:   r8   )r'   r?   s   &r,   _write*writeWithAttributeEscaping.<locals>._write   s    t$,,T9=>r.   r*   )r?   rG   s   f r,   writeWithAttributeEscapingrI   m   s    R? ? Mr.   c                    V ^8  d   QhRRRR/# r%   r*   )r+   s   "r,   r-   r-      s     4 4( 4U 4r.   c                t    \        V \        4      '       d   V P                  R4      p V P                  RR4      # )z
Escape CDATA for inclusion in a document.

@param data: The string to escape.

@return: The quoted form of C{data}. If C{data} is unicode, return a utf-8
    encoded string.
r0      ]]>s   ]]]]><![CDATA[>r4   r9   s   &r,   escapedCDATArM      s1     ${{7#<< 233r.   c                    V ^8  d   QhRRRR/# r%   r*   )r+   s   "r,   r-   r-      s      * u r.   c                    \        V \        4      '       d   V P                  R4      p V P                  RR4      p V '       d   V RR R8X  d
   V R,          p V # )a  
Within comments the sequence C{-->} can be mistaken as the end of the comment.
To ensure consistent parsing and valid output the sequence is replaced with C{--&gt;}.
Furthermore, whitespace is added when a comment ends in a dash. This is done to break
the connection of the ending C{-} with the closing C{-->}.

@param data: The string to escape.

@return: The quoted form of C{data}. If C{data} is unicode, return a utf-8
    encoded string.
r0      -->s   --&gt;N   -    r4   r9   s   &r,   escapedCommentrT      sM     ${{7#<<	*DRS	T!Kr.   c               (    V ^8  d   QhRRRRRRRR/# )	r&   namer6   slotDataz-Sequence[Optional[Mapping[str, Flattenable]]]defaultzOptional[Flattenable]r(   Flattenabler*   )r+   s   "r,   r-   r-      s0     ! !
!;! #! 	!r.   c                t    \        V4       F  pVf   K	  W9   g   K  W0,          u # 	  Ve   V# \        V 4      h)zC
Find the value of the named slot in the given stack of slot data.
)reversedr   )rV   rW   rX   	slotFrames   &&& r,   _getSlotValuer]      s>     h'	 T%6?" ( N4  r.   c                    V ^8  d   QhRRRR/# )r&   dzDeferred[T]r(   r*   )r+   s   "r,   r-   r-      s      [ [ r.   c                n   a a \        V 3R l4      oR V3R llpR V3R llpS P                  W4       S# )z
Create a new L{Deferred} based on C{d} that will fire and fail with C{d}'s
result or error, but will not modify C{d}'s callback type.
c                $   < SP                  4       # N)cancel)_r_   s   &r,   <lambda>_fork.<locals>.<lambda>   s    r.   c                    V ^8  d   QhRRRR/# )r&   resultr#   r(   r*   )r+   s   "r,   r-   _fork.<locals>.__annotate__   s       q r.   c                *   < SP                  V 4       V # rb   )callback)rh   d2s   &r,   rk   _fork.<locals>.callback   s    
Fr.   c                    V ^8  d   QhRRRR/# )r&   failurer   r(   r*   )r+   s   "r,   r-   ri      s       W r.   c                *   < SP                  V 4       V # rb   )errback)ro   rl   s   &r,   rq   _fork.<locals>.errback   s    


7r.   )r   addCallbacks)r_   rk   rq   rl   s   f  @r,   _forkrt      s7    
 34B   NN8%Ir.   c               4    V ^8  d   QhRRRRRRRRR	R
RRRR/# )r&   requestOptional[IRequest]rootrY   r?   r@   rW   z)List[Optional[Mapping[str, Flattenable]]]renderFactoryOptional[IRenderable]dataEscaper$Callable[[Union[bytes, str]], bytes]r(   zMGenerator[Union[Generator[Any, Any, Any], Deferred[Flattenable]], None, None]r*   )r+   s   "r,   r-   r-      sX     N$ N$N$
N$ %N$ 8	N$
 )N$ 6N$ SN$r.   c           
   #    a aa"   VVV3R V V3R llloR V3R llp\        V\        \        34      '       d   V! V! V4      4       R	# \        V\        4      '       d.   \	        VP
                  SVP                  4      pS! V4      x  R	# \        V\        4      '       d.   V! R4       V! \        VP                  4      4       V! R4       R	# \        V\        4      '       d.   V! R4       V! \        VP                  4      4       V! R4       R	# \        V\        4      '       Ed   SP                  VP                  4       VP                  pVeb   Vf   \!        R
V R24      hVP#                  R4      p	R	V	n        VP%                  V4      p
V
! S V	4      pS! V4      x  SP'                  4        R	# VP(                  '       g   S! VP*                  4      x  R	# V! R4       \        VP(                  \        4      '       d   VP(                  P-                  R4      pMVP(                  pV! V4       VP.                  P1                  4        Fd  w  r\        V\        4      '       d   VP-                  R4      pV! RV,           R,           4       S! V\2        \5        V4      R7      x  V! R4       Kf  	  VP*                  '       g   \7        V4      \8        9  d:   V! R4       S! VP*                  \:        4      x  V! RV,           R,           4       R	# V! R4       R	# \        V\<        \>        \@        34      '       d   V F  pS! V4      x  K  	  R	# \        V\B        4      '       d.   RVPD                  3,          pV! VP-                  R4      4       R	# \        V\F        4      '       d   V! \I        V4      4      x  R	# \K        V4      '       dP   V! \F        PL                  ! \O        \P        \F        \R        ,          \T        \R        3,          V4      4      4      x  R	# \V        PX                  ! V4      '       d   VP                  S 4      pS! WR7      x  R	# \[        V4      h5i)a  
Make C{root} slightly more flat by yielding all its immediate contents as
strings, deferreds or generators that are recursive calls to itself.

@param request: A request object which will be passed to
    L{IRenderable.render}.

@param root: An object to be made flatter.  This may be of type C{unicode},
    L{str}, L{slot}, L{Tag <twisted.web.template.Tag>}, L{tuple}, L{list},
    L{types.GeneratorType}, L{Deferred}, or an object that implements
    L{IRenderable}.

@param write: A callable which will be invoked with each L{bytes} produced
    by flattening C{root}.

@param slotData: A L{list} of L{dict} mapping L{str} slot names to data
    with which those slots will be replaced.

@param renderFactory: If not L{None}, an object that provides
    L{IRenderable}.

@param dataEscaper: A 1-argument callable which takes L{bytes} or
    L{unicode} and returns L{bytes}, quoted as appropriate for the
    rendering context.  This is really only one of two values:
    L{attributeEscapingDoneOutside} or L{escapeForContent}, depending on
    whether the rendering context is within an attribute or not.  See the
    explanation in L{writeWithAttributeEscaping}.

@return: An iterator that eventually writes L{bytes} to C{write}.
    It can yield other iterators or L{Deferred}s; if it yields another
    iterator, the caller will iterate it; if it yields a L{Deferred},
    the result of that L{Deferred} will be another generator, in which
    case it is iterated.  See L{_flattenTree} for the trampoline that
    consumes said values.
c          
     ,    V ^8  d   QhRRRRRRRRR	R
/# )r&   newRootrY   r{   r|   ry   rz   r?   r@   r(   z@Generator[Union[Flattenable, Deferred[Flattenable]], None, None]r*   )r+   s   "r,   r-   %_flattenElement.<locals>.__annotate__  s;     
 

9
 -
 )	

 
J
r.   c                    < \        SWSW!4      # rb   )_flattenElement)r   r{   ry   r?   rv   rW   s   &&&&r,   	keepGoing"_flattenElement.<locals>.keepGoing  s     WX}
 	
r.   c                    V ^8  d   QhRRRR/# )r&   rh   zDeferred[Flattenable]r(   r*   )r+   s   "r,   r-   r     s     - -4 -9N -r.   c                &   < V P                  S4      # rb   )addCallback)rh   r   s   &r,   keepGoingAsync'_flattenElement.<locals>.keepGoingAsync  s    !!),,r.   s	   <![CDATA[rL   s   <!--rP   Nz$Tag wants to be rendered by method "z)" but is not contained in any IRenderableFr2   asciirR   s   =")r?   rF   r3   s   </s    />z&#%d;)ry   ).r5   r)   r6   r   r]   rV   rX   r   rM   r'   r   rT   r   appendrW   render
ValueErrorclonelookupRenderMethodpoptagNamechildrenr7   
attributesitemsr=   rI   r   r   r:   tuplelistr   r   ordinalr   rt   r   fromCoroutiner   r
   rY   objectr!   
providedByr    )rv   rx   r?   rW   ry   r{   r   	slotValuerendererName	rootClonerenderMethodrh   r   kvelementescapedr   s   f&&f&&           @r,   r   r      sb    b =H/<+0	
 
- - $%%k$ 	D$		!$))Xt||D		""	D%	 	 ll499%&f	D'	"	"gnTYY'(f	D#		&{{#$ :<. I> ?  

5)I#I(;;LIL!'95FF##LLN|||DMM**ddllC((ll))'2GllGgOO))+DA!S!!HHW%$(U"# /7QRW7X  $K , ===L1E$K DMM+;<<%'/D()&M	D5$6	7	7GG$$ 	D'	"	"T\\O+gnnW%&	D(	#	#U4[))	T		""Yx4fkIJDQ
 	

 
			%	%W%33d##s   GQ*DQ*
E6Q*)Q*c               (    V ^8  d   QhRRRRRRRR/# )	r&   rv   rw   rx   rY   r?   r@   r(   rC   r*   )r+   s   "r,   r-   r-   s  s2     E EE'2E;TE	Er.   c           	       aa	a
a"   . o	^ o
R V	V
V3R llpR V	V
V3R llo\        WV. R\        4      .pV'       dN    \        VR,          4      p\        V\        4      '       d   S! 4        VG Rj  xL
 pVP                  V4       KU  S! 4        R#  L   \         d    TP                  4         K~  \         d   p. pT F?  pTP                  f   K  TP                  TP                  P                  R,          4       KA  	  TP                  4        \        Yg\        \        4       ^,          4      4      hRp?ii ; i5i)aY  
Make C{root} into an iterable of L{bytes} and L{Deferred} by doing a depth
first traversal of the tree.

@param request: A request object which will be passed to
    L{IRenderable.render}.

@param root: An object to be made flatter.  This may be of type C{unicode},
    L{bytes}, L{slot}, L{Tag <twisted.web.template.Tag>}, L{tuple},
    L{list}, L{types.GeneratorType}, L{Deferred}, or something providing
    L{IRenderable}.

@param write: A callable which will be invoked with each L{bytes} produced
    by flattening C{root}.

@return: A C{Deferred}-returning coroutine that resolves to C{None}.
c                    V ^8  d   QhRRRR/# )r&   bsr)   r(   rC   r*   )r+   s   "r,   r-   "_flattenTree.<locals>.__annotate__  s      % D r.   c                v   < SP                  V 4       S\        V 4      ,          oS\        8  d
   S! 4        R # R # rb   )r   lenBUFFER_SIZE)r   bufbufSizeflushBuffers   &r,   bufferedWrite#_flattenTree.<locals>.bufferedWrite  s.    

23r7k!M "r.   c                   V ^8  d   QhRR/# )r&   r(   rC   r*   )r+   s   "r,   r-   r     s       r.   c                 R   < S^ 8  d   S! RP                  S 4      4       S R ^ oR# R# )    r.   :NNNN)join)r   r   r?   s   r,   r   !_flattenTree.<locals>.flushBuffer  s+    Q;#((3- AG r.   Nrx   rS   )r   r:   nextr5   r   r   StopIterationr   	Exceptiongi_framef_localsr   r   r   )rv   rx   r?   r   stackr   eroots	generatorr   r   r   s   &&f      @@@r,   _flattenTreer   s  s	    ( CG   	}b$@PQ-E 	"59oG'8,,  '- LL! M ( 	IIK 	FE"	%%1LL!3!3!<!<V!DE # IIK :hjm+DEE	FsS   6E 4B 2B3B 7E B D=0E 3D=<D==D8A$D88D==E c               (    V ^8  d   QhRRRRRRRR/# )	r&   rv   rw   rx   rY   r?   r@   r(   zDeferred[None]r*   )r+   s   "r,   r-   r-     s,     > >>'2>;T>>r.   c                ,    \        \        WV4      4      # )a  
Incrementally write out a string representation of C{root} using C{write}.

In order to create a string representation, C{root} will be decomposed into
simpler objects which will themselves be decomposed and so on until strings
or objects which can easily be converted to strings are encountered.

@param request: A request object which will be passed to the C{render}
    method of any L{IRenderable} provider which is encountered.

@param root: An object to be made flatter.  This may be of type L{str},
    L{bytes}, L{slot}, L{Tag <twisted.web.template.Tag>}, L{tuple},
    L{list}, L{types.GeneratorType}, L{Deferred}, or something that
    provides L{IRenderable}.

@param write: A callable which will be invoked with each L{bytes} produced
    by flattening C{root}.

@return: A L{Deferred} which will be called back with C{None} when C{root}
    has been completely flattened into C{write} or which will be errbacked
    if an unexpected exception occurs.
)r   r   )rv   rx   r?   s   &&&r,   flattenr     s    2 ,we<==r.   c               $    V ^8  d   QhRRRRRR/# )r&   rv   rw   rx   rY   r(   zDeferred[bytes]r*   )r+   s   "r,   r-   r-     s"     $ $- $[ $_ $r.   c                   a \        4       o\        WSP                  4      pVP                  V3R l4       \	        \
        \        ,          V4      # )a  
Collate a string representation of C{root} into a single string.

This is basically gluing L{flatten} to an L{io.BytesIO} and returning
the results. See L{flatten} for the exact meanings of C{request} and
C{root}.

@return: A L{Deferred} which will be called back with a single UTF-8 encoded
    string as its result when C{root} has been completely flattened or which
    will be errbacked if an unexpected exception occurs.
c                $   < SP                  4       # rb   )getvalue)rd   ios   &r,   re   flattenString.<locals>.<lambda>  s    BKKMr.   )r   r   r?   r   r   r   r)   )rv   rx   r_   r   s   && @r,   flattenStringr     s:     
Brxx(AMM)*##r.   i   rb   )A__doc__
__future__r   inspectr   r   r   sysr   	tracebackr   typesr   typingr   r	   r
   r   r   r   r   r   r   r   r   r   twisted.internet.deferr   r   twisted.python.compatr   twisted.python.failurer   twisted.web._stanr   r   r   r   r   r   twisted.web.errorr   r   r    twisted.web.iwebr!   r"   r#   FlattenableRecursiver)   r6   r   rY   r   r:   r=   rI   rM   rT   r]   rt   r   r   r   r   r*   r.   r,   <module>r      s  
 #          < . * N N K K 2CL  			

#$	"D$./!"h+,f6JJK &&,^4(!"&N$bEP>8$r.   