
    >/ip&                         S SK r S SKrS SKr\R                  S:  a  S SKrO S SKrS SKJr  S SKJ	r	  S SKJ
r
  \ R                  " \5      r " S S5      rg! \ a    Sr N9f = f)    N)      )	constants)extension_loader)utilsc                   n    \ rS rSrSS jrS rS r\S 5       rS r	S r
S	 rS
 rS r\S 5       rS rSrg)BanditConfig   Nc                 N   Xl         0 U l        U(       Ga   [        US5      nUR                  S5      (       af  [        c  [        R
                  " SU5      e U   [        R                  " U5      R                  S0 5      R                  S0 5      U l        SSS5        O' U   [        R                  " U5      U l        SSS5        U R!                  U5        [#        U R                  [$        5      (       d  [        R
                  " SU5      eU R'                  5         O S	U R                  S
'   S	S/U R                  S'   U R)                  5         g! [         a    [        R
                  " SU5      ef = f! , (       d  f       N= f! [        R                   a1  n[        R                  U5        [        R
                  " SU5      eSnAff = f! , (       d  f       GN= f! [        R                   a1  n[        R                  U5        [        R
                  " SU5      eSnAff = f)zAttempt to initialize a config dictionary from a yaml file.

Error out if loading the yaml file fails for any reason.
:param config_file: The Bandit yaml config file

:raises bandit.utils.ConfigError: If the config is invalid or
    unreadable.
rbzCould not read config file.z.tomlNz4toml parser not available, reinstall with toml extratoolbanditzError parsing file.z*.pyplugin_name_patternz*.pywinclude)config_file_configopenOSErrorr   ConfigErrorendswithtomllibloadgetTOMLDecodeErrorLOGerroryaml	safe_load	YAMLErrorvalidate
isinstancedictconvert_legacy_config_init_settings)selfr   ferrs       L/home/james-whalen/.local/lib/python3.13/site-packages/bandit/core/config.py__init__BanditConfig.__init__   s    'd+ ##G,,?++N# 
P#LLO//;??"M  P'+~~a'8  MM+& dllD11''(={KK&&( 39DLL./'-w&7DLL#S  ''1;   .. PIIcN++,A;OOP
 ~~ PIIcN++,A;OOPsw   E F <E4F  G "G>G "E14
F>F F G
,GG

GG G H$3,HH$c                 v    UR                  S5      nU R                  nU H  nU(       a  XC;   a  X4   nM    g   U$ )aM  Returns the option from the config specified by the option_string.

'.' can be used to denote levels, for example to retrieve the options
from the 'a' profile you can use 'profiles.a'
:param option_string: The string specifying the option to retrieve
:return: The object specified by the option_string, or None if it can't
be found.
.N)splitr   )r%   option_stringoption_levelscur_itemlevels        r(   
get_optionBanditConfig.get_optionT   s@     &++C0<<"EU.#?	 #     c                 @    XR                   ;   a  U R                   U   $ g N)	_settings)r%   setting_names     r(   get_settingBanditConfig.get_settingg   s    >>)>>,//r4   c                     U R                   $ )zEProperty to return the config dictionary

:return: Config dictionary
)r   r%   s    r(   configBanditConfig.configm   s     ||r4   c                 2    0 U l         U R                  5         g)a%  This function calls a set of other functions (one per setting)

This function calls a set of other functions (one per setting) to build
out the _settings dictionary.  Each other function will set values from
the config (if set), otherwise use defaults (from constants if
possible).
:return: -
N)r7   _init_plugin_name_patternr<   s    r(   r$   BanditConfig._init_settingsu   s     &&(r4   c                     [         R                  nU R                  S5      (       a  U R                  S5      nXR                  S'   g)zASets settings['plugin_name_pattern'] from default or config file.r   N)r   r   r2   r7   )r%   r   s     r(   r@   &BanditConfig._init_plugin_name_pattern   s;    ';;??011"&//2G"H0C,-r4   c                     U R                  5       nU R                  5       u  p#U(       a!  U R                  XU5        XR                  S'   g g )Nprofiles)convert_names_to_idsconvert_legacy_blacklist_dataconvert_legacy_blacklist_testsr   )r%   updated_profiles	bad_callsbad_importss       r(   r#   "BanditConfig.convert_legacy_config   sK    446!%!C!C!E	// [ (8LL$	 r4   c                    [         R                  n0 nU R                  S5      =(       d    0 R                  5        H  u  p4UR	                  S5      =(       d    /  Vs1 s H  nUR                  U5      =(       d    UiM     nnUR	                  S5      =(       d    /  Vs1 s H  nUR                  U5      =(       d    UiM     nnXgS.X#'   M     U$ s  snf s  snf )z<Convert test names to IDs, unknown names are left unchanged.rE   r   exclude)r   rN   )r   MANAGERr2   itemsr   get_test_id)r%   extmanrI   nameprofileir   rN   s           r(   rF   !BanditConfig.convert_names_to_ids   s    !))"ooj9?RFFHMD "++i06B66A ##A&+!+6   "++i06B66A ##A&+!+6   29%M" I  s   $C$Cc                 X   / n/ nU R                  S5      =(       d    0 nUR                  S0 5      nU HI  nUR                  5        H2  u  pVXVS'   US   R                  SS5      US'   UR	                  U5        M4     MK     U R                  S5      =(       d    0 nUR                  S0 5      nU HT  nUR                  5        H=  u  pVXVS'   US   R                  S	S5      US'   US
   US'   US
	 UR	                  U5        M?     MV     U(       d  U(       a  [
        R                  S5        X4$ )z:Detect legacy blacklist data and convert it to new format.blacklist_callsbad_name_setsrS   messagez{func}z{name}blacklist_importsbad_import_setsz{module}imports	qualnamesz>Legacy blacklist data found in config, overriding data plugins)r2   r   rP   replaceappendr   warning)r%   bad_calls_listbad_imports_listrJ   itemkeyvalrK   s           r(   rG   *BanditConfig.convert_legacy_blacklist_data   s&   OO$56<"	MM/26	D JJL!F!$Y!7!7(!KI%%c* )  oo&9:@b!oo&7<D JJL!F!$Y!7!7
H!MI#&y>K 	N '', )   ~KK //r4   c                 6   S nU R                  5        GH  u  pE0 nUS   nUS   nSnXG;   a&  XH;  a!  UR                  S/ 5      R                  U5        U" XG5        U" XH5        SnXG;   ah  XH;  ac  UR                  S/ 5      R                  U5        UR                  S/ 5      R                  U5        UR                  S/ 5      R                  U5        U" XG5        U" XH5        U" S	U5        U" S	U5        S
U;   a  S
U;   a  UR                  S
5        XeS'   GM     g)z7Detect old blacklist tests, convert to use new builtin.c                 T    X;   a#  UR                  U 5        UR                  S5        g g )NB001)removeadd)rS   datas     r(   
_clean_set?BanditConfig.convert_legacy_blacklist_tests.<locals>._clean_set   s$    |D!  r4   r   rN   rX   Callr[   Import
ImportFromblacklist_import_funcrj   	blacklistN)rP   
setdefaultextendrk   )	rE   rK   rJ   rn   rS   rT   rt   r   rN   s	            r(   rH   +BanditConfig.convert_legacy_blacklist_tests   s   	!
 &^^-MDIi(Gi(G$D4#6$$VR077	Bt%t%&D4#6$$Xr299+F$$\26==kJ$$VR077Dt%t%.8.8  Vw%6v&#,K 9 .r4   c                   ^ ^^ SnSmUUU 4S jnST R                   ;   a  SnT R                   S   R                  5        He  nUR                  S5      =(       d
    [        5       nUR                  S5      =(       d
    [        5       nU" SSXV5        U" S	SXV5        U" S
S
XV5        Mg     U(       a  [        R                  ST5        gg)zValidate the config data.Fa  Config file has an include or exclude reference to legacy test '{0}' but no configuration data for it. Configuration data is required for this test. Please consider switching to the new config file format, the tool 'bandit-config-generator' can help you with this.c                    > X;   d  X;   aC  TR                   R                  U5      c&  [        R                  " TR	                  U 5      T5      eg g r6   )r   r   r   r   format)re   blockrN   r   rZ   pathr%   s       r(   _test$BanditConfig.validate.<locals>._test   sG    ~<<##E*2++GNN3,?FF 3 "0r4   rE   Tr   rN   r[   rs   rX   zConfig file '%s' contains deprecated legacy config data. Please consider upgrading to the new config format. The tool 'bandit-config-generator' can help you with this. Support for legacy configs will be removed in a future bandit version.N)r   valuesr   setr   ra   )r%   r|   legacyr}   rT   incexcrZ   s   ``     @r(   r    BanditConfig.validate   s     		G
 %F<<
3::<kk),5kk),5)+>I-/BCM'):CE = KK6
  r4   )r   r7   r   r6   )__name__
__module____qualname____firstlineno__r)   r2   r9   propertyr=   r$   r@   r#   rF   rG   staticmethodrH   r    __static_attributes__ r4   r(   r	   r	      sZ    8t&  
)D8 (0< $- $-L$r4   r	   )loggingsysr   version_infor   tomliImportErrorbandit.corer   r   r   	getLoggerr   r   r	   r   r4   r(   <module>r      sf   
  
 w " ( !v v  s   A A! A!