
    >/i)                     ,    S SK r S SKJr   " S S5      rg)    N)utilsc                   8   \ rS rSrSS jrS r\S 5       r\S 5       r\S 5       r	\S 5       r
\S	 5       r\S
 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       rS rS rSS jrS rS rS rS rS r\S 5       r\S 5       r\S 5       rSrg)Context
   Nc                 6    Ub  Xl         g[        5       U l         g)zInitialize the class with a context, empty dict otherwise

:param context_object: The context object to create class from
:return: -
N)_contextdict)selfcontext_objects     M/home/james-whalen/.local/lib/python3.13/site-packages/bandit/core/context.py__init__Context.__init__   s     %*M FDM    c                 "    SU R                    S3$ )a  Generate representation of object for printing / interactive use

Most likely only interested in non-default properties, so we return
the string version of _context.

Example string returned:
<Context {'node': <_ast.Call object at 0x110252510>, 'function': None,
'name': 'socket', 'imports': set(['socket']), 'module': None,
'filename': 'examples/binding.py',
'call': <_ast.Call object at 0x110252510>, 'lineno': 3,
'import_aliases': {}, 'qualname': 'socket.socket'}>

:return: A string representation of the object
z	<Context >r   r
   s    r   __repr__Context.__repr__   s     4==/++r   c                 B   / nSU R                   ;   a  [        U R                   S   S5      (       an  U R                   S   R                   HQ  n[        US5      (       a  UR                  UR                  5        M1  UR                  U R                  U5      5        MS     U$ )z>Get a list of function args

:return: A list of function args
callargsattr)r   hasattrr   appendr   _get_literal_value)r
   r   args      r   	call_argsContext.call_args'   s~     T]]"wt}}V/Df'M'M}}V,113''KK)KK 7 7 <=	 2
 r   c                     SU R                   ;   a@  [        U R                   S   S5      (       a"  [        U R                   S   R                  5      $ g)zdGet the number of args a function call has

:return: The number of args a function call has or None
r   r   N)r   r   lenr   r   s    r   call_args_countContext.call_args_count6   sB     T]]"wt}}V/Df'M'Mt}}V,1122r   c                 8    U R                   R                  S5      $ )zXGet the name (not FQ) of a function call

:return: The name (not FQ) of a function call
namer   getr   s    r   call_function_nameContext.call_function_nameA        }}  ((r   c                 8    U R                   R                  S5      $ )zLGet the FQ name of a function call

:return: The FQ name of a function call
qualnamer&   r   s    r   call_function_name_qualContext.call_function_name_qualI   s     }}  ,,r   c                 t   SU R                   ;   a  [        U R                   S   S5      (       a  0 nU R                   S   R                   Hi  n[        UR                  S5      (       a$  UR                  R                  XR
                  '   MB  U R                  UR                  5      XR
                  '   Mk     U$ g)zjGet a dictionary of keyword parameters

:return: A dictionary of keyword parameters for a call as strings
r   keywordsr   N)r   r   r0   valuer   r   r   )r
   return_dictlis      r   call_keywordsContext.call_keywordsQ   s     T]]"wMM&!:(
 (
 KmmF+44288V,,*,((--K'*.*A*A"((*KK'	 5
 r   c                 8    U R                   R                  S5      $ )zhGet the raw AST node associated with the context

:return: The raw AST node associated with the context
noder&   r   s    r   r7   Context.noded   r*   r   c                 8    U R                   R                  S5      $ )zpGet the value of a standalone unicode or string object

:return: value of a standalone unicode or string object
strr&   r   s    r   
string_valContext.string_vall   s     }}  ''r   c                 8    U R                   R                  S5      $ )zcGet the value of a standalone bytes object (py3 only)

:return: value of a standalone bytes object
bytesr&   r   s    r   	bytes_valContext.bytes_valt   s     }}  ))r   c                     U R                   nUb  UR                  S5      $ U R                  nUb  [        R                  " U5      $ g)aM  Get escaped value of the object.

Turn the value of a string or bytes object into byte sequence with
unknown, control, and \ characters escaped.

This function should be used when looking for a known sequence in a
potentially badly encoded string in the code.

:return: sequence of printable ascii bytes representing original string
Nunicode_escape)r;   encoder?   r   escaped_bytes_representation)r
   vals     r   string_val_as_escaped_bytes#Context.string_val_as_escaped_bytes|   sD     oo?::.//nn?55c::r   c                 8    U R                   R                  S5      $ )zZGet the raw AST for the current statement

:return: The raw AST for the current statement
	statementr&   r   s    r   rI   Context.statement   s     }}  --r   c                 n   / nSU R                   ;   a  [        U R                   S   S5      (       a  [        U R                   S   R                  S5      (       a\  U R                   S   R                  R                   H5  nUR	                  [
        R                  " X R                   S   5      5        M7     U$ )zZGet a list of fully qualified default values in a function def

:return: List of defaults
r7   r   defaultsimport_aliases)r   r   r   rL   r   r   get_qual_attr)r
   rL   defaults      r   function_def_defaults_qual"Context.function_def_defaults_qual   s     dmm#f-v66f-22J??==055>>''/?!@ ? r   c                 0   [        U[        R                  5      (       ai  [        UR                  [        5      (       a  [        UR                  5      nU$ UR                  c  [        UR                  5      nU$ UR                  n U$ [        U[        R                  5      (       aA  [        5       nUR                   H#  nUR                  U R                  U5      5        M%     UnU$ [        U[        R                  5      (       a5  [        5       nUR                   H  nXPR                  U5      4-  nM     UnU$ [        U[        R                  5      (       aA  [        5       nUR                   H#  nUR                  U R                  U5      5        M%     UnU$ [        U[        R                   5      (       a+  [#        [%        UR&                  UR(                  5      5      nU$ [        U[        R*                  5      (       a  UR,                  nU$ SnU$ )zUtility function to turn AST literals into native Python types

:param literal: The AST literal to convert
:return: The value of the AST literal
N)
isinstanceastConstantr1   boolr:   Listlisteltsr   r   TupletupleSetsetaddDictr	   zipkeysvaluesNameid)	r
   literalliteral_valuereturn_listr3   return_tupleti
return_setsis	            r   r   Context._get_literal_value   s    gs||,,'--.. #GMM 2B A & #GMM 2> ; !(: 7 **&Kll""4#:#:2#>? #'M. + ++ 7Lll!8!8!< >> #(M"  ))Jllt66r:; #&M  ** W\\7>>!BCM  **#JJM
  !Mr   c                 6    U R                   nUb
  X;   a  X!   $ gg)zVGets the value of a named argument in a function call.

:return: named argument value
N)r4   )r
   argument_name
kwd_valuess      r   get_call_arg_valueContext.get_call_arg_value   s,    
 ''
!m&A,, 'B!r   c                     U R                  U5      nUb2  [        U[        5      (       d  [        U45      nU H
  nX4:X  d  M
    g   gg)ao  Checks for a value of a named argument in a function call.

Returns none if the specified argument is not found.
:param argument_name: A string - name of the argument to look for
:param argument_values: the value, or list of values to test against
:return: Boolean True if argument found and matched, False if
found and not matched, None if argument not found at all
NTF)rp   rS   rX   )r
   rn   argument_values	arg_valuerE   s        r   check_call_arg_valueContext.check_call_arg_value   sQ     ++M:	 ot44"&'9":&# '  r   c                     [        U R                  S5      (       aF  U R                  R                   H+  nUR                  U:X  d  M  UR                  R
                  s  $    gg)a
  Get the line number for a specific named argument

In case the call is split over multiple lines, get the correct one for
the argument.
:param argument_name: A string - name of the argument to look for
:return: Integer - the line number of the found argument, or -1
r0   N)r   r7   r0   r   r1   lineno)r
   rn   keys      r   get_lineno_for_call_argContext.get_lineno_for_call_arg   sJ     499j))yy))77m+99+++ * *r   c                     U R                   nU(       aF  X:  aA  U R                  S   R                  U   n[        USS5      =(       d    U R	                  U5      $ g)zReturns positional argument at the specified position (if it exists)

:param position_num: The index of the argument to return the value for
:return: Value of the argument at the specified position if it exists
r   r   N)r"   r   r   getattrr   )r
   position_nummax_argsr   s       r   get_call_arg_at_position Context.get_call_arg_at_position  sR     ''/--',,\:C3-M1H1H1MMr   c                 >    U R                   R                  S5      U:H  $ )zCheck for the specified module is currently being imported

:param module: The module name to look for
:return: True if the module is found, False otherwise
moduler&   r
   r   s     r   is_module_being_imported Context.is_module_being_imported  s     }}  *f44r   c                 >    XR                   R                  S/ 5      ;   $ )zCheck if a specified module has been imported; only exact matches.

:param module: The module name to look for
:return: True if the module is found, False otherwise
importsr&   r   s     r   is_module_imported_exact Context.is_module_imported_exact  s     **9b999r   c                 ^    SU R                   ;   a  U R                   S    H
  nX;   d  M
    g   g)zCheck if a specified module has been imported

Check if a specified module has been imported; specified module exists
as part of any import statement.
:param module: The module name to look for
:return: True if the module is found, False otherwise
r   TFr   )r
   r   imps      r   is_module_imported_likeContext.is_module_imported_like$  s0     %}}Y/= 0 r   c                 8    U R                   R                  S5      $ )Nfilenamer&   r   s    r   r   Context.filename2  s    }}  ,,r   c                 8    U R                   R                  S5      $ )N	file_datar&   r   s    r   r   Context.file_data6  s    }}  --r   c                 8    U R                   R                  S5      $ )NrM   r&   r   s    r   rM   Context.import_aliases:  s    }}  !122r   r   )N)__name__
__module____qualname____firstlineno__r   r   propertyr   r"   r(   r-   r4   r7   r;   r?   rF   rI   rP   r   rp   ru   rz   r   r   r   r   r   r   rM   __static_attributes__ r   r   r   r   
   sM   	#,"     ) ) - -  $ ) ) ( ( * *  , . .  &)V-.,5: - - . . 3 3r   r   )rT   bandit.corer   r   r   r   r   <module>r      s   
  r3 r3r   