diff options
Diffstat (limited to 'coverage')
-rw-r--r-- | coverage/backward.py | 33 | ||||
-rw-r--r-- | coverage/files.py | 5 | ||||
-rw-r--r-- | coverage/phystokens.py | 2 |
3 files changed, 18 insertions, 22 deletions
diff --git a/coverage/backward.py b/coverage/backward.py index 236bef8e..637a5976 100644 --- a/coverage/backward.py +++ b/coverage/backward.py @@ -79,26 +79,19 @@ if sys.version_info >= (3, 0): try: open_source = tokenize.open # pylint: disable=E1101 except AttributeError: - try: - detect_encoding = tokenize.detect_encoding # pylint: disable=E1101 - except AttributeError: - assert 3 == 4 - def open_source(fname): - """Open a source file the best way.""" - return open(fname, "rU") - else: - from io import TextIOWrapper - # Copied from the 3.2 stdlib: - def open_source(fname): - """Open a file in read only mode using the encoding detected by - detect_encoding(). - """ - buffer = open(fname, 'rb') - encoding, _ = detect_encoding(buffer.readline) - buffer.seek(0) - text = TextIOWrapper(buffer, encoding, line_buffering=True) - text.mode = 'r' - return text + from io import TextIOWrapper + detect_encoding = tokenize.detect_encoding # pylint: disable=E1101 + # Copied from the 3.2 stdlib: + def open_source(fname): + """Open a file in read only mode using the encoding detected by + detect_encoding(). + """ + buffer = open(fname, 'rb') + encoding, _ = detect_encoding(buffer.readline) + buffer.seek(0) + text = TextIOWrapper(buffer, encoding, line_buffering=True) + text.mode = 'r' + return text else: def open_source(fname): """Open a source file the best way.""" diff --git a/coverage/files.py b/coverage/files.py index 81ec196f..e6dc4aa1 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -215,5 +215,8 @@ def find_python_files(dirname): del dirnames[:] continue for filename in filenames: - if fnmatch.fnmatch(filename, "*.py"): + # We're only interested in files that look like reasonable Python + # files: Must end with .py, and must not have certain funny + # characters that probably mean they are editor junk. + if re.match(r"^[^.#~!$@%^&*()+=,]+\.py$", filename): yield os.path.join(dirpath, filename) diff --git a/coverage/phystokens.py b/coverage/phystokens.py index 850f78bd..3beebab1 100644 --- a/coverage/phystokens.py +++ b/coverage/phystokens.py @@ -117,7 +117,7 @@ def source_encoding(source): # built-in tools to do this. assert sys.version_info < (3, 0) - # This is mostly code adapted rom Py3.2's tokenize module. + # This is mostly code adapted from Py3.2's tokenize module. cookie_re = re.compile("coding[:=]\s*([-\w.]+)") |