original_docstring: Helper method to write per operator blacklist violation report.
  
      Arguments:
          logger: DIRBS logger object
          config: DIRBS config object
          report_dir: reporting directory
          conn: DIRBS PostgreSQL connection object
          month: reporting month
          year: reporting year
      Returns:
          Report Metadata
      
docstring: Helper method to write per operator blacklist violation report.
docstring_tokens: Helper method to write per operator blacklist violation report .
code: def write_blacklist_violations(logger: callable, config: callable, report_dir: str,
                                 conn: callable, month: int, year: int) -> callable:
      """Helper method to write per operator blacklist violation report.
  
      Arguments:
          logger: DIRBS logger object
          config: DIRBS config object
          report_dir: reporting directory
          conn: DIRBS PostgreSQL connection object
          month: reporting month
          year: reporting year
      Returns:
          Report Metadata
      """
      logger.info('Generating per-MNO blacklist violations...')
      with contextlib.ExitStack() as stack:
          # push files to the stack to handle
          operator_ids = [o.id for o in config.region_config.operators]
          filename_op_map = {'blacklist_violations_{0}.csv'.format(o): o for o in operator_ids}
          opname_file_map = {o: stack.enter_context(open(os.path.join(report_dir, fn), 'w', encoding='utf-8'))
                             for fn, o in filename_op_map.items()}
          opname_csvwriter_map = {o: csv.writer(opname_file_map[o]) for o in operator_ids}
  
          # write the headers
          for _, writer in opname_csvwriter_map.items():
              writer.writerow(['imei', 'last_seen'])
  
          # query to find blacklist violations
          with conn.cursor() as cursor:
              cursor.execute("""SELECT imei_norm AS imei, last_seen, operator_id
                                  FROM classification_state
                                  JOIN monthly_network_triplets_per_mno_no_null_imeis
                                 USING (imei_norm)
                                 WHERE triplet_month = %s
                                   AND triplet_year = %s
                                   AND end_date IS NULL
                                   AND block_date IS NOT NULL
                                   AND last_seen > block_date""",
                             [month, year])
              for res in cursor:
                  opname_csvwriter_map[res.operator_id].writerow([res.imei, res.last_seen])
          logger.info('Per-MNO blacklist violation generated successfully.')
      return _gen_metadata_for_reports(list(filename_op_map.keys()), report_dir)
code_tokens: def write_blacklist_violations ( logger : callable , config : callable , report_dir : str , conn : callable , month : int , year : int ) -> callable : logger . info ( 'Generating per-MNO blacklist violations...' ) with contextlib . ExitStack ( ) as stack : operator_ids = [ o . id for o in config . region_config . operators ] filename_op_map = { 'blacklist_violations_{0}.csv' . format ( o ) : o for o in operator_ids } opname_file_map = { o : stack . enter_context ( open ( os . path . join ( report_dir , fn ) , 'w' , encoding = 'utf-8' ) ) for fn , o in filename_op_map . items ( ) } opname_csvwriter_map = { o : csv . writer ( opname_file_map [ o ] ) for o in operator_ids } for _ , writer in opname_csvwriter_map . items ( ) : writer . writerow ( [ 'imei' , 'last_seen' ] ) with conn . cursor ( ) as cursor : cursor . execute ( """SELECT imei_norm AS imei, last_seen, operator_id
                                  FROM classification_state
                                  JOIN monthly_network_triplets_per_mno_no_null_imeis
                                 USING (imei_norm)
                                 WHERE triplet_month = %s
                                   AND triplet_year = %s
                                   AND end_date IS NULL
                                   AND block_date IS NOT NULL
                                   AND last_seen > block_date""" , [ month , year ] ) for res in cursor : opname_csvwriter_map [ res . operator_id ] . writerow ( [ res . imei , res . last_seen ] ) logger . info ( 'Per-MNO blacklist violation generated successfully.' ) return _gen_metadata_for_reports ( list ( filename_op_map . keys ( ) ) , report_dir )
short_docstring: Helper method to write per operator blacklist violation report.
short_docstring_tokens: Helper method to write per operator blacklist violation report .
comment: """Helper method to write per operator blacklist violation report.
  
      Arguments:
          logger: DIRBS logger object
          config: DIRBS config object
          report_dir: reporting directory
          conn: DIRBS PostgreSQL connection object
          month: reporting month
          year: reporting year
      Returns:
          Report Metadata
      """$SEP$# push files to the stack to handle$SEP$# write the headers$SEP$# query to find blacklist violations