
    =*fa/                         S r SrSrSSKrSSKrSSKrSSKJr  SSKJ	r
JrJrJrJr   " S S	\5      rS
 r\" \5      rSrS/r " S S\
5      rg)z0Yaroslav Halchenko, Serg G. Brester (aka sebres)zHCopyright (c) 2007 Yaroslav Halchenko, 2015 Serg G. Brester (aka sebres)GPL    N   )	getLogger)ConfigParserBasicInterpolationInterpolationMissingOptionErrorNoOptionErrorNoSectionErrorc                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )BasicInterpolationWithName&   a  Decorator to bring __name__ interpolation back.

Original handling of __name__ was removed because of
functional deficiencies: http://bugs.python.org/issue10489

commit v3.2a4-105-g61f2761
Author: Lukasz Langa <lukasz@langa.pl>
Date:   Sun Nov 21 13:41:35 2010 +0000

Issue #10489: removed broken `__name__` support from configparser

But should be fine to reincarnate for our use case
c                    > U(       aK  [         U;  a@  UR                  5       nXVS'   UR                  XRXF5        [        [        U ]  " XX4XV/UQ70 UD6$ g g N__name__)r   copy_map_section_optionssuperr   _interpolate_some)
selfparseroptionaccumrestsectionmapargskwargs	__class__s
            A/usr/lib/python3/dist-packages/fail2ban/client/configparserinc.pyr   ,BasicInterpolationWithName._interpolate_some4   se    h#o	3z?	w:
*D
C
E@04@8>@ @ &W     )r   
__module____qualname____firstlineno____doc__r   __static_attributes____classcell__r   s   @r   r   r   &   s    @ @r!   r   c                    / nU  Hw  nUR                  U5        [        R                  R                  U5      S   S-   nX0;  d  M@  [        R                  R	                  U5      (       d  Mf  UR                  U5        My     U$ )z3Expands config files with local extension.
        r   z.local)appendospathsplitextisfile)	filenamesnewFilenamesfilename	localnames       r   _expandConfFilesWithLocalr4   ?   sm     Xhggx(+h6)BGGNN9$=$=y!	 
 	r!      SafeConfigParserWithIncludesc                     ^  \ rS rSrSrSr\R                  " S5      r\R                  " S5      r	\R                  " S5      r
SU 4S jjrS0 4S	 jrS
 r\S 5       rS r/ 4S jr/ 4S jrS rS rSS jrSS jrSS jrSrU =r$ )r6   R   a{  
        Class adds functionality to SafeConfigParser to handle included
        other configuration files (or may be urls, whatever in the future)

        File should have section [includes] and only 2 options implemented
        are 'files_before' and 'files_after' where files are listed 1 per
        line.

        Example:

[INCLUDES]
before = 1.conf
         3.conf

after = 1.conf

        It is a simple implementation, so just basic care is taken about
        recursion. Includes preserve right order, ie new files are
        inserted to the list of read configs before original, and their
        includes correspondingly so the list should follow the leaves of
        the tree.

        I wasn't sure what would be the right way to implement generic (aka c++
        template) so we could base at any *configparser class... so I will
        leave it for the future

        INCLUDESz^([\w\-]+)/([^\s>]+)$z%\(([\w\-]+/([^\)]+))\)sz^(\w+)(\?.+)$c                 ~   > UR                  5       n[        5       US'   SUS'   [        [        U ]  " U0 UD6  Xl        g )Ninterpolation;inline_comment_prefixes)r   r   r   r6   __init__
_cfg_share)r   share_configr   r   r   s       r   r>   %SafeConfigParserWithIncludes.__init__x   sF    ;;=&68&&)&	"#$d4 /r!   Fc                    SnSU;   a  [         R                  R                  U5      nU(       ag  UR                  S5      nUR                  S5      nUR	                  5       nUS:X  a  SU-   U4nOUS:w  a  U4OSnU H  n U R                  XgUS	9n	U	s  $    U R                  XX4S
9n	U	$ ! [        [        4 a  n
 Sn
A
MB  Sn
A
ff = f)z}Get an option value for a given section.

In opposite to `get`, it differentiate session-related option name like `sec/opt`.
N/   r   knownKNOWN/default)DEFAULT)raw)rI   vars)r6   SECTION_OPTNAME_CREsearchgrouplowergetr
   r	   )r   r   r   rI   rJ   soptsecoptseclwrves              r   get_ex#SafeConfigParserWithIncludes.get_ex   s    
 
$F]
&
:
:
A
A&
I4		A3	A3IIK6Wg&Dy(C6lDs
	#	$QX  hhwCh3!	
(	 M* 
	
s    B((C>Cc                 |   SU;  d  SU;  a  gSn[         R                  R                  U5      nU(       d  gU H  u  pxXt;  d  M  US[        U5      )  n	U	R	                  5       n
U
S:w  a5  SnU
S:X  a   U R
                  SU-      U   nO  U R
                  U	   n	X   nOSnU(       a   U R                  U   nSn WXG'   M     U$ ! [         a    Sn N2f = f! [         a     M  f = f! [         a    Sn NUf = f! [         a     M  f = f!    WUR                  S   U'    M  !   WU R                  U'     M  = f= f)	z
Interpolates values of the section options (name syntax `%(section/option)s`).

Fallback: try to wrap missing default options as "default/options" resp. "known/options"
rC   z%(r   NrG   rE   rF   rD   )	r6   SECTION_OPTSUBST_CREfindalllenrN   	_sectionsKeyError	_defaults_maps)r   r   r   r   defaultsrplcmntsoptreprP   rR   rQ   rS   usedefrT   s                r   r   1SafeConfigParserWithIncludes._map_section_options   su    	_D(
'(==EEdK'	
id

zS	
CYY[FV'>>(7*+C0q	nnS! 8q
 V
..
a GX^G V 
.C  v    v   !hnnQdnnTsx   3CCC()C:;DCC
C%!C($C%%C((C76C7:
DDD;D##D84D;8D;c                     U R                   $ Nr?   r   s    r   r@   )SafeConfigParserWithIncludes.share_config   s    	r!   c                    [         nU R                  (       a  S[        U[        5      (       d  UOSR	                  U5      -   nU R                  R                  US5      u  pEUc3  U" U R                  S9nUR                  USS9nXE4U R                  U'   XE4$ [        R                  5       [        ::  a  [        R                  [        SU5        XE4$ U" 5       nUR                  USS9nXE4$ )Nzinc:)NN)r@   F)get_includesz    Shared file: %s)r6   r?   
isinstancelistjoinrO   readlogSysgetEffectiveLevellogLevellog)r   r2   SCPWIhashvcfgis         r   _getSharedSCPWI,SafeConfigParserWithIncludes._getSharedSCPWI   s    
&%	__:h#=#=86;;xCXY5OO|463	k
T__
-C.A!XDOOE / 	  "h.
JJx.9
 / 
3
xxux-1
/r!   c                 j   [        U[        5      (       d  U/n[        U5      nU R                  (       a`  SSR	                  U5      -   nU R                  R                  U5      nUc,  / nU H  nX@R                  XR5      -  nM     X@R                  U'   U$ / nU H  nX@R                  XR5      -  nM     U$ )Nz	inc-path:rk   )rm   rn   r4   r?   ro   rO   2_SafeConfigParserWithIncludes__getIncludesUncached)r   r0   seenrv   fileNamesFullr2   s         r   _getIncludes)SafeConfigParserWithIncludes._getIncludes   s    	It	$	$}9'	2)	__I./5??&&u-=M00@@] *OOE
-h..x>>= 	r!   c                    [         n U R                  U5      u  pEU(       d  / $  [
        R                  R                  U5      nS/ 4S/ 4/nUR                  UR                  5       ;   a  U H  u  pXR                  UR                  5      ;   d  M%  UR                  UR                  U	5      nUR                  S5       Hh  n[
        R                  R                  U5      (       a  UnO[
        R                  R                  X|5      nX;   a  MP  X!/-   nXR                  X5      -  n
Mj     M     US   S   U/-   US   S   -   $ ! [         a)  n[        R	                  SU< SU< 35        / s SnA$ SnAff = f)	z
Given 1 config resource returns list of included files
(recursively) with the original one as well
Simple loops are taken care about
zError decoding config file 'z': Nbeforeafter
r   rD   )r6   ry   UnicodeDecodeErrorrq   errorr,   r-   dirnameSECTION_NAMEsectionsoptionsrO   splitisabsro   r   )r   resourcer}   ru   r   rx   rU   resourceDirnewFilesoption_nameoption_listnewResourcesnewResourcerss                  r   __getIncludesUncached2SafeConfigParserWithIncludes.__getIncludesUncached  sP    '%##H-96
I  )+"~}.(
6??,,#+{nnU%7%788JJu11;?\$**40	{	#	#q77<<1q	


a&&q,,k 1 $, 
!Q8*	$x{1~	55+ 
 	<<1EF
9s   E 
E6E1+E61E6c                     U R                   $ rf   )r^   rh   s    r   get_defaults)SafeConfigParserWithIncludes.get_defaults$      	r!   c                     U R                   $ rf   )r\   rh   s    r   get_sections)SafeConfigParserWithIncludes.get_sections'  r   r!   c                      U R                   U   nU(       a/  [        UR	                  5       5      [        U R
                  5      -  $ [        UR	                  5       5      $ ! [         a    [        U5      ef = f)zReturn a list of option names for the given section name.

Parameter `withDefault` controls the include of names from section `[DEFAULT]`
)r\   r]   r
   setkeysr^   rn   )r   r   withDefaultoptss       r   r   $SafeConfigParserWithIncludes.options*  sf    
!
..
!4 
diik
S0
00	diik	 
 !		  !s   A   A6c                    [        U[        5      (       d  U/n/ nU(       a  X0R                  U5      -  nOUnU(       d  / $ [        R	                  SU5        U(       d  [        U5      S:  Ga  / nU R                  5       nU R                  5       nU GH  nU R                  U5      u  pU	(       d  M   XI-  nUR                  UR                  5       5        UR                  5       R                  5        GH&  u  p[        R                  R                  U
5      nU(       a]  UR                  5       u  pUR                  5       n US	 [        UR#                  5       5       H  nUR%                  U5      nXX-   '   M     UR'                  U
5      n[        U[(        5      (       ae  U R+                  SU
-   [)        [-        UR                  5       5       V	s/ s H  oS   U;   d  M  U	PM     sn	5      S5        UR                  U5        GM  UR                  5       Xj'   GM)     GM     U$ [        R/                  5       [0        ::  a  [        R3                  [0        SUS   5        [4        R6                  " XSS	9$ ! [          a     GN<f = fs  sn	f )
Nz  Loading files: %srD   r   rF   r    z    Reading file: %szutf-8)encoding)rm   rn   r   rq   infor[   r   r   ry   updateitemsr6   CONDITIONAL_REmatchgroupsr   r]   r   poprO   dictmerge_sectioniterrr   rs   rt   SafeConfigParserrp   )r   r0   rl   r~   retalldallsr2   rw   rx   nr   condkrT   s2s                   r   rp   !SafeConfigParserWithIncludes.read9  s   	It	$	$}9-%%i00==	
9++#]3S'!+	3



4



4 x!!(+FCqXS	[[!!#$!!#))+)88>>qAd	wq668qjM QVVX1EE!H!(  88A;b	B		(1*bhhj)7)AqTQYa)78"> 
yy|tw+ , !< : 8+	::h.a0@A			tW	EE+   8s   I4J!J4
JJc                 @   U R                  5       n XA   nU(       d  UR                  U5        g 0 nUR	                  5        H+  u  pxUR                  U5      (       a  M  US:w  d  M%  XX7-   '   M-     UR                  U5        g ! [         a    [        5       =XA'   n Nf = fr   )r   r]   r   r   r   
startswith)	r   r   r   prefr   rQ   skr   rT   s	            r   r   *SafeConfigParserWithIncludes.merge_sections  s    				$ 	3 
::g		"mmoda
,,t

jtvJ  **R. 
  4=3 s   B BBrg   rf   )T)r   r#   r$   r%   r&   r   recompilerK   rY   r   r>   rV   r   propertyr@   ry   r   r|   r   r   r   rp   r   r'   r(   r)   s   @r   r6   r6   R   s    8 zz":;

#>?**-.! (-2 :7r  & )+ * 13  6D8Ft r!   )
__author____copyright____license__r,   r   syshelpersr   configparserr   r   r   r   r	   r
   r   r4   r   rq   rs   __all__r6   r"   r!   r   <module>r      sm   . @
Z 	 	 
 @ @
@!3 @2	 
8	 *
*n#3 nr!   