
    af                         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    ?/var/www/html/env/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 1vv~~fufI xx(++ 	&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    Bxx5AHHbRRSSSBxx5AHHbRRSSS
2ww#b''QXXY\]_Y`Y`befhbibijjkkk	sBB	sBB3r77^^  
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      sV    & :B11::1	z_==%;<<SbS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     88Or;   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

:(((DJzr;   c                 *    |                                  S N)rX   rR   s    r,   __next__zIdGenerator.__next__   s    yy{{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-      =rz!}}--a0=@KG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[     	DIeFmmb(2-..//ABJqMM**7F7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KK3...1L1S1STXY^T_T_1`1`...((E 
*C



C''ZZZZZU;;X5Y5YZZZZZKxxBGS4+<+<*=*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^anr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     88Or;   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;      	"!GGDM DMMM DM!DMMMr;   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MMS4=00MM!DM= = 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!GGDM DM= ''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     ww"/++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     #WW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
        gh㈵>z%d nsg    eAg{Gz?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     dm##	T](B(Bg&y)AAA w;;%K"8"88AAXX%H"5"55AAVV%E	"2"22AAq)Awwqzz! ||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)?07:;;;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>!+<<< 55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bRTBJsRZZU33;;CFFFLMMbbbr;   rM   )	wildcardss    r,   wildcards2patternsr     s      cbXa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99T%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     	%   ?""ffDO''%'DOE"%%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   #ffDOOO&e$$$''?....55g>>>>>%    ('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JJv<#JJ(t|(@@@@@@AAASU;;;$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#    
  /(CI...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 (!vvxx~~''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (	(%'''''					 $,-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    dC   !{{4   {4E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 ':J3:O:O ^^CNC,<==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e8$///"S388BqrrF;K;K5KS[bg2h2h2hhD:r;   c                 L    t          d                    |           dd          S )Nr6  blueTrF  r   rC   oids    r,   r!   r!     s#    dkk#f4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    c3 kk#fmmC  t<<<<r;   whitec                 L    t          d                    |           ||          S )Nr6  rF  rL  )valr<  r8  s      r,   r#   r#     s#    dkk#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    c3 kk#fmmC  	====r;   c                 `    | r+|                      d          sd                    |           S | S )N0xz0x{address}address)r   rC   rX  s    r,   r%   r%     s;     5w))$// 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++ qrr{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	 JJLL 	7 	7LS% 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24EFGGG==D	h		 "&&(( 	" 	"Dzz||r!! $ "!ZZQ//
Uiikk''))l**#$E$L$LSRZ$[$[\\\$;;#$G$N$NsT\$]$]^^^!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   DDD>   / / / /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 "rz%*="="LOb"beq"q  uH  #H  KU  #U  V  V  , , , , , t t t r r r <5!! 
 6!!"AA YF   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LLLJJ   JJJ       9 9 9= = =8 8 8 8> > >    7 7 7+ +C +$ ++ + + + + + +s$   A A)(A)H HH