<s> r"""<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import datetime <EOL> import logging <EOL> from bandit . core import constants <EOL> from bandit . core . test_properties import accepts_baseline <EOL> logger = logging . getLogger ( __name__ ) <EOL> color = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> def header ( text , * args ) : <EOL> return u'<STR_LIT>' % ( color [ '<STR_LIT>' ] , ( text % args ) , color [ '<STR_LIT>' ] ) <EOL> def get_verbose_details ( manager ) : <EOL> bits = [ ] <EOL> bits . append ( header ( u'<STR_LIT>' , len ( manager . files_list ) ) ) <EOL> tpl = u"<STR_LIT>" <EOL> bits . extend ( [ tpl % ( item , sum ( score [ '<STR_LIT>' ] ) , sum ( score [ '<STR_LIT>' ] ) ) <EOL> for ( item , score ) <EOL> in zip ( manager . files_list , manager . scores ) ] ) <EOL> bits . append ( header ( u'<STR_LIT>' , len ( manager . excluded_files ) ) ) <EOL> bits . extend ( [ u"<STR_LIT>" % fname for fname in manager . excluded_files ] ) <EOL> return '<STR_LIT:\n>' . join ( [ str ( bit ) for bit in bits ] ) <EOL> def get_metrics ( manager ) : <EOL> bits = [ ] <EOL> bits . append ( header ( "<STR_LIT>" ) ) <EOL> for ( criteria , default ) in constants . CRITERIA : <EOL> bits . append ( "<STR_LIT>" % ( criteria . lower ( ) ) ) <EOL> for rank in constants . RANKING : <EOL> bits . append ( "<STR_LIT>" % ( <EOL> rank . capitalize ( ) , <EOL> manager . metrics . data [ '<STR_LIT>' ] [ '<STR_LIT>' % ( criteria , rank ) ] ) ) <EOL> return '<STR_LIT:\n>' . join ( [ str ( bit ) for bit in bits ] ) <EOL> def _output_issue_str ( issue , indent , show_lineno = True , show_code = True , <EOL> lines = - <NUM_LIT:1> ) : <EOL> bits = [ ] <EOL> bits . append ( "<STR_LIT>" % ( <EOL> indent , color [ issue . severity ] , issue . test_id , issue . test , issue . text ) ) <EOL> bits . append ( "<STR_LIT>" % ( <EOL> indent , issue . severity . capitalize ( ) , issue . confidence . capitalize ( ) ) ) <EOL> bits . append ( "<STR_LIT>" % ( <EOL> indent , issue . fname , <EOL> issue . lineno if show_lineno else "<STR_LIT>" , <EOL> color [ '<STR_LIT>' ] ) ) <EOL> if show_code : <EOL> bits . extend ( [ indent + l for l in <EOL> issue . get_code ( lines , True ) . split ( '<STR_LIT:\n>' ) ] ) <EOL> return '<STR_LIT:\n>' . join ( [ bit for bit in bits ] ) <EOL> def get_results ( manager , sev_level , conf_level , lines ) : <EOL> bits = [ ] <EOL> issues = manager . get_issue_list ( sev_level , conf_level ) <EOL> baseline = not isinstance ( issues , list ) <EOL> candidate_indent = '<STR_LIT:U+0020>' * <NUM_LIT:10> <EOL> if not len ( issues ) : <EOL> return u"<STR_LIT>" <EOL> for issue in issues : <EOL> if not baseline or len ( issues [ issue ] ) == <NUM_LIT:1> : <EOL> bits . append ( _output_issue_str ( issue , "<STR_LIT>" , lines = lines ) ) <EOL> else : <EOL> bits . append ( _output_issue_str ( issue , "<STR_LIT>" , <EOL> show_lineno = False , <EOL> show_code = False ) ) <EOL> bits . append ( u'<STR_LIT>' ) <EOL> for candidate in issues [ issue ] : <EOL> bits . append ( _output_issue_str ( candidate , <EOL> candidate_indent , <EOL> lines = lines ) ) <EOL> bits . append ( '<STR_LIT:\n>' ) <EOL> bits . append ( u'<STR_LIT:->' * <NUM_LIT:50> ) <EOL> return '<STR_LIT:\n>' . join ( [ bit for bit in bits ] ) <EOL> def do_print ( bits ) : <EOL> print ( '<STR_LIT:\n>' . join ( [ bit for bit in bits ] ) ) <EOL> @ accepts_baseline <EOL> def report ( manager , filename , sev_level , conf_level , lines = - <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> bits = [ ] <EOL> bits . append ( header ( "<STR_LIT>" , datetime . datetime . utcnow ( ) ) ) <EOL> if manager . verbose : <EOL> bits . append ( get_verbose_details ( manager ) ) <EOL> bits . append ( header ( "<STR_LIT>" ) ) <EOL> bits . append ( get_results ( manager , sev_level , conf_level , lines ) ) <EOL> bits . append ( header ( "<STR_LIT>" ) ) <EOL> bits . append ( '<STR_LIT>' % <EOL> ( manager . metrics . data [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) ) <EOL> bits . append ( '<STR_LIT>' % <EOL> ( manager . metrics . data [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) ) <EOL> bits . append ( get_metrics ( manager ) ) <EOL> bits . append ( header ( "<STR_LIT>" , len ( manager . skipped ) ) ) <EOL> bits . extend ( [ "<STR_LIT>" % skip for skip in manager . skipped ] ) <EOL> do_print ( bits ) <EOL> if filename is not None : <EOL> logger . info ( ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % filename ) </s>
