Skip to content

Commit 0ee95a6

Browse files
committed
fixup! [IMP] snippets: move all work from parent to mp workers
1 parent fe9b2c8 commit 0ee95a6

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/util/snippets.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
from .misc import import_script, log_progress
2323
from .pg import column_exists, column_type, get_max_workers, table_exists
2424

25+
# python3 shims
26+
try:
27+
basestring # noqa: B018
28+
except NameError:
29+
basestring = unicode = str
30+
2531
_logger = logging.getLogger(__name__)
2632
utf8_parser = html.HTMLParser(encoding="utf-8")
2733

@@ -248,17 +254,22 @@ def _dumps(self, node):
248254

249255

250256
class Convertor:
251-
def __init__(self, converters, callback, dbname, update_query):
257+
def __init__(self, converters, callback, dbname=None, update_query=None):
252258
self.converters = converters
253259
self.callback = callback
254260
self.dbname = dbname
255261
self.update_query = update_query
256262

257263
def __call__(self, query):
264+
# backwards compatibility
265+
if not (self.dbname and self.update_query and isinstance(query, basestring)):
266+
return self._convert_row(query)
267+
# called with a query to fetch a number of rows
258268
with db_connect(self.dbname).cursor() as cr:
259269
cr.execute(query)
260270
for changes in filter(None, map(self._convert_row, cr.fetchall())):
261271
cr.execute(self.update_query, changes)
272+
return None
262273

263274
def _convert_row(self, row):
264275
converters = self.converters

0 commit comments

Comments
 (0)