Commit d06e99a4 authored by Vincent A's avatar Vincent A

python3: force list coercion of some generators

Some functions changed return type from python2 to python3

TODO: not everything is tested, a full review is needed + run is needed
parent 6e86983e
......@@ -107,19 +107,17 @@ class Weboob(ConsoleApplication):
def choose_capability(self, capApplicationDict):
cap = None
while cap not in capApplicationDict.keys():
for _cap in capApplicationDict.keys():
print(' %s%2d)%s %s' % (self.BOLD,
capApplicationDict.keys().index(_cap) + 1,
self.NC,
_cap))
caps = list(capApplicationDict.keys())
while cap not in caps:
for n, _cap in enumerate(caps):
print(' %s%2d)%s %s' % (self.BOLD, n + 1, self.NC, _cap))
r = self.ask(' Select a capability', regexp='(\d+|)', default='')
if not r.isdigit():
continue
r = int(r)
if r <= 0 or r > len(capApplicationDict.keys()):
if r <= 0 or r > len(caps):
continue
cap = capApplicationDict.keys()[r - 1]
cap = caps[r - 1]
return cap
def init_CapApplicationDict(self):
......
......@@ -296,7 +296,7 @@ class Boobathon(ReplApplication):
print('Please give the name of the boobathon', file=self.stderr)
return 1
self.event = Event(argv[1], choice(self.weboob.backend_instances.values()))
self.event = Event(argv[1], choice(list(self.weboob.backend_instances.values())))
if self.event.description is None:
if not self.ask("This event doesn't seem to exist. Do you want to create it?", default=True):
return 1
......
......@@ -466,7 +466,7 @@ Weboob Team
if len(args) == 2:
return self._complete_object()
if len(args) == 3:
return dict(self.ISSUE_FIELDS).keys()
return list(dict(self.ISSUE_FIELDS).keys())
def do_edit(self, line):
"""
......
......@@ -108,12 +108,12 @@ class Comparoob(ReplApplication):
products[product.name] = [product]
products_type = None
products_names = products.keys()
products_names = list(products.keys())
if len(products_names) == 0:
print('Error: no product found with this pattern', file=self.stderr)
return 1
elif len(products_names) == 1:
products_type = products.keys()[0]
products_type = products_names[0]
else:
print('What product do you want to compare?')
for i, p in enumerate(products_names):
......
......@@ -161,7 +161,7 @@ class Parceloob(ReplApplication):
Display status for all of the tracked parcels.
"""
backends = map(get_backend_name, self.enabled_backends)
backends = list(map(get_backend_name, self.enabled_backends))
self.start_format()
# XXX cleaning of cached objects may be by start_format()?
self.objects = []
......
......@@ -163,7 +163,7 @@ class Pastoob(ReplApplication):
backends.setdefault(score, []).append(backend)
# select a random backend from the best scores
if len(backends):
backend = choice(backends[max(backends.keys())])
backend = choice(backends[max(list(backends.keys()))])
else:
print('No suitable backend found.', file=self.stderr)
return 1
......
......@@ -322,7 +322,7 @@ class ContactProfile(QWidget):
self.ui.photoUrlLabel.setText('')
return
photo = self.contact.photos.values()[self.displayed_photo_idx]
photo = list(self.contact.photos.values())[self.displayed_photo_idx]
if photo.data:
data = photo.data
if photo.id in self.process_photo:
......@@ -534,7 +534,7 @@ class ContactsWidget(QWidget):
self.photo_processes[contact.id] = process
elif len(contact.photos) > 0:
if not self.setPhoto(contact, item):
photo = contact.photos.values()[0]
photo = list(contact.photos.values())[0]
process = QtDo(self.weboob, lambda p: self.setPhoto(contact, item))
process.do('fillobj', photo, ['thumbnail_data'], backends=contact.backend)
self.photo_processes[contact.id] = process
......
......@@ -153,7 +153,7 @@ class EventsWidget(QWidget):
self.photo_processes[contact.id] = process
elif len(contact.photos) > 0:
if not self.setPhoto(contact, item):
photo = contact.photos.values()[0]
photo = list(contact.photos.values())[0]
process = QtDo(self.weboob, lambda p: self.setPhoto(contact, item))
process.do('fillobj', photo, ['thumbnail_data'], backends=contact.backend)
self.photo_processes[contact.id] = process
......
......@@ -602,7 +602,7 @@ class _PagesBrowserMeta(type):
Private meta-class used to keep order of URLs instances of PagesBrowser.
"""
def __new__(mcs, name, bases, attrs):
urls = [(url_name, attrs.pop(url_name)) for url_name, obj in attrs.items() if isinstance(obj, URL)]
urls = [(url_name, attrs.pop(url_name)) for url_name, obj in list(attrs.items()) if isinstance(obj, URL)]
urls.sort(key=lambda x: x[1]._creation_counter)
new_class = super(_PagesBrowserMeta, mcs).__new__(mcs, name, bases, attrs)
......
......@@ -649,7 +649,7 @@ class Regexp(Filter):
return self.default_or_raise(RegexpError(msg))
if isinstance(m, Iterator):
return map(self.expand, m)
return list(map(self.expand, m))
return self.expand(m)
......@@ -789,7 +789,7 @@ class BrowserURL(MultiFilter):
def __init__(self, url_name, **kwargs):
super(BrowserURL, self).__init__(*kwargs.values())
self.url_name = url_name
self.keys = kwargs.keys()
self.keys = list(kwargs.keys())
def __call__(self, item):
values = super(BrowserURL, self).__call__(item)
......
......@@ -391,7 +391,7 @@ class CsvPage(Page):
for i, row in enumerate(reader):
if self.HEADER and i+1 < self.HEADER:
continue
row = map(unicode.strip, self.decode_row(row, encoding))
row = [c.strip() for c in self.decode_row(row, encoding)]
if header is None and self.HEADER:
header = row
else:
......@@ -424,7 +424,7 @@ class JsonPage(Page):
def get(self, path):
node = self.doc
for name in filter(None, path.strip('.').split('.')):
for name in [_f for _f in path.strip('.').split('.') if _f]:
node = node.get(name)
if node is None:
break
......@@ -473,7 +473,7 @@ class XLSPage(Page):
continue
row = sh.row_values(i)
if header is None and self.HEADER:
header = map(lambda s: s.replace('/', ''), row)
header = [s.replace('/', '') for s in row]
else:
rows.append(row)
if header:
......
......@@ -136,7 +136,7 @@ class URL(object):
url = pattern
# only use full-name substitutions, to allow % in URLs
args = kwargs.copy()
for key in args.keys(): # need to use keys() because of pop()
for key in list(args.keys()): # need to use keys() because of pop()
search = '%%(%s)s' % key
if search in pattern:
url = url.replace(search, to_unicode(args.pop(key)))
......
......@@ -34,11 +34,12 @@ __all__ = ['UserError', 'FieldNotFound', 'NotAvailable',
def enum(**enums):
_values = enums.values()
_keys = enums.keys()
_items = enums.items()
_values = list(enums.values())
_keys = list(enums.keys())
_items = list(enums.items())
_types = list((type(value) for value in enums.values()))
_index = dict((value if not isinstance(value, dict) else next(value.itervalues()), i) for i, value in enumerate(enums.values()))
_index = {(value if not isinstance(value, dict) else next(iter(value.values()))): i
for i, value in enumerate(enums.values())}
enums['keys'] = _keys
enums['values'] = _values
......@@ -295,7 +296,7 @@ class BytesField(Field):
class _BaseObjectMeta(type):
def __new__(cls, name, bases, attrs):
fields = [(field_name, attrs.pop(field_name)) for field_name, obj in attrs.items() if isinstance(obj, Field)]
fields = [(field_name, attrs.pop(field_name)) for field_name, obj in list(attrs.items()) if isinstance(obj, Field)]
fields.sort(key=lambda x: x[1]._creation_counter)
new_class = super(_BaseObjectMeta, cls).__new__(cls, name, bases, attrs)
......
......@@ -177,7 +177,7 @@ class CapDocument(CapCollection):
:rtype: iter[:class:`Bill`]
"""
documents = self.iter_documents(subscription)
return filter(lambda doc: doc.type == "bill", documents)
return [doc for doc in documents if doc.type == "bill"]
def get_details(self, subscription):
"""
......
......@@ -159,7 +159,7 @@ class WebNip(object):
if isinstance(names, basestring):
names = [names]
elif names is None:
names = self.backend_instances.keys()
names = list(self.backend_instances.keys())
for name in names:
backend = self.backend_instances.pop(name)
......@@ -243,7 +243,7 @@ class WebNip(object):
:type caps: list[:class:`weboob.capabilities.base.Capability`]
:rtype: A :class:`weboob.core.bcall.BackendsCall` object (iterable)
"""
backends = self.backend_instances.values()
backends = list(self.backend_instances.values())
_backends = kwargs.pop('backends', None)
if _backends is not None:
if isinstance(_backends, Module):
......
......@@ -172,7 +172,7 @@ class IFormatter(object):
if isinstance(obj, BaseObject):
if selected_fields: # can be an empty list (nothing to do), or None (return all fields)
obj = obj.copy()
for name, value in obj.iter_fields():
for name, value in list(obj.iter_fields()):
if name not in selected_fields:
delattr(obj, name)
......
......@@ -96,8 +96,8 @@ class TableFormatter(IFormatter):
def format_dict(self, item):
if self.keys is None:
self.keys = item.keys()
self.queue.append(item.values())
self.keys = list(item.keys())
self.queue.append(list(item.values()))
def set_header(self, string):
self.header = string
......
......@@ -345,7 +345,7 @@ def parse_date(string):
year = 2000 + int(year)
return date(int(year), int(matches.group(2)), int(matches.group(1)))
elif string.upper() in WEEK.keys():
elif string.upper() in list(WEEK.keys()):
return get_date_from_day(string)
elif string.upper() == "TODAY":
......
......@@ -56,7 +56,7 @@ def mini_jsonpath(node, path):
"""
def iterkeys(i):
return range(len(i)) if type(i) is list else i
return range(len(i)) if isinstance(i, list) else i
def cut(s):
p = s.split('.', 1) if s else [None]
......
......@@ -240,7 +240,7 @@ def build_rows(lines):
box = Rect(hline.x0, hline.y0, hline.x1, vline.y1)
boxes.setdefault((vline.y0, vline.y1), []).append(box)
rows = boxes.values()
rows = list(boxes.values())
for row in rows:
row.sort(key=lambda box: box.x0)
rows.sort(key=lambda row: row[0].y0)
......
......@@ -111,7 +111,7 @@ def normalize(pattern):
try:
ch, escaped = next(pattern_iter)
except StopIteration:
return zip([u''], [[]])
return list(zip([u''], [[]]))
try:
while True:
......@@ -224,9 +224,9 @@ def normalize(pattern):
pass
except NotImplementedError:
# A case of using the disjunctive form. No results for you!
return zip([u''], [[]])
return list(zip([u''], [[]]))
return zip(*flatten_result(result))
return list(zip(*flatten_result(result)))
def next_char(input_iter):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment