[thorstenp] use sorted() and list comprehension

This commit is contained in:
Yann Leboulanger 2008-12-03 22:07:44 +00:00
parent 89f02b1feb
commit 0830a5fe73
9 changed files with 39 additions and 41 deletions

View file

@ -109,7 +109,7 @@ class ConfigPaths:
u'iconsets', u'moods', u'activities', u'cacerts.pem') u'iconsets', u'moods', u'activities', u'cacerts.pem')
if os.name == 'nt': if os.name == 'nt':
v = map(lambda x: x.capitalize(), v) v = [x.capitalize() for x in v]
for n, p in zip(k, v): for n, p in zip(k, v):
self.add_from_root(n, p) self.add_from_root(n, p)

View file

@ -33,6 +33,7 @@ import base64
import sha import sha
import socket import socket
import sys import sys
import operator
from time import (altzone, daylight, gmtime, localtime, mktime, strftime, from time import (altzone, daylight, gmtime, localtime, mktime, strftime,
time as time_time, timezone, tzname) time as time_time, timezone, tzname)
@ -166,7 +167,7 @@ class ConnectionBytestream:
sender = file_props['sender'] sender = file_props['sender']
proxyhosts = [] proxyhosts = []
if fast and cfg_proxies: if fast and cfg_proxies:
proxies = map(lambda e:e.strip(), cfg_proxies.split(',')) proxies = [e.strip() for e in cfg_proxies.split(',')]
default = gajim.proxy65_manager.get_default_for_name(self.name) default = gajim.proxy65_manager.get_default_for_name(self.name)
if default: if default:
# add/move default proxy at top of the others # add/move default proxy at top of the others
@ -194,8 +195,7 @@ class ConnectionBytestream:
file_props['sha_str'] = sha_str file_props['sha_str'] = sha_str
ft_add_hosts = [] ft_add_hosts = []
if ft_add_hosts_to_send: if ft_add_hosts_to_send:
ft_add_hosts_to_send = map(lambda e:e.strip(), ft_add_hosts_to_send = [e.strip() for e in ft_add_hosts_to_send.split(',')]
ft_add_hosts_to_send.split(','))
for ft_host in ft_add_hosts_to_send: for ft_host in ft_add_hosts_to_send:
ft_add_hosts.append(ft_host) ft_add_hosts.append(ft_host)
listener = gajim.socks5queue.start_listener(port, listener = gajim.socks5queue.start_listener(port,
@ -1324,13 +1324,13 @@ sent a message to.'''
idless = [s for s in sessions if not s.received_thread_id] idless = [s for s in sessions if not s.received_thread_id]
# filter out everything except the default session type # filter out everything except the default session type
p = lambda s: isinstance(s, gajim.default_session_type) chat_sessions = [s for s in idless if isinstance(s,
chat_sessions = filter(p, idless) gajim.default_session_type)]
if chat_sessions: if chat_sessions:
# return the session that we last sent a message in # return the session that we last sent a message in
chat_sessions.sort(key=lambda s: s.last_send) return sorted(chat_sessions,
return chat_sessions[-1] key=operator.attrgetter("last_send"))[-1]
else: else:
return None return None
@ -1341,8 +1341,8 @@ sent a message to.'''
sessions = self.sessions[jid].values() sessions = self.sessions[jid].values()
# filter out everything except the default session type # filter out everything except the default session type
p = lambda s: isinstance(s, gajim.default_session_type) chat_sessions = [s for s in sessions if isinstance(s,
chat_sessions = filter(p, sessions) gajim.default_session_type)]
orphaned = [s for s in chat_sessions if not s.control] orphaned = [s for s in chat_sessions if not s.control]
@ -2307,7 +2307,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
our_jid = helpers.parse_jid(gajim.get_jid_from_account(self.name) + '/' +\ our_jid = helpers.parse_jid(gajim.get_jid_from_account(self.name) + '/' +\
self.server_resource) self.server_resource)
if cfg_proxies: if cfg_proxies:
proxies = map(lambda e:e.strip(), cfg_proxies.split(',')) proxies = [e.strip() for e in cfg_proxies.split(',')]
for proxy in proxies: for proxy in proxies:
gajim.proxy65_manager.resolve(proxy, self.connection, our_jid) gajim.proxy65_manager.resolve(proxy, self.connection, our_jid)

View file

@ -762,7 +762,7 @@ def get_random_string_16():
''' create random string of length 16''' ''' create random string of length 16'''
rng = range(65, 90) rng = range(65, 90)
rng.extend(range(48, 57)) rng.extend(range(48, 57))
char_sequence = map(lambda e:chr(e), rng) char_sequence = [chr(e) for e in rng]
from random import sample from random import sample
return ''.join(sample(char_sequence, 16)) return ''.join(sample(char_sequence, 16))
@ -938,7 +938,7 @@ def reduce_chars_newlines(text, max_chars = 0, max_lines = 0):
lines = text.split('\n', max_lines)[:max_lines] lines = text.split('\n', max_lines)[:max_lines]
if max_chars > 0: if max_chars > 0:
if lines: if lines:
lines = map(lambda e: _cut_if_long(e), lines) lines = [_cut_if_long(e) for e in lines]
if lines: if lines:
reduced_text = '\n'.join(lines) reduced_text = '\n'.join(lines)
if reduced_text != text: if reduced_text != text:

View file

@ -365,7 +365,7 @@ class EncryptedStanzaSession(StanzaSession):
def c7lize_mac_id(self, form): def c7lize_mac_id(self, form):
kids = form.getChildren() kids = form.getChildren()
macable = [x for x in kids if x.getVar() not in ('mac', 'identity')] macable = [x for x in kids if x.getVar() not in ('mac', 'identity')]
return ''.join(map(lambda el: xmpp.c14n.c14n(el), macable)) return ''.join(xmpp.c14n.c14n(el) for el in macable)
def verify_identity(self, form, dh_i, sigmai, i_o): def verify_identity(self, form, dh_i, sigmai, i_o):
m_o = base64.b64decode(form['mac']) m_o = base64.b64decode(form['mac'])
@ -393,8 +393,8 @@ class EncryptedStanzaSession(StanzaSession):
if self.negotiated['sign_algs'] == (XmlDsig + 'rsa-sha256'): if self.negotiated['sign_algs'] == (XmlDsig + 'rsa-sha256'):
keyvalue = parsed.getTag(name='RSAKeyValue', namespace=XmlDsig) keyvalue = parsed.getTag(name='RSAKeyValue', namespace=XmlDsig)
n, e = map(lambda x: crypto.decode_mpi(base64.b64decode( n, e = (crypto.decode_mpi(base64.b64decode(
keyvalue.getTagData(x))), ('Modulus', 'Exponent')) keyvalue.getTagData(x))) for x in ('Modulus', 'Exponent'))
eir_pubkey = RSA.construct((n,long(e))) eir_pubkey = RSA.construct((n,long(e)))
pubkey_o = xmpp.c14n.c14n(keyvalue) pubkey_o = xmpp.c14n.c14n(keyvalue)
@ -437,8 +437,8 @@ class EncryptedStanzaSession(StanzaSession):
pubkey = secrets.secrets().my_pubkey(self.conn.name) pubkey = secrets.secrets().my_pubkey(self.conn.name)
fields = (pubkey.n, pubkey.e) fields = (pubkey.n, pubkey.e)
cb_fields = map(lambda f: base64.b64encode(crypto.encode_mpi(f)), cb_fields = [base64.b64encode(crypto.encode_mpi(f)) for f in
fields) fields]
pubkey_s = '<RSAKeyValue xmlns="http://www.w3.org/2000/09/xmldsig#"' pubkey_s = '<RSAKeyValue xmlns="http://www.w3.org/2000/09/xmldsig#"'
'><Modulus>%s</Modulus><Exponent>%s</Exponent></RSAKeyValue>' % \ '><Modulus>%s</Modulus><Exponent>%s</Exponent></RSAKeyValue>' % \
@ -446,7 +446,7 @@ class EncryptedStanzaSession(StanzaSession):
else: else:
pubkey_s = '' pubkey_s = ''
form_s2 = ''.join(map(lambda el: xmpp.c14n.c14n(el), form.getChildren())) form_s2 = ''.join(xmpp.c14n.c14n(el) for el in form.getChildren())
old_c_s = self.c_s old_c_s = self.c_s
content = self.n_o + self.n_s + crypto.encode_mpi(dh_i) + pubkey_s + \ content = self.n_o + self.n_s + crypto.encode_mpi(dh_i) + pubkey_s + \
@ -477,7 +477,7 @@ class EncryptedStanzaSession(StanzaSession):
if self.sigmai: if self.sigmai:
# XXX save retained secret? # XXX save retained secret?
self.check_identity(lambda : ()) self.check_identity(tuple)
return (xmpp.DataField(name='identity', value=base64.b64encode(id_s)), return (xmpp.DataField(name='identity', value=base64.b64encode(id_s)),
xmpp.DataField(name='mac', value=base64.b64encode(m_s))) xmpp.DataField(name='mac', value=base64.b64encode(m_s)))
@ -542,12 +542,12 @@ class EncryptedStanzaSession(StanzaSession):
',') ] ',') ]
x.addChild(node=xmpp.DataField(name='modp', typ='list-single', x.addChild(node=xmpp.DataField(name='modp', typ='list-single',
options=map(lambda x: [ None, x ], modp_options))) options=[[None, x] for x in modp_options]))
x.addChild(node=self.make_dhfield(modp_options, sigmai)) x.addChild(node=self.make_dhfield(modp_options, sigmai))
self.sigmai = sigmai self.sigmai = sigmai
self.form_s = ''.join(map(lambda el: xmpp.c14n.c14n(el), x.getChildren())) self.form_s = ''.join(xmpp.c14n.c14n(el) for el in x.getChildren())
feature.addChild(node=x) feature.addChild(node=x)
@ -573,9 +573,9 @@ class EncryptedStanzaSession(StanzaSession):
self.hash_alg = SHA256 self.hash_alg = SHA256
self.compression = None self.compression = None
for name, field in map(lambda name: (name, form.getField(name)), for name in form.asDict():
form.asDict().keys()): field = form.getField(name)
options = map(lambda x: x[1], field.getOptions()) options = [x[1] for x in field.getOptions()]
values = field.getValues() values = field.getValues()
if not field.getType() in ('list-single', 'list-multi'): if not field.getType() in ('list-single', 'list-multi'):
@ -676,9 +676,8 @@ class EncryptedStanzaSession(StanzaSession):
b64ed = base64.b64encode(to_add[name]) b64ed = base64.b64encode(to_add[name])
x.addChild(node=xmpp.DataField(name=name, value=b64ed)) x.addChild(node=xmpp.DataField(name=name, value=b64ed))
self.form_o = ''.join(map(lambda el: xmpp.c14n.c14n(el), self.form_o = ''.join(xmpp.c14n.c14n(el) for el in form.getChildren())
form.getChildren())) self.form_s = ''.join(xmpp.c14n.c14n(el) for el in x.getChildren())
self.form_s = ''.join(map(lambda el: xmpp.c14n.c14n(el), x.getChildren()))
self.status = 'responded-e2e' self.status = 'responded-e2e'
@ -782,8 +781,7 @@ class EncryptedStanzaSession(StanzaSession):
result.addChild(node=xmpp.DataField(name='dhkeys', result.addChild(node=xmpp.DataField(name='dhkeys',
value=base64.b64encode(crypto.encode_mpi(e)))) value=base64.b64encode(crypto.encode_mpi(e))))
self.form_o = ''.join(map(lambda el: xmpp.c14n.c14n(el), self.form_o = ''.join(xmpp.c14n.c14n(el) for el in form.getChildren())
form.getChildren()))
# MUST securely destroy K unless it will be used later to generate the # MUST securely destroy K unless it will be used later to generate the
# final shared secret # final shared secret

View file

@ -81,8 +81,7 @@ class ConnectionBytestream(connection_handlers.ConnectionBytestream):
file_props['sha_str'] = sha_str file_props['sha_str'] = sha_str
ft_add_hosts = [] ft_add_hosts = []
if ft_add_hosts_to_send: if ft_add_hosts_to_send:
ft_add_hosts_to_send = map(lambda e:e.strip(), ft_add_hosts_to_send = [e.strip() for e in ft_add_hosts_to_send.split(',')]
ft_add_hosts_to_send.split(','))
for ft_host in ft_add_hosts_to_send: for ft_host in ft_add_hosts_to_send:
try: try:
ft_host = socket.gethostbyname(ft_host) ft_host = socket.gethostbyname(ft_host)

View file

@ -3708,12 +3708,12 @@ class TransformChatToMUC:
# All contacts beside the following can be invited: # All contacts beside the following can be invited:
# transports, zeroconf contacts, minimized groupchats # transports, zeroconf contacts, minimized groupchats
invitable = lambda contact, contact_transport = None:\ def invitable(contact, contact_transport=None):
contact.jid not in self.auto_jids and\ return (contact.jid not in self.auto_jids and
contact.jid != gajim.get_jid_from_account(self.account) and\ contact.jid != gajim.get_jid_from_account(self.account) and
contact.jid not in gajim.interface.minimized_controls[account] and\ contact.jid not in gajim.interface.minimized_controls[account] and
not contact.is_transport() and\ not contact.is_transport() and
not contact_transport not contact_transport)
# set jabber id and pseudos # set jabber id and pseudos
for account in gajim.contacts.get_accounts(): for account in gajim.contacts.get_accounts():

View file

@ -435,7 +435,7 @@ class GlibIdleQueue(idlequeue.IdleQueue):
self.events = {} self.events = {}
# time() is already called in glib, we just get the last value # time() is already called in glib, we just get the last value
# overrides IdleQueue.current_time() # overrides IdleQueue.current_time()
self.current_time = lambda: gobject.get_current_time() self.current_time = gobject.get_current_time
def add_idle(self, fd, flags): def add_idle(self, fd, flags):
''' this method is called when we plug a new idle object. ''' this method is called when we plug a new idle object.

View file

@ -240,7 +240,8 @@ def _parse_css_color(color):
return gtk.gdk.color_parse(color) return gtk.gdk.color_parse(color)
def style_iter(style): def style_iter(style):
return (map(lambda x:x.strip(),item.split(':', 1)) for item in style.split(';') if len(item.strip())) return ([x.strip() for x in item.split(':', 1)] for item in style.split(';')\
if len(item.strip()))
class HtmlHandler(xml.sax.handler.ContentHandler): class HtmlHandler(xml.sax.handler.ContentHandler):

View file

@ -69,7 +69,7 @@ class Secrets:
def find_srs(self, account, jid, srs): def find_srs(self, account, jid, srs):
our_secrets = self.srs[account][jid] our_secrets = self.srs[account][jid]
return filter(lambda (x,y): x == srs, our_secrets)[0] return [(x, y) for x, y in our_secrets if x == srs][0]
# has the user verified this retained secret? # has the user verified this retained secret?
def srs_verified(self, account, jid, srs): def srs_verified(self, account, jid, srs):