本文整理匯總了Python中common.TabChecker類的典型用法代碼示例。如果您正苦於以下問題:Python TabChecker類的具體用法?Python TabChecker怎麽用?Python TabChecker使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了TabChecker類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: ChangeLogChecker
class ChangeLogChecker(object):
"""Processes text lines for checking style."""
categories = set(['changelog/bugnumber', 'changelog/filechangedescriptionwhitespace'])
def __init__(self, file_path, handle_style_error, should_line_be_checked):
self.file_path = file_path
self.handle_style_error = handle_style_error
self.should_line_be_checked = should_line_be_checked
self._tab_checker = TabChecker(file_path, handle_style_error)
def check_entry(self, first_line_checked, entry_lines):
if not entry_lines:
return
for line in entry_lines:
if parse_bug_id_from_changelog(line):
break
if re.search("Unreviewed", line, re.IGNORECASE):
break
if re.search("build", line, re.IGNORECASE) and re.search("fix", line, re.IGNORECASE):
break
else:
self.handle_style_error(first_line_checked,
"changelog/bugnumber", 5,
"ChangeLog entry has no bug number")
# check file change descriptions for style violations
line_no = first_line_checked - 1
for line in entry_lines:
line_no = line_no + 1
# filter file change descriptions
if not re.match('\s*\*\s', line):
continue
if re.search(':\s*$', line) or re.search(':\s', line):
continue
self.handle_style_error(line_no,
"changelog/filechangedescriptionwhitespace", 5,
"Need whitespace between colon and description")
def check(self, lines):
self._tab_checker.check(lines)
first_line_checked = 0
entry_lines = []
for line_index, line in enumerate(lines):
if not self.should_line_be_checked(line_index + 1):
# If we transitioned from finding changed lines to
# unchanged lines, then we are done.
if first_line_checked:
break
continue
if not first_line_checked:
first_line_checked = line_index + 1
entry_lines.append(line)
self.check_entry(first_line_checked, entry_lines)
示例2: TextChecker
class TextChecker(object):
"""Processes text lines for checking style."""
def __init__(self, file_path, handle_style_error):
self.file_path = file_path
self.handle_style_error = handle_style_error
self._tab_checker = TabChecker(file_path, handle_style_error)
def check(self, lines):
self._tab_checker.check(lines)
示例3: JSChecker
class JSChecker(object):
"""Processes JavaScript lines for checking style."""
# FIXME: plug in a JavaScript parser to find syntax errors.
categories = set(('js/syntax',))
def __init__(self, file_path, handle_style_error):
self._handle_style_error = handle_style_error
self._tab_checker = TabChecker(file_path, handle_style_error)
def check(self, lines):
self._tab_checker.check(lines)
示例4: assert_tab
def assert_tab(self, input_lines, error_lines):
"""Assert when the given lines contain tabs."""
self._error_lines = []
def style_error_handler(line_number, category, confidence, message):
self.assertEqual(category, 'whitespace/tab')
self.assertEqual(confidence, 5)
self.assertEqual(message, 'Line contains tab character.')
self._error_lines.append(line_number)
checker = TabChecker('', style_error_handler)
checker.check(input_lines)
self.assertEquals(self._error_lines, error_lines)
示例5: MessagesInChecker
class MessagesInChecker(object):
"""Processes .messages.in lines for checking style."""
def __init__(self, file_path, handle_style_error):
self.file_path = file_path
self.handle_style_error = handle_style_error
self._tab_checker = TabChecker(file_path, handle_style_error)
def check(self, lines):
self._tab_checker.check(lines)
self.check_WTF_prefix(lines)
def check_WTF_prefix(self, lines):
comment = re.compile("^\s*#")
for line_number, line in enumerate(lines):
if not comment.match(line) and "WTF::" in line:
self.handle_style_error(line_number + 1, "build/messagesin/wtf", 5, "Line contains WTF:: prefix.")
示例6: ChangeLogChecker
class ChangeLogChecker(object):
"""Processes text lines for checking style."""
def __init__(self, file_path, handle_style_error, should_line_be_checked):
self.file_path = file_path
self.handle_style_error = handle_style_error
self.should_line_be_checked = should_line_be_checked
self._tab_checker = TabChecker(file_path, handle_style_error)
def check_entry(self, first_line_checked, entry_lines):
if not entry_lines:
return
for line in entry_lines:
if parse_bug_id_from_changelog(line):
break
if re.search("Unreviewed", line, re.IGNORECASE):
break
if re.search("build", line, re.IGNORECASE) and re.search("fix", line, re.IGNORECASE):
break
else:
self.handle_style_error(first_line_checked,
"changelog/bugnumber", 5,
"ChangeLog entry has no bug number")
def check(self, lines):
self._tab_checker.check(lines)
first_line_checked = 0
entry_lines = []
for line_index, line in enumerate(lines):
if not self.should_line_be_checked(line_index + 1):
# If we transitioned from finding changed lines to
# unchanged lines, then we are done.
if first_line_checked:
break
continue
if not first_line_checked:
first_line_checked = line_index + 1
entry_lines.append(line)
self.check_entry(first_line_checked, entry_lines)
示例7: TestExpectationsChecker
class TestExpectationsChecker(object):
"""Processes TestExpectations lines for validating the syntax."""
categories = set(["test/expectations"])
def __init__(self, file_path, handle_style_error, host=None):
self._file_path = file_path
self._handle_style_error = handle_style_error
self._tab_checker = TabChecker(file_path, handle_style_error)
# FIXME: host should be a required parameter, not an optional one.
host = host or Host()
host.initialize_scm()
self._port_obj = host.port_factory.get()
# Suppress error messages of test_expectations module since they will be reported later.
log = logging.getLogger("webkitpy.layout_tests.layout_package.test_expectations")
log.setLevel(logging.CRITICAL)
def _handle_error_message(self, lineno, message, confidence):
pass
def check_test_expectations(self, expectations_str, tests=None):
parser = TestExpectationParser(self._port_obj, tests, is_lint_mode=True)
expectations = parser.parse("expectations", expectations_str)
level = 5
for expectation_line in expectations:
for warning in expectation_line.warnings:
self._handle_style_error(expectation_line.line_numbers, "test/expectations", level, warning)
def check_tabs(self, lines):
self._tab_checker.check(lines)
def check(self, lines):
expectations = "\n".join(lines)
if self._port_obj:
self.check_test_expectations(expectations_str=expectations, tests=None)
# Warn tabs in lines as well
self.check_tabs(lines)
示例8: __init__
def __init__(self, file_path, handle_style_error, host=None):
self._file_path = file_path
self._handle_style_error = handle_style_error
self._tab_checker = TabChecker(file_path, handle_style_error)
# FIXME: host should be a required parameter, not an optional one.
host = host or Host()
host.initialize_scm()
self._port_obj = host.port_factory.get()
# Suppress error messages of test_expectations module since they will be reported later.
log = logging.getLogger("webkitpy.layout_tests.layout_package.test_expectations")
log.setLevel(logging.CRITICAL)
示例9: __init__
def __init__(self, file_path, handle_style_error, should_line_be_checked):
self.file_path = file_path
self.handle_style_error = handle_style_error
self.should_line_be_checked = should_line_be_checked
self._tab_checker = TabChecker(file_path, handle_style_error)
示例10: __init__
def __init__(self, file_path, handle_style_error):
self.file_path = file_path
self.handle_style_error = handle_style_error
self._tab_checker = TabChecker(file_path, handle_style_error)
示例11: CMakeChecker
class CMakeChecker(object):
"""Processes CMake lines for checking style."""
# NO_SPACE_CMDS list are based on commands section of CMake document.
# Now it is generated from
# http://www.cmake.org/cmake/help/v2.8.10/cmake.html#section_Commands.
# Some commands are from default CMake modules such as pkg_check_modules.
# Please keep list in alphabet order.
#
# For commands in this list, spaces should not be added it and its
# parentheses. For eg, message("testing"), not message ("testing")
#
# The conditional commands like if, else, endif, foreach, endforeach,
# while, endwhile and break are listed in ONE_SPACE_CMDS
NO_SPACE_CMDS = [
'add_custom_command', 'add_custom_target', 'add_definitions',
'add_dependencies', 'add_executable', 'add_library',
'add_subdirectory', 'add_test', 'aux_source_directory',
'build_command',
'cmake_minimum_required', 'cmake_policy', 'configure_file',
'create_test_sourcelist',
'define_property',
'enable_language', 'enable_testing', 'endfunction', 'endmacro',
'execute_process', 'export',
'file', 'find_file', 'find_library', 'find_package', 'find_path',
'find_program', 'fltk_wrap_ui', 'function',
'get_cmake_property', 'get_directory_property',
'get_filename_component', 'get_property', 'get_source_file_property',
'get_target_property', 'get_test_property',
'include', 'include_directories', 'include_external_msproject',
'include_regular_expression', 'install',
'link_directories', 'list', 'load_cache', 'load_command',
'macro', 'mark_as_advanced', 'math', 'message',
'option',
#From FindPkgConfig.cmake
'pkg_check_modules',
'project',
'remove_definitions', 'return',
'separate_arguments', 'set', 'set_directory_properties', 'set_property',
'set_source_files_properties', 'set_target_properties',
'set_tests_properties', 'site_name', 'source_group', 'string',
'target_link_libraries', 'try_compile', 'try_run',
'unset',
'variable_watch',
]
# CMake conditional commands, require one space between command and
# its parentheses, such as "if (", "foreach (", etc.
ONE_SPACE_CMDS = [
'if', 'else', 'elseif', 'endif',
'foreach', 'endforeach',
'while', 'endwhile',
'break',
]
def __init__(self, file_path, handle_style_error):
self._handle_style_error = handle_style_error
self._tab_checker = TabChecker(file_path, handle_style_error)
def check(self, lines):
self._tab_checker.check(lines)
for line_number, line in enumerate(lines, start=1):
self._process_line(line_number, line)
self._check_list_order(lines)
def _process_line(self, line_number, line_content):
if match('(^|\ +)#', line_content):
# ignore comment line
return
l = line_content.expandtabs(4)
# check command like message( "testing")
if search('\(\ +', l):
self._handle_style_error(line_number, 'whitespace/parentheses', 5,
'No space after "("')
# check command like message("testing" )
if search('\ +\)', l) and not search('^\ +\)$', l):
self._handle_style_error(line_number, 'whitespace/parentheses', 5,
'No space before ")"')
self._check_trailing_whitespace(line_number, l)
self._check_no_space_cmds(line_number, l)
self._check_one_space_cmds(line_number, l)
self._check_indent(line_number, line_content)
def _check_trailing_whitespace(self, line_number, line_content):
line_content = line_content.rstrip('\n') # chr(10), newline
line_content = line_content.rstrip('\r') # chr(13), carriage return
line_content = line_content.rstrip('\x0c') # chr(12), form feed, ^L
stripped = line_content.rstrip()
if line_content != stripped:
self._handle_style_error(line_number, 'whitespace/trailing', 5,
'No trailing spaces')
def _check_no_space_cmds(self, line_number, line_content):
# check command like "SET (" or "Set("
for t in self.NO_SPACE_CMDS:
self._check_non_lowercase_cmd(line_number, line_content, t)
if search('(^|\ +)' + t.lower() + '\ +\(', line_content):
msg = 'No space between command "' + t.lower() + '" and its parentheses, should be "' + t + '("'
self._handle_style_error(line_number, 'whitespace/parentheses', 5, msg)
#.........這裏部分代碼省略.........
示例12: CMakeChecker
class CMakeChecker(object):
"""Processes CMake lines for checking style."""
# NO_SPACE_CMDS list are based on commands section of CMake document.
# Now it is generated from
# http://www.cmake.org/cmake/help/v2.8.10/cmake.html#section_Commands.
# Some commands are from default CMake modules such as pkg_check_modules.
# Please keep list in alphabet order.
#
# For commands in this list, spaces should not be added it and its
# parentheses. For eg, message("testing"), not message ("testing")
#
# The conditional commands like if, else, endif, foreach, endforeach,
# while, endwhile and break are listed in ONE_SPACE_CMDS
NO_SPACE_CMDS = [
'add_custom_command', 'add_custom_target', 'add_definitions',
'add_dependencies', 'add_executable', 'add_library',
'add_subdirectory', 'add_test', 'aux_source_directory',
'build_command',
'cmake_minimum_required', 'cmake_policy', 'configure_file',
'create_test_sourcelist',
'define_property',
'enable_language', 'enable_testing', 'endfunction', 'endmacro',
'execute_process', 'export',
'file', 'find_file', 'find_library', 'find_package', 'find_path',
'find_program', 'fltk_wrap_ui', 'function',
'get_cmake_property', 'get_directory_property',
'get_filename_component', 'get_property', 'get_source_file_property',
'get_target_property', 'get_test_property',
'include', 'include_directories', 'include_external_msproject',
'include_regular_expression', 'install',
'link_directories', 'list', 'load_cache', 'load_command',
'macro', 'mark_as_advanced', 'math', 'message',
'option',
#From FindPkgConfig.cmake
'pkg_check_modules',
'project',
'qt_wrap_cpp', 'qt_wrap_ui',
'remove_definitions', 'return',
'separate_arguments', 'set', 'set_directory_properties', 'set_property',
'set_source_files_properties', 'set_target_properties',
'set_tests_properties', 'site_name', 'source_group', 'string',
'target_link_libraries', 'try_compile', 'try_run',
'unset',
'variable_watch',
]
# CMake conditional commands, require one space between command and
# its parentheses, such as "if (", "foreach (", etc.
ONE_SPACE_CMDS = [
'if', 'else', 'elseif', 'endif',
'foreach', 'endforeach',
'while', 'endwhile',
'break',
]
def __init__(self, file_path, handle_style_error):
self._handle_style_error = handle_style_error
self._tab_checker = TabChecker(file_path, handle_style_error)
def check(self, lines):
self._tab_checker.check(lines)
self._num_lines = len(lines)
for l in xrange(self._num_lines):
self._process_line(l + 1, lines[l])
def _process_line(self, line_number, line_content):
if re.match('(^|\ +)#', line_content):
# ignore comment line
return
l = line_content.expandtabs(4)
# check command like message( "testing")
if re.search('\(\ +', l):
self._handle_style_error(line_number, 'whitespace/parentheses', 5,
'No space after "("')
# check command like message("testing" )
if re.search('\ +\)', l) and not re.search('^\ +\)$', l):
self._handle_style_error(line_number, 'whitespace/parentheses', 5,
'No space before ")"')
self._check_trailing_whitespace(line_number, l)
self._check_no_space_cmds(line_number, l)
self._check_one_space_cmds(line_number, l)
self._check_indent(line_number, line_content)
def _check_trailing_whitespace(self, line_number, line_content):
line_content = line_content.rstrip('\n') # chr(10), newline
line_content = line_content.rstrip('\r') # chr(13), carriage return
line_content = line_content.rstrip('\x0c') # chr(12), form feed, ^L
stripped = line_content.rstrip()
if line_content != stripped:
self._handle_style_error(line_number, 'whitespace/trailing', 5,
'No trailing spaces')
def _check_no_space_cmds(self, line_number, line_content):
# check command like "SET (" or "Set("
for t in self.NO_SPACE_CMDS:
self._check_non_lowercase_cmd(line_number, line_content, t)
if re.search('(^|\ +)' + t.lower() + '\ +\(', line_content):
msg = 'No space between command "' + t.lower() + '" and its parentheses, should be "' + t + '("'
#.........這裏部分代碼省略.........
示例13: ChangeLogChecker
class ChangeLogChecker(object):
"""Processes text lines for checking style."""
categories = set(['changelog/bugnumber', 'changelog/filechangedescriptionwhitespace'])
def __init__(self, file_path, handle_style_error, should_line_be_checked):
self.file_path = file_path
self.handle_style_error = handle_style_error
self.should_line_be_checked = should_line_be_checked
self._tab_checker = TabChecker(file_path, handle_style_error)
def check_entry(self, first_line_checked, entry_lines):
if not entry_lines:
return
for line in entry_lines:
if parse_bug_id_from_changelog(line):
break
if searchIgnorecase("Unreviewed", line):
break
if searchIgnorecase("build", line) and searchIgnorecase("fix", line):
break
else:
self.handle_style_error(first_line_checked,
"changelog/bugnumber", 5,
"ChangeLog entry has no bug number")
# check file change descriptions for style violations
line_no = first_line_checked - 1
for line in entry_lines:
line_no = line_no + 1
# filter file change descriptions
if not match('\s*\*\s', line):
continue
if search(':\s*$', line) or search(':\s', line):
continue
self.handle_style_error(line_no,
"changelog/filechangedescriptionwhitespace", 5,
"Need whitespace between colon and description")
# check for a lingering "No new tests. (OOPS!)" left over from prepare-changeLog.
line_no = first_line_checked - 1
for line in entry_lines:
line_no = line_no + 1
if match('\s*No new tests. \(OOPS!\)$', line):
self.handle_style_error(line_no,
"changelog/nonewtests", 5,
"You should remove the 'No new tests' and either add and list tests, or explain why no new tests were possible.")
def check(self, lines):
self._tab_checker.check(lines)
first_line_checked = 0
entry_lines = []
for line_index, line in enumerate(lines):
if not self.should_line_be_checked(line_index + 1):
# If we transitioned from finding changed lines to
# unchanged lines, then we are done.
if first_line_checked:
break
continue
if not first_line_checked:
first_line_checked = line_index + 1
entry_lines.append(line)
self.check_entry(first_line_checked, entry_lines)
示例14: __init__
def __init__(self, file_path, handle_style_error):
self._handle_style_error = handle_style_error
self._tab_checker = TabChecker(file_path, handle_style_error)
self._single_quote_checker = SingleQuoteChecker(file_path, handle_style_error)
示例15: ChangeLogChecker
class ChangeLogChecker(object):
"""Processes text lines for checking style."""
categories = set(['changelog/bugnumber', 'changelog/filechangedescriptionwhitespace'])
def __init__(self, file_path, handle_style_error, should_line_be_checked):
self.file_path = file_path
self.handle_style_error = handle_style_error
self.should_line_be_checked = should_line_be_checked
self._tab_checker = TabChecker(file_path, handle_style_error)
def check_entry(self, first_line_checked, entry_lines):
if not entry_lines:
return
for line in entry_lines:
if parse_bug_id_from_changelog(line):
break
if searchIgnorecase("Unreviewed", line):
break
if searchIgnorecase("build", line) and searchIgnorecase("fix", line):
break
else:
self.handle_style_error(first_line_checked,
"changelog/bugnumber", 5,
"ChangeLog entry has no bug number")
# check file change descriptions for style violations
line_no = first_line_checked - 1
for line in entry_lines:
line_no = line_no + 1
# filter file change descriptions
if not match('\s*\*\s', line):
continue
if search(':\s*$', line) or search(':\s', line):
continue
self.handle_style_error(line_no,
"changelog/filechangedescriptionwhitespace", 5,
"Need whitespace between colon and description")
# check for a lingering "No new tests (OOPS!)." left over from prepare-changeLog.
line_no = first_line_checked - 1
for line in entry_lines:
line_no = line_no + 1
if match('\s*No new tests \(OOPS!\)\.$', line):
self.handle_style_error(line_no,
"changelog/nonewtests", 5,
"You should remove the 'No new tests' and either add and list tests, or explain why no new tests were possible.")
self.check_for_unwanted_security_phrases(first_line_checked, entry_lines)
def check(self, lines):
self._tab_checker.check(lines)
first_line_checked = 0
entry_lines = []
for line_index, line in enumerate(lines):
if not self.should_line_be_checked(line_index + 1):
# If we transitioned from finding changed lines to
# unchanged lines, then we are done.
if first_line_checked:
break
continue
if not first_line_checked:
first_line_checked = line_index + 1
entry_lines.append(line)
self.check_entry(first_line_checked, entry_lines)
def contains_phrase_in_first_line_or_across_two_lines(self, phrase, line1, line2):
return searchIgnorecase(phrase, line1) or ((not searchIgnorecase(phrase, line2)) and searchIgnorecase(phrase, line1 + " " + line2))
def check_for_unwanted_security_phrases(self, first_line_checked, lines):
unwanted_security_phrases = [
"arbitrary code execution", "buffer overflow", "buffer overrun",
"buffer underrun", "dangling pointer", "double free", "fuzzer", "fuzzing", "fuzz test",
"invalid cast", "jsfunfuzz", "malicious", "memory corruption", "security bug",
"security flaw", "use after free", "use-after-free", "UXSS",
"WTFCrashWithSecurityImplication",
"spoof", # Captures spoof, spoofed, spoofing
"vulnerab", # Captures vulnerable, vulnerability, vulnerabilities
]
lines_with_single_spaces = []
for line in lines:
lines_with_single_spaces.append(" ".join(line.split()))
found_unwanted_security_phrases = []
last_index = len(lines_with_single_spaces) - 1
first_line_number_with_unwanted_phrase = maxsize
for unwanted_phrase in unwanted_security_phrases:
for line_index, line in enumerate(lines_with_single_spaces):
next_line = "" if line_index >= last_index else lines_with_single_spaces[line_index + 1]
if self.contains_phrase_in_first_line_or_across_two_lines(unwanted_phrase, line, next_line):
found_unwanted_security_phrases.append(unwanted_phrase)
first_line_number_with_unwanted_phrase = min(first_line_number_with_unwanted_phrase, first_line_checked + line_index)
if len(found_unwanted_security_phrases) > 0:
self.handle_style_error(first_line_number_with_unwanted_phrase,
"changelog/unwantedsecurityterms", 3,
"Please consider whether the use of security-sensitive phrasing could help someone exploit WebKit: {}".format(", ".join(found_unwanted_security_phrases)))