
    >/iQ                         S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKJ	r
  SSKJr  SSKJr  SSKJr  Sr\R                   " 5       r\R$                  S4S jrS	 rS
 rS rS rS rS rS r\S:X  a  \" 5         gg)zHBandit is a tool designed to find common security issues in Python code.    N)config)	constants)manager)utilszbandit.yamlc                    / [         l        U(       d  [        R                  nOUn[        R
                  " S5        [         R                  U 5        [        R                  " [        R                  5      nUR                  [        R                  " U5      5        [         R                  U5        [         R                  S5        g)zmInitialize the logger.

:param debug: Whether to enable debug mode
:return: An instantiated logging instance
Tzlogging initializedN)LOGhandlersr   log_format_stringloggingcaptureWarningssetLevelStreamHandlersysstderrsetFormatter	Formatter
addHandlerdebug)	log_level
log_formatr
   handlers       I/home/james-whalen/.local/lib/python3.13/site-packages/bandit/cli/main.py_init_loggerr      s     CL%77&D!LL##CJJ/G**+<=>NN7II#$    c           	      4   SnU (       a  U nO/ nU Ho  n[         R                  " U5       HR  u  pVn[        R                  " US5       H1  nUR	                  [         R
                  R                  XX5      5        M3     MT     Mq     [        U5      S:  a<  [        R                  SSR                  U5      5        [        R                  " S5        O-[        U5      S:X  a  US   n[        R                  SUS   5        U(       a  [        R                  " U5      $ g)	zCReturn a dictionary of config options or None if we can't load any.Nz.bandit   zKMultiple .bandit files found - scan separately or choose one with --ini
	%sz,    r   z$Found project level .bandit file: %s)oswalkfnmatchfilterappendpathjoinlenr   errorr   exitinfor   parse_ini_file)	ini_pathtargetini_filebandit_filestroot_	filenamesfilenames	            r   _get_options_from_inir3   .   s    HA&(ggaj" 'y) DH ''T(DE !E '1 
 |q II.		,'
 HHQK!##AHHH;\!_M##H--r   c                  &    SSK Jn   U R                  $ )Nr   )extension_loader)bandit.corer5   MANAGER)
ext_loaders    r   _init_extensionsr9   N   s    :r   c                     U c?  U(       a  [         R                  SU5        U$ U(       a  [         R                  SU5        U$ gX:X  a  U(       a  U$ U$ U$ )z.It's useful to show the source of each option.NzUsing command line arg for %szUsing ini file for %s)r   r(   )default_valarg_valini_valoption_names       r   _log_option_sourcer?   T   sU     HH4kBNHH,k:N		!w.w. r   c                      [        [        S5      (       a  g[        R                  [        [        S[        R                  5      :w  a  gg )Nreal_prefixTbase_prefix)hasattrr   prefixgetattr r   r   _running_under_virtualenvrG   h   s3    sM""	wsM3::>	> 
?r   c                 h   0 nU(       a\  U R                  S5      =(       d    0 nUR                  U5      nUc  [        R                  " X!5      e[        R                  SX5        U$ [        U R                  S5      =(       d    / 5      US'   [        U R                  S5      =(       d    / 5      US'   U$ )Nprofileszread in legacy profile '%s': %stestsincludeskipsexclude)
get_optiongetr   ProfileNotFoundr   r   set)r   profile_nameconfig_pathprofilerI   s        r   _get_profilerU   o   s    G$$Z06B,,|,?''BB		3\K N !!2!27!;!ArB	 !2!27!;!ArB	Nr   c                    SR                  US    Vs/ s H  o"PM     sn5      =(       d    SnSR                  US    Vs/ s H  o"PM     sn5      =(       d    Sn[        R                  SU5        [        R                  SU5        [        R                  SU R                  5        [        R                  SU R                  5        g s  snf s  snf )	N,rK   NonerM   zprofile include tests: %szprofile exclude tests: %szcli include tests: %szcli exclude tests: %s)r$   r   r(   rJ   rL   )argsrT   r.   incexcs        r   	_log_infor\   }   s    
((wy121!A12
3
=vC
((wy121!A12
3
=vCHH(#.HH(#.HH$djj1HH$djj1 32s   C Cc                      S[         R                  ;   d  S[         R                  ;   a  [        R                  O[        R                  n [        U 5        [        5       n[        S UR                  5       Vs/ s H  nUR                  PM     nn[        R                  " S[        R                  S9n[         R                  S:  a  SUl        SUl        UR!                  S	S	["        S
SS9  UR!                  SSSSSS9  UR!                  SSSSS["        SS/SS9  UR!                  SSSSS[$        SS 9  UR!                  S!S"S#SS$["        S%S 9  UR!                  S&S'S(SS$["        S)S 9  UR!                  S*S+S,SS$["        S-S 9  UR!                  S.S/S0SS$["        S1S 9  UR'                  SS29nUR!                  S3S4S5S6S7S8S99  UR!                  S:S;SS</ S=QS>9  UR'                  SS29nUR!                  S?S@SAS6S7SBS99  UR!                  SCSDSSE/ S=QS>9  [         R(                  R+                  5       (       a3  [,        R.                  " SF5      c  [,        R.                  " SG5      SH:w  a  SIOSJnUR!                  SKSLSMSUSN[1        UR2                  5      SO9  UR!                  SPSS$SQSR9  UR!                  SSSTSUSSV[        R4                  " SWSXSY9[         R(                  SZS[9  UR'                  SS29nUR!                  S\S]S^SS_S9  UR!                  SSS`SSaS9  UR!                  SbScSdSeSSfS9  UR!                  SgShSSiS9  UR!                  SjSkSlSSmR7                  [8        R:                  5      SnSmR7                  [8        R:                  5      -   So-   S99  UR!                  SpSqSrSS$SsS99  UR!                  StSuSS$SvS99  UR!                  SwSSxSSySz9  [         R<                  R?                  S{S|5      n	UR!                  S}S~S[@        RB                   SU	 3S9  URE                  SS9  URE                  SS9  URE                  SS9  URE                  SS9  URF                  RI                  5        V
s/ s H  oS    SU
S7   R                   3PM     nn
/ nURJ                  RI                  5        H+  n
U
S7    H  nURM                  US    SUS    35        M!     M-     SR7                  [1        [O        X-   5      5      5      n[P        RR                  " S5      nUSU 3-   Ul*        URW                  5       nURX                  S:w  a  URZ                  b  UR]                  S5        UR^                  b_  UR^                  S:X  a  S7Ul0        OGUR^                  S:X  a  SUl0        O/UR^                  S:X  a  SUl0        OUR^                  S:X  a  SUl0        URb                  b_  URb                  S:X  a  S7Ul2        OGURb                  S:X  a  SUl2        O/URb                  S:X  a  SUl2        OURb                  S:X  a  SUl2        [g        URh                  URj                  5      nU(       Ga  [m        URo                  S5      URp                  URs                  S5      S5      Ul8        [m        URo                  Sl5      URt                  URs                  S5      S5      Ul:        [m        URo                  S05      URv                  URs                  S05      S5      Ul;        [m        URo                  S,5      URx                  URs                  S,5      S5      Ul<        URs                  S	5      nU(       a  UR{                  Sm5      n[m        URo                  S	5      URj                  US5      Ul5        [m        URo                  S5      UR|                  URs                  S5      S5      Ul>        [m        URo                  S5      UR~                  URs                  S5      S5      Ul?        [m        URo                  S5      UR                  [%        URs                  S5      =(       d    S5      =(       d    S$S5      Ul@        [m        URo                  S(5      UR                  URs                  S(5      S(5      UlA        [m        URo                  S55      UR`                  URs                  S5      S5      Ul0        [m        URo                  SA5      URd                  URs                  SA5      S5      Ul2        [m        URo                  SM5      URX                  URs                  S5      S5      Ul,        [m        URo                  S5      URZ                  URs                  S5      S5      Ul-        [m        URo                  SU5      UR                  URs                  S5      S5      UlB        [m        URo                  S^5      UR                  URs                  S^5      S5      UlC        [m        URo                  S`5      UR                  URs                  S`5      S5      UlD        [m        URo                  Se5      UR                  URs                  Se5      S5      UlE        [m        URo                  Sh5      UR                  URs                  S5      S5      UlF        [m        URo                  Sr5      UR                  URs                  Sr5      S5      UlG         [        R                  " URp                  S9nURj                  (       d&  UR                  5         [         R                  " S5        WR                  S5      (       a)  UR                  S5      n[        [        R                  US9  UR                  (       a  [        [        R                  S9   [        UUR                  URp                  5      n[        UU5        US   R                  URx                  (       a  URx                  R{                  Sm5      O/ 5        US   R                  URv                  (       a  URv                  R{                  Sm5      O/ 5        UR                  U5        [        R                  " UUR~                  UR                  WUR                  UR                  UR                  S9nUR                  b   [        UR                  5       nUR                  5       nUR                  U5        S$S$S$5        URX                  U;  a7  [        R                  S[#        U5      -   5        [         R                  " S5        URX                  S:w  a  URp                  (       a   [        R                  SURp                  5        [        R                  S[         R                  R                  [         R                  R                  [         R                  R                  5        UR                  URj                  UR|                  URt                  5        UR                  Rx                  (       d+  [        R]                  S5        [         R                  " S5        UR                  5         [        R                  UR                  5        [        R                  UR                  5        [8        R                  UR`                  S7-
     n[8        R                  URd                  S7-
     nUR                  UR                  UUUR                  URX                  URZ                  5        UR                  UUS9S:  a(  UR                  (       d  [         R                  " S75        g$[         R                  " S5        g$s  snf s  sn
f ! [        R                   a6  n[        R]                  U5        [         R                  " S5         S$nAGNS$nAff = f! [        R                  [        4 a6  n[        R]                  U5        [         R                  " S5         S$nAGNS$nAff = f! , (       d  f       GN7= f! [         a:    [        R                  SUR                  5        [         R                  " S5         GN}f = f)zBandit CLI.z-dz--debugc                 .    [        U R                  S5      $ )N_accepts_baseline)rC   plugin)xs    r   <lambda>main.<locals>.<lambda>   s    gahh(;<r   z/Bandit - a Python source code security analyzer)descriptionformatter_class)      TFtargets*z+source file(s) or directory(s) to be tested)metavartypenargshelpz-rz--recursive	recursive
store_truez(find and process files in subdirectories)destactionrm   z-az--aggregateagg_typestorefilevulnz:aggregate output by vulnerability (default) or by filename)rp   rq   defaultrk   choicesrm   z-nz--numbercontext_linesrf   z5maximum number of code lines to output for each issue)rp   rq   rv   rk   rm   z-cz--configfileconfig_fileNzIoptional config file to use for selecting plugins and overriding defaultsz-pz	--profilerT   z0profile to use (defaults to executing all tests)z-tz--testsrJ   z'comma-separated list of test IDs to runz-sz--skiprL   z(comma-separated list of test IDs to skip)requiredz-lz--levelseveritycountr   zbreport only issues of a given severity level or higher (-l for LOW, -ll for MEDIUM, -lll for HIGH))rp   rq   rv   rm   z--severity-levelseverity_stringzreport only issues of a given severity level or higher. "all" and "low" are likely to produce the same results, but it is possible for rules to be undefined which will not be listed in "low".)alllowmediumhigh)rp   rq   rm   rw   z-iz--confidence
confidencezdreport only issues of a given confidence level or higher (-i for LOW, -ii for MEDIUM, -iii for HIGH)z--confidence-levelconfidence_stringzreport only issues of a given confidence level or higher. "all" and "low" are likely to produce the same results, but it is possible for rules to be undefined which will not be listed in "low".NO_COLORTERMdumbscreentxtz-fz--formatoutput_formatzspecify output format)rp   rq   rv   rm   rw   z--msg-templatezzspecify output message template (only usable with --format custom), see CUSTOM FORMAT section for list of available values)rq   rv   rm   z-oz--outputoutput_file?wzutf-8)encodingzwrite report to filename)rp   rq   rl   rk   rv   rm   z-vz	--verboseverbosez9output extra information like excluded and included filesr   zturn on debug modez-qz--quietz--silentquietz(only show output in the case of an errorz--ignore-nosecignore_nosecz'do not skip lines with # nosec commentsz-xz	--excludeexcluded_pathsrW   zcomma-separated list of paths (glob patterns supported) to exclude from scan (note that these are in addition to the excluded paths provided in the config file) (default: )z-bz
--baselinebaselinezUpath of a baseline report to compare against (only JSON-formatted files are accepted)z--inir*   z;path to a .bandit file that supplies command line argumentsz--exit-zero	exit_zeroz$exit with 0, even with results found)rq   rp   rv   rm   
 z	--versionversionz	%(prog)s z
  python version = )rq   r   )r   )r   )r   )r   r   	idnamez
	ab  
    CUSTOM FORMATTING
    -----------------

    Available tags:

        {abspath}, {relpath}, {line}, {col}, {test_id},
        {severity}, {msg}, {confidence}, {range}

    Example usage:

        Default template:
        bandit -r examples/ --format custom --msg-template \
        "{abspath}:{line}: {test_id}[bandit]: {severity}: {msg}"

        Provides same output as:
        bandit -r examples/ --format custom

        Tags can also be formatted in python string.format() style:
        bandit -r examples/ --format custom --msg-template \
        "{relpath:20.20s}: {line:03}: {test_id:^8}: DEFECT: {msg:>20}"

        See python documentation for more information about formatting style:
        https://docs.python.org/3/library/string.html

    The following tests were discovered and loaded:
    -----------------------------------------------
    customz4--msg-template can only be used with --format=customr~   r   r   r   r      
configfilezconfig filerM   zexcluded pathszskipped testszselected testszselected targetszrecursive scan	aggregatezaggregate output typenumberzmax code lines output for issuelevelzseverity levelzconfidence levelformatzoutput formatmsg_templatezmsg-templatezoutput message templateoutputzoutput filezoutput extra informationz
debug modezsilent modezignore-noseczdo not skip lines with # noseczpath of a baseline report)ry   r   )r   r   )r   rK   )rT   r   r   r   z"Could not open baseline report: %sz9Baseline must be used with one of the following formats: jsonzusing config: %szrunning on Python %d.%d.%dz0No tests would be run, please check the profile.)
sev_filterconf_filter)kr   argvr   DEBUGINFOr   r9   r!   
formattersr   argparseArgumentParserRawDescriptionHelpFormatterversion_infosuggest_on_errorcoloradd_argumentstrintadd_mutually_exclusive_groupstdoutisattyr   getenvsortedformatter_namesFileTyper$   r   EXCLUDEr   replacebandit__version__set_defaultsplugins_by_iditems	blacklistr"   rQ   textwrapdedentepilog
parse_argsr   r   r&   r}   r{   r   r   r3   r*   rh   r?   get_defaultry   rO   r   rL   rJ   splitrn   rr   rx   rT   r   r   r   r   r   r   b_configBanditConfigr   ConfigErrorr   r'   print_usagerN   WARNrU   r\   updatevalidate_profilerP   
ValueError	b_managerBanditManageropenreadpopulate_baselineOSErrorwarningr(   majorminormicrodiscover_filesb_ts	run_testsb_mametricsRANKINGoutput_resultsresults_countr   )r   extension_mgrfbaseline_formattersparserseverity_groupconfidence_groupr   group
python_veraplugin_infoblacklist_infobplugin_listdedent_textrY   ini_optionsini_targetsb_confer   rT   b_mgrbldata	sev_level
conf_levels                               r   mainr      sl   
 388yCHH4 	\\ 

 $&M <$$

A 	

   $$E <<F 7""&
:   7    I  	 D     	 ?   6   7   88%8HN=    # 1   	 ::E:J!!= "  !! # 1 " 	 JJ		*%-		&!V+	 	   $}445   (	   sW5

'  	 ///?E	H   !   
7   6	   **+8 ((9$$
%	&
    3   J   6   $$T2.J
F../ 0(\+   e$
&
e$
U+ )6(C(C(I(I(K(K1Q4&1Q499+(K   N$$**,1A!!QtWIR&	{";<  - ++fS)E%FGHK//	K<  B{m"44FM DX%$*;*;*GKL '5(DM!!U*DM!!X-DM!!V+DM )!!U*DO##u,DO##x/DO##v-DO (t||DK-|,OOL)	
 1/0OOI&	
 (w'JJOOG$	

 (w'JJOOG$	

 "ooi0%++C0K)y)LL	
 ,{+NNOOK(	
 +z*MMOOK(#	
 0/).Q/74-	
 *y)LLOOI&	
 +z*MMOOG$	
 -|,OOOOL)	
 0/OOH%	
 /~.OON+%	
 .}-OOH%	
 *y)LLOOI&&	
 (w'JJOOG$	

 (w'JJOOG$	

 /~.OON+,	
 +z*MMOOJ''	
&&43C3CD
 << &&&&|4
w}}Dzzw||,
vt||T5E5EF$ 	!!4::$**"2"23"72N	!!4::$**"2"23"72N&&w/ ##

jj&&E }} 	dmm$wwy''- % %88KK!"567 HHQKV#HH')9)9:(""""""		
 
t~~t7J7JK::		DE 
OOIIejjIIemm !!$--!"34I""4??Q#67J	 	yjIAMQdn  		!0 !!:. 		!  %$  	KK<dmmLHHQK	s   7}2 }7 }< B>	 5A@. 
"A@,A@. <+	A@#+A@@A@@
A@+@&A@. @+A@. @.A AA2A1AA2__main__)__doc__r   r    r   r   r   r   r   r6   r   r   r   r   r   r   BASE_CONFIG	getLoggerr   r   r   r3   r9   r?   rG   rU   r\   r   __name__rF   r   r   <module>r      s   
 O    	 
   * ! ,  #<<D %.@(2sl zF r   