<s> from __future__ import absolute_import <EOL> from __future__ import unicode_literals <EOL> import collections <EOL> from git_code_debt . metric import Metric <EOL> from git_code_debt . metrics . base import DiffParserBase <EOL> from git_code_debt . metrics . common import FILE_TYPE_MAP <EOL> from git_code_debt . metrics . curse_words import word_list <EOL> def count_curse_words ( lines ) : <EOL> curses = <NUM_LIT:0> <EOL> for line in lines : <EOL> for word in line . split ( ) : <EOL> if word in word_list : <EOL> curses += <NUM_LIT:1> <EOL> return curses <EOL> class CurseWordsParser ( DiffParserBase ) : <EOL> """<STR_LIT>""" <EOL> def get_metrics_from_stat ( self , file_diff_stats ) : <EOL> total_curses = <NUM_LIT:0> <EOL> curses_by_file_type = collections . defaultdict ( int ) <EOL> for file_diff_stat in file_diff_stats : <EOL> curses_added = count_curse_words ( file_diff_stat . lines_added ) <EOL> curses_removed = count_curse_words ( file_diff_stat . lines_removed ) <EOL> curses_changed = curses_added - curses_removed <EOL> total_curses = total_curses + curses_changed <EOL> file_type = FILE_TYPE_MAP . get ( file_diff_stat . extension , '<STR_LIT>' ) <EOL> curses_by_file_type [ file_type ] += curses_changed <EOL> yield Metric ( '<STR_LIT>' , total_curses ) <EOL> for file_type in set ( FILE_TYPE_MAP . values ( ) ) | set ( [ '<STR_LIT>' ] ) : <EOL> curses_changed = curses_by_file_type . get ( file_type , <NUM_LIT:0> ) <EOL> yield Metric ( <EOL> '<STR_LIT>' . format ( file_type ) , <EOL> curses_changed , <EOL> ) <EOL> def get_possible_metric_ids ( self ) : <EOL> return [ '<STR_LIT>' ] + [ <EOL> '<STR_LIT>' . format ( file_type ) <EOL> for file_type in set ( FILE_TYPE_MAP . values ( ) ) | set ( [ '<STR_LIT>' ] ) <EOL> ] </s>
