Apply Python 3 futurize transform libmodernize.fixes.fix_map.

This commit is contained in:
Tim Abbott
2015-11-01 08:14:53 -08:00
parent ffc900fe6e
commit cd6f8e9191
6 changed files with 19 additions and 12 deletions

View File

@@ -17,6 +17,7 @@ import time
import re
import pytz
from six.moves import filter
from six.moves import map
eastern_tz = pytz.timezone('US/Eastern')
def make_table(title, cols, rows, has_row_class=False):
@@ -24,7 +25,7 @@ def make_table(title, cols, rows, has_row_class=False):
if not has_row_class:
def fix_row(row):
return dict(cells=row, row_class=None)
rows = map(fix_row, rows)
rows = list(map(fix_row, rows))
data = dict(title=title, cols=cols, rows=rows)
@@ -377,7 +378,7 @@ def ad_hoc_queries():
cursor = connection.cursor()
cursor.execute(query)
rows = cursor.fetchall()
rows = map(list, rows)
rows = list(map(list, rows))
cursor.close()
def fix_rows(i, fixup_func):
@@ -611,7 +612,7 @@ def raw_user_activity_table(records):
format_date_for_activity_reports(record.last_visit)
]
rows = map(row, records)
rows = list(map(row, records))
title = 'Raw Data'
return make_table(title, cols, rows)

View File

@@ -20,8 +20,10 @@
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
from __future__ import absolute_import
import sys
from six.moves import map
try:
import simplejson
except ImportError:

View File

@@ -31,6 +31,7 @@ from django.utils.timezone import now
from confirmation.models import Confirmation
import six
from six.moves import filter
from six.moves import map
session_engine = import_module(settings.SESSION_ENGINE)
@@ -2272,7 +2273,7 @@ def do_update_message(user_profile, message_id, subject, propagate_mode, content
'id': um.user_profile_id,
'flags': um.flags_list()
}
send_event(event, map(user_info, ums))
send_event(event, list(map(user_info, ums)))
def encode_email_address(stream):
return encode_email_address_helper(stream.name, stream.email_token)
@@ -2409,7 +2410,7 @@ def get_status_dict(requesting_user_profile):
def get_realm_user_dicts(user_profile):
# Due to our permission model, it is advantageous to find the admin users in bulk.
admins = user_profile.realm.get_admin_users()
admin_emails = set(map(lambda up: up.email, admins))
admin_emails = set([up.email for up in admins])
return [{'email' : userdict['email'],
'is_admin' : userdict['email'] in admin_emails,
'is_bot' : userdict['is_bot'],
@@ -2573,7 +2574,7 @@ def apply_events(state, events, user_profile):
return sub['name'].lower()
if event['op'] == "add":
added_names = map(name, event["subscriptions"])
added_names = list(map(name, event["subscriptions"]))
was_added = lambda s: name(s) in added_names
# add the new subscriptions
@@ -2583,7 +2584,7 @@ def apply_events(state, events, user_profile):
state['unsubscribed'] = list(itertools.ifilterfalse(was_added, state['unsubscribed']))
elif event['op'] == "remove":
removed_names = map(name, event["subscriptions"])
removed_names = list(map(name, event["subscriptions"]))
was_removed = lambda s: name(s) in removed_names
# Find the subs we are affecting.

View File

@@ -3,6 +3,7 @@ from __future__ import absolute_import
import re
import os.path
import sourcemap
from six.moves import map
class SourceMap(object):
@@ -31,7 +32,7 @@ class SourceMap(object):
minified_src = match.groups()[0] + '.js'
index = self._index_for(minified_src)
gen_line, gen_col = map(int, match.groups()[2:4])
gen_line, gen_col = list(map(int, match.groups()[2:4]))
# The sourcemap lib is 0-based, so subtract 1 from line and col.
try:
result = index.lookup(line=gen_line-1, column=gen_col-1)

View File

@@ -95,6 +95,7 @@ import hmac
from collections import defaultdict
from zerver.lib.rest import rest_dispatch as _rest_dispatch
from six.moves import map
rest_dispatch = csrf_exempt((lambda request, *args, **kwargs: _rest_dispatch(request, globals(), *args, **kwargs)))
def list_to_streams(streams_raw, user_profile, autocreate=False, invite_only=False):
@@ -2198,7 +2199,7 @@ def get_bots_backend(request, user_profile):
default_all_public_streams=bot_profile.default_all_public_streams,
)
return json_success({'bots': map(bot_info, bot_profiles)})
return json_success({'bots': list(map(bot_info, bot_profiles))})
@authenticated_json_post_view
@has_request_variables

View File

@@ -38,6 +38,7 @@ import re
import ujson
from zerver.lib.rest import rest_dispatch as _rest_dispatch
from six.moves import map
rest_dispatch = csrf_exempt((lambda request, *args, **kwargs: _rest_dispatch(request, globals(), *args, **kwargs)))
# This is a Pool that doesn't close connections. Therefore it can be used with
@@ -349,7 +350,7 @@ def narrow_parameter(json):
raise ValueError("element is not a dictionary")
return map(convert_term, data)
return list(map(convert_term, data))
def is_public_stream(stream, realm):
if not valid_stream_name(stream):
@@ -403,7 +404,7 @@ def exclude_muting_conditions(user_profile, narrow):
in_home_view=False,
recipient__type=Recipient.STREAM
).values('recipient_id')
muted_recipient_ids = map(lambda row: row['recipient_id'], rows)
muted_recipient_ids = [row['recipient_id'] for row in rows]
condition = not_(column("recipient_id").in_(muted_recipient_ids))
conditions.append(condition)
@@ -429,7 +430,7 @@ def exclude_muting_conditions(user_profile, narrow):
topic_cond = func.upper(column("subject")) == func.upper(muted[1])
return and_(stream_cond, topic_cond)
condition = not_(or_(*map(mute_cond, muted_topics)))
condition = not_(or_(*list(map(mute_cond, muted_topics))))
return conditions + [condition]
return conditions