From 5d341ba07870cfde336e21f1f922a889984ba54d Mon Sep 17 00:00:00 2001 From: Ana Maria Martinez Gomez Date: Tue, 16 Mar 2021 10:48:36 +0100 Subject: [PATCH] py3: remove six As we are not supporting Python 2 any longer, we can stop using six and use the equivalent Python 3 method instead. --- capa/ida/helpers/__init__.py | 5 ++--- capa/ida/plugin/proxy.py | 3 +-- capa/render/__init__.py | 4 +--- capa/render/default.py | 1 - capa/render/utils.py | 5 +++-- capa/rules.py | 13 +++++++------ setup.py | 1 - 7 files changed, 14 insertions(+), 18 deletions(-) diff --git a/capa/ida/helpers/__init__.py b/capa/ida/helpers/__init__.py index 020483f9..ab91baec 100644 --- a/capa/ida/helpers/__init__.py +++ b/capa/ida/helpers/__init__.py @@ -10,7 +10,6 @@ import logging import datetime import idc -import six import idaapi import idautils @@ -85,7 +84,7 @@ def get_func_start_ea(ea): def get_file_md5(): """ """ md5 = idautils.GetInputFileMD5() - if not isinstance(md5, six.string_types): + if not isinstance(md5, str): md5 = capa.features.bytes_to_str(md5) return md5 @@ -93,7 +92,7 @@ def get_file_md5(): def get_file_sha256(): """ """ sha256 = idaapi.retrieve_input_file_sha256() - if not isinstance(sha256, six.string_types): + if not isinstance(sha256, str): sha256 = capa.features.bytes_to_str(sha256) return sha256 diff --git a/capa/ida/plugin/proxy.py b/capa/ida/plugin/proxy.py index 7511cc64..2ce48134 100644 --- a/capa/ida/plugin/proxy.py +++ b/capa/ida/plugin/proxy.py @@ -5,7 +5,6 @@ # Unless required by applicable law or agreed to in writing, software distributed under the License # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and limitations under the License. -import six from PyQt5 import QtCore from PyQt5.QtCore import Qt @@ -208,7 +207,7 @@ class CapaExplorerSearchProxyModel(QtCore.QSortFilterProxyModel): if not data: continue - if not isinstance(data, six.string_types): + if not isinstance(data, str): # sanity check: should already be a string, but double check continue diff --git a/capa/render/__init__.py b/capa/render/__init__.py index 9de20bd5..7deb9b17 100644 --- a/capa/render/__init__.py +++ b/capa/render/__init__.py @@ -8,8 +8,6 @@ import json -import six - import capa.rules import capa.engine @@ -249,7 +247,7 @@ class CapaJsonObjectEncoder(json.JSONEncoder): """JSON encoder that emits Python sets as sorted lists""" def default(self, obj): - if isinstance(obj, (list, dict, int, float, bool, type(None))) or isinstance(obj, six.string_types): + if isinstance(obj, (list, dict, int, float, bool, type(None))) or isinstance(obj, str): return json.JSONEncoder.default(self, obj) elif isinstance(obj, set): return list(sorted(obj)) diff --git a/capa/render/default.py b/capa/render/default.py index 7ebad0da..52488011 100644 --- a/capa/render/default.py +++ b/capa/render/default.py @@ -8,7 +8,6 @@ import collections -import six import tabulate import capa.render.utils as rutils diff --git a/capa/render/utils.py b/capa/render/utils.py index a484dbb0..001fb4dc 100644 --- a/capa/render/utils.py +++ b/capa/render/utils.py @@ -6,7 +6,8 @@ # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and limitations under the License. -import six +import io + import termcolor @@ -49,7 +50,7 @@ def capability_rules(doc): yield rule -class StringIO(six.StringIO): +class StringIO(io.StringIO): def writeln(self, s): self.write(s) self.write("\n") diff --git a/capa/rules.py b/capa/rules.py index aeb2754a..30815318 100644 --- a/capa/rules.py +++ b/capa/rules.py @@ -18,7 +18,8 @@ try: except ImportError: from backports.functools_lru_cache import lru_cache -import six +import io + import yaml import ruamel.yaml @@ -244,7 +245,7 @@ def parse_description(s, value_type, description=None): """ s can be an int or a string """ - if value_type != "string" and isinstance(s, six.string_types) and DESCRIPTION_SEPARATOR in s: + if value_type != "string" and isinstance(s, str) and DESCRIPTION_SEPARATOR in s: if description: raise InvalidRule( 'unexpected value: "%s", only one description allowed (inline description with `%s`)' @@ -256,7 +257,7 @@ def parse_description(s, value_type, description=None): else: value = s - if isinstance(value, six.string_types): + if isinstance(value, str): if value_type == "bytes": try: value = codecs.decode(value.replace(" ", ""), "hex") @@ -406,7 +407,7 @@ def build_statements(d, scope): return Range(feature, min=min, max=max, description=description) else: raise InvalidRule("unexpected range: %s" % (count)) - elif key == "string" and not isinstance(d[key], six.string_types): + elif key == "string" and not isinstance(d[key], str): raise InvalidRule("ambiguous string value %s, must be defined as explicit string" % d[key]) else: Feature = parse_feature(key) @@ -699,7 +700,7 @@ class Rule(object): for key in hidden_meta.keys(): del meta[key] - ostream = six.BytesIO() + ostream = io.BytesIO() self._get_ruamel_yaml_parser().dump(definition, ostream) for key, value in hidden_meta.items(): @@ -938,7 +939,7 @@ class RuleSet(object): rules_filtered = set([]) for rule in rules: for k, v in rule.meta.items(): - if isinstance(v, six.string_types) and tag in v: + if isinstance(v, str) and tag in v: logger.debug('using rule "%s" and dependencies, found tag in meta.%s: %s', rule.name, k, v) rules_filtered.update(set(capa.rules.get_rules_and_dependencies(rules, rule.name))) break diff --git a/setup.py b/setup.py index 1c424808..b13ebabf 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,6 @@ import sys import setuptools requirements = [ - "six==1.15.0", "tqdm==4.60.0", "pyyaml==5.4.1", "tabulate==0.8.9",