
    h:                     p   d 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ej                  j                         rddl
mZ nddlmZ i Z ej                  d      Zd_dZ e       d        Z G d de      Z G d	 d
e      Z e       Zej-                   ed       ed             ej/                   ed              ej0                  j2                  j4                  g defd ed      fd ed      fd ed      fd ed      fd ed      fd ed      fd ed      fd ed      fd ed       fd! ed"      fd# ed$      fd% ed&      fd' ed(      fd) ed*      fd+ ed,      fd- ed&      fd. ed/      fd0 ed1      fd2 ed3      fd4 ed3      fd5 ed3      fd6 ed3      fd7 ed3      fd8 ed9      fd: ed;      fd< ed;      fd= ed      fd> ed?      fd@ edA      fdB edA      fdC edD      fdE ed$      fdF edG      fdH ed$      fdI ed$      fdJ edK      fdL edM      fdN ed(      fdO edP      fdQ edR      fdS ed      fdT edU      fdV edW      fdX ed,      fdY edZ      fd[ ed\      fd] ed^      f Zy)`ah  
Tor versioning information and requirements for its features. These can be
easily parsed and compared, for instance...

::

  >>> from stem.version import get_system_tor_version, Requirement
  >>> my_version = get_system_tor_version()
  >>> print(my_version)
  0.2.1.30
  >>> my_version >= Requirement.TORRC_CONTROL_SOCKET
  True

**Module Overview:**

::

  get_system_tor_version - gets the version of our system's tor installation

  Version - Tor versioning information

.. data:: Requirement (enum)

  Enumerations for the version requirements of features.

  .. deprecated:: 1.6.0
     Requirement entries belonging to tor versions which have been obsolete for
     at least six months will be removed when we break backward compatibility
     in the 2.x stem release.

  ===================================== ===========
  Requirement                           Description
  ===================================== ===========
  **AUTH_SAFECOOKIE**                   SAFECOOKIE authentication method
  **DESCRIPTOR_COMPRESSION**            `Expanded compression support for ZSTD and LZMA <https://gitweb.torproject.org/torspec.git/commit/?id=1cb56afdc1e55e303e3e6b69e90d983ee217d93f>`_
  **DORMANT_MODE**                      **DORMANT** and **ACTIVE** :data:`~stem.Signal`
  **DROPGUARDS**                        DROPGUARDS requests
  **EVENT_AUTHDIR_NEWDESCS**            AUTHDIR_NEWDESC events
  **EVENT_BUILDTIMEOUT_SET**            BUILDTIMEOUT_SET events
  **EVENT_CIRC_MINOR**                  CIRC_MINOR events
  **EVENT_CLIENTS_SEEN**                CLIENTS_SEEN events
  **EVENT_CONF_CHANGED**                CONF_CHANGED events
  **EVENT_DESCCHANGED**                 DESCCHANGED events
  **EVENT_GUARD**                       GUARD events
  **EVENT_HS_DESC_CONTENT**             HS_DESC_CONTENT events
  **EVENT_NETWORK_LIVENESS**            NETWORK_LIVENESS events
  **EVENT_NEWCONSENSUS**                NEWCONSENSUS events
  **EVENT_NS**                          NS events
  **EVENT_SIGNAL**                      SIGNAL events
  **EVENT_STATUS**                      STATUS_GENERAL, STATUS_CLIENT, and STATUS_SERVER events
  **EVENT_STREAM_BW**                   STREAM_BW events
  **EVENT_TRANSPORT_LAUNCHED**          TRANSPORT_LAUNCHED events
  **EVENT_CONN_BW**                     CONN_BW events
  **EVENT_CIRC_BW**                     CIRC_BW events
  **EVENT_CELL_STATS**                  CELL_STATS events
  **EVENT_TB_EMPTY**                    TB_EMPTY events
  **EVENT_HS_DESC**                     HS_DESC events
  **EXTENDCIRCUIT_PATH_OPTIONAL**       EXTENDCIRCUIT queries can omit the path if the circuit is zero
  **FEATURE_EXTENDED_EVENTS**           'EXTENDED_EVENTS' optional feature
  **FEATURE_VERBOSE_NAMES**             'VERBOSE_NAMES' optional feature
  **GETINFO_CONFIG_TEXT**               'GETINFO config-text' query
  **GETINFO_GEOIP_AVAILABLE**           'GETINFO ip-to-country/ipv4-available' query and its ipv6 counterpart
  **GETINFO_MICRODESCRIPTORS**          'GETINFO md/all' query
  **GETINFO_UPTIME**                    'GETINFO uptime' query
  **HIDDEN_SERVICE_V3**                 Support for v3 hidden services
  **HSFETCH**                           HSFETCH requests
  **HSFETCH_V3**                        HSFETCH for version 3 hidden services
  **HSPOST**                            HSPOST requests
  **ADD_ONION**                         ADD_ONION and DEL_ONION requests
  **ADD_ONION_BASIC_AUTH**              ADD_ONION supports basic authentication
  **ADD_ONION_NON_ANONYMOUS**           ADD_ONION supports non-anonymous mode
  **ADD_ONION_MAX_STREAMS**             ADD_ONION support for MaxStreamsCloseCircuit
  **LOADCONF**                          LOADCONF requests
  **MICRODESCRIPTOR_IS_DEFAULT**        Tor gets microdescriptors by default rather than server descriptors
  **SAVECONF_FORCE**                    Added the 'FORCE' flag to SAVECONF
  **TAKEOWNERSHIP**                     TAKEOWNERSHIP requests
  **TORRC_CONTROL_SOCKET**              'ControlSocket <path>' config option
  **TORRC_PORT_FORWARDING**             'PortForwarding' config option
  **TORRC_DISABLE_DEBUGGER_ATTACHMENT** 'DisableDebuggerAttachment' config option
  **TORRC_VIA_STDIN**                   Allow torrc options via 'tor -f -' (:trac:`13865`)
  **ONION_SERVICE_AUTH_ADD**            For adding ClientAuthV3 to a v3 onion service via ADD_ONION
  ===================================== ===========
    N)	lru_cachez=^([0-9]+)\.([0-9]+)\.([0-9]+)(\.[0-9]+)?(-\S*)?(( \(\S*\))*)$c                 L   | t         vrd| z  }	 t        j                  j                  j	                  |      }|D ]?  }|j                  d      s|j                  d      s'	 |dd	 }t        |      t         | <    n | t         vr t        d
|ddj                  |            t         |    S # t
        $ rQ}dt        |      v r4t        j                  j                  |       rd| z  }t        |      d|z  }t        |      d}~ww xY w# t        $ r}t        |      d}~ww xY w)a  
  Queries tor for its version. This is os dependent, only working on linux,
  osx, and bsd.

  :param str tor_cmd: command used to run tor

  :returns: :class:`~stem.version.Version` provided by the tor command

  :raises: **IOError** if unable to query or parse the version
  z%s --versionzNo such file or directoryz2Unable to check tor's version. '%s' doesn't exist.z1Unable to run '%s'. Maybe tor isn't in your PATH?NzTor version .   'z'' didn't provide a parseable version:


)VERSION_CACHEstemutilsystemcallOSErrorstrospathisabsIOError
startswithendswithVersion
ValueErrorjoin)tor_cmdversion_cmdversion_outputexclineversion_strs         V/var/www/betterdocs.net/sherlock_api/venv/lib/python3.12/site-packages/stem/version.pyget_system_tor_versionr!   k   s+    M! 7*Kyy'',,[9n  
 
	(T]]3-?	R+#*;#7-
 
 m#UYU^U^_mUnopp	w	7  	 
%C	077==!DwN# CL DkQ#CL	*  	
	s0   )B- "D
-	D6ADD
	D#DD#c                     t        |       S N)r   r   s    r    _get_versionr%      s    		    c                   @    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)r   a  
  Comparable tor version. These are constructed from strings that conform to
  the 'new' style in the `tor version-spec
  <https://gitweb.torproject.org/torspec.git/tree/version-spec.txt>`_,
  such as "0.1.4" or "0.2.2.23-alpha (git-7dcd105be34a4f44)".

  .. versionchanged:: 1.6.0
     Added all_extra parameter.

  :var int major: major version
  :var int minor: minor version
  :var int micro: micro version
  :var int patch: patch level (**None** if undefined)
  :var str status: status tag such as 'alpha' or 'beta-dev' (**None** if undefined)
  :var str extra: first extra information without its parentheses such as
    'git-8be6058d8f31e578' (**None** if undefined)
  :var list all_extra: all extra information entries, without their parentheses
  :var str git_commit: git commit id (**None** if it wasn't provided)

  :param str version_str: version to be parsed

  :raises: **ValueError** if input isn't a valid tor version
  c                 p   || _         t        j                  |      }|r|j                         \  }}}}}}}	|rt	        |dd        }|r|dd  }t	        |      | _        t	        |      | _        t	        |      | _        || _        || _	        |r/|j                         j                         D 
cg c]  }
|
dd 	 c}
ng | _        | j                  r| j                  d   nd | _        d | _        | j                  D ]'  }|st        j                  d|      s|dd  | _         y  y t!        d|z        c c}
w )N   r   r   z^git-[0-9a-f]{16}$   z+'%s' isn't a properly formatted tor version)r   VERSION_PATTERNmatchgroupsintmajorminormicropatchstatusstripsplit	all_extraextra
git_commitrer   )selfr   version_partsr/   r0   r1   r2   r3   	extra_str_entryr7   s               r    __init__zVersion.__init__   s$   "D#))+6M9F9M9M9O6eUE5&)Q
 
E!"I	u:dju:dju:djdjdkOX1B1H1H1JKaK^`dn(,4>>!$Ddjdo>> %RXX2E:!!"I$/

 D{RSS Ls   /D3c                     | j                   S )z<
    Provides the string used to construct the version.
    r$   r:   s    r    __str__zVersion.__str__   s    
 r&   c                    t        |t              sydD ]2  }t        | |      }t        ||      }|d}|d}||k7  s) |||      c S  | j                  r| j                  nd}|j                  r|j                  nd} |||      S )z:
    Compares version ordering according to the spec.
    F)r/   r0   r1   r2   r    )
isinstancer   getattrr3   )r:   othermethodattr
my_versionother_version	my_statusother_statuss           r    _comparezVersion._compare   s    
 eW%4 14&jeT*m		
			}	$j-001$  ${{I#(<<5<<RL)\**r&   c           	      N    t         j                  j                  | dddddd      S )Nr/   r0   r1   r2   r3   T)cache)r   r   
_hash_attrrA   s    r    __hash__zVersion.__hash__   s'    99gw(\`aar&   c                 (    | j                  |d       S )Nc                     | |k(  S r#    sos     r    <lambda>z Version.__eq__.<locals>.<lambda>  
    Q!V r&   )rN   r:   rG   s     r    __eq__zVersion.__eq__  s    == 344r&   c                     | |k(   S r#   rU   r[   s     r    __ne__zVersion.__ne__  s    u}r&   c                     t        |t              r|j                  D ]  } ||       s y y| j                  |d       S )z
    Checks if this version meets the requirements for a given feature. We can
    be compared to either a :class:`~stem.version.Version` or
    :class:`~stem.version._VersionRequirements`.
    TFc                     | |kD  S r#   rU   rV   s     r    rY   z Version.__gt__.<locals>.<lambda>  s
    QU r&   rE   _VersionRequirementsrulesrN   r:   rG   rules      r    __gt__zVersion.__gt__  sC     %-.++ $: == 233r&   c                     t        |t              r|j                  D ]  } ||       s y y| j                  |d       S )NTFc                     | |k\  S r#   rU   rV   s     r    rY   z Version.__ge__.<locals>.<lambda>  rZ   r&   ra   rd   s      r    __ge__zVersion.__ge__  sA    %-.++ $: == 344r&   N)__name__
__module____qualname____doc__r?   rB   rN   rR   r\   r^   rf   ri   rU   r&   r    r   r      s2    0T@+>b54 5r&   r   c                   .    e Zd ZdZd ZddZddZddZy)	rb   a  
  Series of version constraints that can be compared to. For instance, this
  allows for comparisons like 'if I'm greater than version X in the 0.2.2
  series, or greater than version Y in the 0.2.3 series'.

  This is a logical 'or' of the series of rules.
  c                     g | _         y r#   )rc   rA   s    r    r?   z_VersionRequirements.__init__+  s	    DJr&   c                     |r| j                   j                  fd       y| j                   j                  fd       y)z
    Adds a constraint that we're greater than the given version.

    :param stem.version.Version version: version we're checking against
    :param bool inclusive: if comparison is inclusive or not
    c                     | k  S r#   rU   vversions    r    rY   z3_VersionRequirements.greater_than.<locals>.<lambda>7      'Q, r&   c                     | k  S r#   rU   rr   s    r    rY   z3_VersionRequirements.greater_than.<locals>.<lambda>9      'A+ r&   Nrc   appendr:   rt   	inclusives    ` r    greater_thanz!_VersionRequirements.greater_than.  .     
jj./
jj-.r&   c                     |r| j                   j                  fd       y| j                   j                  fd       y)z
    Adds a constraint that we're less than the given version.

    :param stem.version.Version version: version we're checking against
    :param bool inclusive: if comparison is inclusive or not
    c                     | k\  S r#   rU   rr   s    r    rY   z0_VersionRequirements.less_than.<locals>.<lambda>D  ru   r&   c                     | kD  S r#   rU   rr   s    r    rY   z0_VersionRequirements.less_than.<locals>.<lambda>F  rw   r&   Nrx   rz   s    ` r    	less_thanz_VersionRequirements.less_than;  r}   r&   c                 R    fd}| j                   j                  |       y)a  
    Adds constraint that we're within the range from one version to another.

    :param stem.version.Version from_version: beginning of the comparison range
    :param stem.version.Version to_version: end of the comparison range
    :param bool from_inclusive: if comparison is inclusive with the starting version
    :param bool to_inclusive: if comparison is inclusive with the ending version
    c                 p    rr| cxk  xr k  S c S r| cxk  xr k  S c S | cxk  xr k  S c S r#   rU   )rs   from_inclusivefrom_versionto_inclusive
to_versions    r    new_rulez/_VersionRequirements.in_range.<locals>.new_ruleR  sM    	Lq.J....q-:----a,*,,,,r&   Nrx   )r:   r   r   r   r   r   s    ```` r    in_rangez_VersionRequirements.in_rangeH  s    - 	JJhr&   N)T)TF)rj   rk   rl   rm   r?   r|   r   r   rU   r&   r    rb   rb   "  s    // r&   rb   z0.2.2.36z0.2.3.0z0.2.3.13AUTH_SAFECOOKIEDESCRIPTOR_COMPRESSIONz0.3.1.1-alphaDORMANT_MODEz0.4.0.1-alpha
DROPGUARDSz0.2.5.1-alphaEVENT_AUTHDIR_NEWDESCSz0.1.1.10-alphaEVENT_BUILDTIMEOUT_SETz0.2.2.7-alphaEVENT_CIRC_MINORz0.2.3.11-alphaEVENT_CLIENTS_SEENz0.2.1.10-alphaEVENT_CONF_CHANGEDz0.2.3.3-alphaEVENT_DESCCHANGEDz0.1.2.2-alphaEVENT_GUARDz0.1.2.5-alphaEVENT_HS_DESC_CONTENTz0.2.7.1-alphaEVENT_NSz0.1.2.3-alphaEVENT_NETWORK_LIVENESSz0.2.7.2-alphaEVENT_NEWCONSENSUSz0.2.1.13-alphaEVENT_SIGNALz0.2.3.1-alphaEVENT_STATUSEVENT_STREAM_BWz0.1.2.8-betaEVENT_TRANSPORT_LAUNCHEDz0.2.5.0-alphaEVENT_CONN_BWz0.2.5.2-alphaEVENT_CIRC_BWEVENT_CELL_STATSEVENT_TB_EMPTYEVENT_HS_DESCEXTENDCIRCUIT_PATH_OPTIONALz0.2.2.9FEATURE_EXTENDED_EVENTSz0.2.2.1-alphaFEATURE_VERBOSE_NAMESGETINFO_CONFIG_TEXTGETINFO_GEOIP_AVAILABLEz0.3.2.1-alphaGETINFO_MICRODESCRIPTORSz0.3.5.1-alphaGETINFO_UPTIMEHIDDEN_SERVICE_V3z0.3.3.1-alphaHSFETCH
HSFETCH_V3z0.4.1.1-alphaHSPOST	ADD_ONIONADD_ONION_BASIC_AUTHz0.2.9.1-alphaADD_ONION_NON_ANONYMOUSz0.2.9.3-alphaADD_ONION_MAX_STREAMSLOADCONFz0.2.1.1MICRODESCRIPTOR_IS_DEFAULTz0.2.3.3SAVECONF_FORCETAKEOWNERSHIPz0.2.2.28-betaTORRC_CONTROL_SOCKETz0.2.0.30TORRC_PORT_FORWARDING!TORRC_DISABLE_DEBUGGER_ATTACHMENTz0.2.3.9TORRC_VIA_STDINz0.2.6.3-alphaONION_SERVICE_AUTH_ADDz0.4.6.1-alpha)tor)rm   r   r9   stem.prereqr   	stem.utilstem.util.enumstem.util.systemprereq_is_lru_cache_available	functoolsr   stem.util.lru_cacher
   compiler+   r!   r%   objectr   rb   safecookie_reqr   r|   r   enumEnumRequirementrU   r&   r    <module>r      s  Rh 
 	    ;;&&(!+ "**]^, ^  @5f @5F8 6 8 v &'   
+WY-? @   GJ/ 0!diinn!! 1n%1W_561 7?+,1 )*	1
 W%5671 W_561 w/011 !1231 121 011 '/*+1 GO451 w'(1 W_561 !1231  7?+,!1" 7?+,#1$ gn-.%1& w78'1( GO,-)1* GO,-+1, w/0-1. W_-./10 GO,-112 !')"45314 go67516 GO45718 '/2391: go67;1< w78=1> W_-.?1@ 01A1B go&'C1D )*E1F W_%&G1H ()I1J 7?34K1L go67M1N GO45O1P wy!"Q1R  !34S1T W_-.U1V GO,-W1X 7:./Y1Z GO45[1\ '	(:;]1^ go./_1` W_56a1r&   