§
    Ìtºf €  ã                   ó„  — d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlmZ d dlmZ d dlmZmZ d dlmZ d dlmZ d dlZ	 dZd dlmZ n# e$ r d	ZY nw xY wd
Zd„ ZedLd„¦   «         Zedededefd„¦   «         ZedMd„¦   «         Zed„ ¦   «         Z  G d„ de!¦  «        Z" ej#        dd¦  «        d          Z$d„ Z%d„ Z&dNd„Z'dZ(	 dZ)	 e	 	 	 dOde*de*d ee+         d!ee+         d"ee,         de+fd#„¦   «         Z-ed$„ ¦   «         Z. ej/        d%e(z   d&z   e(z   d&z   e(z   d'z   ¦  «        Z0ed(e+fd)„¦   «         Z1ed*„ ¦   «         Z2ed+„ ¦   «         Z3ej4         5                    d,¦  «        r%ej6        d-k    rej7        Z8nej9        Z8 e8¦   «         Z:nej        Z8ed.„ ¦   «         Z; G d/„ d0e!¦  «        Z< G d1„ d2e!¦  «        Z= G d3„ d4e!¦  «        Z>d5„ Z? G d6„ d7e!¦  «        Z@ G d8„ d9e!¦  «        ZAd:„ ZBd;„ ZCde+fd<„ZD	 d dlEZEdZFn# e$ r d	ZFY nw xY wdPd>„ZGd?„ ZHd@„ ZIdA„ ZJdB„ ZKdQdD„ZLdE„ ZMdF„ ZNdG„ ZOdH„ ZPdRdIe+dJe,defdK„ZQdS )Sé    N)ÚOrderedDict)ÚOptional)ÚdatetimeÚ	timedelta)Úpformat)ÚarrayT)ÚSSLF)ÚpublicÚencode_truncateÚxorÚutcnowÚutcstrÚidÚridÚnewidÚrtimeÚ	StopwatchÚTrackerÚEqualityMixinÚObservableMixinÚIdGeneratorÚgenerate_tokenÚgenerate_activation_codeÚgenerate_serial_numberÚgenerate_user_passwordÚ
machine_idÚparse_keyfileÚwrite_keyfileÚhlÚhltypeÚhlidÚhluseridÚhlvalÚ
hlcontractÚwith_0xÚ
without_0xc                 ó8   — 	 d| _         n# t          $ r Y nw xY w| S )zÓ
    The public user API of Autobahn is marked using this decorator.
    Everything that is not decorated @public is library internal, can
    change at any time and should not be used in user program code.
    T)Ú
_is_publicÚAttributeError©Úobjs    úL/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/autobahn/util.pyr
   r
   U   s7   € ðØˆŒˆøÝð ð ð àˆðøøøð €Js   ‚
 Š
–Úutf8c                 óP  — | �t          | ¦  «        t          k    sJ ‚t          |¦  «        t          k    sJ ‚|dk    sJ ‚| €dS |                      |¦  «        }t	          |¦  «        |k    r7|d|…         }|                     |d¦  «        } |r|                      |¦  «        }|r|S | S )aB  
    Given a string, return a truncated version of the string such that
    the UTF8 encoding of the string is smaller than the given limit.

    This function correctly truncates even in the presence of Unicode code
    points that encode to multi-byte encodings which must not be truncated
    in the middle.

    :param text: The (Unicode) string to truncate.
    :type text: str
    :param limit: The number of bytes to limit the UTF8 encoding to.
    :type limit: int
    :param encoding: Truncate the string in this encoding (default is ``utf-8``).
    :type encoding: str
    :param return_encoded: If ``True``, return the string encoded into bytes
        according to the specified encoding, else return the string as a string.
    :type return_encoded: bool

    :returns: The truncated string.
    :rtype: str or bytes
    Nr   Úignore)ÚtypeÚstrÚintÚencodeÚlenÚdecode)ÚtextÚlimitÚencodingÚreturn_encodedÚss        r,   r   r   c   s¾   € ð. ˆ<�4 ™:œ:­Ò,Ð,Ð,Ð,Ý�‰;Œ;�#ÒÐÐÐØ�AŠ:ˆ:ˆ:ˆ:à€|Øˆð 	�Š�HÑÔ€Aõ ˆ1�v„v�‚~€~àˆfˆuˆfŒIˆð �xŠx˜ (Ñ+Ô+ˆàð 	&Ø—’˜HÑ%Ô%ˆAàð Øˆàˆó    Úd1Úd2Úreturnc                 óª  — t          | ¦  «        t          k    r/t          d                     t          | ¦  «        ¦  «        ¦  «        ‚t          |¦  «        t          k    r/t          d                     t          |¦  «        ¦  «        ¦  «        ‚t	          | ¦  «        t	          |¦  «        k    r=t          d                     t	          | ¦  «        t	          |¦  «        ¦  «        ¦  «        ‚t          d| ¦  «        } t          d|¦  «        }t          t	          | ¦  «        ¦  «        D ]}| |xx         ||         z  cc<   Œ|                      ¦   «         S )zÊ
    XOR two binary strings of arbitrary (equal) length.

    :param d1: The first binary string.
    :param d2: The second binary string.

    :returns: XOR of the binary strings (``XOR(d1, d2)``)
    z'invalid type {} for d1 - must be binaryz'invalid type {} for d2 - must be binaryz7cannot XOR binary string of differing length ({} != {})ÚB)r0   ÚbytesÚ	ExceptionÚformatr4   r   ÚrangeÚtobytes)r<   r=   Úis      r,   r   r   –   s  € õ ˆB�x„x•5ÒÐÝÐA×HÒHÍÈbÉÌÑRÔRÑSÔSÐSÝˆB�x„x•5ÒÐÝÐA×HÒHÍÈbÉÌÑRÔRÑSÔSÐSÝ
ˆ2�w„w•#�b‘'”'ÒÐÝÐQ×XÒXÕY\Ð]_ÑY`ÔY`ÕbeÐfhÑbiÔbiÑjÔjÑkÔkÐkå	ˆs�B‰Œ€BÝ	ˆs�B‰Œ€Bå•3�r‘7”7‰^Œ^ð ð ˆØ
ˆ1ˆˆŒ��A”‰ˆˆ‰ˆà�:Š:‰<Œ<Ðr;   c                 ó¾   — | �t          | t          ¦  «        sJ ‚| €t          j        ¦   «         } d                     |                      d¦  «        dd…         ¦  «        S )a  
    Format UTC timestamp in ISO 8601 format.

    Note: to parse an ISO 8601 formatted string, use the **iso8601**
    module instead (e.g. ``iso8601.parse_date("2014-05-23T13:03:44.123Z")``).

    >>> txaio.time_ns()
    1641121311914026419
    >>> int(iso8601.parse_date(utcnow()).timestamp() * 1000000000.)
    1641121313209000192

    :param ts: The timestamp to format.
    :type ts: instance of :py:class:`datetime.datetime` or ``None``

    :returns: Timestamp formatted in ISO 8601 format.
    :rtype: str
    Nz{0}Zz%Y-%m-%dT%H:%M:%S.%féýÿÿÿ)Ú
isinstancer   r   rC   Ústrftime)Útss    r,   r   r   °   sU   € ð& ˆ:� B­Ñ1Ô1ˆ:ˆ:ˆ:Ø	€zÝŒ_ÑÔˆØ�=Š=˜ŸšÐ%;Ñ<Ô<¸S¸b¸SÔAÑBÔBÐBr;   c                  ó   — t          ¦   «         S )z
    Get current time in UTC as ISO 8601 string.

    :returns: Current time as string in ISO 8601 format.
    :rtype: str
    )r   © r;   r,   r   r   É   s   € õ ‰8Œ8€Or;   c                   ó$   — e Zd ZdZd„ Zd„ Zd„ ZdS )r   a@  
    ID generator for WAMP request IDs.

    WAMP request IDs are sequential per WAMP session, starting at 1 and
    wrapping around at 2**53 (both value are inclusive [1, 2**53]).

    The upper bound **2**53** is chosen since it is the maximum integer that can be
    represented as a IEEE double such that all smaller integers are representable as well.

    Hence, IDs can be safely used with languages that use IEEE double as their
    main (or only) number type (JavaScript, Lua, etc).

    See https://github.com/wamp-proto/wamp-proto/blob/master/spec/basic.md#ids
    c                 ó   — d| _         d S )Nr   ©Ú_next©Úselfs    r,   Ú__init__zIdGenerator.__init__ä   s   € ØˆŒ
ˆ
ˆ
r;   c                 óT   — | xj         dz  c_         | j         dk    rd| _         | j         S )zV
        Returns next ID.

        :returns: The next ID.
        :rtype: int
        é   ì          rP   rR   s    r,   ÚnextzIdGenerator.nextç   s0   € ð 	ˆ
Œ
�a‰ˆ
Œ
ØŒ:Ð(Ò(Ð(ØˆDŒJØŒzÐr;   c                 ó*   — |                       ¦   «         S ©N)rX   rR   s    r,   Ú__next__zIdGenerator.__next__ô   s   € Ø�yŠy‰{Œ{Ðr;   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rT   rX   r[   rM   r;   r,   r   r   Ô   sK   € € € € € ðð ðð ð ð
ð 
ð 
ðð ð ð ð r;   r   ú>Qs    ÿÿÿÿÿÿc                  óp   — t          j        dt          j        d¦  «        ¦  «        d         t          z  pdS )aR  
    Generate a new random integer ID from range **[1, 2**53]**.

    The generated ID is uniformly distributed over the whole range, doesn't have
    a period (no pseudo-random generator is used) and cryptographically strong.

    The upper bound **2**53** is chosen since it is the maximum integer that can be
    represented as a IEEE double such that all smaller integers are representable as well.

    Hence, IDs can be safely used with languages that use IEEE double as their
    main (or only) number type (JavaScript, Lua, etc).

    :returns: A random integer ID.
    :rtype: int
    r`   é   r   rW   )ÚstructÚunpackÚosÚurandomÚ_WAMP_ID_MASKrM   r;   r,   r   r     s-   € õ  Œ=˜�rœz¨!™}œ}Ñ-Ô-¨aÔ0µ=Ñ@ÐKÀGÐKr;   c                  ó,   — t          j        dd¦  «        S )a›  
    Generate a new random integer ID from range **[1, 2**53]**.

    The generated ID is based on a pseudo-random number generator (Mersenne Twister,
    which has a period of 2**19937-1). It is NOT cryptographically strong, and
    hence NOT suitable to generate e.g. secret keys or access tokens.

    The upper bound **2**53** is chosen since it is the maximum integer that can be
    represented as a IEEE double such that all smaller integers are representable as well.

    Hence, IDs can be safely used with languages that use IEEE double as their
    main (or only) number type (JavaScript, Lua, etc).

    :returns: A random integer ID.
    :rtype: int
    rV   rW   )ÚrandomÚrandintrM   r;   r,   r   r   1  s   € õ" Œ>˜!Ð-Ñ.Ô.Ð.r;   é   c                 óì   — t          t          j        t          | ¦  «        dz  dz  ¦  «        ¦  «        }t	          j        t          j        |¦  «        ¦  «        d| …                              d¦  «        S )aG  
    Generate a new random string ID.

    The generated ID is uniformly distributed and cryptographically strong. It is
    hence usable for things like secret keys and access tokens.

    :param length: The length (in chars) of the ID to generate.
    :type length: int

    :returns: A random string ID.
    :rtype: str
    g      @g       @NÚascii)	r2   ÚmathÚceilÚfloatÚbase64Ú	b64encodere   rf   r5   )ÚlengthÚls     r,   r   r   E  s[   € õ 	�DŒI•e˜F‘m”m bÑ(¨2Ñ-Ñ.Ô.Ñ/Ô/€AÝÔ�BœJ q™MœMÑ*Ô*¨7¨F¨7Ô3×:Ò:¸7ÑCÔCÐCr;   Ú345679ACEFGHJKLMNPQRSTUVWXYÚ 13456789abcdefghijkmnopqrstuwxyzÚchar_groupsÚchars_per_groupÚcharsÚsepÚ
lower_casec           
      óV  ‡‡— t          | ¦  «        t          k    sJ ‚t          |¦  «        t          k    sJ ‚‰�Bt          ‰¦  «        t          k    s*J d                     t          ‰¦  «        ¦  «        ¦   «         ‚‰pt          Š|r‰                     ¦   «         Š|pd}t          j        ¦   «         Šd                     ˆˆfd„t          | |z  ¦  «        D ¦   «         ¦  «        }|dk    r@|                     t          dj        t          t          |¦  «        g|z  Ž ¦  «        ¦  «        S |S )aÍ  
    Generate cryptographically strong tokens, which are strings like `M6X5-YO5W-T5IK`.
    These can be used e.g. for used-only-once activation tokens or the like.

    The returned token has an entropy of
    ``math.log(len(chars), 2.) * chars_per_group * char_groups``
    bits.

    With the default charset and 4 characters per group, ``generate_token()`` produces
    strings with the following entropy:

    ================   ===================  ========================================
    character groups    entropy (at least)  recommended use
    ================   ===================  ========================================
    2                    38 bits
    3                    57 bits            one-time activation or pairing code
    4                    76 bits            secure user password
    5                    95 bits
    6                   114 bits            globally unique serial / product code
    7                   133 bits
    ================   ===================  ========================================

    Here are some examples:

    * token(3): ``9QXT-UXJW-7R4H``
    * token(4): ``LPNN-JMET-KWEP-YK45``
    * token(6): ``NXW9-74LU-6NUH-VLPV-X6AG-QUE3``

    :param char_groups: Number of character groups (or characters if chars_per_group == 1).
    :param chars_per_group: Number of characters per character group (or 1 to return a token with no grouping).
    :param chars: Characters to choose from. Default is 27 character subset
        of the ISO basic Latin alphabet (see: ``DEFAULT_TOKEN_CHARS``).
    :param sep: When separating groups in the token, the separater string.
    :param lower_case: If ``True``, generate token in lower-case.

    :returns: The generated token.
    Nzchars must be str, was {}ú-Ú c              3   óB   •K  — | ]}‰                      ‰¦  «        V — Œd S rZ   )Úchoice)Ú.0Ú_ry   Úrngs     €€r,   ú	<genexpr>z!generate_token.<locals>.<genexpr>¤  s/   øè è € ÐZÐZ°˜#Ÿ*š* UÑ+Ô+ÐZÐZÐZÐZÐZÐZr;   rV   )r0   r2   r1   rC   ÚDEFAULT_TOKEN_CHARSÚlowerri   ÚSystemRandomÚjoinrD   ÚmapÚzipÚiter)rw   rx   ry   rz   r{   Útoken_valuerƒ   s     `   @r,   r   r   q  s&  øø€ õV �ÑÔ¥Ò#Ð#Ð#Ð#Ý�Ñ Ô ¥CÒ'Ð'Ð'Ð'Øˆ=�D ™KœK­3Ò.Ð.Ð.Ð1L×1SÒ1SÕTXÐY^ÑT_ÔT_Ñ1`Ô1`Ñ.Ô.Ð.ØÐ(Õ(€EØð Ø—’‘”ˆØ
ˆ*�€CÝ
Ô
Ñ
Ô
€CØ—'’'ÐZÐZÐZÐZÐZµU¸;ÈÑ;XÑ5YÔ5YÐZÑZÔZÑZÔZ€KØ˜ÒÐØ�xŠx�˜BœG¥S­4°Ñ+<Ô+<Ð*=ÀÑ*OÐ%PÑQÔQÑRÔRÐRàÐr;   c                  ó4   — t          ddt          dd¬¦  «        S )zñ
    Generate a one-time activation code or token of the form ``'W97F-96MJ-YGJL'``.
    The generated value is cryptographically strong and has (at least) 57 bits of entropy.

    :returns: The generated activation code.
    :rtype: str
    é   é   r}   F©rw   rx   ry   rz   r{   ©r   r…   rM   r;   r,   r   r   «  ó    € õ  a¸ÕBUÐ[^ÐkpÐqÑqÔqÐqr;   z^([z
]{4,4})-([z]{4,4})$Úcodec                 ó6   — t                                | ¦  «        S )aw  
    Parse an activation code generated by :func:<autobahn.util.generate_activation_code>:

    .. code:: console

        "RWCN-94NV-CEHR" -> ("RWCN", "94NV", "CEHR") | None

    :param code: The code to parse, e.g. ``'W97F-96MJ-YGJL'``.
    :return: If the string is a properly conforming activation code, return
        the matched pattern, otherwise return ``None``.
    )Ú_PAT_ACTIVATION_CODEÚmatch)r“   s    r,   Úparse_activation_coder—   º  s   € õ  ×%Ò% dÑ+Ô+Ð+r;   c                  ó4   — t          ddt          dd¬¦  «        S )zç
    Generate a secure, random user password of the form ``'kgojzi61dn5dtb6d'``.
    The generated value is cryptographically strong and has (at least) 76 bits of entropy.

    :returns: The generated password.
    :rtype: str
    rk   rV   r}   Tr�   )r   ÚDEFAULT_ZBASE32_CHARSrM   r;   r,   r   r   Ê  s    € õ  b¸!ÕCXÐ^aÐnrÐsÑsÔsÐsr;   c                  ó4   — t          ddt          dd¬¦  «        S )a  
    Generate a globally unique serial / product code of the form ``'YRAC-EL4X-FQQE-AW4T-WNUV-VN6T'``.
    The generated value is cryptographically strong and has (at least) 114 bits of entropy.

    :returns: The generated serial number / product code.
    :rtype: str
    é   r�   r}   Fr�   r‘   rM   r;   r,   r   r   Ö  r’   r;   Úwin)rŽ   rb   c                  ó   — t          ¦   «         S )z¾
    Precise, fast wallclock time.

    :returns: The current wallclock in seconds. Returned values are only guaranteed
       to be meaningful relative to each other.
    :rtype: float
    )Ú_rtimerM   r;   r,   r   r   ÷  s   € õ ‰8Œ8€Or;   c                   ó2   — e Zd ZdZd	d„Zd„ Zd„ Zd„ Zd„ ZdS )
r   zå
    Stopwatch based on walltime.

    This can be used to do code timing and uses the most precise walltime measurement
    available on the platform. This is a very light-weight object,
    so create/dispose is very cheap.
    Tc                 ól   — d| _         |rt          ¦   «         | _        d| _        dS d| _        d| _        dS )zh

        :param start: If ``True``, immediately start the stopwatch.
        :type start: bool
        r   TNF)Ú_elapsedr   Ú_startedÚ_running)rS   Ústarts     r,   rT   zStopwatch.__init__  s;   € ð ˆŒØð 	"Ý!™GœGˆDŒMØ ˆDŒMˆMˆMà ˆDŒMØ!ˆDŒMˆMˆMr;   c                 ó^   — | j         r t          ¦   «         }| j        || j        z
  z   S | j        S )z¤
        Return total time elapsed in seconds during which the stopwatch was running.

        :returns: The elapsed time in seconds.
        :rtype: float
        ©r£   r   r¡   r¢   ©rS   Únows     r,   ÚelapsedzStopwatch.elapsed  s3   € ð Œ=ð 	!Ý‘'”'ˆCØ”= C¨$¬-Ñ$7Ñ8Ð8à”=Ð r;   c                 ó†   — | j         r4t          ¦   «         }| xj        || j        z
  z  c_        d| _         | j        S | j        S )zÆ
        Pauses the stopwatch and returns total time elapsed in seconds during which
        the stopwatch was running.

        :returns: The elapsed time in seconds.
        :rtype: float
        Fr¦   r§   s     r,   ÚpausezStopwatch.pause'  sE   € ð Œ=ð 	!Ý‘'”'ˆCØˆMŒM˜S 4¤=Ñ0Ñ0ˆMŒMØ!ˆDŒMØ”=Ð à”=Ð r;   c                 ó’   — | j         s!t          ¦   «         | _        d| _         | j        S t          ¦   «         }| j        || j        z
  z   S )zÌ
        Resumes a paused stopwatch and returns total elapsed time in seconds
        during which the stopwatch was running.

        :returns: The elapsed time in seconds.
        :rtype: float
        T)r£   r   r¢   r¡   r§   s     r,   ÚresumezStopwatch.resume7  sE   € ð Œ}ð 	9Ý!™GœGˆDŒMØ ˆDŒMØ”=Ð å‘'”'ˆCØ”= C¨$¬-Ñ$7Ñ8Ð8r;   c                 óX   — |                       ¦   «         }d| _        d| _        d| _        |S )zÒ
        Stops the stopwatch and returns total time elapsed in seconds during which
        the stopwatch was (previously) running.

        :returns: The elapsed time in seconds.
        :rtype: float
        r   NF)r«   r¡   r¢   r£   )rS   r©   s     r,   ÚstopzStopwatch.stopG  s+   € ð —*’*‘,”,ˆØˆŒØˆŒØˆŒØˆr;   N©T)	r\   r]   r^   r_   rT   r©   r«   r­   r¯   rM   r;   r,   r   r     sn   € € € € € ðð ð"ð "ð "ð "ð!ð !ð !ð!ð !ð !ð 9ð 9ð 9ð ð ð ð ð r;   r   c                   ó>   — e Zd ZdZd„ Zd„ Zdd„Zd„ Zd„ Zd„ Z	d	„ Z
d
S )r   z)
    A key-based statistics tracker.
    c                 ó†   — || _         || _        i | _        t          ¦   «         | _        t          j        ¦   «         | _        dS )z	
        N)ÚtrackerÚtrackedÚ_timingsr   Ú_offsetr   r   Ú
_dt_offset)rS   r³   r´   s      r,   rT   zTracker.__init__[  s7   € ð ˆŒØˆŒØˆŒÝ‘w”wˆŒÝ"œ/Ñ+Ô+ˆŒˆˆr;   c                 ó2   — t          ¦   «         | j        |<   dS )zy
        Track elapsed for key.

        :param key: Key under which to track the timing.
        :type key: str
        N)r   rµ   ©rS   Úkeys     r,   ÚtrackzTracker.trackd  s   € õ #™WœWˆŒ�cÑÐÐr;   Tc                 óŒ  — || j         v r£|| j         v rš| j         |         | j         |         z
  }|r{|dk     rdt          |dz  ¦  «        z  }nJ|dk     rdt          |dz  ¦  «        z  }n.|dk     rdt          |d	z  ¦  «        z  }nd
t          |¦  «        z  }|                     d¦  «        S |S |rd                     d¦  «        S dS )aê  
        Get elapsed difference between two previously tracked keys.

        :param start_key: First key for interval (older timestamp).
        :type start_key: str
        :param end_key: Second key for interval (younger timestamp).
        :type end_key: str
        :param formatted: If ``True``, format computed time period and return string.
        :type formatted: bool

        :returns: Computed time period in seconds (or formatted string).
        :rtype: float or str
        gñhãˆµøä>z%d nsg    eÍÍAg{®Gáz„?z%d usg    €„.Aé
   z%d msg     @�@z%d srb   zn.a.N)rµ   ÚroundÚrjust)rS   Ú	start_keyÚend_keyÚ	formattedÚdr:   s         r,   ÚdiffzTracker.diffm  sâ   € ð �d”mÐ#Ð#¨	°T´]Ð(BÐ(BØ”˜gÔ&¨¬°yÔ)AÑAˆAØð Ø�w’;�;Ø¥%¨¨K©Ñ"8Ô"8Ñ8�A�AØ˜’X�XØ¥%¨¨H©Ñ"5Ô"5Ñ5�A�AØ˜’V�VØ¥%¨¨E©	Ñ"2Ô"2Ñ2�A�Aà¥ q¡¤Ñ)�AØ—w’w˜q‘z”zÐ!à�àð Ø—|’| A‘”Ð&à�tr;   c                 ój   — | |         }|€t          d|z  ¦  «        ‚| j        t          |¬¦  «        z   S )zí
        Return the UTC wall-clock time at which a tracked event occurred.

        :param key: The key
        :type key: str

        :returns: Timezone-naive datetime.
        :rtype: instance of :py:class:`datetime.datetime`
        NzNo such key "%s".)Úseconds)ÚKeyErrorr·   r   )rS   rº   r©   s      r,   ÚabsolutezTracker.absolute�  s>   € ð �s”)ˆØˆ?ÝÐ0°7Ñ:Ñ;Ô;Ð;ØŒ¥°7Ð!;Ñ!;Ô!;Ñ;Ð;r;   c                 óB   — || j         v r| j         |         | j        z
  S d S rZ   )rµ   r¶   r¹   s     r,   Ú__getitem__zTracker.__getitem__ž  s(   € Ø�$”-ÐÐØ”= Ô%¨¬Ñ4Ð4à�4r;   c                 ó4   — | j                              ¦   «         S rZ   )rµ   Ú__iter__rR   s    r,   rÌ   zTracker.__iter__¤  s   € ØŒ}×%Ò%Ñ'Ô'Ð'r;   c                 ó*   — t          | j        ¦  «        S rZ   )r   rµ   rR   s    r,   Ú__str__zTracker.__str__§  s   € Ý�t”}Ñ%Ô%Ð%r;   Nr°   )r\   r]   r^   r_   rT   r»   rÄ   rÈ   rÊ   rÌ   rÎ   rM   r;   r,   r   r   V  s�   € € € € € ðð ð,ð ,ð ,ð%ð %ð %ð ð  ð  ð  ðD<ð <ð <ðð ð ð(ð (ð (ð&ð &ð &ð &ð &r;   r   c                   ó   — e Zd ZdZd„ Zd„ ZdS )r   zÝ
    Mixing to add equality comparison operators to a class.

    Two objects are identical under this mixin, if and only if:

    1. both object have the same class
    2. all non-private object attributes are equal
    c                 ó°   — t          || j        ¦  «        sdS | j        D ]6}|                     d¦  «        s| j        |         |j        |         k    s dS Œ7dS )zã
        Compare this object to another object for equality.

        :param other: The other object to compare with.
        :type other: obj

        :returns: ``True`` iff the objects are equal.
        :rtype: bool
        Fr‚   T)rI   Ú	__class__Ú__dict__Ú
startswith)rS   ÚotherÚks      r,   Ú__eq__zEqualityMixin.__eq__µ  sh   € õ ˜% ¤Ñ0Ô0ð 	Ø�5à”ð 	!ð 	!ˆAØ—<’< Ñ$Ô$ð !Ø”} QÔ'¨5¬>¸!Ô+<Ò<Ð<Ø ˜5˜5øØˆtr;   c                 ó.   — |                       |¦  «         S )zé
        Compare this object to another object for inequality.

        :param other: The other object to compare with.
        :type other: obj

        :returns: ``True`` iff the objects are not equal.
        :rtype: bool
        )rÖ   )rS   rÔ   s     r,   Ú__ne__zEqualityMixin.__ne__É  s   € ð —;’;˜uÑ%Ô%Ð%Ð%r;   N)r\   r]   r^   r_   rÖ   rØ   rM   r;   r,   r   r   «  s<   € € € € € ðð ðð ð ð(
&ð 
&ð 
&ð 
&ð 
&r;   r   c                 ó   — d„ | D ¦   «         S )ah  
    Compute a list of regular expression patterns from a list of
    wildcard strings. A wildcard string uses '*' as a wildcard character
    matching anything.

    :param wildcards: List of wildcard strings to compute regular expression patterns for.
    :type wildcards: list of str

    :returns: Computed regular expressions.
    :rtype: list of obj
    c           	      ó’   — g | ]D}t          j        d |                     dd¦  «                             dd¦  «        z   dz   ¦  «        ‘ŒES )ú^ú.z\.Ú*z.*ú$)ÚreÚcompileÚreplace)r�   Úwcs     r,   ú
<listcomp>z&wildcards2patterns.<locals>.<listcomp>æ  sK   € ÐbÐbÐbÐRT�BŒJ�s˜RŸZšZ¨¨UÑ3Ô3×;Ò;¸CÀÑFÔFÑFÈÑLÑMÔMÐbÐbÐbr;   rM   )Ú	wildcardss    r,   Úwildcards2patternsrå   Ö  s   € ð  cÐbÐXaÐbÑbÔbÐbr;   c                   óD   — e Zd ZdZdZdZdZdZdd„Zd„ Z	d„ Z
d	d„Zd„ ZdS )
r   zM
    Internal utility for enabling event-listeners on particular objects
    Nc                 óZ   — t          |¦  «        | _        d„ | j        D ¦   «         | _        dS )zŽ
        :param valid_events: if non-None, .on() or .fire() with an event
            not listed in valid_events raises an exception.
        c                 ó   — i | ]}|d “ŒS rZ   rM   )r�   rÕ   s     r,   ú
<dictcomp>z4ObservableMixin.set_valid_events.<locals>.<dictcomp>  s   € Ð=Ð=Ð= Q˜˜DÐ=Ð=Ð=r;   N)ÚlistÚ_valid_eventsÚ_results)rS   Úvalid_eventss     r,   Úset_valid_eventsz ObservableMixin.set_valid_eventsý  s0   € õ
 " ,Ñ/Ô/ˆÔØ=Ð=¨$Ô*<Ð=Ñ=Ô=ˆŒˆˆr;   c                 ó¢   — | j         rE|| j         vr>t          d                     |d                     | j         ¦  «        ¬¦  «        ¦  «        ‚dS dS )z—
        Internal helper. Throws RuntimeError if we have a valid_events
        list, and the given event isnt' in it. Does nothing otherwise.
        z2Invalid event '{event}'. Expected one of: {events}z, )ÚeventÚeventsN)rë   ÚRuntimeErrorrC   rˆ   )rS   rð   s     r,   Ú_check_eventzObservableMixin._check_event  sl   € ð
 Ôð 	 %¨tÔ/AÐ"AÐ"AÝØD×KÒKØØŸ9š9 TÔ%7Ñ8Ô8ð Lñ ô ñô ð ð	ð 	Ð"AÐ"Ar;   c                 óÊ   — |                       |¦  «         | j        €t          ¦   «         | _        || j        vr
g | j        |<   | j        |                              |¦  «         dS )zü
        Add a handler for an event.

        :param event: the name of the event

        :param handler: a callable thats invoked when .fire() is
            called for this events. Arguments will be whatever are given
            to .fire()
        N)ró   Ú
_listenersÚdictÚappend©rS   rð   Úhandlers      r,   ÚonzObservableMixin.on  se   € ð 	×Ò˜%Ñ Ô Ð ØŒ?Ð"Ý"™fœfˆDŒOØ˜œÐ'Ð'Ø%'ˆDŒO˜EÑ"ØŒ˜Ô×%Ò% gÑ.Ô.Ð.Ð.Ð.r;   c                 ó$  — |€&|�t          d¦  «        ‚t          ¦   «         | _        dS | j        €dS |                      |¦  «         || j        v r@|€
| j        |= dS 	 | j        |                              |¦  «         dS # t
          $ r Y dS w xY wdS )a=  
        Stop listening for a single event, or all events.

        :param event: if None, remove all listeners. Otherwise, remove
            listeners for the single named event.

        :param handler: if None, remove all handlers for the named
            event; otherwise remove just the given handler.
        Nz3Can't specificy a specific handler without an event)rò   rö   rõ   ró   ÚremoveÚ
ValueErrorrø   s      r,   ÚoffzObservableMixin.off$  sÊ   € ð ˆ=ØÐ"õ #ØIñô ð õ #™fœfˆDŒOˆOˆOàŒÐ&Ø�Ø×Ò˜eÑ$Ô$Ð$Ø˜œÐ'Ð'Ø�?Øœ¨Ð.Ð.Ð.ðØœ¨Ô.×5Ò5°gÑ>Ô>Ð>Ð>Ð>øÝ%ð ð ð Ø˜˜ðøøøð (Ð's   Á A? Á?
BÂBc                 óœ  — | j         €t          j        g ¬¦  «        S |                      |¦  «         g }| j                              |g ¦  «        D ],}t          j        |g|¢R i |¤Ž}|                     |¦  «         Œ-| j        �)|                      | j        j        |g|¢R i |¤Ž¦  «         t          j	        |d¬¦  «        }|| j
        |<   |S )a  
        Fire a particular event.

        :param event: the event to fire. All other args and kwargs are
            passed on to the handler(s) for the event.

        :return: a Deferred/Future gathering all async results from
            all handlers and/or parent handlers.
        N)ÚresultF)Úconsume_exceptions)rõ   ÚtxaioÚcreate_futureró   ÚgetÚ	as_futurer÷   Ú_parentÚfireÚgatherrì   )rS   rð   ÚargsÚkwargsÚresrù   ÚfutureÚd_ress           r,   r  zObservableMixin.fireC  sí   € ð Œ?Ð"ÝÔ&¨bÐ1Ñ1Ô1Ð1à×Ò˜%Ñ Ô Ð ØˆØ”×*Ò*¨5°"Ñ5Ô5ð 	ð 	ˆGÝ”_ WÐ>¨tÐ>Ð>Ð>°vÐ>Ð>ˆFØ�JŠJ�vÑÔÐÐØŒ<Ð#Ø�JŠJÐ(�t”|Ô(¨Ð@°Ð@Ð@Ð@¸Ð@Ð@ÑAÔAÐAÝ”˜S°UÐ;Ñ;Ô;ˆØ$ˆŒ�eÑØˆr;   rZ   )NN)r\   r]   r^   r_   r  rë   rõ   rì   rî   ró   rú   rþ   r  rM   r;   r,   r   r   é  s‰   € € € € € ðð ð €GØ€MØ€JØ€Hð>ð >ð >ð >ðð ð ð/ð /ð /ð$ð ð ð ð>ð ð ð ð r;   r   c                   ó"   — e Zd ZdZdZd„ Zd„ ZdS )Ú_LazyHexFormattera
  
    This is used to avoid calling binascii.hexlify() on data given to
    log.debug() calls unless debug is active (for example). Like::

        self.log.debug(
            "Some data: {octets}",
            octets=_LazyHexFormatter(os.urandom(32)),
        )
    r*   c                 ó   — || _         d S rZ   r*   )rS   r+   s     r,   rT   z_LazyHexFormatter.__init__i  s   € ØˆŒˆˆr;   c                 óZ   — t          j        | j        ¦  «                             d¦  «        S )Nrm   )ÚbinasciiÚhexlifyr+   r5   rR   s    r,   rÎ   z_LazyHexFormatter.__str__l  s#   € ÝÔ ¤Ñ)Ô)×0Ò0°Ñ9Ô9Ð9r;   N)r\   r]   r^   r_   Ú	__slots__rT   rÎ   rM   r;   r,   r  r  ]  sC   € € € € € ðð ð €Iðð ð ð:ð :ð :ð :ð :r;   r  c                 óH   — t           rt          | t          j        ¦  «        S dS )zƒ
    :returns: True if we have TLS support and 'instance' is an
        instance of :class:`OpenSSL.SSL.Error` otherwise False
    F)Ú_TLSrI   r	   ÚError)Úinstances    r,   Ú_is_tls_errorr  p  s#   € õ
 ð /Ý˜(¥C¤IÑ.Ô.Ð.Øˆ5r;   c                 ó�   — t          | ¦  «        r6| j        d         d         }d                     |d         |d         ¬¦  «        S dS )zb
    :returns: a TLS error-message, or empty-string if 'instance' is
        not a TLS error.
    r   zSSL error: {msg} (in {func})rV   é   )ÚfuncÚmsgr~   )r  r	  rC   )r  Ú	ssl_errors     r,   Ú_maybe_tls_reasonr  z  sW   € õ
 �XÑÔð 
Ø”M !Ô$ QÔ'ˆ	Ø-×4Ò4Ø˜1”Ø˜!”ð 5ñ 
ô 
ð 	
ð ˆ2r;   c                  óÐ  — ddl m}  |                      ¦   «         rk	 t          dd¦  «        5 }|                     ¦   «                              ¦   «         cddd¦  «         S # 1 swxY w Y   dS #  t          j        ¦   «         cY S xY w|                      ¦   «         r;ddl	}t          j        g d¢¦  «        }|                     |¦  «        d         d         S t          j        ¦   «         S )z¹
    For informational purposes, get a unique ID or serial for this machine (device).

    :returns: Unique machine (device) ID (serial), e.g. ``81655b901e334fc1ad59cbf2719806b7``.
    r   )Úplatformz/var/lib/dbus/machine-idÚrN)Úioregz-rd1z-cÚIOPlatformExpertDevicez-aÚIOPlatformSerialNumber)Útwisted.python.runtimer!  ÚisLinuxÚopenÚreadÚstripÚsocketÚgethostnameÚisMacOSXÚplistlibÚ
subprocessÚcheck_outputÚloads)r!  Úfr.  Ú
plist_datas       r,   r   r   ˆ  s4  € ð 0Ð/Ð/Ð/Ð/Ð/à×ÒÑÔð $ð	(åÐ0°#Ñ6Ô6ð (¸!Ø—v’v‘x”x—~’~Ñ'Ô'ð(ð (ð (ð (ñ (ô (ð (ð (ð (ð (ð (ð (øøøð (ð (ð (ð (ð (ð (øð	(åÔ%Ñ'Ô'Ð'Ð'Ð'øøøØ	×	Ò	Ñ	Ô	ð $ØˆˆˆÝÔ,Ð-dÐ-dÐ-dÑeÔeˆ
Ø�~Š~˜jÑ)Ô)¨!Ô,Ð-EÔFÐFåÔ!Ñ#Ô#Ð#s.   œA, ¬&AÁA, ÁA#Á#A, Á&A#Á'A, Á,BÚyellowc                 ó–   — t          | t          ¦  «        sd                     | ¦  «        } t          rt	          j        | ||¬¦  «        S | S )Nú{})ÚfgÚbold)rI   r1   rC   Ú
_HAS_CLICKÚclickÚstyle)r6   r8  Úcolors      r,   r   r   §  sI   € Ý�d�CÑ Ô ð !Ø�{Š{˜4Ñ Ô ˆÝð ÝŒ{˜4 E°Ð5Ñ5Ô5Ð5àˆr;   c                 óÄ   — t          j        | ¦  «        s(t          j        | ¦  «        st          j        | ¦  «        r!d                     | j        | j        ¦  «        }nd}|S )Nz{}.{}Úunknown)ÚinspectÚisclassÚ
isfunctionÚismethodrC   r]   r^   )r+   Úqns     r,   Ú_qnrD  °  s\   € Ý„�sÑÔð �wÔ1°#Ñ6Ô6ð ½'Ô:JÈ3Ñ:OÔ:Oð Ø�^Š^˜CœN¨CÔ,<Ñ=Ô=ˆˆàˆØ€Ir;   c           	      óè   — t          | ¦  «                             d¦  «        }t          |d         dd¬¦  «        t          dd                     |dd …         ¦  «        z   dd¬¦  «        z   }d|z   d	z   S )
NrÜ   r   r4  T©r<  r8  rV   Fú<ú>)rD  Úsplitr   rˆ   )r+   rC  r6   s      r,   r    r    ¸  so   € Ý	ˆS‰Œ�Š˜Ñ	Ô	€BÝˆb�Œe˜8¨$Ð/Ñ/Ô/µ"°S¸3¿8º8ÀBÀqÀrÀrÄFÑ;KÔ;KÑ5KÐS[ÐbgÐ2hÑ2hÔ2hÑh€DØ�‰:˜ÑÐr;   c                 óL   — t          d                     | ¦  «        dd¬¦  «        S )Nr6  ÚblueTrF  ©r   rC   ©Úoids    r,   r!   r!   ¾  s#   € Ýˆd�kŠk˜#ÑÔ f°4Ð8Ñ8Ô8Ð8r;   c                 ó    — t          | t          ¦  «        sd                     | ¦  «        } t          d                     | ¦  «        dd¬¦  «        S )Nr6  z"{}"r4  TrF  ©rI   r1   rC   r   rM  s    r,   r"   r"   Â  sF   € Ý�c�3ÑÔð Ø�kŠk˜#ÑÔˆÝˆf�mŠm˜CÑ Ô ¨°tÐ<Ñ<Ô<Ð<r;   Úwhitec                 óL   — t          d                     | ¦  «        ||¬¦  «        S )Nr6  rF  rL  )Úvalr<  r8  s      r,   r#   r#   È  s#   € Ýˆd�kŠk˜#ÑÔ e°$Ð7Ñ7Ô7Ð7r;   c                 ó    — t          | t          ¦  «        sd                     | ¦  «        } t          d                     | ¦  «        dd¬¦  «        S )Nr6  z<{}>ÚmagentaTrF  rP  rM  s    r,   r$   r$   Ì  sF   € Ý�c�3ÑÔð Ø�kŠk˜#ÑÔˆÝˆf�mŠm˜CÑ Ô ¨	¸Ð=Ñ=Ô=Ð=r;   c                 ó`   — | r+|                       d¦  «        sd                     | ¬¦  «        S | S )NÚ0xz0x{address}©Úaddress)rÓ   rC   rX  s    r,   r%   r%   Ò  s;   € Øð 5�w×)Ò)¨$Ñ/Ô/ð 5Ø×#Ò#¨GÐ#Ñ4Ô4Ð4Ø€Nr;   c                 óH   — | r|                       d¦  «        r
| dd …         S | S )NrW  r  )rÓ   rX  s    r,   r&   r&   Ø  s2   € Øð �7×%Ò% dÑ+Ô+ð Ø�q�r�rŒ{ÐØ€Nr;   c                 ó  — t          | d¦  «        5 }|                     |¦  «         |                     ¦   «         D ]0\  }}|r)|                     d                     ||¦  «        ¦  «         Œ1	 ddd¦  «         dS # 1 swxY w Y   dS )zB
    Internal helper, write the given tags to the given file-
    Úwz{}: {}
N)r(  ÚwriteÚitemsrC   )ÚfilepathÚtagsr  r2  ÚtagÚvalues         r,   r   r   Þ  sÏ   € õ 
ˆh˜Ñ	Ô	ð 7 Ø	�Š�‰ŒˆØ ŸJšJ™LœLð 	7ð 	7‰LˆS�%Øð 7Ø—’˜
×)Ò)¨#¨uÑ5Ô5Ñ6Ô6Ð6øð	7ð7ð 7ð 7ñ 7ô 7ð 7ð 7ð 7ð 7ð 7ð 7ð 7øøøð 7ð 7ð 7ð 7ð 7ð 7s   ‘AA:Á:A>ÂA>Úkey_pathÚprivatec                 ó&  — t           j                             | ¦  «        rAt           j                             | ¦  «        s"t	          d                     | ¦  «        ¦  «        ‚g d¢}|r|                     ddg¦  «         t          ¦   «         }t          | d¦  «        5 }d}| 	                    ¦   «         D ]Å}| 
                    ¦   «         dk    rd}Œ|r¦|                     d	d
¦  «        \  }}| 
                    ¦   «                              ¦   «         }| 
                    ¦   «         }||vr#t	          d                     || ¦  «        ¦  «        ‚||v r#t	          d                     || ¦  «        ¦  «        ‚|||<   ŒÆ	 ddd¦  «         n# 1 swxY w Y   |S )zr
    Internal helper. This parses a node.pub or node.priv file and
    returns a dict mapping tags -> values.
    z&Key file '{}' exists, but isn't a file)zpublic-key-ed25519zpublic-adr-ethz
created-atÚcreatorzuser-idz
machine-idznode-authidznode-cluster-ipzprivate-key-ed25519zprivate-key-ethr"  Fr~   Tú:rV   zInvalid tag '{}' in key file {}z!Duplicate tag '{}' in key file {}N)re   ÚpathÚexistsÚisfilerB   rC   Úextendr   r(  Ú	readlinesr*  rI  r†   )	rc  rd  Úallowed_tagsr`  Úkey_fileÚgot_blanklineÚlinera  rb  s	            r,   r   r   é  sÙ  € õ
 
„w‡~‚~�hÑÔð S­¬¯ª°xÑ(@Ô(@ð SÝÐ@×GÒGÈÑQÔQÑRÔRÐRðð ð €Lð  ð Hà×ÒÐ2Ð4EÐFÑGÔGÐGå‰=Œ=€DÝ	ˆh˜Ñ	Ô	ð " ØˆØ×&Ò&Ñ(Ô(ð 	"ð 	"ˆDØ�zŠz‰|Œ|˜rÒ!Ð!Ø $��Øð "Ø!ŸZšZ¨¨QÑ/Ô/‘
��UØ—i’i‘k”k×'Ò'Ñ)Ô)�ØŸš™œ�Ø˜lÐ*Ð*Ý#Ð$E×$LÒ$LÈSÐRZÑ$[Ô$[Ñ\Ô\Ð\Ø˜$�;�;Ý#Ð$G×$NÒ$NÈsÐT\Ñ$]Ô$]Ñ^Ô^Ð^Ø!��S‘	øð	"ð"ð "ð "ñ "ô "ð "ð "ð "ð "ð "ð "øøøð "ð "ð "ð "ð €Ks   ÂCFÆF
ÆF
)r-   TrZ   )rk   )NNF)Fr4  )rQ  Tr°   )Rr?  re   Útimerc   Úsysrß   rq   rn   ri   r  r+  r/  Úcollectionsr   Útypingr   r   r   Úpprintr   r   r  r  ÚOpenSSLr	   ÚImportErrorÚ__all__r
   r   rA   r   r   r   Úobjectr   rd   rg   r   r   r   r…   r™   r2   r1   Úboolr   r   rà   r•   r—   r   r   r!  rÓ   Úversion_infoÚperf_counterrž   Úclockr‚   r   r   r   r   rå   r   r  r  r  r   r:  r9  r   rD  r    r!   r"   r#   r$   r%   r&   r   r   rM   r;   r,   ú<module>r~     sZ  ðð4 €€€Ø 	€	€	€	Ø €€€Ø €€€Ø 
€
€
€
Ø 	€	€	€	Ø €€€Ø €€€Ø €€€Ø €€€Ø €€€Ø Ð Ð Ð Ø #Ð #Ð #Ð #Ð #Ð #à Ð Ð Ð Ð Ð Ø (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à €€€ðØ€DØÐÐÐÐÐÐøØð ð ð Ø€D€D€Dðøøøð€ð>ð ð ð ð/ð /ð /ñ „ð/ðd ðˆEð �uð  ð ð ð ñ „ðð2 ðCð Cð Cñ „ðCð0 ðð ñ „ðð!ð !ð !ð !ð !�&ñ !ô !ð !ðL �”˜dÐ$GÑHÔHÈÔK€ðLð Lð Lð(/ð /ð /ð(Dð Dð Dð Dð, 4Ð ðð ;Ð ðð  ð +/Ø(,Ø05ð	6ð 6 ð 6Ø$'ð6à" 3œ-ð6ð ! œð6ð  (¨œ~ð	6ð ;>ð	6ð 6ð 6ñ „ð6ðr ðrð rñ „ðrð "�r”z %Ð*=Ñ"=ÀÑ"LÐObÑ"bÐeqÑ"qð  uHñ  #Hð  KUñ  #Uñ  Vô  VÐ ð ð, ð ,ð ,ð ,ñ „ð,ð ðtð tñ „ðtð ðrð rñ „ðrð „<×Ò˜5Ñ!Ô!ð ð
 Ô˜6Ò!Ð!ØÔ"ˆˆà”ˆØˆ‰Œ€A€Að ŒY€Fð ðð ñ „ððPð Pð Pð Pð P�ñ Pô Pð PðfR&ð R&ð R&ð R&ð R&ˆfñ R&ô R&ð R&ðj(&ð (&ð (&ð (&ð (&�Fñ (&ô (&ð (&ðVcð cð cð&qð qð qð qð q�fñ qô qð qðh:ð :ð :ð :ð :˜ñ :ô :ð :ð&ð ð ðð ð ð$�Cð $ð $ð $ð $ð0Ø€L€L€LØ€J€JøØð ð ð Ø€J€J€Jðøøøðð ð ð ðð ð ðð ð ð9ð 9ð 9ð=ð =ð =ð8ð 8ð 8ð 8ð>ð >ð >ðð ð ðð ð ð7ð 7ð 7ð+ð +˜Cð +¨$ð +¸+ð +ð +ð +ð +ð +ð +s$   ÁA ÁA)Á(A)ÈH ÈHÈH