
    hSo                     T   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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 ej                   j#                         rddlmZ nddlmZ 	 ddlmZ ej2                  j4                  j7                  ddddd	d
ddd	      ZdZej<                  j?                  ej<                  jA                  e!      d      Z"da#ej2                  jH                  jK                          xrL ej2                  jH                  jM                          xr% ej2                  jH                  jO                          Z(dZ)dde)z  dddddfZ* edejV                  fdejX                  fdejZ                  fdej\                  fdej^                  fdej`                  fdejb                  fdejd                  ff      Z3 G d  d!e4      Z5d" Z6 G d# d$e7      Z8 e       d0d%       Z9d& Z:d' Z;dded(fd)Z< G d* d+e7      Z=d, Z>d- Z?d. Z@d/ ZAy# e$ r
 ddlmZ Y w xY w# e$ r ddlZY w xY w)1a  
Information available about Tor from `its manual
<https://www.torproject.org/docs/tor-manual.html.en>`_. This provides three
methods of getting this information...

* :func:`~stem.manual.Manual.from_cache` provides manual content bundled with
  Stem. This is the fastest and most reliable method but only as up-to-date as
  Stem's release.

* :func:`~stem.manual.Manual.from_man` reads Tor's local man page for
  information about it.

* :func:`~stem.manual.Manual.from_remote` fetches the latest manual information
  remotely. This is the slowest and least reliable method but provides the most
  recent information about Tor.

Manual information includes arguments, signals, and probably most usefully the
torrc configuration options. For example, say we want a little script that told
us what our torrc options do...

.. literalinclude::  /_static/example/manual_config_options.py
   :language: python

|

.. image:: /_static/manual_output.png

|

**Module Overview:**

::

  query - performs a query on our cached sqlite manual information
  is_important - Indicates if a configuration option is of particularly common importance.
  download_man_page - Downloads tor's latest man page.

  Manual - Information about Tor available from its manual.
   | |- from_cache - Provides manual information cached with Stem.
   | |- from_man - Retrieves manual information from its man page.
   | +- from_remote - Retrieves manual information remotely from tor's latest manual.
   |
   +- save - writes the manual contents to a given location

.. versionadded:: 1.5.0
    N)OrderedDict)	lru_cacheGENERALCLIENTRELAY	DIRECTORY	AUTHORITYHIDDEN_SERVICEDENIAL_OF_SERVICETESTINGUNKNOWNz9https://gitweb.torproject.org/tor.git/plain/doc/tor.1.txtzcached_manual.sqlite   z$CREATE TABLE schema(version INTEGER)z'INSERT INTO schema(version) VALUES (%i)zdCREATE TABLE metadata(name TEXT, synopsis TEXT, description TEXT, man_commit TEXT, stem_commit TEXT)zACREATE TABLE commandline(name TEXT PRIMARY KEY, description TEXT)z=CREATE TABLE signals(name TEXT PRIMARY KEY, description TEXT)z;CREATE TABLE files(name TEXT PRIMARY KEY, description TEXT)zCREATE TABLE torrc(key TEXT PRIMARY KEY, name TEXT, category TEXT, usage TEXT, summary TEXT, description TEXT, position INTEGER)zGENERAL OPTIONSzCLIENT OPTIONSzSERVER OPTIONSzDIRECTORY SERVER OPTIONSz"DIRECTORY AUTHORITY SERVER OPTIONSzHIDDEN SERVICE OPTIONSz$DENIAL OF SERVICE MITIGATION OPTIONSzTESTING NETWORK OPTIONSc                   "     e Zd ZdZ fdZ xZS )SchemaMismatchz
  Database schema doesn't match what Stem supports.

  .. versionadded:: 1.6.0

  :var int database_schema: schema of the database
  :var tuple supported_schemas: schemas library supports
  c                 H    t         t        |   |       || _        || _        y N)superr   __init__database_schemalibrary_schema)selfmessager   r   	__class__s       U/var/www/betterdocs.net/sherlock_api/venv/lib/python3.12/site-packages/stem/manual.pyr   zSchemaMismatch.__init__y   s"    	.$(1*D(D    )__name__
__module____qualname____doc__r   __classcell__)r   s   @r   r   r   o   s    ) )r   r   c                     t         j                  j                         st        d      ddl}t
        |j                  t              at
        j                  | |      S )a,  
  Performs the given query on our sqlite manual cache. This database should
  be treated as being read-only. File permissions generally enforce this, and
  in the future will be enforced by this function as well.

  ::

    >>> import stem.manual
    >>> print(stem.manual.query('SELECT description FROM torrc WHERE key=?', 'CONTROLSOCKET').fetchone()[0])
    Like ControlPort, but listens on a Unix domain socket, rather than a TCP socket.  0 disables ControlSocket. (Unix and Unix-like systems only.) (Default: 0)

  .. versionadded:: 1.6.0

  :param str query: query to run on the cache
  :param list param: query parameters

  :returns: :class:`sqlite3.Cursor` with the query results

  :raises:
    * **ImportError** if the sqlite3 module is unavailable
    * **sqlite3.OperationalError** if query fails
  z$Querying requires the sqlite3 moduler   N)	stemprereqis_sqlite_availableImportErrorsqlite3DATABASEconnect
CACHE_PATHexecute)queryparamr&   s      r   r+   r+      sL    0 
	(	(	*
<
== z*H			%	''r   c                   F    e Zd ZdZej
                  dddfdZd Zd Zd Z	y)ConfigOptiona  
  Tor configuration attribute found in its torrc.

  :var str name: name of the configuration option
  :var stem.manual.Category category: category the config option was listed
    under, this is Category.UNKNOWN if we didn't recognize the category
  :var str usage: arguments accepted by the option
  :var str summary: brief description of what the option does
  :var str description: longer manual description with details
   c                 J    || _         || _        || _        || _        || _        y r   namecategoryusagesummarydescription)r   r2   r3   r4   r5   r6   s         r   r   zConfigOption.__init__   s&    DIDMDJDL"Dr   c           	      N    t         j                  j                  | dddddd      S )Nr2   r3   r4   r5   r6   Tcacher"   util
_hash_attrr   s    r   __hash__zConfigOption.__hash__   s'    99fj'9meijjr   c                 T    t        |t              rt        |       t        |      k(  S dS NF)
isinstancer.   hashr   others     r   __eq__zConfigOption.__eq__   s#    (25,(G4:e$RURr   c                     | |k(   S r    rC   s     r   __ne__zConfigOption.__ne__       u}r   N)
r   r   r   r   Categoryr   r   r>   rE   rH   rG   r   r   r.   r.      s/    	 '/&6&6b`b #kSr   r.   c           	         t         j                  j                  j                         }t        j
                  j                  t        j
                  j                  t              d      }	 |j                  |       t        |j                         D cg c]9  }|j                  d      s| r|j                         n||j                  |      f; c}      }|j                  dg d      D cg c]  }| r|j                         n| c}|d<   |S c c}w c c}w # t        $ r;}t         j                  j                   j#                  d|d|       i cY d}~S d}~ww xY w)	aM  
  Provides a dictionary for our settings.cfg. This has a couple categories...

    * manual.important (list) - configuration options considered to be important
    * manual.summary.* (str) - summary descriptions of config options

  :param bool lowercase: uses lowercase keys if **True** to allow for case
    insensitive lookups
  zsettings.cfgzmanual.summary.manual.importantT)multiplez?BUG: stem failed to load its internal manual information from '': N)r"   r;   confConfigospathjoindirname__file__loaddictkeys
startswithlower	get_value	Exceptionlogwarn)	lowercaseconfigconfig_pathkeyconfig_dictr2   excs          r   _configre      s0    99>>  "&RWW__X6G+
KK^d^i^i^k  RWZoro}o}  P  pQ	sF<L<LS<QR  R  SKW]WgWghz|~  LPWg  XQ  'Rtytzz|d'J  'RK"# R 'R	 IIMMcnpstuIsB   +(D D*'DD .D	D 
D 	E$0EEEc                     g }dD ]  }t        | |      }t        ||      }||k7  s"|j                  d|z         |dv r*|j                  d|z         |j                  d|z         n|dk(  r|j                         D ]x  \  }}|j                  |      }||j                  d|z         .||k7  s4dD ]@  }t        ||      t        ||      k7  s|j                  d	|d
|dt        ||             B z t	        |j                               j                  |j                               D ]  }|j                  d|z          nt	        |j                               j                  |j                               }	t	        |j                               j                  |j                               }
|	D ]  }|j                  d|z          |
D ]  }|j                  d|z          |j                  d        dj                  |      S )z7
  Provides a description of how two manuals differ.
  )r2   synopsisr6   commandline_optionssignalsfilesconfig_optionsz * Manual's %s attribute changed
)r2   rg   r6   z  Previously...

%s
z  Updating to...

%srk   z   adding new config option => %sr1   z  modified z (z) => z  removing config option => %sz  adding %s => %sz  removing %s => %s
)getattrappenditemsgetsetrX   
differencerS   )previous_manual
new_manuallinesattrprevious_attrnew_attrconfig_nameconfig_attrpreviousadded_itemsremoved_items
added_itemremoved_items                r   _manual_differencesr      s   
 %n !dOT2Mz4(H ll6=>	4	4.>?-89##(0(8 	k$K"&&{3(LL;kIJh&O kd+wx/FF;gVacgNhijk	k }1134??P 	GK
,,7+E
F	G (..*+66}7J7J7LMM//12==hnn>NO% 	9J
,,*Z7
8	9 * 	=L
,,,|;
<	= ll4C!F 
5	r   c                 <    | j                         t               d   v S )z
  Indicates if a configuration option of particularly common importance or not.

  :param str option: tor configuration option to check

  :returns: **bool** that's **True** if this is an important option and
    **False** otherwise
  rL   )rZ   re   )options    r   is_importantr     s     
79%78	88r      c                    | s|st        d      t        j                  j                  j	                  d      st        d      t        j                         }t        j                  j                  |d      }t        j                  j                  |d      }	 	 t        |d      5 }t        j                  ||      }t        j                  ||       ddd       	 t        j                  j                  j'                  d|z         t        j                  j)                  |      st+        d      	 | rj	 t        j                  j3                  |       }t        j                  j)                  |      st        j4                  |       t        j6                  ||        |r;t        |d      5 }t        j                  ||       |j9                          ddd       t        j:                  |       y# 1 sw Y   !xY w#  t!        j"                         d	d
 \  }	}
d|d|d|	}t        j$                  ||	|
|      xY w# t        j                  j                  j,                  $ r*}	t        d|	j.                  d|	j0                        d}	~	ww xY w# t*        $ r}	t        |	      d}	~	ww xY w# 1 sw Y   xY w# t        j:                  |       w xY w)a#  
  Downloads tor's latest man page from `gitweb.torproject.org
  <https://gitweb.torproject.org/tor.git/plain/doc/tor.1.txt>`_. This method is
  both slow and unreliable - please see the warnings on
  :func:`~stem.manual.Manual.from_remote`.

  :param str path: path to save tor's man page to
  :param file file_handle: file handler to save tor's man page to
  :param str url: url to download tor's asciidoc manual from
  :param int timeout: seconds to wait before timing out the request

  :raises: **IOError** if unable to retrieve the manual
  z?Either the path or file_handle we're saving to must be provideda2xz2We require a2x from asciidoc to provide a man pagez	tor.1.txtztor.1wb)timeoutNr      z%Unable to download tor's manual from z to : za2x -f manpage %szno man page was generatedUnable to run 'rN   rb)
ValueErrorr"   r;   systemis_availableIOErrortempfilemkdtemprQ   rR   rS   openurlliburlopenshutilcopyfileobjsysexc_infoDownloadFailedcallexistsOSError	CallErrorcommandstderrrT   makedirscopyfileflushrmtree)rR   file_handleurlr   dirpathasciidoc_pathmanual_pathasciidoc_filerequestrd   
stacktracer   path_dirmanual_files                 r   download_man_pager     s;    
k
V
WW99((/
F
GG''',,w4-Wg.+"?t$ 3..87M23J
ii/-?@WW^^K(122 )
 77??4(ww~~h'
++h
T* T" k;4 MM'A3 3?q+oc:GJM[^_gS*g>> 99%% JSZZHIIJ  cl  MM's   H  &.G3H  AI 3J> 7A)J  J> .'J2J> 3G=8H   ?H??J> 'J)%JJJ> 	J/J**J//J> 2J;7J> >Kc                       e Zd ZdZd Zedd       Zed        Zed        Zedd       Z	edd       Z
d	 Zd
 Zd Zd Zd Zd Zy)Manuala  
  Parsed tor man page. Tor makes no guarantees about its man page format so
  this may not always be compatible. If not you can use the cached manual
  information stored with Stem.

  This does not include every bit of information from the tor manual. For
  instance, I've excluded the 'THE CONFIGURATION FILE FORMAT' section. If
  there's a part you'd find useful then `file an issue
  <https://trac.torproject.org/projects/tor/wiki/doc/stem/bugs>`_ and we can
  add it.

  :var str name: brief description of the tor command
  :var str synopsis: brief tor command usage
  :var str description: general description of what tor does

  :var collections.OrderedDict commandline_options: mapping of commandline arguments to their descripton
  :var collections.OrderedDict signals: mapping of signals tor accepts to their description
  :var collections.OrderedDict files: mapping of file paths to their description

  :var collections.OrderedDict config_options: :class:`~stem.manual.ConfigOption` tuples for tor configuration options

  :var str man_commit: latest tor commit editing the man page when this
    information was cached
  :var str stem_commit: stem commit to cache this manual information
  c                     || _         || _        || _        t        |      | _        t        |      | _        t        |      | _        t        |      | _        d | _        d | _	        d | _
        y r   )r2   rg   r6   r   rh   ri   rj   rk   
man_commitstem_commitschema)r   r2   rg   r6   rh   ri   rj   rk   s           r   r   zManual.__init__u  sa    DIDM"D*+>?Dw'DLU#DJ%n5DDODDKr   Nc                     | t         } | &| j                  d      rt        j                  |       S t        j	                  |       S )ax  
    Provides manual information cached with Stem. Unlike
    :func:`~stem.manual.Manual.from_man` and
    :func:`~stem.manual.Manual.from_remote` this doesn't have any system
    requirements, and is faster too. Only drawback is that this manual
    content is only as up to date as the Stem release we're using.

    .. versionchanged:: 1.6.0
       Added support for sqlite cache. Support for
       :class:`~stem.util.conf.Config` caches will be dropped in Stem 2.x.

    :param str path: cached manual content to read, if not provided this uses
      the bundled manual information

    :returns: :class:`~stem.manual.Manual` with our bundled manual information

    :raises:
      * **ImportError** if cache is sqlite and the sqlite3 module is
        unavailable
      * **IOError** if a **path** was provided and we were unable to read
        it or the schema is out of date
    .sqlite)r)   endswithr   _from_sqlite_cache_from_config_cache)rR   s    r   
from_cachezManual.from_cache  sA    6 |dDMM)4&&t,,&&t,,r   c           
         t         j                  j                         st        d      dd l}t
        j                  j                  |       st        d| z        |j                  |       5 }	 |j                  d      j                         d   }|t        k7  rt        dt        d| d||t        f      |j                  d      j                         \  }}}}}t        |j                  d      j!                               }
t        |j                  d      j!                               }t        |j                  d      j!                               }t#               }|j                  d      j!                         D ]  }|\  }}}}}t%        |||||      ||<    t'        ||||
|||      }||_        ||_        ||_        |cd d d        S # |j                  $ r}	t        d	| d
|	      d }	~	ww xY w# 1 sw Y   y xY w)Nz2Reading a sqlite cache requires the sqlite3 moduler   z%s doesn't existzSELECT version FROM schemaz(Stem's current manual schema version is z, but z was version zISELECT name, synopsis, description, man_commit, stem_commit FROM metadataz&Failed to read database metadata from r   z)SELECT name, description FROM commandlinez%SELECT name, description FROM signalsz#SELECT name, description FROM fileszOSELECT name, category, usage, summary, description FROM torrc ORDER BY position)r"   r#   r$   r%   r&   rQ   rR   r   r   r(   r*   fetchoneSCHEMA_VERSIONr   OperationalErrorrW   fetchallr   r.   r   r   r   r   )rR   r&   connr   r2   rg   r6   r   r   rd   commandlineri   rj   rk   entryr   r3   r4   r5   option_descriptionmanuals                        r   r   zManual._from_sqlite_cache  s   ;;**,LMM77>>$&-..		 $T:;DDFqI^#ftvz  }C   D  FL  O]  N_  `  `?C||  MX  @Y  @b  @b  @d<hZ &QR[[]^kT\\"IJSSUVg4<< EFOOQRe"}n<< qr{{} d%?D<%*<!-fhwPb!cvd dHk;P^_f$f&ffm5  %% TcRSST s2   ,G6.A/GC'G6G3G..G33G66G?c                 `   t         j                  j                  j                         }|j	                  | d       t               }|j                         D ]  }|j                  d      s|j                  d      d   }||vs.t        |j                  d|z  d      |j                  d|z  d      |j                  d	|z  d      |j                  d
|z  d      |j                  d|z  d            ||<    t        |j                  dd      |j                  dd      |j                  dd      |j                  dt                     |j                  dt                     |j                  dt                     |      }|j                  dd       |_        |j                  dd       |_        |S )NF)
commentingzconfig_options..r   config_options.%s.namer/   config_options.%s.categoryconfig_options.%s.usageconfig_options.%s.summaryconfig_options.%s.descriptionr2   rg   r6   rh   ri   rj   r   r   )r"   r;   rO   rP   rV   r   rX   rY   splitr.   rp   r   r   r   )rR   rO   rk   rb   r   s        r   r   zManual._from_config_cache  su   99>>  "DIIdI' ]Nyy{ 	)	*iinQn$ ,HH-3R8HH1C7<HH.4b9HH036;HH4s:B?!.
 
hhvr
hhz2
hh}b!
hh$km4
hhy+-(
hhw&F t4F-6FMr   c                 P   dt         rdndd| }	 t        j                  j                  j	                  |ddi      }t        |      t               }}t        j                         D ]"  \  }}t        |||j                  |g              $ |D ]M  }|j                  d      s|t        vs|dvs#t        |t        j                  |j                  |g              O t!        t#        |j                  dg             t#        |j                  dg             t#        |j                  dg             t%        |j                  dg             t%        |j                  dg             t%        |j                  dg             |      S # t
        $ r}t        d|d	|      d
}~ww xY w)a  
    Reads and parses a given man page.

    On OSX the man command doesn't have an '--encoding' argument so its results
    may not quite match other platforms. For instance, it normalizes long
    dashes into '--'.

    :param str man_path: path argument for 'man', for example you might want
      '/path/to/tor/doc/tor.1' to read from tor's git repository

    :returns: :class:`~stem.manual.Manual` for the system's man page

    :raises: **IOError** if unable to retrieve the manual
    zman z--encoding=asciir/   z -P cat MANWIDTH10000000)envr   rN   Nz OPTIONS)COMMAND-LINE OPTIONSzNON-PERSISTENT OPTIONSNAMESYNOPSISDESCRIPTIONr   SIGNALSFILES)HAS_ENCODING_ARGr"   r;   r   r   r   r   _get_categoriesr   CATEGORY_SECTIONSro   _add_config_optionsrp   r   rJ   r   r   _join_lines_get_indented_descriptions)	man_pathman_cmd
man_outputrd   
categoriesrk   category_headercategory_enumr3   s	            r   from_manzManual.from_man  s   " ;K$6PR$RT\]G?99##((Z8P(Qj "1!<kmJ*;*A*A*C ^&.-Y[9\]^  \			:	&8;L+LQY  bT  RTNH,<,<jnnXWY>Z[\ *..,-*..R01*..34 0F!KL 	2!>? !<=   ?=>>?s   -F 	F%F  F%c                     t        j                         5 }t        ||        t        j	                  |j
                        cddd       S # 1 sw Y   yxY w)a  
    Reads and parses the latest tor man page `from gitweb.torproject.org
    <https://gitweb.torproject.org/tor.git/plain/doc/tor.1.txt>`_. Note that
    while convenient, this reliance on GitWeb means you should alway call with
    a fallback, such as...

    ::

      try:
        manual = stem.manual.from_remote()
      except IOError:
        manual = stem.manual.from_cache()

    In addition to our GitWeb dependency this requires 'a2x' which is part of
    `asciidoc <http://asciidoc.org/INSTALL.html>`_ and... isn't quick.
    Personally this takes ~7.41s, breaking down for me as follows...

      * 1.67s to download tor.1.txt
      * 5.57s to convert the asciidoc to a man page
      * 0.17s for stem to read and parse the manual

    :param int timeout: seconds to wait before timing out the request

    :returns: latest :class:`~stem.manual.Manual` available for tor

    :raises: **IOError** if unable to retrieve the manual
    )r   r   N)r   NamedTemporaryFiler   r   r   r2   )r   tmps     r   from_remotezManual.from_remote  sA    < 
	$	$	& '#cW=__SXX&' ' 's   ,AAc                 h    |j                  d      r| j                  |      S | j                  |      S )a  
    Persists the manual content to a given location.

    .. versionchanged:: 1.6.0
       Added support for sqlite cache. Support for
       :class:`~stem.util.conf.Config` caches will be dropped in Stem 2.x.

    :param str path: path to save our manual content to

    :raises:
      * **ImportError** if saving as sqlite and the sqlite3 module is
        unavailable
      * **IOError** if unsuccessful
    r   )r   _save_as_sqlite_save_as_config)r   rR   s     r   savezManual.save:  s2    $ }}Y!!$''!!$''r   c                    t         j                  j                         st        d      dd l}|dz   }t
        j                  j                  |      rt        j                  |       |j                  |      5 }t        D ]  }|j                  |        |j                  d| j                  | j                  | j                  | j                  | j                   f       | j"                  j%                         D ]  \  }}|j                  d||f        | j&                  j%                         D ]  \  }}|j                  d||f        | j(                  j%                         D ]  \  }}|j                  d||f        t+        | j,                  j/                               D ]h  \  }}|j                  d|j                  j1                         |j                  |j2                  |j4                  |j6                  |j                  |f       j 	 d d d        t
        j                  j                  |      rt        j                  |       t        j8                  ||       y # 1 sw Y   TxY w)	Nz1Saving a sqlite cache requires the sqlite3 moduler   z.newz]INSERT INTO metadata(name, synopsis, description, man_commit, stem_commit) VALUES (?,?,?,?,?)z7INSERT INTO commandline(name, description) VALUES (?,?)z3INSERT INTO signals(name, description) VALUES (?,?)z1INSERT INTO files(name, description) VALUES (?,?)zdINSERT INTO torrc(key, name, category, usage, summary, description, position) VALUES (?,?,?,?,?,?,?))r"   r#   r$   r%   r&   rQ   rR   r   remover(   SCHEMAr*   r2   rg   r6   r   r   rh   ro   ri   rj   	enumeraterk   valuesupperr3   r4   r5   rename)	r   rR   r&   tmp_pathr   cmdkvis	            r   r   zManual._save_as_sqliteQ  s   ;;**,KLLf}H	ww~~hii		" Id #S llruyu~u~  AE  AN  AN  PT  P`  P`  bf  bq  bq  sw  sC  sC  uD  E**002 X$!QNQRTUPVWX ,,$$& T$!QJQPQFST **""$ R$!QH1a&QR D//6689 I$!Q{~  E  E  K  K  M  OP  OU  OU  WX  Wa  Wa  cd  cj  cj  lm  lu  lu  wx  wD  wD  FG  ~H  	III$ 
ww~~diioIIh+I Is   8FI""I+c                    t         j                  j                  j                         }|j	                  d| j
                         |j	                  d| j                         |j	                  d| j                         | j                  r|j	                  d| j                         | j                  r|j	                  d| j                         | j                  j                         D ]  \  }}|j	                  d|d|d	         | j                  j                         D ]  \  }}|j	                  d
|d|d	         | j                  j                         D ]  \  }}|j	                  d|d|d	         | j                  j                         D ]  \  }}|j	                  d|z  |j                         |j	                  d|z  |j
                         |j	                  d|z  |j                          |j	                  d|z  |j"                         |j	                  d|z  |j                          |j%                  |       y )Nr2   rg   r6   r   r   rh   z => F)	overwriteri   rj   r   r   r   r   r   )r"   r;   rO   rP   rq   r2   rg   r6   r   r   rh   ro   ri   rj   rk   r3   r4   r5   r   )r   rR   rO   r   r   s        r   r   zManual._save_as_configr  s   99>>  "DHHVTYYHHZ'HH]D,,-
hh|T__-
hh}d../((..0 N1
hh$Aq&9uhMN ""$ B1
hhy1-5hAB 

  " @1
hhwa+h?@ ##))+ C1
hh+a/<
hh'!+QVV4
hh(1,agg6
hh*Q.		:
hh.2AMMBC 	IIdOr   c                 R    t         j                  j                  | dddddddd		      S )
Nr2   rg   r6   rh   ri   rj   rk   Tr8   r:   r=   s    r   r>   zManual.__hash__  s=    99fj-I^`ikr  uE  OS  T  Tr   c                 T    t        |t              rt        |       t        |      k(  S dS r@   )rA   r   rB   rC   s     r   rE   zManual.__eq__  s#    (25&(A4:e$LuLr   c                     | |k(   S r   rG   rC   s     r   rH   zManual.__ne__  rI   r   r   )tor)<   )r   r   r   r   r   staticmethodr   r   r   r   r   r   r   r   r>   rE   rH   rG   r   r   r   r   Z  s    4
  -  -D # #J    D ( (T ' 'B(.B<TMr   r   c                 2   | rd| d   v r| dd } | r| d   j                  d      r| dd } t               }dg }}| D ]  }t        j                  j	                         rt
        nt        }|j                   |d      d      j                   |d	      d
      j                   |d      d      }|r:|j                  d      s)|r|r|d   dk(  r|dd }|||<   |j                         g }}|j                  d      r|dd }|j                  |        |r|||<   |S )z
  The man page is headers followed by an indented section. First pass gets
  the mapping of category titles to their lines.
  zTOR(1)r   r   NTori   'i   -   * r/   z          )
rY   r   r"   r#   is_python_3chrunichrreplacestriprn   )contentr   r3   ru   linechar_fors         r   r   r     s)    WQZ'abkG''.crlG}*"E( d kk--/sVH<<(#.66x7GMUUV^_cVdfijDDOOC(	U2Y"_*%$
8

bh		#ABxll4-0  Jx	r   c           
      T   t               d}}| D ]R  }|dk(  rd}|r|j                  d      s	g |c||<   }'|s*|j                  d      s<||   j                  |dd        T t        |j	                         D cg c]  \  }}|s	|dj                  |      f c}}      S c c}}w )a  
  Parses the commandline argument and signal sections. These are options
  followed by an indented description. For example...

  ::

    -f FILE
        Specify a new configuration file to contain further Tor configuration
        options OR pass - to make Tor read its configuration from standard
        input. (Default: /usr/local/etc/tor/torrc, or $HOME/.torrc if that file
        is not found)

  There can be additional paragraphs not related to any particular argument but
  ignoring those.
  Nz    Noter	         )r   rY   rn   rW   ro   rS   )ru   optionslast_argr  arg
desc_liness         r   r   r     s    " "mT8' )dzh	dooc* "DgdmX	doof-htABx() 
'--/`sJU_SXXj)*`	aa`s   <
B$
B$
c                 z     fdt        |      D cg c]  \  }}d|v sd|v s| }}}|r"|t        |      d }||j                  d      d }dg }}|D ]L  }|r!|j                  d      s|r	 ||       |g }}&|j                  d      r|dd }|j	                  |       N |r
 ||       yyc c}}w )	ai  
  Parses a section of tor configuration options. These have usage information,
  followed by an indented description. For instance...

  ::

    ConnLimit NUM
        The minimum number of file descriptors that must be available to the
        Tor process before it will start. Tor will ask the OS for as many file
        descriptors as the OS will allow (you can find this by "ulimit -H -n").
        If this number is less than ConnLimit, then Tor will refuse to start.


        You probably don't need to adjust this. It has no effect on Windows
        since that platform lacks getrlimit(). (Default: 1000)
  c           	      :   d| v ry d| v r | j                  d      D ]  } ||        y d| v r| j                  dd      n| df\  }}t               j                  d|j                         z  d      }t	        |||t        |      j                               |<   y )NzPER INSTANCE OPTIONSz, r	  r   r/   zmanual.summary.%s)r   re   rp   rZ   r.   r   r  )	titler6   subtitler2   r4   r5   
add_optionr3   rk   s	         r   r  z'_add_config_options.<locals>.add_option  s    &u} kk$' *(8[)* ,/%<EKKQ'eR[kdE	1DJJL@"Eg)$%+VaJbJhJhJjknTr   zThe following optionszPER SERVICE OPTIONSNr/   r	  r  r  )r   maxindexrY   rn   )	rk   r3   ru   r   r  end_indices
last_titler6   r  s	   ``      @r   r   r     s    $l( %.e$4{y49PTX9X\quy\y{+{#k"#$E%++b/"#E "k* 
dDOOC(	:{+ $b+j		 ABx
 z;' ) |s
   B7B7c                     g }| D ]6  }|s|s|d   dk7  s|j                  d       #|j                  |dz          8 dj                  |      j                         S )zI
  Simple join, except we want empty lines to still provide a newline.
  r  rl   r/   )rn   rS   r  )ru   resultr  s      r   r   r   %  s^    
 & !d	F2J$&dmmD4K ! 
			  r   )T)Br   rQ   r   r   r   r"   stem.prereq	stem.utilstem.util.confstem.util.enumstem.util.logstem.util.systemcollectionsr   r%   stem.util.ordereddictr#   _is_lru_cache_available	functoolsr   stem.util.lru_cacheurllib.requestr   r   urllib2r;   enumEnumrJ   GITWEB_MANUAL_URLrR   rS   rT   rU   r)   r'   r   is_macis_bsdis_slackwarer   r   r   r   r   r   r   r	   r
   r   r   r   r   r   r+   objectr.   re   r   r   r   r   r   r   r   r   rG   r   r   <module>r9     s[  -^ 
  
        0% ;;&&(!+! 99>>y(G[+Wgi|  H  JS  TO WW\\"''//(35KL
yy''..00z9I9I9P9P9R5Rz[_[d[d[k[k[x[x[zWz (+n<hEA? E	
  h&&'X__%X^^$x112'););<X445)8+E+EFh../	! 	 )W ) +(\6 :  0*Z
9 "=NZ\ :z}V }@
,^b<;(|!E  0//0  s#   H H HH	H'&H'