summaryrefslogtreecommitdiff
path: root/buildscripts/errorcodes.py
diff options
context:
space:
mode:
authorMathew Robinson <chasinglogic@gmail.com>2019-02-19 10:50:57 -0500
committerMathew Robinson <chasinglogic@gmail.com>2019-04-08 14:08:49 -0400
commit8dd6d4755734ed37c1b98dfdefce3ca6bc65f1f6 (patch)
tree69e936c4953cbead2e3bae2690157c5fe75e709d /buildscripts/errorcodes.py
parentc600aa9d7423eca8151daf626e2799d9a6c7b31c (diff)
downloadmongo-8dd6d4755734ed37c1b98dfdefce3ca6bc65f1f6.tar.gz
SERVER-32295 Support Python 3
Diffstat (limited to 'buildscripts/errorcodes.py')
-rwxr-xr-xbuildscripts/errorcodes.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/buildscripts/errorcodes.py b/buildscripts/errorcodes.py
index 1060e6ed9f4..6faeffca589 100755
--- a/buildscripts/errorcodes.py
+++ b/buildscripts/errorcodes.py
@@ -5,14 +5,15 @@ Parses .cpp files for assertions and verifies assertion codes are distinct.
Optionally replaces zero codes in source code with new distinct values.
"""
-from __future__ import absolute_import
-from __future__ import print_function
+
+
import bisect
import os.path
import sys
from collections import defaultdict, namedtuple
from optparse import OptionParser
+from functools import reduce
# Get relative imports to work when the package is not installed on the PYTHONPATH.
if __name__ == "__main__" and __package__ is None:
@@ -44,21 +45,21 @@ list_files = False # pylint: disable=invalid-name
def parse_source_files(callback):
"""Walk MongoDB sourcefiles and invoke a callback for each AssertLocation found."""
- quick = ["assert", "Exception", "ErrorCodes::Error"]
+ quick = [b"assert", b"Exception", b"ErrorCodes::Error"]
patterns = [
- re.compile(r"(?:u|m(?:sg)?)asser(?:t|ted)(?:NoTrace)?\s*\(\s*(\d+)", re.MULTILINE),
- re.compile(r"(?:DB|Assertion)Exception\s*[({]\s*(\d+)", re.MULTILINE),
- re.compile(r"fassert(?:Failed)?(?:WithStatus)?(?:NoTrace)?(?:StatusOK)?\s*\(\s*(\d+)",
+ re.compile(b"(?:u|m(?:sg)?)asser(?:t|ted)(?:NoTrace)?\s*\(\s*(\d+)", re.MULTILINE),
+ re.compile(b"(?:DB|Assertion)Exception\s*[({]\s*(\d+)", re.MULTILINE),
+ re.compile(b"fassert(?:Failed)?(?:WithStatus)?(?:NoTrace)?(?:StatusOK)?\s*\(\s*(\d+)",
re.MULTILINE),
- re.compile(r"ErrorCodes::Error\s*[({]\s*(\d+)", re.MULTILINE)
+ re.compile(b"ErrorCodes::Error\s*[({]\s*(\d+)", re.MULTILINE)
]
for source_file in utils.get_all_source_files(prefix='src/mongo/'):
if list_files:
print('scanning file: ' + source_file)
- with open(source_file) as fh:
+ with open(source_file, 'rb') as fh:
text = fh.read()
if not any([zz in text for zz in quick]):
@@ -168,7 +169,7 @@ def read_error_codes():
print("EXCESSIVE SKIPPING OF ERROR CODES:")
print(" %s:%d:%d:%s" % (loc.sourceFile, line, col, loc.lines))
- for code, locations in dups.items():
+ for code, locations in list(dups.items()):
print("DUPLICATE IDS: %s" % code)
for loc in locations:
line, col = get_line_and_column_for_position(loc)