<s> import os <EOL> import re <EOL> import pep8 <EOL> import six <EOL> def flake8ext ( f ) : <EOL> """<STR_LIT>""" <EOL> f . name = __name__ <EOL> return f <EOL> _all_log_levels = { <EOL> '<STR_LIT>' : '<STR_LIT:_>' , <EOL> '<STR_LIT:error>' : '<STR_LIT>' , <EOL> '<STR_LIT:info>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> _all_hints = set ( _all_log_levels . values ( ) ) <EOL> mutable_default_args = re . compile ( r"<STR_LIT>" ) <EOL> def _regex_for_level ( level , hint ) : <EOL> return r"<STR_LIT>" % { <EOL> '<STR_LIT>' : level , <EOL> '<STR_LIT>' : '<STR_LIT:|>' . join ( _all_hints - set ( [ hint ] ) ) , <EOL> } <EOL> log_translation_hint = re . compile ( <EOL> '<STR_LIT:|>' . join ( '<STR_LIT>' % _regex_for_level ( level , hint ) <EOL> for level , hint in six . iteritems ( _all_log_levels ) ) ) <EOL> log_warn = re . compile ( <EOL> r"<STR_LIT>" ) <EOL> contextlib_nested = re . compile ( r"<STR_LIT>" ) <EOL> @ flake8ext <EOL> def validate_log_translations ( logical_line , physical_line , filename ) : <EOL> if "<STR_LIT>" in filename : <EOL> return <EOL> if pep8 . noqa ( physical_line ) : <EOL> return <EOL> msg = "<STR_LIT>" <EOL> if log_translation_hint . match ( logical_line ) : <EOL> yield ( <NUM_LIT:0> , msg ) <EOL> @ flake8ext <EOL> def use_jsonutils ( logical_line , filename ) : <EOL> msg = "<STR_LIT>" <EOL> json_check_skipped_patterns = [ <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> ] <EOL> for pattern in json_check_skipped_patterns : <EOL> if pattern in filename : <EOL> return <EOL> if "<STR_LIT>" in logical_line : <EOL> json_funcs = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> for f in json_funcs : <EOL> pos = logical_line . find ( '<STR_LIT>' % f ) <EOL> if pos != - <NUM_LIT:1> : <EOL> yield ( pos , msg % { '<STR_LIT>' : f [ : - <NUM_LIT:1> ] } ) <EOL> @ flake8ext <EOL> def no_translate_debug_logs ( logical_line , filename ) : <EOL> """<STR_LIT>""" <EOL> for hint in _all_hints : <EOL> if logical_line . startswith ( "<STR_LIT>" % hint ) : <EOL> yield ( <NUM_LIT:0> , "<STR_LIT>" ) <EOL> @ flake8ext <EOL> def check_assert_called_once_with ( logical_line , filename ) : <EOL> if '<STR_LIT>' in filename : <EOL> if '<STR_LIT>' in logical_line : <EOL> return <EOL> uncased_line = logical_line . lower ( ) . replace ( '<STR_LIT:_>' , '<STR_LIT>' ) <EOL> check_calls = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if any ( x for x in check_calls if x in uncased_line ) : <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> yield ( <NUM_LIT:0> , msg ) <EOL> if '<STR_LIT>' in uncased_line : <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> yield ( <NUM_LIT:0> , msg ) <EOL> @ flake8ext <EOL> def check_no_contextlib_nested ( logical_line , filename ) : <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if contextlib_nested . match ( logical_line ) : <EOL> yield ( <NUM_LIT:0> , msg ) <EOL> @ flake8ext <EOL> def check_python3_xrange ( logical_line ) : <EOL> if re . search ( r"<STR_LIT>" , logical_line ) : <EOL> yield ( <NUM_LIT:0> , "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> @ flake8ext <EOL> def check_no_basestring ( logical_line ) : <EOL> if re . search ( r"<STR_LIT>" , logical_line ) : <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> yield ( <NUM_LIT:0> , msg ) <EOL> @ flake8ext <EOL> def check_python3_no_iteritems ( logical_line ) : <EOL> if re . search ( r"<STR_LIT>" , logical_line ) : <EOL> msg = ( "<STR_LIT>" ) <EOL> yield ( <NUM_LIT:0> , msg ) <EOL> @ flake8ext <EOL> def check_asserttrue ( logical_line , filename ) : <EOL> if '<STR_LIT>' in filename : <EOL> if re . search ( r"<STR_LIT>" , logical_line ) : <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> yield ( <NUM_LIT:0> , msg ) <EOL> if re . search ( r"<STR_LIT>" , logical_line ) : <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> yield ( <NUM_LIT:0> , msg ) <EOL> @ flake8ext <EOL> def no_mutable_default_args ( logical_line ) : <EOL> msg = "<STR_LIT>" <EOL> if mutable_default_args . match ( logical_line ) : <EOL> yield ( <NUM_LIT:0> , msg ) <EOL> @ flake8ext <EOL> def check_assertfalse ( logical_line , filename ) : <EOL> if '<STR_LIT>' in filename : <EOL> if re . search ( r"<STR_LIT>" , logical_line ) : <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> yield ( <NUM_LIT:0> , msg ) <EOL> if re . search ( r"<STR_LIT>" , logical_line ) : <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> yield ( <NUM_LIT:0> , msg ) <EOL> @ flake8ext <EOL> def check_assertempty ( logical_line , filename ) : <EOL> if '<STR_LIT>' in filename : <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> empties = r"<STR_LIT>" <EOL> reg = r"<STR_LIT>" % empties <EOL> if re . search ( reg , logical_line ) : <EOL> yield ( <NUM_LIT:0> , msg ) <EOL> @ flake8ext <EOL> def check_assertisinstance ( logical_line , filename ) : <EOL> if '<STR_LIT>' in filename : <EOL> if re . search ( r"<STR_LIT>" , <EOL> logical_line ) : <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> yield ( <NUM_LIT:0> , msg ) <EOL> @ flake8ext <EOL> def check_assertequal_for_httpcode ( logical_line , filename ) : <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if '<STR_LIT>' in filename : <EOL> if re . search ( r"<STR_LIT>" , <EOL> logical_line ) : <EOL> yield ( <NUM_LIT:0> , msg ) <EOL> @ flake8ext <EOL> def check_log_warn_deprecated ( logical_line , filename ) : <EOL> msg = "<STR_LIT>" <EOL> if log_warn . match ( logical_line ) : <EOL> yield ( <NUM_LIT:0> , msg ) <EOL> @ flake8ext <EOL> def check_oslo_i18n_wrapper ( logical_line , filename , noqa ) : <EOL> """<STR_LIT>""" <EOL> if noqa : <EOL> return <EOL> split_line = logical_line . split ( ) <EOL> modulename = os . path . normpath ( filename ) . split ( '<STR_LIT:/>' ) [ <NUM_LIT:0> ] <EOL> bad_i18n_module = '<STR_LIT>' % modulename <EOL> if ( len ( split_line ) > <NUM_LIT:1> and split_line [ <NUM_LIT:0> ] in ( '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> if ( split_line [ <NUM_LIT:1> ] == bad_i18n_module or <EOL> modulename != '<STR_LIT>' and split_line [ <NUM_LIT:1> ] in ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) ) : <EOL> msg = ( "<STR_LIT>" <EOL> % { '<STR_LIT>' : split_line [ <NUM_LIT:1> ] , '<STR_LIT>' : modulename } ) <EOL> yield ( <NUM_LIT:0> , msg ) <EOL> @ flake8ext <EOL> def check_builtins_gettext ( logical_line , tokens , filename , lines , noqa ) : <EOL> """<STR_LIT>""" <EOL> if noqa : <EOL> return <EOL> modulename = os . path . normpath ( filename ) . split ( '<STR_LIT:/>' ) [ <NUM_LIT:0> ] <EOL> if '<STR_LIT>' % modulename in filename : <EOL> return <EOL> if os . path . basename ( filename ) in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return <EOL> token_values = [ t [ <NUM_LIT:1> ] for t in tokens ] <EOL> i18n_wrapper = '<STR_LIT>' % modulename <EOL> if '<STR_LIT:_>' in token_values : <EOL> i18n_import_line_found = False <EOL> for line in lines : <EOL> split_line = [ elm . rstrip ( '<STR_LIT:U+002C>' ) for elm in line . split ( ) ] <EOL> if ( len ( split_line ) > <NUM_LIT:1> and split_line [ <NUM_LIT:0> ] == '<STR_LIT>' and <EOL> split_line [ <NUM_LIT:1> ] == i18n_wrapper and <EOL> '<STR_LIT:_>' in split_line ) : <EOL> i18n_import_line_found = True <EOL> break <EOL> if not i18n_import_line_found : <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" % i18n_wrapper ) <EOL> yield ( <NUM_LIT:0> , msg ) <EOL> def factory ( register ) : <EOL> register ( validate_log_translations ) <EOL> register ( use_jsonutils ) <EOL> register ( check_assert_called_once_with ) <EOL> register ( no_translate_debug_logs ) <EOL> register ( check_no_contextlib_nested ) <EOL> register ( check_python3_xrange ) <EOL> register ( check_no_basestring ) <EOL> register ( check_python3_no_iteritems ) <EOL> register ( check_asserttrue ) <EOL> register ( no_mutable_default_args ) <EOL> register ( check_assertfalse ) <EOL> register ( check_assertempty ) <EOL> register ( check_assertisinstance ) <EOL> register ( check_assertequal_for_httpcode ) <EOL> register ( check_log_warn_deprecated ) <EOL> register ( check_oslo_i18n_wrapper ) <EOL> register ( check_builtins_gettext ) </s>
