cleanup python 2 compat
This commit is contained in:
parent
bd8d2d2ba2
commit
c95e4714d7
@ -45,7 +45,7 @@ class DebugEmitter(Emitter):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, outfile=None):
|
def __init__(self, outfile=None):
|
||||||
super(DebugEmitter, self).__init__()
|
super().__init__()
|
||||||
if not outfile:
|
if not outfile:
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ class CountEmitter(Emitter):
|
|||||||
|
|
||||||
def __init__(self, every=1000, of=None, outfile=None, format=None):
|
def __init__(self, every=1000, of=None, outfile=None, format=None):
|
||||||
|
|
||||||
super(CountEmitter, self).__init__()
|
super().__init__()
|
||||||
|
|
||||||
if not outfile:
|
if not outfile:
|
||||||
import sys
|
import sys
|
||||||
@ -108,7 +108,7 @@ class CSVEmitter(Emitter):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, csvfile, fieldnames):
|
def __init__(self, csvfile, fieldnames):
|
||||||
super(CSVEmitter, self).__init__()
|
super().__init__()
|
||||||
import csv
|
import csv
|
||||||
|
|
||||||
self._dictwriter = csv.DictWriter(csvfile, fieldnames)
|
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):
|
def __init__(self, dbname, table_name, fieldnames=None, replace=False, quiet=False):
|
||||||
super(SqliteEmitter, self).__init__()
|
super().__init__()
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
self._conn = sqlite3.connect(dbname)
|
self._conn = sqlite3.connect(dbname)
|
||||||
@ -182,7 +182,7 @@ class SqlDumpEmitter(Emitter):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, outfile, table_name, fieldnames):
|
def __init__(self, outfile, table_name, fieldnames):
|
||||||
super(SqlDumpEmitter, self).__init__()
|
super().__init__()
|
||||||
self._fieldnames = fieldnames
|
self._fieldnames = fieldnames
|
||||||
if not outfile:
|
if not outfile:
|
||||||
import sys
|
import sys
|
||||||
@ -228,7 +228,7 @@ class DjangoModelEmitter(Emitter):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, dj_settings, app_label, model_name):
|
def __init__(self, dj_settings, app_label, model_name):
|
||||||
super(DjangoModelEmitter, self).__init__()
|
super().__init__()
|
||||||
from saucebrush.utils import get_django_model
|
from saucebrush.utils import get_django_model
|
||||||
|
|
||||||
self._dbmodel = get_django_model(dj_settings, app_label, model_name)
|
self._dbmodel = get_django_model(dj_settings, app_label, model_name)
|
||||||
@ -256,7 +256,7 @@ class MongoDBEmitter(Emitter):
|
|||||||
drop_collection=False,
|
drop_collection=False,
|
||||||
conn=None,
|
conn=None,
|
||||||
):
|
):
|
||||||
super(MongoDBEmitter, self).__init__()
|
super().__init__()
|
||||||
|
|
||||||
from pymongo.database import Database
|
from pymongo.database import Database
|
||||||
|
|
||||||
@ -288,7 +288,7 @@ class LoggingEmitter(Emitter):
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
def __init__(self, logger, msg_template, level=logging.DEBUG):
|
def __init__(self, logger, msg_template, level=logging.DEBUG):
|
||||||
super(LoggingEmitter, self).__init__()
|
super().__init__()
|
||||||
self.logger = logger
|
self.logger = logger
|
||||||
self.msg_template = msg_template
|
self.msg_template = msg_template
|
||||||
self.level = level
|
self.level = level
|
||||||
|
@ -75,7 +75,7 @@ class FieldFilter(Filter):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, keys):
|
def __init__(self, keys):
|
||||||
super(FieldFilter, self).__init__()
|
super().__init__()
|
||||||
self._target_keys = utils.str_or_list(keys)
|
self._target_keys = utils.str_or_list(keys)
|
||||||
|
|
||||||
def process_record(self, record):
|
def process_record(self, record):
|
||||||
@ -131,7 +131,7 @@ class ConditionalFilter(YieldFilter):
|
|||||||
|
|
||||||
class ValidationError(Exception):
|
class ValidationError(Exception):
|
||||||
def __init__(self, record):
|
def __init__(self, record):
|
||||||
super(ValidationError, self).__init__(repr(record))
|
super().__init__(repr(record))
|
||||||
self.record = record
|
self.record = record
|
||||||
|
|
||||||
|
|
||||||
@ -215,7 +215,7 @@ class FieldModifier(FieldFilter):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, keys, func):
|
def __init__(self, keys, func):
|
||||||
super(FieldModifier, self).__init__(keys)
|
super().__init__(keys)
|
||||||
self._filter_func = func
|
self._filter_func = func
|
||||||
|
|
||||||
def process_field(self, item):
|
def process_field(self, item):
|
||||||
@ -237,7 +237,7 @@ class FieldKeeper(Filter):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, keys):
|
def __init__(self, keys):
|
||||||
super(FieldKeeper, self).__init__()
|
super().__init__()
|
||||||
self._target_keys = utils.str_or_list(keys)
|
self._target_keys = utils.str_or_list(keys)
|
||||||
|
|
||||||
def process_record(self, record):
|
def process_record(self, record):
|
||||||
@ -255,7 +255,7 @@ class FieldRemover(Filter):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, keys):
|
def __init__(self, keys):
|
||||||
super(FieldRemover, self).__init__()
|
super().__init__()
|
||||||
self._target_keys = utils.str_or_list(keys)
|
self._target_keys = utils.str_or_list(keys)
|
||||||
|
|
||||||
def process_record(self, record):
|
def process_record(self, record):
|
||||||
@ -277,7 +277,7 @@ class FieldMerger(Filter):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, mapping, merge_func, keep_fields=False):
|
def __init__(self, mapping, merge_func, keep_fields=False):
|
||||||
super(FieldMerger, self).__init__()
|
super().__init__()
|
||||||
self._field_mapping = mapping
|
self._field_mapping = mapping
|
||||||
self._merge_func = merge_func
|
self._merge_func = merge_func
|
||||||
self._keep_fields = keep_fields
|
self._keep_fields = keep_fields
|
||||||
@ -313,7 +313,7 @@ class FieldAdder(Filter):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, field_name, field_value, replace=True):
|
def __init__(self, field_name, field_value, replace=True):
|
||||||
super(FieldAdder, self).__init__()
|
super().__init__()
|
||||||
self._field_name = field_name
|
self._field_name = field_name
|
||||||
self._field_value = field_value
|
self._field_value = field_value
|
||||||
if hasattr(self._field_value, "__iter__"):
|
if hasattr(self._field_value, "__iter__"):
|
||||||
@ -348,7 +348,7 @@ class FieldCopier(Filter):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, copy_mapping):
|
def __init__(self, copy_mapping):
|
||||||
super(FieldCopier, self).__init__()
|
super().__init__()
|
||||||
self._copy_mapping = copy_mapping
|
self._copy_mapping = copy_mapping
|
||||||
|
|
||||||
def process_record(self, record):
|
def process_record(self, record):
|
||||||
@ -365,7 +365,7 @@ class FieldRenamer(Filter):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, rename_mapping):
|
def __init__(self, rename_mapping):
|
||||||
super(FieldRenamer, self).__init__()
|
super().__init__()
|
||||||
self._rename_mapping = rename_mapping
|
self._rename_mapping = rename_mapping
|
||||||
|
|
||||||
def process_record(self, record):
|
def process_record(self, record):
|
||||||
@ -383,7 +383,7 @@ class FieldNameModifier(Filter):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, func):
|
def __init__(self, func):
|
||||||
super(FieldNameModifier, self).__init__()
|
super().__init__()
|
||||||
self._filter_func = func
|
self._filter_func = func
|
||||||
|
|
||||||
def process_record(self, record):
|
def process_record(self, record):
|
||||||
@ -405,7 +405,7 @@ class Splitter(Filter):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, split_mapping):
|
def __init__(self, split_mapping):
|
||||||
super(Splitter, self).__init__()
|
super().__init__()
|
||||||
self._split_mapping = split_mapping
|
self._split_mapping = split_mapping
|
||||||
|
|
||||||
def process_record(self, record):
|
def process_record(self, record):
|
||||||
@ -449,7 +449,7 @@ class Flattener(FieldFilter):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, keys):
|
def __init__(self, keys):
|
||||||
super(Flattener, self).__init__(keys)
|
super().__init__(keys)
|
||||||
|
|
||||||
def process_field(self, item):
|
def process_field(self, item):
|
||||||
result = []
|
result = []
|
||||||
@ -463,7 +463,7 @@ class Flattener(FieldFilter):
|
|||||||
|
|
||||||
class DictFlattener(Filter):
|
class DictFlattener(Filter):
|
||||||
def __init__(self, keys, separator="_"):
|
def __init__(self, keys, separator="_"):
|
||||||
super(DictFlattener, self).__init__()
|
super().__init__()
|
||||||
self._keys = utils.str_or_list(keys)
|
self._keys = utils.str_or_list(keys)
|
||||||
self._separator = separator
|
self._separator = separator
|
||||||
|
|
||||||
@ -475,7 +475,7 @@ class Unique(ConditionalFilter):
|
|||||||
"""Filter that ensures that all records passing through are unique."""
|
"""Filter that ensures that all records passing through are unique."""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(Unique, self).__init__()
|
super().__init__()
|
||||||
self._seen = set()
|
self._seen = set()
|
||||||
|
|
||||||
def test_record(self, record):
|
def test_record(self, record):
|
||||||
@ -499,7 +499,7 @@ class UniqueID(ConditionalFilter):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, field="id", *args):
|
def __init__(self, field="id", *args):
|
||||||
super(UniqueID, self).__init__()
|
super().__init__()
|
||||||
self._seen = set()
|
self._seen = set()
|
||||||
self._id_fields = [field]
|
self._id_fields = [field]
|
||||||
self._id_fields.extend(args)
|
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"):
|
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._number_format = number_format
|
||||||
self._num_re = re.compile(r"\d")
|
self._num_re = re.compile(r"\d")
|
||||||
|
|
||||||
@ -551,7 +551,7 @@ class DateCleaner(FieldFilter):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, keys, from_format, to_format):
|
def __init__(self, keys, from_format, to_format):
|
||||||
super(DateCleaner, self).__init__(keys)
|
super().__init__(keys)
|
||||||
self._from_format = from_format
|
self._from_format = from_format
|
||||||
self._to_format = to_format
|
self._to_format = to_format
|
||||||
|
|
||||||
@ -590,7 +590,7 @@ class NameCleaner(Filter):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, keys, prefix="", formats=None, nomatch_name=None):
|
def __init__(self, keys, prefix="", formats=None, nomatch_name=None):
|
||||||
super(NameCleaner, self).__init__()
|
super().__init__()
|
||||||
self._keys = utils.str_or_list(keys)
|
self._keys = utils.str_or_list(keys)
|
||||||
self._name_prefix = prefix
|
self._name_prefix = prefix
|
||||||
self._nomatch_name = nomatch_name
|
self._nomatch_name = nomatch_name
|
||||||
|
@ -68,10 +68,6 @@ class FixedWidthFileSource:
|
|||||||
record[name] = line[range_[0] : range_[1]].rstrip(self._fillchars)
|
record[name] = line[range_[0] : range_[1]].rstrip(self._fillchars)
|
||||||
return record
|
return record
|
||||||
|
|
||||||
def next(self):
|
|
||||||
"""Keep Python 2 next() method that defers to __next__()."""
|
|
||||||
return self.__next__()
|
|
||||||
|
|
||||||
|
|
||||||
class HtmlTableSource:
|
class HtmlTableSource:
|
||||||
"""Saucebrush source for reading data from an HTML table.
|
"""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):
|
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.node_list = node_path.split(".")
|
||||||
self.attr_prefix = attr_prefix
|
self.attr_prefix = attr_prefix
|
||||||
self.postprocessor = postprocessor
|
self.postprocessor = postprocessor
|
||||||
|
@ -85,7 +85,7 @@ class Sum(StatsFilter):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, field, initial=0, **kwargs):
|
def __init__(self, field, initial=0, **kwargs):
|
||||||
super(Sum, self).__init__(field, **kwargs)
|
super().__init__(field, **kwargs)
|
||||||
self._value = initial
|
self._value = initial
|
||||||
|
|
||||||
def process_field(self, item):
|
def process_field(self, item):
|
||||||
@ -101,7 +101,7 @@ class Average(StatsFilter):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, field, initial=0, **kwargs):
|
def __init__(self, field, initial=0, **kwargs):
|
||||||
super(Average, self).__init__(field, **kwargs)
|
super().__init__(field, **kwargs)
|
||||||
self._value = initial
|
self._value = initial
|
||||||
self._count = 0
|
self._count = 0
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ class Median(StatsFilter):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, field, **kwargs):
|
def __init__(self, field, **kwargs):
|
||||||
super(Median, self).__init__(field, **kwargs)
|
super().__init__(field, **kwargs)
|
||||||
self._values = []
|
self._values = []
|
||||||
|
|
||||||
def process_field(self, item):
|
def process_field(self, item):
|
||||||
@ -139,7 +139,7 @@ class MinMax(StatsFilter):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, field, **kwargs):
|
def __init__(self, field, **kwargs):
|
||||||
super(MinMax, self).__init__(field, **kwargs)
|
super().__init__(field, **kwargs)
|
||||||
self._max = None
|
self._max = None
|
||||||
self._min = None
|
self._min = None
|
||||||
|
|
||||||
@ -165,7 +165,7 @@ class StandardDeviation(StatsFilter):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, field, **kwargs):
|
def __init__(self, field, **kwargs):
|
||||||
super(StandardDeviation, self).__init__(field, **kwargs)
|
super().__init__(field, **kwargs)
|
||||||
self._values = []
|
self._values = []
|
||||||
|
|
||||||
def process_field(self, item):
|
def process_field(self, item):
|
||||||
@ -200,7 +200,7 @@ class Histogram(StatsFilter):
|
|||||||
label_length = 6
|
label_length = 6
|
||||||
|
|
||||||
def __init__(self, field, **kwargs):
|
def __init__(self, field, **kwargs):
|
||||||
super(Histogram, self).__init__(field, **kwargs)
|
super().__init__(field, **kwargs)
|
||||||
self._counter = collections.Counter()
|
self._counter = collections.Counter()
|
||||||
|
|
||||||
def process_field(self, item):
|
def process_field(self, item):
|
||||||
|
Loading…
Reference in New Issue
Block a user