Skip to content

Commit

Permalink
Run 2to3-3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
stefankoegl committed Nov 29, 2014
1 parent 6151a2b commit 667780a
Show file tree
Hide file tree
Showing 152 changed files with 357 additions and 358 deletions.
2 changes: 1 addition & 1 deletion mygpo/administration/clients.py
Expand Up @@ -62,7 +62,7 @@ def get_entries(self):
self._clients = Counter()

uas = super(ClientStats, self).get_entries()
for ua_string, count in uas.items():
for ua_string, count in list(uas.items()):
client = self.parse_ua_string(ua_string) or ua_string
self._clients[client] += count

Expand Down
4 changes: 2 additions & 2 deletions mygpo/administration/group.py
Expand Up @@ -34,12 +34,12 @@ def group(self, get_features):

episode_groups = defaultdict(list)

episode_features = map(get_features, episodes.items())
episode_features = list(map(get_features, list(episodes.items())))

for features, episode_id in episode_features:
episode = episodes[episode_id]
episode_groups[features].append(episode)

groups = sorted(episode_groups.values(), key=_SORT_KEY)
groups = sorted(list(episode_groups.values()), key=_SORT_KEY)

return enumerate(groups)
12 changes: 6 additions & 6 deletions mygpo/administration/views.py
Expand Up @@ -62,7 +62,7 @@ def get(self, request):
if not scheduled:
num_celery_tasks = None
else:
num_celery_tasks = sum(len(node) for node in scheduled.values())
num_celery_tasks = sum(len(node) for node in list(scheduled.values()))

feed_queue_status = self._get_feed_queue_status()

Expand Down Expand Up @@ -126,7 +126,7 @@ def post(self, request):

grouper = PodcastGrouper(podcasts)

get_features = lambda (e_id, e): ((e.url, e.title), e_id)
get_features = lambda e_id_e: ((e_id_e[1].url, e_id_e[1].title), e_id_e[0])

num_groups = grouper.group(get_features)

Expand Down Expand Up @@ -160,13 +160,13 @@ def post(self, request):
grouper = PodcastGrouper(podcasts)

features = {}
for key, feature in request.POST.items():
for key, feature in list(request.POST.items()):
m = self.RE_EPISODE.match(key)
if m:
episode_id = m.group(1)
features[episode_id] = feature

get_features = lambda (e_id, e): (features.get(e_id, e_id), e_id)
get_features = lambda e_id_e1: (features.get(e_id_e1[0], e_id_e1[0]), e_id_e1[0])

num_groups = grouper.group(get_features)

Expand Down Expand Up @@ -214,7 +214,7 @@ def get(self, request, task_id):

return self.render_to_response({
'ready': True,
'actions': actions.items(),
'actions': list(actions.items()),
'podcast': podcast,
})

Expand Down Expand Up @@ -256,7 +256,7 @@ def get(self, request):
cs = ClientStats()
clients = cs.get_entries()

return JsonResponse(map(self.to_dict, clients.most_common()))
return JsonResponse(list(map(self.to_dict, clients.most_common())))

def to_dict(self, res):
obj, count = res
Expand Down
2 changes: 1 addition & 1 deletion mygpo/api/__init__.py
Expand Up @@ -68,7 +68,7 @@ def parsed_body(self, request):
# after all views using it have been refactored
return parse_request_body(request)
except (JSONDecodeError, UnicodeDecodeError, ValueError) as e:
msg = u'Could not decode request body for user {}: {}'.format(
msg = 'Could not decode request body for user {}: {}'.format(
request.user.username,
request.body.decode('ascii', errors='replace'))
logger.warn(msg, exc_info=True)
Expand Down
10 changes: 5 additions & 5 deletions mygpo/api/advanced/__init__.py
Expand Up @@ -16,7 +16,7 @@
#

from functools import partial
from itertools import imap

from collections import defaultdict
from datetime import datetime
from importlib import import_module
Expand Down Expand Up @@ -102,7 +102,7 @@ def episodes(request, username, version=1):
try:
update_urls = update_episodes(request.user, actions, now, ua_string)
except ValidationError as e:
logger.warn(u'Validation Error while uploading episode actions for user %s: %s', username, unicode(e))
logger.warn('Validation Error while uploading episode actions for user %s: %s', username, str(e))
return HttpResponseBadRequest(str(e))

except InvalidEpisodeActionAttributes as e:
Expand Down Expand Up @@ -173,12 +173,12 @@ def get_episode_changes(user, podcast, device, since, until, aggregated, version
history = history.filter(client=device)

if version == 1:
history = imap(convert_position, history)
history = map(convert_position, history)

actions = [episode_action_json(a, user) for a in history]

if aggregated:
actions = dict( (a['episode'], a) for a in actions ).values()
actions = list(dict( (a['episode'], a) for a in actions ).values())

return {'actions': actions, 'timestamp': until}

Expand Down Expand Up @@ -343,7 +343,7 @@ def favorites(request, username):
favorites = FavoriteEpisode.episodes_for_user(request.user)
domain = RequestSite(request).domain
e_data = lambda e: episode_data(e, domain)
ret = map(e_data, favorites)
ret = list(map(e_data, favorites))
return JsonResponse(ret)


Expand Down
2 changes: 1 addition & 1 deletion mygpo/api/advanced/directory.py
Expand Up @@ -39,7 +39,7 @@
def top_tags(request, count):
count = parse_range(count, 1, 100, 100)
tag_cloud = Topics(count, num_cat=0)
resp = map(category_data, tag_cloud.tagcloud)
resp = list(map(category_data, tag_cloud.tagcloud))
return JsonResponse(resp)


Expand Down
2 changes: 1 addition & 1 deletion mygpo/api/advanced/episode.py
Expand Up @@ -62,7 +62,7 @@ def get(self, request, username):
if since:
chapters = chapters.filter(created__gte=since)

chapters_json = map(self.chapter_to_json, chapters)
chapters_json = list(map(self.chapter_to_json, chapters))

return JsonResponse({
'chapters': chapters_json,
Expand Down
2 changes: 1 addition & 1 deletion mygpo/api/advanced/lists.py
Expand Up @@ -118,7 +118,7 @@ def get_lists(request, username):

get_data = partial(_get_list_data, username=user.username,
domain=site.domain)
lists_data = map(get_data, lists)
lists_data = list(map(get_data, lists))

return JsonResponse(lists_data)

Expand Down
2 changes: 1 addition & 1 deletion mygpo/api/advanced/settings.py
Expand Up @@ -70,7 +70,7 @@ def get_scope(self, request, scope):

def update_settings(self, settings, actions):
""" Update the settings according to the actions """
for key, value in actions.get('set', {}).iteritems():
for key, value in actions.get('set', {}).items():
settings.set_setting(key, value)

for key in actions.get('remove', []):
Expand Down
4 changes: 2 additions & 2 deletions mygpo/api/legacy.py
Expand Up @@ -61,8 +61,8 @@ def upload(request):
i = Importer(opml)

podcast_urls = [p['url'] for p in i.items]
podcast_urls = map(normalize_feed_url, podcast_urls)
podcast_urls = filter(None, podcast_urls)
podcast_urls = list(map(normalize_feed_url, podcast_urls))
podcast_urls = [_f for _f in podcast_urls if _f]

new = [u for u in podcast_urls if u not in existing_urls]
rem = [u for e in existing_urls if u not in podcast_urls]
Expand Down
24 changes: 12 additions & 12 deletions mygpo/api/simple.py
Expand Up @@ -98,7 +98,7 @@ def all_subscriptions(request, username, format):
except (TypeError, ValueError):
return HttpResponseBadRequest('scale_logo has to be a numeric value')

if scale not in range(1, 257):
if scale not in list(range(1, 257)):
return HttpResponseBadRequest('scale_logo has to be a number from 1 to 256')


Expand Down Expand Up @@ -131,18 +131,18 @@ def default_get_podcast(p):
get_podcast = get_podcast or default_get_podcast

if format == 'txt':
podcasts = map(get_podcast, obj_list)
podcasts = list(map(get_podcast, obj_list))
s = '\n'.join([p.url for p in podcasts] + [''])
return HttpResponse(s, content_type='text/plain')

elif format == 'opml':
podcasts = map(get_podcast, obj_list)
podcasts = list(map(get_podcast, obj_list))
exporter = Exporter(title)
opml = exporter.generate(podcasts)
return HttpResponse(opml, content_type='text/xml')

elif format == 'json':
objs = map(json_map, obj_list)
objs = list(map(json_map, obj_list))
return JsonResponse(objs)

elif format == 'jsonp':
Expand All @@ -154,14 +154,14 @@ def default_get_podcast(p):
if any(x not in ALLOWED_FUNCNAME for x in jsonp_padding):
return HttpResponseBadRequest('JSONP padding can only contain the characters %(char)s' % {'char': ALLOWED_FUNCNAME})

objs = map(json_map, obj_list)
objs = list(map(json_map, obj_list))
return JsonResponse(objs, jsonp_padding=jsonp_padding)

elif format == 'xml':
if None in (xml_template, request):
return HttpResponseBadRequest('XML is not a valid format for this request')

podcasts = map(json_map, obj_list)
podcasts = list(map(json_map, obj_list))
template_args.update({'podcasts': podcasts})

return render(request, xml_template, template_args,
Expand Down Expand Up @@ -196,7 +196,7 @@ def parse_subscription(raw_post_data, format):
return []

urls = filter(None, urls)
urls = map(normalize_feed_url, urls)
urls = list(map(normalize_feed_url, urls))
return urls


Expand All @@ -205,8 +205,8 @@ def set_subscriptions(urls, user, device_uid, user_agent):
device = get_device(user, device_uid, user_agent, undelete=True)

subscriptions = dict( (p.url, p) for p in device.get_subscribed_podcasts())
new = [p for p in urls if p not in subscriptions.keys()]
rem = [p for p in subscriptions.keys() if p not in urls]
new = [p for p in urls if p not in list(subscriptions.keys())]
rem = [p for p in list(subscriptions.keys()) if p not in urls]

remove_podcasts = Podcast.objects.filter(urls__url__in=rem)
for podcast in remove_podcasts:
Expand Down Expand Up @@ -235,7 +235,7 @@ def toplist(request, count, format):
except (TypeError, ValueError):
return HttpResponseBadRequest('scale_logo has to be a numeric value')

if scale not in range(1, 257):
if scale not in list(range(1, 257)):
return HttpResponseBadRequest('scale_logo has to be a number from 1 to 256')


Expand Down Expand Up @@ -274,7 +274,7 @@ def search(request, format):
except (TypeError, ValueError):
return HttpResponseBadRequest('scale_logo has to be a numeric value')

if scale not in range(1, 257):
if scale not in list(range(1, 257)):
return HttpResponseBadRequest('scale_logo has to be a number from 1 to 256')

if not query:
Expand Down Expand Up @@ -318,7 +318,7 @@ def example_podcasts(request, format):
except (TypeError, ValueError):
return HttpResponseBadRequest('scale_logo has to be a numeric value')

if scale not in range(1, 257):
if scale not in list(range(1, 257)):
return HttpResponseBadRequest('scale_logo has to be a number from 1 to 256')

if not podcasts:
Expand Down
18 changes: 9 additions & 9 deletions mygpo/api/subscriptions.py
Expand Up @@ -59,8 +59,8 @@ def post(self, request, version, username, device_uid):

actions = self.parsed_body(request)

add = filter(None, actions.get('add', []))
rem = filter(None, actions.get('remove', []))
add = [_f for _f in actions.get('add', []) if _f]
rem = [_f for _f in actions.get('remove', []) if _f]
logger.info('Subscription Upload @{username}/{device_uid}: add '
'{num_add}, remove {num_remove}'.format(
username=request.user.username, device_uid=device_uid,
Expand All @@ -82,20 +82,20 @@ def update_subscriptions(self, user, device, add, remove):
logger.warn(msg)
raise RequestException(msg)

add_s = map(normalize_feed_url, add)
rem_s = map(normalize_feed_url, remove)
add_s = list(map(normalize_feed_url, add))
rem_s = list(map(normalize_feed_url, remove))

assert len(add) == len(add_s) and len(remove) == len(rem_s)

pairs = zip(add + remove, add_s + rem_s)
updated_urls = filter(lambda (a, b): a != b, pairs)
pairs = list(zip(add + remove, add_s + rem_s))
updated_urls = [a_b for a_b in pairs if a_b[0] != a_b[1]]

add_s = filter(None, add_s)
rem_s = filter(None, rem_s)
add_s = [_f for _f in add_s if _f]
rem_s = [_f for _f in rem_s if _f]

# If two different URLs (in add and remove) have
# been sanitized to the same, we ignore the removal
rem_s = filter(lambda x: x not in add_s, rem_s)
rem_s = [x for x in rem_s if x not in add_s]

for add_url in add_s:
podcast = Podcast.objects.get_or_create_for_url(add_url)
Expand Down
6 changes: 3 additions & 3 deletions mygpo/api/tests.py
Expand Up @@ -15,11 +15,11 @@
# along with my.gpodder.org. If not, see <http://www.gnu.org/licenses/>.
#

from __future__ import unicode_literals


import unittest
import doctest
from urllib import urlencode
from urllib.parse import urlencode
from copy import deepcopy

from django.test.client import Client
Expand Down Expand Up @@ -103,7 +103,7 @@ def compare_action_list(self, as1, as2):
return True

def compare_actions(self, a1, a2):
for key, val in a1.items():
for key, val in list(a1.items()):
if a2.get(key, None) != val:
return False
return True
Expand Down
2 changes: 1 addition & 1 deletion mygpo/cache.py
Expand Up @@ -22,7 +22,7 @@ def _wrapper(f):
def _get(*args, **kwargs):

key = sha1(str(f.__module__) + str(f.__name__) +
unicode(args) + unicode(kwargs)).hexdigest()
str(args) + str(kwargs)).hexdigest()

# the timeout parameter can't be used when getting from a cache
get_kwargs = dict(cache_kwargs)
Expand Down
2 changes: 1 addition & 1 deletion mygpo/categories/migrations/0001_initial.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals


from django.db import models, migrations
import datetime
Expand Down
2 changes: 1 addition & 1 deletion mygpo/celery.py
@@ -1,4 +1,4 @@
from __future__ import absolute_import


from django.conf import settings

Expand Down
2 changes: 1 addition & 1 deletion mygpo/chapters/migrations/0001_initial.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals


from django.db import models, migrations
from django.conf import settings
Expand Down
2 changes: 1 addition & 1 deletion mygpo/chapters/migrations/0002_chapter_index.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals


from django.db import models, migrations

Expand Down
6 changes: 3 additions & 3 deletions mygpo/core/json.py
Expand Up @@ -14,16 +14,16 @@
JSONDecodeError = ValueError

except ImportError:
print >> sys.stderr, 'ujson not found'
print('ujson not found', file=sys.stderr)

try:
# If SimpleJSON is installed separately, it might be a recent version
import simplejson as json
JSONDecodeError = json.JSONDecodeError

except ImportError:
print >> sys.stderr, 'simplejson not found'
print('simplejson not found', file=sys.stderr)

# Otherwise use json from the stdlib
import json
from . import json
JSONDecodeError = ValueError
2 changes: 1 addition & 1 deletion mygpo/core/models.py
@@ -1,6 +1,6 @@
""" This module contains abstract models that are used in multiple apps """

from __future__ import absolute_import, unicode_literals


import json

Expand Down

0 comments on commit 667780a

Please sign in to comment.