ó
    ×›‘hÁF  ã                  ó.  • S r SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SSKJr  SSKJrJrJrJrJrJrJrJrJrJrJrJr  SS	KJrJr  SS
KJr  SSKJ r   SSK!J"r"J#r#J$r$J%r%J&r&J'r'  SSK(J)r)J*r*J+r+  SSK,J-r-J.r.  \" S5      r/\r0 \\1\2\&\"\$\%\\0S4   \\0   \\0SS4   \#\\0   \\\0   \3\04   \-4   r4 Sr5SS jr6SS jr7    SS jr8SS jr9SS jr: S        S!S jjr;S"S jr<              S#S jr=        S$S jr>        S%S jr?S&S jr@g)'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.Ni   c                ó¶   • [        U [        5      (       a  U R                  S5      n U R                  SS5      R                  SS5      R                  SS5      n U $ )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©Údatas    ÚXC:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/web/_flatten.pyÚescapeForContentr2   G   sN   € ô �$œ×ÑØ�{‰{˜7Ó#ˆØ�<‰<˜˜hÓ'×/Ñ/°°gÓ>×FÑFÀtÈWÓU€DØ€Kó    c                óR   • [        U [        5      (       a  U R                  S5      $ U $ )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.
r&   )r+   r,   r-   r/   s    r1   ÚattributeEscapingDoneOutsider5   Z   s%   € ô �$œ×ÑØ�{‰{˜7Ó#Ð#Ø€Kr3   c                ó   ^ • SU 4S jjnU$ )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                óH   >• T" [        U 5      R                  SS5      5        g )Nó   "s   &quot;)r2   r.   )r0   Úwrites    €r1   Ú_writeÚ*writeWithAttributeEscaping.<locals>._write–   s   ø€ ÙÔ˜tÓ$×,Ñ,¨T°9Ó=Õ>r3   )r0   ÚbytesÚreturnÚNone© )r9   r:   s   ` r1   ÚwriteWithAttributeEscapingr@   m   s   ø€ ÷R?ð €Mr3   c                ór   • [        U [        5      (       a  U R                  S5      n U R                  SS5      $ )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.
r&   ó   ]]>s   ]]]]><![CDATA[>r*   r/   s    r1   ÚescapedCDATArC   œ   s1   € ô �$œ×ÑØ�{‰{˜7Ó#ˆØ�<‰<˜Ð 2Ó3Ð3r3   c                ó    • [        U [        5      (       a  U R                  S5      n U R                  SS5      n U (       a  U SS S:X  a  U S-  n U $ )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.
r&   ó   -->s   --&gt;éÿÿÿÿNó   -ó    r*   r/   s    r1   ÚescapedCommentrI   ª   sM   € ô �$œ×ÑØ�{‰{˜7Ó#ˆØ�<‰<˜ 	Ó*€DÞ��R�S�	˜TÓ!Ø�‰ˆØ€Kr3   c                óf   • [        U5       H  nUc  M  X;   d  M  X0   s  $    Ub  U$ [        U 5      e)zC
Find the value of the named slot in the given stack of slot data.
)Úreversedr    )ÚnameÚslotDataÚdefaultÚ	slotFrames       r1   Ú_getSlotValuerP   ¾   s>   € ô ˜hÖ'ˆ	ØÓ  TÕ%6Ø‘?Ò"ñ (ð ÑØˆNÜ˜4Ó Ð r3   c                ój   ^ ^• [        U 4S j5      mSU4S jjnSU4S jjnT R                  X5        T$ )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                ó$   >• TR                  5       $ ©N)Úcancel)Ú_Úds    €r1   Ú<lambda>Ú_fork.<locals>.<lambda>Ô   s   ø€ ¨¯©¬r3   c                ó*   >• TR                  U 5        U $ rS   )Úcallback)ÚresultÚd2s    €r1   rZ   Ú_fork.<locals>.callbackÖ   s   ø€ Ø
�‰�FÔØˆr3   c                ó*   >• TR                  U 5        U $ rS   )Úerrback)Úfailurer\   s    €r1   r_   Ú_fork.<locals>.errbackÚ   s   ø€ Ø
�
‰
�7ÔØˆr3   )r[   r$   r=   r$   )r`   r   r=   r   )r   ÚaddCallbacks)rV   rZ   r_   r\   s   `  @r1   Ú_forkrc   Ï   s-   ù€ ô
 Ô3Ó4€B÷÷ð ‡N�N�8Ô%Ø€Ir3   c           
   #  óf  ^ ^^#   • UUU4         SU U4S jjjmSU4S jjn[        U[        [        45      (       a  U" U" U5      5        g[        U[        5      (       a,  [	        UR
                  TUR                  5      nT" U5      v •  g[        U[        5      (       a,  U" S5        U" [        UR                  5      5        U" S5        g[        U[        5      (       a,  U" S5        U" [        UR                  5      5        U" S5        g[        U[        5      (       GaÙ  TR                  UR                  5        UR                  nUb_  Uc  [!        SU S	35      eUR#                  S
5      n	SU	l        UR%                  U5      n
U
" T U	5      nT" U5      v •  TR'                  5         gUR(                  (       d  T" UR*                  5      v •  gU" S5        [        UR(                  [        5      (       a  UR(                  R-                  S5      nOUR(                  nU" U5        UR.                  R1                  5        HX  u  pÞ[        U[        5      (       a  UR-                  S5      nU" SU-   S-   5        T" U[2        [5        U5      S9v •  U" S5        MZ     UR*                  (       d  [7        U5      [8        ;  a0  U" S5        T" UR*                  [:        5      v •  U" SU-   S-   5        gU" S5        g[        U[<        [>        [@        45      (       a  U H  nT" U5      v •  M     g[        U[B        5      (       a(  SURD                  4-  nU" UR-                  S5      5        g[        U[F        5      (       a  U" [I        U5      5      v •  g[K        U5      (       aF  U" [F        RL                  " [O        [P        [F        [R           [T        [R        4   U5      5      5      v •  g[V        RX                  " U5      (       a  UR                  T 5      nT" X±S9v •  g[[        U5      e7f)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                ó    >• [        TXTX!5      $ rS   )Ú_flattenElement)ÚnewRootÚdataEscaperÚrenderFactoryr9   ÚrequestrM   s       €€r1   Ú	keepGoingÚ"_flattenElement.<locals>.keepGoing  s   ø€ ô Ø�W X¨}ó
ð 	
r3   c                ó&   >• U R                  T5      $ rS   )ÚaddCallback)r[   rk   s    €r1   ÚkeepGoingAsyncÚ'_flattenElement.<locals>.keepGoingAsync  s   ø€ Ø×!Ñ! )Ó,Ð,r3   s	   <![CDATA[rB   s   <!--rE   Nz$Tag wants to be rendered by method "z)" but is not contained in any IRenderableFr(   ÚasciirH   s   =")r9   r8   r)   s   </s    />z&#%d;)ri   )
rg   ÚFlattenablerh   ú$Callable[[Union[bytes, str]], bytes]ri   úOptional[IRenderable]r9   úCallable[[bytes], object]r=   z@Generator[Union[Flattenable, Deferred[Flattenable]], None, None])r[   úDeferred[Flattenable]r=   rv   ).r+   r<   r,   r   rP   rL   rN   r   rC   r0   r   rI   r   ÚappendrM   ÚrenderÚ
ValueErrorÚcloneÚlookupRenderMethodÚpopÚtagNameÚchildrenr-   Ú
attributesÚitemsr5   r@   r   r   r2   ÚtupleÚlistr   r   Úordinalr   rc   r   ÚfromCoroutiner   r   rr   Úobjectr"   Ú
providedByr!   )rj   Úrootr9   rM   ri   rh   ro   Ú	slotValueÚrendererNameÚ	rootCloneÚrenderMethodr[   r}   ÚkÚvÚelementÚescapedrk   s   `  `             @r1   rf   rf   â   sˆ  úé € ðb =HØ/<Ø+0ð	
Øð
à9ð
ð -ð
ð )ð	
ð
 
J÷
ñ 
÷-ô �$œ¤˜×%Ñ%Ù‰k˜$ÓÕ Ü	�Dœ$×	Ñ	Ü! $§)¡)¨X°t·|±|ÓDˆ	Ù˜	Ó"Ó"Ü	�Dœ%×	 Ñ	 ÙˆlÔÙŒl˜4Ÿ9™9Ó%Ô&Ùˆf�Ü	�Dœ'×	"Ñ	"ÙˆgŒÙŒn˜TŸY™YÓ'Ô(Ùˆf�Ü	�Dœ#×	Ò	Ø�‰˜Ÿ™Ô&Ø—{‘{ˆØÑ#ØÑ$Ü Ø:¸<¸.ð I>ð ?óð ð Ÿ
™
 5Ó)ˆIØ#ˆIÔØ(×;Ñ;¸LÓIˆLÙ! '¨9Ó5ˆFÙ˜FÓ#Ò#Ø�L‰LŒNØà�|�|Ù˜DŸM™MÓ*Ò*ØáˆdŒÜ�d—l‘l¤C×(Ñ(Ø—l‘l×)Ñ)¨'Ó2‰Gà—l‘lˆGÙˆgŒØ—O‘O×)Ñ)Ö+‰DˆAÜ˜!œS×!Ñ!Ø—H‘H˜WÓ%�Ù�$˜‘(˜UÑ"Ô#ñ ØÔ/Ô7QÐRWÓ7Xñò ñ �$ŽKñ ,ð �=�=œL¨Ó1¼ÓEÙ�$ŒKñ ˜DŸM™MÔ+;Ó<Ò<Ù�%˜'‘/ DÑ(Õ)á�&�Mä	�Dœ5¤$¬Ð6×	7Ñ	7ÛˆGÙ˜GÓ$Ô$ò ä	�Dœ'×	"Ñ	"Ø˜TŸ\™\˜OÑ+ˆÙˆg�n‰n˜WÓ%Õ&Ü	�Dœ(×	#Ñ	#ÙœU 4›[Ó)Ó)Ü	�T×	Ñ	ÙÜ×"Ò"Ü”Yœx¬Ñ4´f¼kÐIÑJÈDÓQóó
ó 	
ô
 
×	Ò	 ×	%Ñ	%Ø—‘˜WÓ%ˆÙ˜Ñ3Ó3ä˜dÓ#Ð#ùs   …P,P1c           	   ƒ  óh  ^^	^
^#   • / m	Sm
SU	U
U4S jjnS	U	U
U4S jjm[        XU/ S[        5      /nU(       aO   [        US   5      n[        U[        5      (       a  T" 5         UI Sh  v•N nUR                  U5        U(       a  MO  T" 5         g N&! [         a    UR                  5          N/[         aw  n/ nU H:  nUR                  c  M  UR                  UR                  R                  S   5        M<     UR                  5         [        Xg[        [        5       S   5      5      eSnAff = f7f)
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}.
r   c                óh   >• TR                  U 5        T[        U 5      -  mT[        :¼  a  T" 5         g g rS   )rw   ÚlenÚBUFFER_SIZE)ÚbsÚbufÚbufSizeÚflushBuffers    €€€r1   ÚbufferedWriteÚ#_flattenTree.<locals>.bufferedWriteŒ  s.   ø€ à�
‰
�2ŒØ”3�r“7ÑˆØ”kÓ!Ù�Mð "r3   c                 óP   >• TS:”  a  T" SR                  T 5      5        T S S 2	 Smg g )Nr   r3   )Újoin)r•   r–   r9   s   €€€r1   r—   Ú!_flattenTree.<locals>.flushBuffer˜  s+   ø€ à�Q‹;Ù�#—(‘(˜3“-Ô Ø’A�Ø‰Gð r3   NrF   r‡   é   )r”   r<   r=   r>   )r=   r>   )rf   r2   Únextr+   r   rw   ÚStopIterationr|   Ú	ExceptionÚgi_frameÚf_localsr   r   r   )rj   r‡   r9   r˜   ÚstackrŽ   ÚeÚrootsÚ	generatorr•   r–   r—   s     `      @@@r1   Ú_flattenTreer§   s  s  ûé € ð( €CØ€G÷ñ ÷ñ ô 	˜ }°b¸$Ô@PÓQð-€Eö ð	"Ü˜5 ™9“oˆGÜ˜'¤8×,Ñ,ñ ”Ø 'Ÿ-�ð �L‰L˜Ô!÷% ˆ%ñ* …Mñ (øÜó 	Ø�I‰IŽKÜó 	FØˆEÛ"�	Ø×%Ñ%Ó1Ø—L‘L ×!3Ñ!3×!<Ñ!<¸VÑ!DÖEñ #ð �I‰IŒKÜ  ¬:´h³jÀ±mÓ+DÓEÐEûð	FüsS   †4D2»/B Á*BÁ+B Á/D2Â	D2ÂB ÂD/Â-D2Â/	D/Â8D*ÃAD*Ä*D/Ä/D2c                ó,   • [        [        XU5      5      $ )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§   )rj   r‡   r9   s      r1   Úflattenr©   »  s   € ô2 œ, w°eÓ<Ó=Ð=r3   c                óœ   ^• [        5       m[        XTR                  5      nUR                  U4S j5        [	        [
        [           U5      $ )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                ó$   >• TR                  5       $ rS   )Úgetvalue)rU   Úios    €r1   rW   ÚflattenString.<locals>.<lambda>å  s   ø€ ˜BŸK™KœMr3   )r   r©   r9   rn   r   r   r<   )rj   r‡   rV   r­   s      @r1   ÚflattenStringr¯   ×  s:   ø€ ô 
‹€BÜ�˜rŸx™xÓ(€AØ‡M�MÔ)Ô*Ü”œ‘ Ó#Ð#r3   )r0   zUnion[bytes, str]r=   r<   )r9   ru   r=   zCallable[[bytes], None]rS   )rL   r,   rM   z-Sequence[Optional[Mapping[str, Flattenable]]]rN   zOptional[Flattenable]r=   rr   )rV   úDeferred[T]r=   r°   )rj   úOptional[IRequest]r‡   rr   r9   ru   rM   z)List[Optional[Mapping[str, Flattenable]]]ri   rt   rh   rs   r=   zMGenerator[Union[Generator[Any, Any, Any], Deferred[Flattenable]], None, None])rj   r±   r‡   rr   r9   ru   r=   r>   )rj   r±   r‡   rr   r9   ru   r=   zDeferred[None])rj   r±   r‡   rr   r=   zDeferred[bytes])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<   r,   r…   rr   r“   r2   r5   r@   rC   rI   rP   rc   rf   r§   r©   r¯   r?   r3   r1   Ú<module>rÀ      sÞ  ðñ
õ #å Ý Ý Ý  Ý ÷÷ ÷ ó ÷ <Ý .Ý *ß N× Nß KÑ Kß 2áˆCƒL€àÐ ðð Ø	ØØØ	ØØØ	Ð
 Ð
#Ñ$ØÐ	ÑØÐ" D¨$Ð.Ñ/ØØÐ!Ñ"ØˆhÐ+Ñ,¨fÐ6JÐJÑKØðñ€ðð €ôô&ð&,Ø$ð,àô,ô^4ôð. &*ð!Ø
ð!à;ð!ð #ð!ð õ	!ô"ð&N$ØðN$à
ðN$ð %ðN$ð 8ð	N$ð
 )ðN$ð 6ðN$ð SôN$ðbEØðEØ'2ðEØ;TðEà	ôEðP>Øð>Ø'2ð>Ø;Tð>àô>õ8$r3   