From 0830a5fe737d0150d51dd73c87c4a419e7e83816 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Wed, 3 Dec 2008 22:07:44 +0000 Subject: [PATCH] [thorstenp] use sorted() and list comprehension --- src/common/configpaths.py | 2 +- src/common/connection_handlers.py | 20 ++++++------ src/common/helpers.py | 4 +-- src/common/stanza_session.py | 32 +++++++++---------- .../zeroconf/connection_handlers_zeroconf.py | 3 +- src/dialogs.py | 12 +++---- src/gajim.py | 2 +- src/htmltextview.py | 3 +- src/secrets.py | 2 +- 9 files changed, 39 insertions(+), 41 deletions(-) diff --git a/src/common/configpaths.py b/src/common/configpaths.py index 5f59fa4c5..5fd30de24 100644 --- a/src/common/configpaths.py +++ b/src/common/configpaths.py @@ -109,7 +109,7 @@ class ConfigPaths: u'iconsets', u'moods', u'activities', u'cacerts.pem') 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): self.add_from_root(n, p) diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index 8e0fe6e39..472bb53bd 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -33,6 +33,7 @@ import base64 import sha import socket import sys +import operator from time import (altzone, daylight, gmtime, localtime, mktime, strftime, time as time_time, timezone, tzname) @@ -166,7 +167,7 @@ class ConnectionBytestream: sender = file_props['sender'] proxyhosts = [] 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) if default: # add/move default proxy at top of the others @@ -194,8 +195,7 @@ class ConnectionBytestream: file_props['sha_str'] = sha_str ft_add_hosts = [] if ft_add_hosts_to_send: - ft_add_hosts_to_send = map(lambda e:e.strip(), - ft_add_hosts_to_send.split(',')) + ft_add_hosts_to_send = [e.strip() for e in ft_add_hosts_to_send.split(',')] for ft_host in ft_add_hosts_to_send: ft_add_hosts.append(ft_host) 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] # filter out everything except the default session type - p = lambda s: isinstance(s, gajim.default_session_type) - chat_sessions = filter(p, idless) + chat_sessions = [s for s in idless if isinstance(s, + gajim.default_session_type)] if chat_sessions: # return the session that we last sent a message in - chat_sessions.sort(key=lambda s: s.last_send) - return chat_sessions[-1] + return sorted(chat_sessions, + key=operator.attrgetter("last_send"))[-1] else: return None @@ -1341,8 +1341,8 @@ sent a message to.''' sessions = self.sessions[jid].values() # filter out everything except the default session type - p = lambda s: isinstance(s, gajim.default_session_type) - chat_sessions = filter(p, sessions) + chat_sessions = [s for s in sessions if isinstance(s, + gajim.default_session_type)] 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) + '/' +\ self.server_resource) 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: gajim.proxy65_manager.resolve(proxy, self.connection, our_jid) diff --git a/src/common/helpers.py b/src/common/helpers.py index 3183e9982..f88accbfc 100644 --- a/src/common/helpers.py +++ b/src/common/helpers.py @@ -762,7 +762,7 @@ def get_random_string_16(): ''' create random string of length 16''' rng = range(65, 90) 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 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] if max_chars > 0: if lines: - lines = map(lambda e: _cut_if_long(e), lines) + lines = [_cut_if_long(e) for e in lines] if lines: reduced_text = '\n'.join(lines) if reduced_text != text: diff --git a/src/common/stanza_session.py b/src/common/stanza_session.py index 791fe91a3..f136e292f 100644 --- a/src/common/stanza_session.py +++ b/src/common/stanza_session.py @@ -365,7 +365,7 @@ class EncryptedStanzaSession(StanzaSession): def c7lize_mac_id(self, form): kids = form.getChildren() 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): m_o = base64.b64decode(form['mac']) @@ -393,8 +393,8 @@ class EncryptedStanzaSession(StanzaSession): if self.negotiated['sign_algs'] == (XmlDsig + 'rsa-sha256'): keyvalue = parsed.getTag(name='RSAKeyValue', namespace=XmlDsig) - n, e = map(lambda x: crypto.decode_mpi(base64.b64decode( - keyvalue.getTagData(x))), ('Modulus', 'Exponent')) + n, e = (crypto.decode_mpi(base64.b64decode( + keyvalue.getTagData(x))) for x in ('Modulus', 'Exponent')) eir_pubkey = RSA.construct((n,long(e))) pubkey_o = xmpp.c14n.c14n(keyvalue) @@ -437,8 +437,8 @@ class EncryptedStanzaSession(StanzaSession): pubkey = secrets.secrets().my_pubkey(self.conn.name) fields = (pubkey.n, pubkey.e) - cb_fields = map(lambda f: base64.b64encode(crypto.encode_mpi(f)), - fields) + cb_fields = [base64.b64encode(crypto.encode_mpi(f)) for f in + fields] pubkey_s = '%s%s' % \ @@ -446,7 +446,7 @@ class EncryptedStanzaSession(StanzaSession): else: 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 content = self.n_o + self.n_s + crypto.encode_mpi(dh_i) + pubkey_s + \ @@ -477,7 +477,7 @@ class EncryptedStanzaSession(StanzaSession): if self.sigmai: # XXX save retained secret? - self.check_identity(lambda : ()) + self.check_identity(tuple) return (xmpp.DataField(name='identity', value=base64.b64encode(id_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', - 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)) 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) @@ -573,9 +573,9 @@ class EncryptedStanzaSession(StanzaSession): self.hash_alg = SHA256 self.compression = None - for name, field in map(lambda name: (name, form.getField(name)), - form.asDict().keys()): - options = map(lambda x: x[1], field.getOptions()) + for name in form.asDict(): + field = form.getField(name) + options = [x[1] for x in field.getOptions()] values = field.getValues() if not field.getType() in ('list-single', 'list-multi'): @@ -676,9 +676,8 @@ class EncryptedStanzaSession(StanzaSession): b64ed = base64.b64encode(to_add[name]) x.addChild(node=xmpp.DataField(name=name, value=b64ed)) - self.form_o = ''.join(map(lambda el: xmpp.c14n.c14n(el), - form.getChildren())) - self.form_s = ''.join(map(lambda el: xmpp.c14n.c14n(el), x.getChildren())) + self.form_o = ''.join(xmpp.c14n.c14n(el) for el in form.getChildren()) + self.form_s = ''.join(xmpp.c14n.c14n(el) for el in x.getChildren()) self.status = 'responded-e2e' @@ -782,8 +781,7 @@ class EncryptedStanzaSession(StanzaSession): result.addChild(node=xmpp.DataField(name='dhkeys', value=base64.b64encode(crypto.encode_mpi(e)))) - self.form_o = ''.join(map(lambda el: xmpp.c14n.c14n(el), - form.getChildren())) + self.form_o = ''.join(xmpp.c14n.c14n(el) for el in form.getChildren()) # MUST securely destroy K unless it will be used later to generate the # final shared secret diff --git a/src/common/zeroconf/connection_handlers_zeroconf.py b/src/common/zeroconf/connection_handlers_zeroconf.py index f2de68687..6b9a0b661 100644 --- a/src/common/zeroconf/connection_handlers_zeroconf.py +++ b/src/common/zeroconf/connection_handlers_zeroconf.py @@ -81,8 +81,7 @@ class ConnectionBytestream(connection_handlers.ConnectionBytestream): file_props['sha_str'] = sha_str ft_add_hosts = [] if ft_add_hosts_to_send: - ft_add_hosts_to_send = map(lambda e:e.strip(), - ft_add_hosts_to_send.split(',')) + ft_add_hosts_to_send = [e.strip() for e in ft_add_hosts_to_send.split(',')] for ft_host in ft_add_hosts_to_send: try: ft_host = socket.gethostbyname(ft_host) diff --git a/src/dialogs.py b/src/dialogs.py index 8a8f5285d..79613b0a9 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -3708,12 +3708,12 @@ class TransformChatToMUC: # All contacts beside the following can be invited: # transports, zeroconf contacts, minimized groupchats - invitable = lambda contact, contact_transport = None:\ - contact.jid not in self.auto_jids and\ - contact.jid != gajim.get_jid_from_account(self.account) and\ - contact.jid not in gajim.interface.minimized_controls[account] and\ - not contact.is_transport() and\ - not contact_transport + def invitable(contact, contact_transport=None): + return (contact.jid not in self.auto_jids and + contact.jid != gajim.get_jid_from_account(self.account) and + contact.jid not in gajim.interface.minimized_controls[account] and + not contact.is_transport() and + not contact_transport) # set jabber id and pseudos for account in gajim.contacts.get_accounts(): diff --git a/src/gajim.py b/src/gajim.py index 1712499c7..9239e05c4 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -435,7 +435,7 @@ class GlibIdleQueue(idlequeue.IdleQueue): self.events = {} # time() is already called in glib, we just get the last value # 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): ''' this method is called when we plug a new idle object. diff --git a/src/htmltextview.py b/src/htmltextview.py index 6cca4db9f..201c349ff 100644 --- a/src/htmltextview.py +++ b/src/htmltextview.py @@ -240,7 +240,8 @@ def _parse_css_color(color): return gtk.gdk.color_parse(color) 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): diff --git a/src/secrets.py b/src/secrets.py index 407275ee1..a09dc717e 100644 --- a/src/secrets.py +++ b/src/secrets.py @@ -69,7 +69,7 @@ class Secrets: def find_srs(self, account, jid, srs): 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? def srs_verified(self, account, jid, srs):