Skip to content

Commit

Permalink
Merge pull request #120 from vbraun/cpplint-py3
Browse files Browse the repository at this point in the history
Make cpplint.py Python-3 compatible
  • Loading branch information
SRombauts authored Apr 6, 2017
2 parents c6dc1c7 + a537dd6 commit d390342
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@
import unicodedata


try:
xrange(0,1)
PY3 = False
except NameError:
PY3 = True # Python 3
xrange = range
unicode = str


_USAGE = """
Syntax: cpplint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...]
[--counting=total|toplevel|detailed] [--root=subdir]
Expand Down Expand Up @@ -736,7 +745,7 @@ def IncrementErrorCount(self, category):
def PrintErrorCounts(self):
"""Print a summary of errors by category, and the total."""
# SRombauts: "cpplint:" prefix
for category, count in self.errors_by_category.iteritems():
for category, count in self.errors_by_category.items():
sys.stderr.write('cpplint: Category \'%s\' errors found: %d\n' %
(category, count))
# SRombauts: "cpplint:" prefix and error message only when appropriate
Expand Down Expand Up @@ -3694,7 +3703,7 @@ def _GetTextInside(text, start_pattern):

# Give opening punctuations to get the matching close-punctuations.
matching_punctuation = {'(': ')', '{': '}', '[': ']'}
closing_punctuation = set(matching_punctuation.itervalues())
closing_punctuation = set(matching_punctuation.values())

# Find the position to start extracting text.
match = re.search(start_pattern, text, re.M)
Expand Down Expand Up @@ -4779,10 +4788,11 @@ def main():

# Change stderr to write with replacement characters so we don't die
# if we try to print something containing non-ASCII characters.
sys.stderr = codecs.StreamReaderWriter(sys.stderr,
codecs.getreader('utf8'),
codecs.getwriter('utf8'),
'replace')
if not PY3:
sys.stderr = codecs.StreamReaderWriter(sys.stderr,
codecs.getreader('utf8'),
codecs.getwriter('utf8'),
'replace')

_cpplint_state.ResetErrorCounts()
for filename in filenames:
Expand Down

0 comments on commit d390342

Please sign in to comment.