From 3e39b765b32f2b5829621869ed071c3179dd65ed Mon Sep 17 00:00:00 2001 From: Kevin Hock Date: Fri, 27 Mar 2020 17:16:25 -0700 Subject: [PATCH 01/10] :snake: Add pypy -> pypy3 in .travis.yml --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index b3550fe0d..163edbeed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,12 +7,12 @@ matrix: python: 3.6 - env: TOXENV=py37 python: 3.7 - dist: xenial # required for Python >= 3.7 (travis-ci/travis-ci#9069) + dist: xenial # Required for Python >= 3.7 (travis-ci/travis-ci#9069) - env: TOXENV=py38 python: 3.8 - dist: xenial # required for Python >= 3.7 (travis-ci/travis-ci#9069) - - env: TOXENV=pypy - python: pypy + dist: xenial # Required for Python >= 3.7 (travis-ci/travis-ci#9069) + - env: TOXENV=pypy3 + python: pypy3.5-8.0.0 install: - pip install tox script: make test From 00b9bf8dd035fd8046bb41be1efc907c13646fd5 Mon Sep 17 00:00:00 2001 From: Kevin Hock Date: Fri, 27 Mar 2020 17:22:09 -0700 Subject: [PATCH 02/10] :boom: Only python3 pre-commit hook - Remove python2 from setup.py --- .pre-commit-hooks.yaml | 2 +- setup.py | 9 +-------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index f3cc03936..2ec05ad53 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -3,6 +3,6 @@ description: Detects high entropy strings that are likely to be passwords. entry: detect-secrets-hook args: ['--base64-limit', '4.5', '--hex-limit', '3'] - language: python + language: python3 # for backward compatibility files: .* diff --git a/setup.py b/setup.py index 1fd9e5541..8d526b213 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ long_description=( 'Check out detect-secrets on `GitHub `_!' ), - license='Copyright Yelp, Inc. 2018', + license='Copyright Yelp, Inc. 2020', author='Aaron Loo', author_email='aaronloo@yelp.com', url='https://github.com/Yelp/detect-secrets', @@ -23,12 +23,6 @@ 'requests', ], extras_require={ - ':python_version=="2.7"': [ - 'configparser', - 'enum34', - 'future', - 'functools32', - ], 'word_list': [ 'pyahocorasick', ], @@ -40,7 +34,6 @@ ], }, classifiers=[ - 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 3', 'License :: OSI Approved :: Apache Software License', 'Intended Audience :: Developers', From 7c3291885416f4259f38397d12f209321c612944 Mon Sep 17 00:00:00 2001 From: Kevin Hock Date: Fri, 27 Mar 2020 17:31:18 -0700 Subject: [PATCH 03/10] :snake: Remove unused `filename_key` argument --- detect_secrets/core/secrets_collection.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/detect_secrets/core/secrets_collection.py b/detect_secrets/core/secrets_collection.py index a3ee549ef..bd7061803 100644 --- a/detect_secrets/core/secrets_collection.py +++ b/detect_secrets/core/secrets_collection.py @@ -210,28 +210,21 @@ def scan_diff( ), ) - def scan_file(self, filename, filename_key=None): + def scan_file(self, filename): """Scans a specified file, and adds information to self.data :type filename: str :param filename: full path to file to scan. - :type filename_key: str - :param filename_key: key to store in self.data - :returns: boolean; though this value is only used for testing """ - - if not filename_key: - filename_key = filename - if os.path.islink(filename): return False if os.path.splitext(filename)[1] in IGNORED_FILE_EXTENSIONS: return False try: with codecs.open(filename, encoding='utf-8') as f: - self._extract_secrets_from_file(f, filename_key) + self._extract_secrets_from_file(f, filename) return True except IOError: From 6ec6f436fcc6f754603eddf9d593a924ada7e429 Mon Sep 17 00:00:00 2001 From: Kevin Hock Date: Fri, 27 Mar 2020 17:34:34 -0700 Subject: [PATCH 04/10] :snake: Pythonic use of `or` --- detect_secrets/core/log.py | 11 ++++++----- detect_secrets/core/usage.py | 5 +---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/detect_secrets/core/log.py b/detect_secrets/core/log.py index c0898778d..ef37db905 100644 --- a/detect_secrets/core/log.py +++ b/detect_secrets/core/log.py @@ -7,7 +7,7 @@ def get_logger(name=None, format_string=None): :type name: str :param name: used for declaring log channels. - :type format_string: str + :type format_string: str|None :param format_string: for custom formatting """ logging.captureWarnings(True) @@ -18,14 +18,15 @@ def get_logger(name=None, format_string=None): log.set_debug_level = _set_debug_level.__get__(log) log.set_debug_level(0) - if not format_string: - format_string = '[%(module)s]\t%(levelname)s\t%(message)s' - # Setting up log formats log.handlers = [] handler = logging.StreamHandler(sys.stderr) handler.setFormatter( - logging.Formatter(format_string), + logging.Formatter( + format_string + or + '[%(module)s]\t%(levelname)s\t%(message)s', + ), ) log.addHandler(handler) diff --git a/detect_secrets/core/usage.py b/detect_secrets/core/usage.py index e2cc3f3c8..fc5518d90 100644 --- a/detect_secrets/core/usage.py +++ b/detect_secrets/core/usage.py @@ -281,12 +281,9 @@ class PluginDescriptor( ), ): def __new__(cls, related_args=None, **kwargs): - if not related_args: - related_args = [] - return super(PluginDescriptor, cls).__new__( cls, - related_args=related_args, + related_args=related_args or [], **kwargs ) From 5d0d4612d5848a8bd71c8686a20ddf0605f9bf40 Mon Sep 17 00:00:00 2001 From: Kevin Hock Date: Fri, 27 Mar 2020 17:41:58 -0700 Subject: [PATCH 05/10] :snake: Remove all __future__ imports --- detect_secrets/core/audit.py | 3 --- detect_secrets/core/baseline.py | 2 -- detect_secrets/core/code_snippet.py | 2 -- detect_secrets/core/color.py | 2 -- detect_secrets/core/secrets_collection.py | 2 -- detect_secrets/core/usage.py | 2 -- detect_secrets/main.py | 5 ----- detect_secrets/plugins/artifactory.py | 2 -- detect_secrets/plugins/aws.py | 2 -- detect_secrets/plugins/basic_auth.py | 2 -- detect_secrets/plugins/cloudant.py | 2 -- detect_secrets/plugins/common/ini_file_parser.py | 2 -- detect_secrets/plugins/high_entropy_strings.py | 2 -- detect_secrets/plugins/ibm_cloud_iam.py | 2 -- detect_secrets/plugins/ibm_cos_hmac.py | 2 -- detect_secrets/plugins/jwt.py | 2 -- detect_secrets/plugins/keyword.py | 2 -- detect_secrets/plugins/mailchimp.py | 2 -- detect_secrets/plugins/private_key.py | 2 -- detect_secrets/plugins/slack.py | 2 -- detect_secrets/plugins/softlayer.py | 2 -- detect_secrets/plugins/stripe.py | 2 -- detect_secrets/plugins/twilio.py | 2 -- detect_secrets/pre_commit_hook.py | 3 --- 24 files changed, 53 deletions(-) diff --git a/detect_secrets/core/audit.py b/detect_secrets/core/audit.py index de96ca34b..7a8db73e4 100644 --- a/detect_secrets/core/audit.py +++ b/detect_secrets/core/audit.py @@ -1,6 +1,3 @@ -from __future__ import print_function -from __future__ import unicode_literals - import codecs import io import json diff --git a/detect_secrets/core/baseline.py b/detect_secrets/core/baseline.py index 7ff755b30..4a6cf77bb 100644 --- a/detect_secrets/core/baseline.py +++ b/detect_secrets/core/baseline.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import json import os import re diff --git a/detect_secrets/core/code_snippet.py b/detect_secrets/core/code_snippet.py index 8ff70f8a8..5b5a997da 100644 --- a/detect_secrets/core/code_snippet.py +++ b/detect_secrets/core/code_snippet.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - import itertools from .color import AnsiColor diff --git a/detect_secrets/core/color.py b/detect_secrets/core/color.py index 7016250ba..038392fed 100644 --- a/detect_secrets/core/color.py +++ b/detect_secrets/core/color.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - from enum import Enum diff --git a/detect_secrets/core/secrets_collection.py b/detect_secrets/core/secrets_collection.py index bd7061803..9af886cad 100644 --- a/detect_secrets/core/secrets_collection.py +++ b/detect_secrets/core/secrets_collection.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import codecs import json import os diff --git a/detect_secrets/core/usage.py b/detect_secrets/core/usage.py index fc5518d90..d827a75ce 100644 --- a/detect_secrets/core/usage.py +++ b/detect_secrets/core/usage.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import argparse from collections import namedtuple diff --git a/detect_secrets/main.py b/detect_secrets/main.py index c939bfd28..8a033e453 100644 --- a/detect_secrets/main.py +++ b/detect_secrets/main.py @@ -1,8 +1,3 @@ -#!/usr/bin/python -from __future__ import absolute_import -from __future__ import print_function -from __future__ import unicode_literals - import json import sys diff --git a/detect_secrets/plugins/artifactory.py b/detect_secrets/plugins/artifactory.py index 0085b9b7d..0d0ee6a8d 100644 --- a/detect_secrets/plugins/artifactory.py +++ b/detect_secrets/plugins/artifactory.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import re from .base import RegexBasedDetector diff --git a/detect_secrets/plugins/aws.py b/detect_secrets/plugins/aws.py index 8d96894c0..1fa406ef0 100644 --- a/detect_secrets/plugins/aws.py +++ b/detect_secrets/plugins/aws.py @@ -1,8 +1,6 @@ """ This plugin searches for AWS key IDs """ -from __future__ import absolute_import - import hashlib import hmac import re diff --git a/detect_secrets/plugins/basic_auth.py b/detect_secrets/plugins/basic_auth.py index 87e10e21a..5baeb7dd4 100644 --- a/detect_secrets/plugins/basic_auth.py +++ b/detect_secrets/plugins/basic_auth.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import re from .base import RegexBasedDetector diff --git a/detect_secrets/plugins/cloudant.py b/detect_secrets/plugins/cloudant.py index a7219438e..14192deec 100644 --- a/detect_secrets/plugins/cloudant.py +++ b/detect_secrets/plugins/cloudant.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import re import requests diff --git a/detect_secrets/plugins/common/ini_file_parser.py b/detect_secrets/plugins/common/ini_file_parser.py index f9b766c71..0536e997e 100644 --- a/detect_secrets/plugins/common/ini_file_parser.py +++ b/detect_secrets/plugins/common/ini_file_parser.py @@ -1,5 +1,3 @@ -from __future__ import unicode_literals - try: from backports import configparser except ImportError: # pragma: no cover diff --git a/detect_secrets/plugins/high_entropy_strings.py b/detect_secrets/plugins/high_entropy_strings.py index 706ad776b..a3793b916 100644 --- a/detect_secrets/plugins/high_entropy_strings.py +++ b/detect_secrets/plugins/high_entropy_strings.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - try: from backports import configparser except ImportError: # pragma: no cover diff --git a/detect_secrets/plugins/ibm_cloud_iam.py b/detect_secrets/plugins/ibm_cloud_iam.py index 9a2e8f18b..65a23d116 100644 --- a/detect_secrets/plugins/ibm_cloud_iam.py +++ b/detect_secrets/plugins/ibm_cloud_iam.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import requests from .base import RegexBasedDetector diff --git a/detect_secrets/plugins/ibm_cos_hmac.py b/detect_secrets/plugins/ibm_cos_hmac.py index 482bb2e46..5849f844a 100644 --- a/detect_secrets/plugins/ibm_cos_hmac.py +++ b/detect_secrets/plugins/ibm_cos_hmac.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import datetime import hashlib import hmac diff --git a/detect_secrets/plugins/jwt.py b/detect_secrets/plugins/jwt.py index 5a45eba7b..5427874b3 100644 --- a/detect_secrets/plugins/jwt.py +++ b/detect_secrets/plugins/jwt.py @@ -1,8 +1,6 @@ """ This plugin finds JWT tokens """ -from __future__ import absolute_import - import base64 import json import re diff --git a/detect_secrets/plugins/keyword.py b/detect_secrets/plugins/keyword.py index 147550063..42c2c7918 100644 --- a/detect_secrets/plugins/keyword.py +++ b/detect_secrets/plugins/keyword.py @@ -24,8 +24,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ -from __future__ import absolute_import - import re from .base import BasePlugin diff --git a/detect_secrets/plugins/mailchimp.py b/detect_secrets/plugins/mailchimp.py index b39820a72..f90f6cc90 100644 --- a/detect_secrets/plugins/mailchimp.py +++ b/detect_secrets/plugins/mailchimp.py @@ -1,8 +1,6 @@ """ This plugin searches for Mailchimp keys """ -from __future__ import absolute_import - import re from base64 import b64encode diff --git a/detect_secrets/plugins/private_key.py b/detect_secrets/plugins/private_key.py index eab761929..edd4b5681 100644 --- a/detect_secrets/plugins/private_key.py +++ b/detect_secrets/plugins/private_key.py @@ -24,8 +24,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ -from __future__ import absolute_import - import re from .base import RegexBasedDetector diff --git a/detect_secrets/plugins/slack.py b/detect_secrets/plugins/slack.py index 1c29388d0..cb6427d89 100644 --- a/detect_secrets/plugins/slack.py +++ b/detect_secrets/plugins/slack.py @@ -1,8 +1,6 @@ """ This plugin searches for Slack tokens """ -from __future__ import absolute_import - import re import requests diff --git a/detect_secrets/plugins/softlayer.py b/detect_secrets/plugins/softlayer.py index 30268de2e..b2ca78cf6 100644 --- a/detect_secrets/plugins/softlayer.py +++ b/detect_secrets/plugins/softlayer.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import re import requests diff --git a/detect_secrets/plugins/stripe.py b/detect_secrets/plugins/stripe.py index eac70e856..f7f1839b9 100644 --- a/detect_secrets/plugins/stripe.py +++ b/detect_secrets/plugins/stripe.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import re from base64 import b64encode diff --git a/detect_secrets/plugins/twilio.py b/detect_secrets/plugins/twilio.py index 78e149481..4d5b397e3 100644 --- a/detect_secrets/plugins/twilio.py +++ b/detect_secrets/plugins/twilio.py @@ -1,8 +1,6 @@ """ This plugin searches for Twilio API keys """ -from __future__ import absolute_import - import re from .base import RegexBasedDetector diff --git a/detect_secrets/pre_commit_hook.py b/detect_secrets/pre_commit_hook.py index 22ad4da7c..b6740d77b 100644 --- a/detect_secrets/pre_commit_hook.py +++ b/detect_secrets/pre_commit_hook.py @@ -1,6 +1,3 @@ -from __future__ import absolute_import -from __future__ import unicode_literals - import os import subprocess import sys From 141819d26f2a65d0f336ad0f249bf1b837fe4695 Mon Sep 17 00:00:00 2001 From: Kevin Hock Date: Mon, 30 Mar 2020 15:54:32 -0700 Subject: [PATCH 06/10] :boom: Drop pypy support We do not use it internally. --- .travis.yml | 2 -- tox.ini | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 163edbeed..a4765b494 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,8 +11,6 @@ matrix: - env: TOXENV=py38 python: 3.8 dist: xenial # Required for Python >= 3.7 (travis-ci/travis-ci#9069) - - env: TOXENV=pypy3 - python: pypy3.5-8.0.0 install: - pip install tox script: make test diff --git a/tox.ini b/tox.ini index 978620583..4bac44f4d 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] project = detect_secrets # These should match the travis env list -envlist = py{35,36,37,38,py,py3} +envlist = py{35,36,37,38} skip_missing_interpreters = true tox_pip_extensions_ext_venv_update = true From 76bcb64defac86afcf01ed5ae665c1221c59433f Mon Sep 17 00:00:00 2001 From: Kevin Hock Date: Mon, 30 Mar 2020 15:55:07 -0700 Subject: [PATCH 07/10] :mortar_board: Fix link in CHANGELOG From commit a3e7998bfa4924b13df3f9cb49070abdbdff8802 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f40f0de9a..e7db639c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,9 @@ If you love `detect-secrets`, please star our project on GitHub to show your sup [@xxxx]: https://github.com/xxxx --> + # v0.13.1 @@ -651,6 +653,7 @@ This includes using `# pragma: allowlist secret` now for inline allowlisting. # Special thanks to our awesome contributors! :clap: +- [@0atman] - [@adrianbn] - [@baboateng] - [@cclauss] @@ -674,6 +677,7 @@ This includes using `# pragma: allowlist secret` now for inline allowlisting. - [@whathejoe] - [@zioalex] +[@0atman]: https://github.com/0atman [@adrianbn]: https://github.com/adrianbn [@baboateng]: https://github.com/baboateng [@cclauss]: https://github.com/cclauss From 7046220d6cf564b301f0593f90e617a9416b18c2 Mon Sep 17 00:00:00 2001 From: Kevin Hock Date: Mon, 30 Mar 2020 15:55:21 -0700 Subject: [PATCH 08/10] :snake: Normalize `lru_cache` and `configparser` imports --- detect_secrets/core/audit.py | 6 +----- detect_secrets/plugins/common/ini_file_parser.py | 5 +---- detect_secrets/plugins/common/util.py | 6 +----- detect_secrets/plugins/high_entropy_strings.py | 5 +---- 4 files changed, 4 insertions(+), 18 deletions(-) diff --git a/detect_secrets/core/audit.py b/detect_secrets/core/audit.py index 7a8db73e4..ec47d11b8 100644 --- a/detect_secrets/core/audit.py +++ b/detect_secrets/core/audit.py @@ -7,11 +7,7 @@ from builtins import input from collections import defaultdict from copy import deepcopy - -try: - from functools import lru_cache -except ImportError: # pragma: no cover - from functools32 import lru_cache +from functools import lru_cache from ..plugins.common import initialize from ..plugins.common.util import get_mapping_from_secret_type_to_class_name diff --git a/detect_secrets/plugins/common/ini_file_parser.py b/detect_secrets/plugins/common/ini_file_parser.py index 0536e997e..4f74b0b44 100644 --- a/detect_secrets/plugins/common/ini_file_parser.py +++ b/detect_secrets/plugins/common/ini_file_parser.py @@ -1,7 +1,4 @@ -try: - from backports import configparser -except ImportError: # pragma: no cover - import configparser +import configparser import re diff --git a/detect_secrets/plugins/common/util.py b/detect_secrets/plugins/common/util.py index 87602e106..9815b566f 100644 --- a/detect_secrets/plugins/common/util.py +++ b/detect_secrets/plugins/common/util.py @@ -1,10 +1,6 @@ -try: - from functools import lru_cache -except ImportError: # pragma: no cover - from functools32 import lru_cache - import os from abc import abstractproperty +from functools import lru_cache from importlib import import_module from detect_secrets.plugins.base import BasePlugin diff --git a/detect_secrets/plugins/high_entropy_strings.py b/detect_secrets/plugins/high_entropy_strings.py index a3793b916..26bc52c64 100644 --- a/detect_secrets/plugins/high_entropy_strings.py +++ b/detect_secrets/plugins/high_entropy_strings.py @@ -1,8 +1,5 @@ -try: - from backports import configparser -except ImportError: # pragma: no cover - import configparser import base64 +import configparser import math import re import string From 0e1dd3fb371003c2bec96c6fe749e76b72eb73d0 Mon Sep 17 00:00:00 2001 From: Kevin Hock Date: Mon, 30 Mar 2020 15:59:51 -0700 Subject: [PATCH 09/10] :snake: Remove `is_python_2` func and uses --- detect_secrets/plugins/common/filters.py | 6 ------ detect_secrets/util.py | 5 ----- tests/plugins/keyword_test.py | 4 ---- 3 files changed, 15 deletions(-) diff --git a/detect_secrets/plugins/common/filters.py b/detect_secrets/plugins/common/filters.py index e95e4a9b5..f7ad1dafd 100644 --- a/detect_secrets/plugins/common/filters.py +++ b/detect_secrets/plugins/common/filters.py @@ -6,8 +6,6 @@ import re import string -from detect_secrets.util import is_python_2 - def is_found_with_aho_corasick(secret, automaton): """ @@ -22,10 +20,6 @@ def is_found_with_aho_corasick(secret, automaton): if not automaton: return False - if is_python_2(): # pragma: no cover - # Due to pyahocorasick - secret = secret.encode('utf-8') - try: # .lower() to make everything case-insensitive next(automaton.iter(string=secret.lower())) diff --git a/detect_secrets/util.py b/detect_secrets/util.py index 86b73f8b7..b5515be64 100644 --- a/detect_secrets/util.py +++ b/detect_secrets/util.py @@ -1,11 +1,6 @@ import hashlib import os import subprocess -import sys - - -def is_python_2(): - return sys.version_info[0] < 3 def build_automaton(word_list): diff --git a/tests/plugins/keyword_test.py b/tests/plugins/keyword_test.py index 9b8866ba2..8e658e300 100644 --- a/tests/plugins/keyword_test.py +++ b/tests/plugins/keyword_test.py @@ -6,7 +6,6 @@ from detect_secrets.core.potential_secret import PotentialSecret from detect_secrets.plugins.keyword import KeywordDetector -from detect_secrets.util import is_python_2 from testing.mocks import mock_file_object @@ -203,9 +202,6 @@ def test_analyze_standard_positives_with_automaton(self, file_content): automaton = ahocorasick.Automaton() word = 'thisone' - if is_python_2(): # pragma: no cover - # Due to pyahocorasick - word = word.encode('utf-8') automaton.add_word(word, word) automaton.make_automaton() From 05727d23d695cad8ab4ec759f4d296ab91b3d417 Mon Sep 17 00:00:00 2001 From: Kevin Hock Date: Mon, 30 Mar 2020 16:11:27 -0700 Subject: [PATCH 10/10] :snake: Remove all code with "Python 2 compat" comments --- detect_secrets/plugins/common/ini_file_parser.py | 14 ++------------ detect_secrets/plugins/jwt.py | 7 ------- testing/mocks.py | 6 +----- 3 files changed, 3 insertions(+), 24 deletions(-) diff --git a/detect_secrets/plugins/common/ini_file_parser.py b/detect_secrets/plugins/common/ini_file_parser.py index 4f74b0b44..5aaec74a6 100644 --- a/detect_secrets/plugins/common/ini_file_parser.py +++ b/detect_secrets/plugins/common/ini_file_parser.py @@ -32,12 +32,7 @@ def __init__(self, file, add_header=False, exclude_lines_regex=None): :param exclude_lines_regex: optional regex for ignored lines. """ self.parser = configparser.ConfigParser() - try: - # Python2.7 compatible - self.parser.optionxform = unicode - except NameError: # pragma: no cover - # Python3 compatible - self.parser.optionxform = str + self.parser.optionxform = str self.exclude_lines_regex = exclude_lines_regex @@ -47,12 +42,7 @@ def __init__(self, file, add_header=False, exclude_lines_regex=None): # like config files, without a section header. content = '[global]\n' + content - try: - # Python2.7 compatible - self.parser.read_string(unicode(content)) - except NameError: # pragma: no cover - # Python3 compatible - self.parser.read_string(content) + self.parser.read_string(content) # Hacky way to keep track of line location file.seek(0) diff --git a/detect_secrets/plugins/jwt.py b/detect_secrets/plugins/jwt.py index 5427874b3..b16ed9083 100644 --- a/detect_secrets/plugins/jwt.py +++ b/detect_secrets/plugins/jwt.py @@ -8,13 +8,6 @@ from .base import classproperty from .base import RegexBasedDetector -try: - # Python 2 - from future_builtins import filter -except ImportError: # pragma: no cover - # Python 3 - pass - class JwtTokenDetector(RegexBasedDetector): """Scans for JWTs.""" diff --git a/testing/mocks.py b/testing/mocks.py index 6597618a8..4ef010eb0 100644 --- a/testing/mocks.py +++ b/testing/mocks.py @@ -138,11 +138,7 @@ def __init__(self): self.clear() def add(self, message, *args, **kwargs): - try: - # For python 2.x compatible - self.message += unicode(message) + '\n' - except NameError: - self.message += str(message) + '\n' + self.message += str(message) + '\n' def clear(self): self.message = ''