From c95e4714d71cac2e7bd02e5f6cf83ae7cd993aa3 Mon Sep 17 00:00:00 2001 From: James Turk Date: Thu, 10 Nov 2022 22:11:58 -0600 Subject: [PATCH] cleanup python 2 compat --- src/saucebrush/emitters.py | 16 ++++++++-------- src/saucebrush/filters.py | 36 ++++++++++++++++++------------------ src/saucebrush/sources.py | 6 +----- src/saucebrush/stats.py | 12 ++++++------ 4 files changed, 33 insertions(+), 37 deletions(-) diff --git a/src/saucebrush/emitters.py b/src/saucebrush/emitters.py index 49ccf43..1eae2c9 100644 --- a/src/saucebrush/emitters.py +++ b/src/saucebrush/emitters.py @@ -45,7 +45,7 @@ class DebugEmitter(Emitter): """ def __init__(self, outfile=None): - super(DebugEmitter, self).__init__() + super().__init__() if not outfile: import sys @@ -68,7 +68,7 @@ class CountEmitter(Emitter): def __init__(self, every=1000, of=None, outfile=None, format=None): - super(CountEmitter, self).__init__() + super().__init__() if not outfile: import sys @@ -108,7 +108,7 @@ class CSVEmitter(Emitter): """ def __init__(self, csvfile, fieldnames): - super(CSVEmitter, self).__init__() + super().__init__() import csv self._dictwriter = csv.DictWriter(csvfile, fieldnames) @@ -131,7 +131,7 @@ class SqliteEmitter(Emitter): """ def __init__(self, dbname, table_name, fieldnames=None, replace=False, quiet=False): - super(SqliteEmitter, self).__init__() + super().__init__() import sqlite3 self._conn = sqlite3.connect(dbname) @@ -182,7 +182,7 @@ class SqlDumpEmitter(Emitter): """ def __init__(self, outfile, table_name, fieldnames): - super(SqlDumpEmitter, self).__init__() + super().__init__() self._fieldnames = fieldnames if not outfile: import sys @@ -228,7 +228,7 @@ class DjangoModelEmitter(Emitter): """ def __init__(self, dj_settings, app_label, model_name): - super(DjangoModelEmitter, self).__init__() + super().__init__() from saucebrush.utils import get_django_model self._dbmodel = get_django_model(dj_settings, app_label, model_name) @@ -256,7 +256,7 @@ class MongoDBEmitter(Emitter): drop_collection=False, conn=None, ): - super(MongoDBEmitter, self).__init__() + super().__init__() from pymongo.database import Database @@ -288,7 +288,7 @@ class LoggingEmitter(Emitter): import logging def __init__(self, logger, msg_template, level=logging.DEBUG): - super(LoggingEmitter, self).__init__() + super().__init__() self.logger = logger self.msg_template = msg_template self.level = level diff --git a/src/saucebrush/filters.py b/src/saucebrush/filters.py index 5fa6851..3e1a4ab 100644 --- a/src/saucebrush/filters.py +++ b/src/saucebrush/filters.py @@ -75,7 +75,7 @@ class FieldFilter(Filter): """ def __init__(self, keys): - super(FieldFilter, self).__init__() + super().__init__() self._target_keys = utils.str_or_list(keys) def process_record(self, record): @@ -131,7 +131,7 @@ class ConditionalFilter(YieldFilter): class ValidationError(Exception): def __init__(self, record): - super(ValidationError, self).__init__(repr(record)) + super().__init__(repr(record)) self.record = record @@ -215,7 +215,7 @@ class FieldModifier(FieldFilter): """ def __init__(self, keys, func): - super(FieldModifier, self).__init__(keys) + super().__init__(keys) self._filter_func = func def process_field(self, item): @@ -237,7 +237,7 @@ class FieldKeeper(Filter): """ def __init__(self, keys): - super(FieldKeeper, self).__init__() + super().__init__() self._target_keys = utils.str_or_list(keys) def process_record(self, record): @@ -255,7 +255,7 @@ class FieldRemover(Filter): """ def __init__(self, keys): - super(FieldRemover, self).__init__() + super().__init__() self._target_keys = utils.str_or_list(keys) def process_record(self, record): @@ -277,7 +277,7 @@ class FieldMerger(Filter): """ def __init__(self, mapping, merge_func, keep_fields=False): - super(FieldMerger, self).__init__() + super().__init__() self._field_mapping = mapping self._merge_func = merge_func self._keep_fields = keep_fields @@ -313,7 +313,7 @@ class FieldAdder(Filter): """ def __init__(self, field_name, field_value, replace=True): - super(FieldAdder, self).__init__() + super().__init__() self._field_name = field_name self._field_value = field_value if hasattr(self._field_value, "__iter__"): @@ -348,7 +348,7 @@ class FieldCopier(Filter): """ def __init__(self, copy_mapping): - super(FieldCopier, self).__init__() + super().__init__() self._copy_mapping = copy_mapping def process_record(self, record): @@ -365,7 +365,7 @@ class FieldRenamer(Filter): """ def __init__(self, rename_mapping): - super(FieldRenamer, self).__init__() + super().__init__() self._rename_mapping = rename_mapping def process_record(self, record): @@ -383,7 +383,7 @@ class FieldNameModifier(Filter): """ def __init__(self, func): - super(FieldNameModifier, self).__init__() + super().__init__() self._filter_func = func def process_record(self, record): @@ -405,7 +405,7 @@ class Splitter(Filter): """ def __init__(self, split_mapping): - super(Splitter, self).__init__() + super().__init__() self._split_mapping = split_mapping def process_record(self, record): @@ -449,7 +449,7 @@ class Flattener(FieldFilter): """ def __init__(self, keys): - super(Flattener, self).__init__(keys) + super().__init__(keys) def process_field(self, item): result = [] @@ -463,7 +463,7 @@ class Flattener(FieldFilter): class DictFlattener(Filter): def __init__(self, keys, separator="_"): - super(DictFlattener, self).__init__() + super().__init__() self._keys = utils.str_or_list(keys) self._separator = separator @@ -475,7 +475,7 @@ class Unique(ConditionalFilter): """Filter that ensures that all records passing through are unique.""" def __init__(self): - super(Unique, self).__init__() + super().__init__() self._seen = set() def test_record(self, record): @@ -499,7 +499,7 @@ class UniqueID(ConditionalFilter): """ def __init__(self, field="id", *args): - super(UniqueID, self).__init__() + super().__init__() self._seen = set() self._id_fields = [field] self._id_fields.extend(args) @@ -533,7 +533,7 @@ class PhoneNumberCleaner(FieldFilter): """ def __init__(self, keys, number_format="%s%s%s.%s%s%s.%s%s%s%s"): - super(PhoneNumberCleaner, self).__init__(keys) + super().__init__(keys) self._number_format = number_format self._num_re = re.compile(r"\d") @@ -551,7 +551,7 @@ class DateCleaner(FieldFilter): """ def __init__(self, keys, from_format, to_format): - super(DateCleaner, self).__init__(keys) + super().__init__(keys) self._from_format = from_format self._to_format = to_format @@ -590,7 +590,7 @@ class NameCleaner(Filter): ) def __init__(self, keys, prefix="", formats=None, nomatch_name=None): - super(NameCleaner, self).__init__() + super().__init__() self._keys = utils.str_or_list(keys) self._name_prefix = prefix self._nomatch_name = nomatch_name diff --git a/src/saucebrush/sources.py b/src/saucebrush/sources.py index 7fd4d88..a44968f 100644 --- a/src/saucebrush/sources.py +++ b/src/saucebrush/sources.py @@ -68,10 +68,6 @@ class FixedWidthFileSource: record[name] = line[range_[0] : range_[1]].rstrip(self._fillchars) return record - def next(self): - """Keep Python 2 next() method that defers to __next__().""" - return self.__next__() - class HtmlTableSource: """Saucebrush source for reading data from an HTML table. @@ -293,7 +289,7 @@ class XMLSource(FileSource): """ def __init__(self, input, node_path=None, attr_prefix="ATTR_", postprocessor=None): - super(XMLSource, self).__init__(input) + super().__init__(input) self.node_list = node_path.split(".") self.attr_prefix = attr_prefix self.postprocessor = postprocessor diff --git a/src/saucebrush/stats.py b/src/saucebrush/stats.py index c8d53ff..dc88c10 100644 --- a/src/saucebrush/stats.py +++ b/src/saucebrush/stats.py @@ -85,7 +85,7 @@ class Sum(StatsFilter): """ def __init__(self, field, initial=0, **kwargs): - super(Sum, self).__init__(field, **kwargs) + super().__init__(field, **kwargs) self._value = initial def process_field(self, item): @@ -101,7 +101,7 @@ class Average(StatsFilter): """ def __init__(self, field, initial=0, **kwargs): - super(Average, self).__init__(field, **kwargs) + super().__init__(field, **kwargs) self._value = initial self._count = 0 @@ -122,7 +122,7 @@ class Median(StatsFilter): """ def __init__(self, field, **kwargs): - super(Median, self).__init__(field, **kwargs) + super().__init__(field, **kwargs) self._values = [] def process_field(self, item): @@ -139,7 +139,7 @@ class MinMax(StatsFilter): """ def __init__(self, field, **kwargs): - super(MinMax, self).__init__(field, **kwargs) + super().__init__(field, **kwargs) self._max = None self._min = None @@ -165,7 +165,7 @@ class StandardDeviation(StatsFilter): """ def __init__(self, field, **kwargs): - super(StandardDeviation, self).__init__(field, **kwargs) + super().__init__(field, **kwargs) self._values = [] def process_field(self, item): @@ -200,7 +200,7 @@ class Histogram(StatsFilter): label_length = 6 def __init__(self, field, **kwargs): - super(Histogram, self).__init__(field, **kwargs) + super().__init__(field, **kwargs) self._counter = collections.Counter() def process_field(self, item):