Skip to content

Commit

Permalink
reapply patches
Browse files Browse the repository at this point in the history
  • Loading branch information
dirk-thomas committed Sep 30, 2016
1 parent 86dc40f commit 2324287
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions ament_cpplint/ament_cpplint/cpplint.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
#
# Copyright (c) 2009 Google Inc. All rights reserved.
#
Expand Down Expand Up @@ -54,6 +54,17 @@
import sys
import unicodedata

Py3k = (sys.version_info[0] == 3)
"""A boolean to check if we are running Python3000"""

try:
xrange(0, 1)
except NameError:
xrange = range
try:
unicode
except NameError:
unicode = str

_USAGE = """
Syntax: cpplint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...]
Expand Down Expand Up @@ -935,7 +946,11 @@ def IncrementErrorCount(self, category):

def PrintErrorCounts(self):
"""Print a summary of errors by category, and the total."""
for category, count in self.errors_by_category.iteritems():
try:
items = self.errors_by_category.iteritems()
except AttributeError:
items = self.errors_by_category.items()
for category, count in items:
sys.stderr.write('Category \'%s\' errors found: %d\n' %
(category, count))
sys.stdout.write('Total errors found: %d\n' % self.error_count)
Expand Down Expand Up @@ -1118,6 +1133,7 @@ def RepositoryName(self):
os.path.exists(os.path.join(current_dir, ".hg")) or
os.path.exists(os.path.join(current_dir, ".svn"))):
root_dir = current_dir
break
current_dir = os.path.dirname(current_dir)

if (os.path.exists(os.path.join(root_dir, ".git")) or
Expand Down Expand Up @@ -1929,7 +1945,7 @@ def CheckForBadCharacters(filename, lines, error):
error: The function to call with any errors found.
"""
for linenum, line in enumerate(lines):
if u'\ufffd' in line:
if unicode(b'\xef\xbf\xbd', 'utf-8') in line:
error(filename, linenum, 'readability/utf8', 5,
'Line contains invalid UTF-8 (or Unicode replacement character).')
if '\0' in line:
Expand Down Expand Up @@ -2258,7 +2274,7 @@ def CheckEnd(self, filename, clean_lines, linenum, error):
# deciding what these nontrivial things are, so this check is
# triggered by namespace size only, which works most of the time.
if (linenum - self.starting_linenum < 10
and not Match(r'^\s*};*\s*(//|/\*).*\bnamespace\b', line)):
and not Match(r'^\s*};*\s*(//).*\bnamespace\b', line)):
return

# Look for matching comment at end of namespace.
Expand All @@ -2275,7 +2291,7 @@ def CheckEnd(self, filename, clean_lines, linenum, error):
# expected namespace.
if self.name:
# Named namespace
if not Match((r'^\s*};*\s*(//|/\*).*\bnamespace\s+' +
if not Match((r'^\s*};*\s*(//).*\bnamespace\s+' +
re.escape(self.name) + r'[\*/\.\\\s]*$'),
line):
error(filename, linenum, 'readability/namespace', 5,
Expand Down Expand Up @@ -4548,7 +4564,10 @@ def _GetTextInside(text, start_pattern):

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

# Find the position to start extracting text.
match = re.search(start_pattern, text, re.M)
Expand Down Expand Up @@ -5239,6 +5258,10 @@ def CheckCStyleCast(filename, clean_lines, linenum, cast_type, pattern, error):
remainder):
return False

# Don't warn in C files about C-style casts
if os.path.splitext(filename)[1] in ['.c', '.h']:
return False

# At this point, all that should be left is actual casts.
error(filename, linenum, 'readability/casting', 4,
'Using C-style cast. Use %s<%s>(...) instead' %
Expand Down Expand Up @@ -5496,7 +5519,7 @@ def CheckForIncludeWhatYouUse(filename, clean_lines, include_state, error,

# include_dict is modified during iteration, so we iterate over a copy of
# the keys.
header_keys = include_dict.keys()
header_keys = list(include_dict.keys())
for header in header_keys:
(same_module, common_path) = FilesBelongToSameModule(abs_filename, header)
fullpath = common_path + header
Expand Down Expand Up @@ -6138,10 +6161,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 Py3k:
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 2324287

Please sign in to comment.