Ë
    bQbjÖd  ã                  ó¤  — d Z ddlmZ ddlZddlZddlZddlZddlmZm	Z	 ddl
mZmZ ddlmZ  ej                  e«      ZdZe G d„ d	«      «       Ze G d
„ d«      «       Ze G d„ d«      «       Z G d„ de«      Ze G d„ d«      «       Zd"d„Zd#d„Zd$d„Zd%d„Zd&d„Zd'd„Z G d„ d«      Zd(d„Z d)d„Z!d*d„Z"d+d,d„Z# G d„ d«      Z$ G d „ d!«      Z%y)-a#  High-level script-module helpers for the WebDriver BiDi script module.

This module is copied verbatim into the generated ``selenium.webdriver.common.bidi``
package by Bazel (see ``create-bidi-src`` in ``py/BUILD.bazel``).  The generated
``script`` module re-exports the public classes and instantiates the registries,
which layer the cross-binding BiDi API design's handler surface on top of the
CDDL-generated low-level commands:

- :class:`LogHandlerRegistry` owns a single ``log.entryAdded`` subscription and
  routes entries to console and JavaScript-error handlers.  Handlers registered
  through the doc-aligned ``add_console_handler`` / ``add_error_handler`` receive
  :class:`ConsoleMessage` / :class:`ScriptError` payloads carrying source URL,
  line and column numbers extracted from the BiDi stack trace; handlers
  registered through the longer-standing ``add_console_message_handler`` /
  ``add_javascript_error_handler`` keep receiving the generated log-entry
  dataclasses unchanged.
- :class:`DomMutationRegistry` owns the DOM-observation preload script and the
  ``script.message`` channel subscription, and dispatches :class:`DomMutation`
  payloads.  Beyond attribute changes it can observe ``childList`` and
  ``characterData`` mutations on request.
- :class:`PinnedScript` and :class:`ScriptResult` implement the design doc's
  pinned-script surface: ``pin()`` returns a :class:`PinnedScript` (a ``str``
  subclass, so code treating it as a plain script ID keeps working) and
  ``execute(pinned, code)`` returns a non-raising :class:`ScriptResult`.
é    )ÚannotationsN)ÚCallableÚIterable)Ú	dataclassÚfield)ÚAnya•	  function observeMutations(channel, options) {
  const config = options || { attributes: true }
  const idFor = (element) => {
    let id = element.dataset.__webdriver_id
    if (!id) {
      id = Math.random().toString(36).substring(2) + Date.now().toString(36)
      element.dataset.__webdriver_id = id
    }
    return id
  }
  const describeNode = (node) => {
    const description = { nodeType: node.nodeType, nodeName: node.nodeName }
    if (node.nodeType === Node.ELEMENT_NODE) {
      description.id = idFor(node)
    } else {
      description.value = node.nodeValue
    }
    return description
  }
  const observer = new MutationObserver((mutations) => {
    for (const mutation of mutations) {
      switch (mutation.type) {
        case 'attributes': {
          if (!config.attributes) break
          // Don't report our own attribute has changed.
          if (mutation.attributeName === 'data-__webdriver_id') break
          channel(JSON.stringify({
            type: 'attributes',
            target: idFor(mutation.target),
            name: mutation.attributeName,
            value: mutation.target.getAttribute(mutation.attributeName),
            oldValue: mutation.oldValue,
          }))
          break
        }
        case 'childList': {
          if (!config.childList) break
          channel(JSON.stringify({
            type: 'childList',
            target: mutation.target.nodeType === Node.ELEMENT_NODE ? idFor(mutation.target) : null,
            addedNodes: Array.from(mutation.addedNodes, describeNode),
            removedNodes: Array.from(mutation.removedNodes, describeNode),
          }))
          break
        }
        case 'characterData': {
          if (!config.characterData) break
          const parent = mutation.target.parentElement
          channel(JSON.stringify({
            type: 'characterData',
            target: parent ? idFor(parent) : null,
            value: mutation.target.data,
            oldValue: mutation.oldValue,
          }))
          break
        }
        default:
          break
      }
    }
  })
  const observeInit = { subtree: true }
  if (config.attributes) {
    observeInit.attributes = true
    observeInit.attributeOldValue = true
  }
  if (config.childList) {
    observeInit.childList = true
  }
  if (config.characterData) {
    observeInit.characterData = true
    observeInit.characterDataOldValue = true
  }
  observer.observe(document, observeInit)
}
c                  óf   — e Zd ZU dZdZded<   dZded<   dZded<   dZded<   dZ	ded	<   dZ
d
ed<   y)ÚScriptErroraÌ  A JavaScript error observed in the browser.

    Attributes:
        message: The error message.
        source: Source file/URL where the error occurred (top stack frame).
        line_number: Line number of the error.
        column_number: Column number of the error.
        stack_trace: Formatted stack trace, one ``at function (url:line:col)``
            line per frame.
        timestamp: Time the entry was generated, in milliseconds since epoch.
    Nú
str | NoneÚmessageÚsourceú
int | NoneÚline_numberÚcolumn_numberÚstack_traceúfloat | NoneÚ	timestamp)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__annotations__r   r   r   r   r   © ó    úb/var/www/html/venv/lib/python3.12/site-packages/selenium/webdriver/common/bidi/_script_handlers.pyr
   r
   �   sE   … ñ
ð €GˆZÓØ€FˆJÓØ"€K�Ó"Ø $€M�:Ó$Ø"€K�Ó"Ø"€Iˆ|Ô"r   r
   c                  ó�   — e Zd ZU dZdZded<   dZded<   dZded<   dZded<   dZ	ded	<   dZ
ded
<   dZded<   dZded<   dZded<   y)ÚConsoleMessagea�  A console message observed in the browser.

    Attributes:
        level: Console level (``debug``, ``info``, ``warn`` or ``error``).
        text: The console message text.
        source: Source file/URL the message originated from (top stack frame).
        line_number: Line number where the message originated.
        column_number: Column number where the message originated.
        stack_trace: Formatted stack trace where available.
        timestamp: Time the entry was generated, in milliseconds since epoch.
        method: The console method used (e.g. ``log``, ``warn``).
        args: The raw BiDi RemoteValue arguments passed to the console call.
    Nr   ÚlevelÚtextr   r   r   r   r   r   r   Úmethodzlist[Any] | NoneÚargs)r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r   r   r   r   r   £   sd   … ñð €Eˆ:ÓØ€Dˆ*ÓØ€FˆJÓØ"€K�Ó"Ø $€M�:Ó$Ø"€K�Ó"Ø"€Iˆ|Ó"Ø€FˆJÓØ!€DÐ
Ô!r   r   c                  ó<   — e Zd ZU dZdZded<   dZded<   dZded<   y)	ÚScriptResultaZ  Result of executing a pinned script, without raising on failure.

    Attributes:
        value: The BiDi RemoteValue result of the execution, or ``None``
            when the script raised.
        error: A :class:`ScriptError` describing the failure, or ``None``
            on success.
        realm: The realm the script was executed in.
    Nz
Any | NoneÚvaluezScriptError | NoneÚerrorr   Úrealm)r   r   r   r   r$   r   r%   r&   r   r   r   r#   r#   ¾   s(   … ñð €Eˆ:ÓØ $€EÐÓ$Ø€Eˆ:Ôr   r#   c                  ód   ‡ — e Zd ZdZddˆ fd„Zed	d„«       Zed
d„«       Zed
d„«       Zd	d„Z	ˆ xZ
S )ÚPinnedScripta%  Identifier of a pinned script, as returned by ``Script.pin()``.

    Subclasses ``str`` so existing code that treats the return value of
    ``pin()`` as a plain script ID string keeps working, while exposing the
    cross-binding API design's ``id``, ``source`` and ``realm`` properties.
    c                óD   •— t         ‰| �  | |«      }||_        ||_        |S ©N)ÚsuperÚ__new__Ú_sourceÚ_realm)ÚclsÚ	script_idr   r&   ÚinstanceÚ	__class__s        €r   r,   zPinnedScript.__new__×   s'   ø€ Ü‘7‘? 3¨	Ó2ˆØ!ˆÔØˆŒØˆr   c                ó   — t        | «      S )z+The unique identifier of the pinned script.)Ústr©Úselfs    r   ÚidzPinnedScript.idÝ   s   € ô �4‹yÐr   c                ó   — | j                   S )z1The JavaScript source the script was pinned with.)r-   r5   s    r   r   zPinnedScript.sourceâ   s   € ð �|‰|Ðr   c                ó   — | j                   S )z5The realm the script is associated with, where known.)r.   r5   s    r   r&   zPinnedScript.realmç   s   € ð �{‰{Ðr   c                óN   — dt         j                  | «      › d| j                  ›d�S )NzPinnedScript(id=z, realm=ú))r4   Ú__repr__r.   r5   s    r   r<   zPinnedScript.__repr__ì   s%   € Ø!¤#§,¡,¨tÓ"4Ð!5°X¸d¿k¹k¸_ÈAÐNÐNr   )NN)r0   r4   r   r   r&   r   )Úreturnr4   )r=   r   )r   r   r   r   r,   Úpropertyr7   r   r&   r<   Ú__classcell__)r2   s   @r   r(   r(   Ï   sO   ø„ ñöð òó ðð òó ðð òó ð÷Or   r(   c                  óž   — e Zd ZU dZdZded<   dZded<   dZded<   dZded<   dZ	ded<   dZ
ded	<    ee¬
«      Zded<    ee¬
«      Zded<   y)ÚDomMutationaÂ  Represents a DOM mutation event from add_dom_mutation_handler.

    Attributes:
        element_id: The ``data-__webdriver_id`` attribute value set on the
            mutated element by the MutationObserver. Use this to locate the
            element from the main thread if needed.  For ``characterData``
            mutations this identifies the parent element of the text node.
        attribute_name: The name of the changed attribute (``attributes``
            mutations only).
        current_value: The value after the mutation (attribute value or
            character data; ``None`` if the attribute was removed).
        old_value: The value before the mutation.
        type: The mutation type: ``attributes``, ``childList`` or
            ``characterData``.
        target: Same identifier as ``element_id``; named per the
            cross-binding BiDi API design.
        added_nodes: Node descriptors added by a ``childList`` mutation.
            Element descriptors carry ``nodeType``/``nodeName``/``id``
            (a ``data-__webdriver_id`` value); other nodes carry
            ``nodeType``/``nodeName``/``value``.
        removed_nodes: Node descriptors removed by a ``childList`` mutation.
    Nr   Ú
element_idÚattribute_nameÚcurrent_valueÚ	old_valueÚtypeÚtarget)Údefault_factoryz	list[Any]Úadded_nodesÚremoved_nodes)r   r   r   r   rB   r   rC   rD   rE   rF   rG   r   ÚlistrI   rJ   r   r   r   rA   rA   ð   sc   … ñð. "€J�
Ó!Ø!%€N�JÓ%Ø $€M�:Ó$Ø €IˆzÓ Ø€Dˆ*ÓØ€FˆJÓÙ"°4Ô8€K�Ó8Ù$°TÔ:€M�9Ô:r   rA   c                ó´   — t        | t        «      rB| j                  d«      }t        |t        «      r!|D �cg c]  }t        |t        «      sŒ|‘Œ c}S g S c c}w )NÚ
callFrames)Ú
isinstanceÚdictÚgetrK   )r   ÚframesÚframes      r   Ú_stack_framesrS     sI   € Ü�+œtÔ$Ø—‘ Ó.ˆÜ�fœdÔ#Ø'-ÖI˜e´¸EÄ4Õ1H’EÒIÐIØ€Iùò Js   ¶AÁAc                ó  — t        | «      }|sy g }|D ]b  }|j                  d«      xs d}|j                  d|› d|j                  d«      › d|j                  d«      › d|j                  d«      › d	�	«       Œd d
j                  |«      S )NÚfunctionNamez<anonymous>z    at z (Úurlú:Ú
lineNumberÚcolumnNumberr;   ú
)rS   rP   ÚappendÚjoin)r   rQ   ÚlinesrR   Únames        r   Ú_format_stack_tracer_     s—   € Ü˜;Ó'€FÙØØ€EØò rˆØ�y‰y˜Ó(Ò9¨MˆØ�‰�w˜t˜f B u§y¡y°Ó'7Ð&8¸¸%¿)¹)ÀLÓ:QÐ9RÐRSÐTY×T]ÑT]Ð^lÓTmÐSnÐnoÐpÕqðrð �9‰9�UÓÐr   c                ó�  — t        | j                  d«      «      }|r|d   ni }t        | j                  d«      | j                  d«      |j                  d«      |j                  d«      |j                  d«      t        | j                  d«      «      | j                  d«      | j                  d	«      | j                  d
«      ¬«	      S )zCBuild a :class:`ConsoleMessage` from raw ``log.entryAdded`` params.Ú
stackTracer   r   r   rV   rX   rY   r   r    r!   )	r   r   r   r   r   r   r   r    r!   )rS   rP   r   r_   ©ÚparamsrQ   Útops      r   Úconsole_message_from_log_entryre   &  sŸ   € ä˜6Ÿ:™: lÓ3Ó4€FÙˆ&�Š) 2€CÜØ�j‰j˜Ó!Ø�Z‰Z˜ÓØ�w‰w�u‹~Ø—G‘G˜LÓ)Ø—g‘g˜nÓ-Ü'¨¯
©
°<Ó(@ÓAØ—*‘*˜[Ó)Ø�z‰z˜(Ó#Ø�Z‰Z˜Óô
ð 
r   c                ó0  — t        | j                  d«      «      }|r|d   ni }t        | j                  d«      |j                  d«      |j                  d«      |j                  d«      t        | j                  d«      «      | j                  d«      ¬«      S )	z@Build a :class:`ScriptError` from raw ``log.entryAdded`` params.ra   r   r   rV   rX   rY   r   )r   r   r   r   r   r   ©rS   rP   r
   r_   rb   s      r   Úscript_error_from_log_entryrh   7  s{   € ä˜6Ÿ:™: lÓ3Ó4€FÙˆ&�Š) 2€CÜØ—
‘
˜6Ó"Ø�w‰w�u‹~Ø—G‘G˜LÓ)Ø—g‘g˜nÓ-Ü'¨¯
©
°<Ó(@ÓAØ—*‘*˜[Ó)ôð r   c                ó  — t        | j                  d«      «      }|r|d   ni }t        | j                  d«      |j                  d«      | j                  d«      | j                  d«      t        | j                  d«      «      ¬«      S )zCBuild a :class:`ScriptError` from BiDi ``script.ExceptionDetails``.ra   r   r   rV   rX   rY   )r   r   r   r   r   rg   )ÚdetailsrQ   rd   s      r   Ú#script_error_from_exception_detailsrk   E  so   € ä˜7Ÿ;™; |Ó4Ó5€FÙˆ&�Š) 2€CÜØ—‘˜FÓ#Ø�w‰w�u‹~Ø—K‘K Ó-Ø—k‘k .Ó1Ü'¨¯©°LÓ(AÓBôð r   c                óR  — | j                  d«      }|€dn
t        |«      }t        || j                  d«      | j                  d«      | j                  d«      | j                  dd«      |t        | j                  d«      xs g «      t        | j                  d	«      xs g «      ¬
«      S )zFBuild a :class:`DomMutation` from a mutation-listener channel payload.rG   Nr^   r$   ÚoldValuerF   Ú
attributesÚ
addedNodesÚremovedNodes)rB   rC   rD   rE   rF   rG   rI   rJ   )rP   r4   rA   rK   )ÚpayloadrG   Ú	target_ids      r   Údom_mutation_from_payloadrs   R  s�   € à�[‰[˜Ó"€FØ˜‘¬C°«K€IÜØØ—{‘{ 6Ó*Ø—k‘k 'Ó*Ø—+‘+˜jÓ)Ø�[‰[˜ Ó.ØÜ˜Ÿ™ \Ó2Ò8°bÓ9Ü˜7Ÿ;™; ~Ó6Ò<¸"Ó=ô	ð 	r   c                  ó    — e Zd ZdZdd„Zdd„Zy)Ú	_EventRefz@Minimal event wrapper accepted by WebSocketConnection callbacks.c                ó   — || _         y r*   )Úevent_class)r6   rw   s     r   Ú__init__z_EventRef.__init__e  s
   € Ø&ˆÕr   c                ó   — |S r*   r   )r6   rc   s     r   Ú	from_jsonz_EventRef.from_jsonh  s   € Øˆr   N)rw   r4   r=   ÚNone)rc   r   r=   r   )r   r   r   r   rx   rz   r   r   r   ru   ru   b  s   „ ÙJó'ôr   ru   c                ó„   — ddl m}  || «      j                  |g«      }t        |t        «      r|j                  d«      S d S )Nr   ©ÚSessionÚsubscription)Ú&selenium.webdriver.common.bidi.sessionr~   Ú	subscriberN   rO   rP   )ÚconnÚeventr~   Úresults       r   Ú_subscribe_to_eventr…   l  s8   € Ý>á�T‹]×$Ñ$ e WÓ-€FÜ)3°F¼DÔ)Aˆ6�:‰:�nÓ%ÐKÀtÐKr   c                ór   — ddl m}  || «      }|r|j                  |g¬«       y |j                  |g¬«       y )Nr   r}   )Úsubscriptions)Úevents)r€   r~   Úunsubscribe)r‚   rƒ   Úsubscription_idr~   Úsessions        r   Ú_unsubscribe_from_eventrŒ   s  s8   € Ý>á�d‹m€GÙØ×Ñ¨?Ð*;ÐÕ<à×Ñ E 7ÐÕ+r   c                óÖ   — ddl m} dddœj                  | j                  d«      «      }|r-t        ||d«      }|�t	        |d«      r	 |j                  | «      S | S # t        $ r Y | S w xY w)	zDDeserialize raw log params into the generated log-entry dataclasses.r   )ÚlogÚConsoleLogEntryÚJavascriptLogEntry)ÚconsoleÚ
javascriptrF   Nrz   )Úselenium.webdriver.common.bidirŽ   rP   ÚgetattrÚhasattrrz   Ú	Exception)rc   Úlog_modÚcls_namer/   s       r   Ú_legacy_log_entryr™   }  s{   € å=à,Ð<PÑQ×UÑUÐV\×V`ÑV`ÐagÓVhÓi€HÙÜ�g˜x¨Ó.ˆØˆ?œw s¨KÔ8ðØ—}‘} VÓ,Ð,ð €Møô ò ØØ€Mðús   ÁA Á	A(Á'A(c                ól  — t        |t        «      r|j                  nd}d|xs dz   dz   |xs dz   dz   }|€$t        | dd«      �	 | j                  j
                  }|rd|ini }| j                  |d|¬	«      }t        |t        «      r’|j                  d
«      }|j                  d«      dk(  r<|j                  d«      }	t        |	t        «      r|	ni }	t        dt        |	«      |¬«      S |j                  d«      dk(  rt        |j                  d«      d|¬«      S t        |dd¬«      S # t        $ r Y Œ×w xY w)aš  Execute ``code`` with a pinned script's source in scope.

    The pinned source and the code are wrapped into a single function and
    evaluated via ``script.callFunction`` in the given (or current) browsing
    context, so functions declared by the pinned source are callable from
    ``code``.  Unlike ``Script.execute``, failures do not raise: they are
    reported through :attr:`ScriptResult.error`.
    Nzfunction() {
Ú rZ   z
}Ú_driverÚcontextT)Úfunction_declarationÚawait_promiserG   r&   rF   Ú	exceptionÚexceptionDetails)r$   r%   r&   Úsuccessr„   )rN   r(   r   r”   rœ   Úcurrent_window_handler–   Úcall_functionrO   rP   r#   rk   )
ÚscriptÚpinnedÚcodeÚ
context_idr   ÚdeclarationrG   Úrawr&   rj   s
             r   Úexecute_pinnedr«   Œ  s:  € ô )¨´Ô>ˆV�]Š]ÀD€FØ" f¢l°Ñ3°dÑ:¸dºjÀbÑIÈEÑQ€KØÐœg f¨i¸Ó>ÐJð	ØŸ™×=Ñ=ˆJñ )3ˆi˜Ñ$¸€FØ
×
Ñ
Ø(ØØð ó €Cô
 �#”tÔØ—‘˜Ó ˆØ�7‰7�6‹?˜kÒ)Ø—g‘gÐ0Ó1ˆGÜ!+¨G´TÔ!:‘gÀˆGÜ dÔ2UÐV]Ó2^ÐfkÔlÐlØ�7‰7�6‹?˜iÒ'Ü c§g¡g¨hÓ&7¸tÈ5ÔQÐQÜ˜c¨°TÔ:Ð:øô! ò 	Ùð	ús   ÁD' Ä'	D3Ä2D3c                  óJ   — e Zd ZdZdZdZdZedediZdd„Zddd„Z	dd„Z
dd	„Zy
)ÚLogHandlerRegistryaÛ  Routes ``log.entryAdded`` events to console and error handlers.

    All console and JavaScript-error handlers share one BiDi session
    subscription, created when the first handler is added and removed when
    the last one is removed.  Each handler is tracked under a category
    (``console`` or ``error``) so ``clear_console_handlers`` /
    ``clear_error_handlers`` can remove every handler of that category,
    regardless of which ``add_*`` method registered it.
    zlog.entryAddedr‘   r%   r’   c                ó`   — || _         t        j                  «       | _        d | _        i | _        y r*   )Ú_scriptÚ	threadingÚLockÚ_lockÚ_subscription_idÚ_categories©r6   r¥   s     r   rx   zLogHandlerRegistry.__init__½  s'   € ØˆŒÜ—^‘^Ó%ˆŒ
Ø,0ˆÔØ+-ˆÕr   c                óÐ  ‡ ‡‡‡‡— ‰ j                   ‰   Šdˆˆˆˆˆ fd„}‰ j                  j                  }‰ j                  5  |j	                  t        ‰ j                  «      |«      }‰ j                  s	 t        |‰ j                  «      ‰ _	        ‰‰ j                  |<   ddd«       |S # t        $ r' |j                  t        ‰ j                  «      |«       ‚ w xY w# 1 sw Y   S xY w)aÄ  Register a handler and subscribe to ``log.entryAdded`` if needed.

        Args:
            callback: User callback invoked with the shaped payload.
            category: ``console`` or ``error``.
            legacy: When ``True`` the callback receives the generated
                ``ConsoleLogEntry`` / ``JavascriptLogEntry`` dataclasses;
                otherwise it receives :class:`ConsoleMessage` /
                :class:`ScriptError`.
        c                óÈ   •— t        | t        «      r| j                  d«      ‰k7  ry ‰rt        | «      }n&‰‰j                  k(  rt        | «      }nt        | «      } ‰|«       y )NrF   )rN   rO   rP   r™   ÚCONSOLEre   rh   )rc   rq   ÚcallbackÚcategoryÚ
entry_typeÚlegacyr6   s     €€€€€r   Ú	_dispatchz1LogHandlerRegistry.add_handler.<locals>._dispatchÐ  sU   ø€ Ü˜f¤dÔ+¨v¯z©z¸&Ó/AÀZÒ/OØÙÜ+¨FÓ3‘Ø˜TŸ\™\Ò)Ü8¸Ó@‘ä5°fÓ=�Ù�WÕr   N)rc   r   r=   r{   )Ú_CATEGORY_ENTRY_TYPESr¯   Ú_connr²   Úadd_callbackru   ÚEVENTr´   r…   r³   r–   Úremove_callback)r6   r¹   rº   r¼   r½   r‚   Úcallback_idr»   s   ````   @r   Úadd_handlerzLogHandlerRegistry.add_handlerÃ  sÒ   ü€ ð ×/Ñ/°Ñ9ˆ
÷		ñ 		ð �|‰|×!Ñ!ˆØ�Z‰Zñ 	5Ø×+Ñ+¬I°d·j±jÓ,AÀ9ÓMˆKØ×#Ò#ðÜ,?ÀÀdÇjÁjÓ,Q�DÔ)ð -5ˆD×Ñ˜[Ñ)÷	5ð Ðøô	 !ò Ø×(Ñ(¬°4·:±:Ó)>ÀÔLØðú÷	5ð Ðús$   Á2CÁ4B(ÂCÂ(0CÃCÃC%c                ó`  — | j                   j                  }|j                  t        | j                  «      |«       | j
                  5  | j                  j                  |d«      }|�4| j                  s(t        || j                  | j                  «       d| _	        ddd«       y# 1 sw Y   yxY w)zCRemove a handler; drops the session subscription with the last one.N)
r¯   r¿   rÂ   ru   rÁ   r²   r´   ÚpoprŒ   r³   ©r6   rÃ   r‚   Úremoveds       r   Úremove_handlerz!LogHandlerRegistry.remove_handlerç  sŠ   € à�|‰|×!Ñ!ˆØ×ÑœY t§z¡zÓ2°KÔ@Ø�Z‰Zñ 	-Ø×&Ñ&×*Ñ*¨;¸Ó=ˆGØÐ"¨4×+;Ò+;Ü'¨¨d¯j©j¸$×:OÑ:OÔPØ(,�Ô%÷		-÷ 	-ñ 	-ús   ÁAB$Â$B-c                óæ   — | j                   5  | j                  j                  «       D ��cg c]  \  }}||k(  sŒ|‘Œ }}}ddd«       D ]  }| j                  |«       Œ yc c}}w # 1 sw Y   Œ(xY w)z3Remove every handler registered under ``category``.N)r²   r´   ÚitemsrÉ   )r6   rº   rÃ   ÚcatÚidss        r   Úclear_handlersz!LogHandlerRegistry.clear_handlersñ  su   € à�Z‰Zñ 	dØ7;×7GÑ7G×7MÑ7MÓ7O×cÑ#3 ;°ÐSVÐZbÓSb’;ÐcˆCÑc÷	dàò 	-ˆKØ×Ñ Õ,ñ	-ùó d÷	dð 	dús    �A'«A!¹A!½A'Á!A'Á'A0N©r¥   r   r=   r{   )F)r¹   r   rº   r4   r¼   Úboolr=   Úint©rÃ   rÑ   r=   r{   )rº   r4   r=   r{   )r   r   r   r   rÁ   r¸   ÚERRORr¾   rx   rÄ   rÉ   rÎ   r   r   r   r­   r­   ­  s<   „ ñð €EØ€GØ€EØ$ i°¸ÐEÐó.ô"óH-ô-r   r­   c                  óf   — e Zd ZdZdZdZdZdd„Zdd„Zdd„Z	dd„Z
dd	„Zddd„Zdd„Zdd„Zdd„Zy
)ÚDomMutationRegistrya  Owns the DOM-observation preload script and channel subscription.

    The first handler installs a preload script observing the requested
    mutation types and subscribes to ``script.message``; later handlers that
    request additional mutation types install one further observer covering
    only the missing types, so no mutation is reported twice.  Each handler
    only receives the mutation types it asked for.  When the last handler is
    removed the subscription and every observer preload script are removed.
    zscript.message)rn   Ú	childListÚcharacterData)rn   c                óš   — || _         t        j                  «       | _        d | _        d | _        i | _        g | _        t        «       | _	        y r*   )
r¯   r°   r±   r²   Ú_channelr³   Ú	_handlersÚ_preload_script_idsÚsetÚ_active_typesrµ   s     r   rx   zDomMutationRegistry.__init__  s?   € ØˆŒÜ—^‘^Ó%ˆŒ
Ø$(ˆŒØ,0ˆÔØ46ˆŒØ.0ˆÔ Ü'*£uˆÕr   c                ó  — |€t        | j                  «      S t        |t        «      r|f}t        |«      }|t	        | j
                  «      z
  }|r$t        dt        |«      › d| j
                  › �«      ‚|st        d«      ‚|S )Nz!Unsupported DOM mutation type(s) z; expected a subset of z3mutation_types must name at least one mutation type)Ú	frozensetÚDEFAULT_MUTATION_TYPESrN   r4   rÜ   ÚMUTATION_TYPESÚ
ValueErrorÚsorted)r6   Úmutation_typesÚtypesÚunknowns       r   Ú_normalize_typesz$DomMutationRegistry._normalize_types  sŽ   € ØÐ!Ü˜T×8Ñ8Ó9Ð9Ü�n¤cÔ*Ø,Ð.ˆNÜ˜.Ó)ˆØœ#˜d×1Ñ1Ó2Ñ2ˆÙÜØ3´F¸7³OÐ3DÐD[Ð\`×\oÑ\oÐ[pÐqóð ñ ÜÐRÓSÐSØˆr   c                óˆ   — | j                   €&dt        j                  «       j                  › �| _         dd| j                   idœS )Nzselenium.domMutation.Úchannel)rF   r$   )rÙ   ÚuuidÚuuid4Úhexr5   s    r   Ú_channel_argumentz%DomMutationRegistry._channel_argument   s;   € Ø�=‰=Ð à3´D·J±J³L×4DÑ4DÐ3EÐFˆDŒMØ!¨Y¸¿¹Ð,FÑGÐGr   c                óŠ   — t        j                  t        |«      D �ci c]  }|d“Œ c}«      }dt        z   dz   |z   dz   S c c}w )NTzfunction(channel) { return (z)(channel, z); })ÚjsonÚdumpsrã   ÚDOM_MUTATION_LISTENER_JS)r6   rå   r^   Úoptionss       r   Ú_listener_declarationz)DomMutationRegistry._listener_declaration&  sH   € ô —*‘*´V¸E³]ÖC¨T˜d D™jÒCÓDˆØ-Ô0HÑHÈ=ÑXÐ[bÑbÐekÑkÐkùò Ds   �
A c                óR  — | j                  |«      }| j                  j                  ||g¬«      }| j                  j	                  |«       t        | j                  dd «      }|�5d }	 |j                  }|�#| j                  j                  |d|id|g¬«       y y y # t        $ r Y Œ2w xY w)N)Ú	argumentsrœ   r�   F)rž   rG   rŸ   rõ   )	ró   r¯   Ú_add_preload_scriptrÛ   r[   r”   r£   r–   r¤   )r6   Úchannel_argrå   r©   Úpreload_script_idÚdriverr�   s          r   Ú_observe_typesz"DomMutationRegistry._observe_types,  sÄ   € Ø×0Ñ0°Ó7ˆØ ŸL™L×<Ñ<¸[ÐU`ÐTaÐ<ÓbÐØ× Ñ ×'Ñ'Ð(9Ô:ô ˜Ÿ™ y°$Ó7ˆØÐØˆGðØ ×6Ñ6�ð Ð"Ø—‘×*Ñ*Ø)4Ø% wÐ/Ø"'Ø*˜mð	 +õ ð #ð øô ò Ùðús   Á'B Â	B&Â%B&Nc                ó  ‡ ‡‡— ‰ j                  |«      Šdˆˆ ˆfd„}‰ j                  j                  }‰ j                  5  ‰ j	                  «       }t        ‰«      ‰ j                  z
  }|r'‰ j                  ||«       ‰ xj                  |z  c_        ‰ j                  st        |‰ j                  «      ‰ _        |j                  t        ‰ j                  «      |«      }‰‰ j                  |<   ddd«       |S # 1 sw Y   S xY w)z9Register a mutation handler for the given mutation types.c                óä  •— t        | t        «      r| j                  d«      ‰j                  k7  ry | j                  d«      }t        |t        «      r|j                  d«      nd }|€y 	 t	        j
                  |«      }t        |t        «      sy t        |«      }|j                  dk(  r|j                  s|j                  dk7  ry |j                  ‰v r	 ‰|«       y y # t        t        f$ r Y y w xY w)Nré   Údatar$   rn   Ú0)rN   rO   rP   rÙ   rï   Úloadsrâ   Ú	TypeErrorrs   rF   rB   )r   rý   r$   rq   Úmutationr¹   r6   rå   s        €€€r   r½   z2DomMutationRegistry.add_handler.<locals>._dispatchE  sÖ   ø€ Ü˜g¤tÔ,°·±¸IÓ0FÈ$Ï-É-Ò0WØØ—;‘;˜vÓ&ˆDÜ)3°D¼$Ô)?�D—H‘H˜WÔ%ÀTˆEØˆ}ØðÜŸ*™* UÓ+�ô ˜g¤tÔ,ØÜ0°Ó9ˆHØ�}‰} Ò,°X×5HÒ5HÈX×M`ÑM`ÐdgÒMgØØ�}‰} Ñ%Ù˜Õ"ð &øô ¤	Ð*ò Ùðús   Á)C ÃC/Ã.C/N)r   r   r=   r{   )rç   r¯   r¿   r²   rí   rÜ   rÝ   rú   rÚ   r…   rÁ   r³   rÀ   ru   )	r6   r¹   rä   r½   r‚   r÷   ÚmissingrÃ   rå   s	   ``      @r   rÄ   zDomMutationRegistry.add_handlerA  sÙ   ú€ à×%Ñ% nÓ5ˆ÷	#ð& �|‰|×!Ñ!ˆØ�Z‰Zñ 
	0Ø×0Ñ0Ó2ˆKÜ˜%“j 4×#5Ñ#5Ñ5ˆGÙØ×#Ñ# K°Ô9Ø×"Ò" gÑ-Õ"Ø—>’>Ü(;¸DÀ$Ç*Á*Ó(M�Ô%à×+Ñ+¬I°d·j±jÓ,AÀ9ÓMˆKØ*/ˆD�N‰N˜;Ñ'÷
	0ð Ð÷
	0ð Ðús   ¿B-C6Ã6D c                ó2  — | j                   j                  }|j                  t        | j                  «      |«       | j
                  5  | j                  j                  |d«      }|�| j                  s| j                  |«       ddd«       y# 1 sw Y   yxY w)z9Remove a handler; tears down observers with the last one.N)	r¯   r¿   rÂ   ru   rÁ   r²   rÚ   rÆ   Ú	_teardownrÇ   s       r   rÉ   z"DomMutationRegistry.remove_handlerf  st   € à�|‰|×!Ñ!ˆØ×ÑœY t§z¡zÓ2°KÔ@Ø�Z‰Zñ 	%Ø—n‘n×(Ñ(¨°dÓ;ˆGØÐ"¨4¯>ª>Ø—‘˜tÔ$÷	%÷ 	%ñ 	%ús   Á<BÂBc                ó    — | j                   5  t        | j                  «      }ddd«       D ]  }| j                  |«       Œ y# 1 sw Y   Œ"xY w)z"Remove every DOM mutation handler.N)r²   rK   rÚ   rÉ   )r6   rÍ   rÃ   s      r   rÎ   z"DomMutationRegistry.clear_handlerso  sI   € à�Z‰Zñ 	'Ü�t—~‘~Ó&ˆC÷	'àò 	-ˆKØ×Ñ Õ,ñ	-÷	'ð 	'ús   �AÁAc                ó  — 	 t        || j                  | j                  «       d | _        | j                  g c}| _        t	        «       | _        |D ]  }	 | j                  j                  |«       Œ  y # t        $ r t        j                  d|«       Y ŒCw xY w# d | _        | j                  g c}| _        t	        «       | _        |D ]C  }	 | j                  j                  |«       Œ # t        $ r t        j                  d|«       Y ŒAw xY w w xY w)Nz/Failed to remove DOM mutation preload script %s)rŒ   rÁ   r³   rÛ   rÜ   rÝ   r¯   Ú_remove_preload_scriptr–   ÚloggerÚwarning)r6   r‚   Úpreload_script_idsrø   s       r   r  zDomMutationRegistry._teardownv  s  € ð
	iÜ# D¨$¯*©*°d×6KÑ6KÔLà$(ˆDÔ!Ø;?×;SÑ;SÐUWÐ8Ð Ô 8Ü!$£ˆDÔØ%7ò iÐ!ðiØ—L‘L×7Ñ7Ð8IÕJñiøô !ò iÜ—N‘NÐ#TÐVgÖhðiûð %)ˆDÔ!Ø;?×;SÑ;SÐUWÐ8Ð Ô 8Ü!$£ˆDÔØ%7ò iÐ!ðiØ—L‘L×7Ñ7Ð8IÕJøÜ ò iÜ—N‘NÐ#TÐVgÖhðiúñiúsA   ‚!B ÁA1Á1BÂBÂ0D
ÃC#Ã"D
Ã#D	ÄD
ÄD	ÄD
rÏ   )rä   ústr | Iterable[str] | Noner=   zfrozenset[str])r=   rO   )rå   úset[str]r=   r4   )r÷   rO   rå   r  r=   r{   r*   )r¹   r   rä   r  r=   rÑ   rÒ   )r=   r{   )r‚   r   r=   r{   )r   r   r   r   rÁ   rá   rà   rx   rç   rí   ró   rú   rÄ   rÉ   rÎ   r  r   r   r   rÕ   rÕ   ù  sJ   „ ñð €EØA€NØ,Ðó-óóHólóô*#óJ%ó-ôir   rÕ   )r   r   r=   z
list[dict])r   r   r=   r   )rc   rO   r=   r   )rc   rO   r=   r
   )rj   rO   r=   r
   )rq   rO   r=   rA   )r‚   r   rƒ   r4   r=   r   )r‚   r   rƒ   r4   rŠ   r   r=   r{   )rc   rO   r=   r   r*   )
r¥   r   r¦   r(   r§   r4   r¨   r   r=   r#   )&r   Ú
__future__r   rï   Úloggingr°   rê   Úcollections.abcr   r   Údataclassesr   r   Útypingr   Ú	getLoggerr   r  rñ   r
   r   r#   r4   r(   rA   rS   r_   re   rh   rk   rs   ru   r…   rŒ   r™   r«   r­   rÕ   r   r   r   ú<module>r     s  ðñ$õ4 #ã Û Û Û ß .ß (Ý à	ˆ×	Ñ	˜8Ó	$€ðLÐ ð^ ÷#ð #ó ð#ð* ÷"ð "ó ð"ð4 ÷ð ó ðô O�3ô OðB ÷;ð ;ó ð;óDóóó"ó
ó÷ ñ óLó,óô;÷BI-ñ I-÷XHiò Hir   