Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/gajim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYann Leboulanger <asterix@lagaule.org>2008-10-11 13:49:30 +0400
committerYann Leboulanger <asterix@lagaule.org>2008-10-11 13:49:30 +0400
commit2ffad6647354326d3e339a15cb132cddcd62262d (patch)
tree5ed65523ffbed4891f3d555f08858232b0fe6c0e /src
parent73aee40542e00c51eb0369e37211748bd0b03448 (diff)
[thorstenp] replace reduce instances
Diffstat (limited to 'src')
-rw-r--r--src/common/helpers.py5
-rw-r--r--src/common/nslookup.py2
-rw-r--r--src/common/socks5.py2
-rwxr-xr-xsrc/gajim.py3
-rw-r--r--src/ipython_view.py33
5 files changed, 20 insertions, 25 deletions
diff --git a/src/common/helpers.py b/src/common/helpers.py
index d5605c18a..5488404ff 100644
--- a/src/common/helpers.py
+++ b/src/common/helpers.py
@@ -770,8 +770,7 @@ def get_random_string_16():
rng.extend(range(48, 57))
char_sequence = map(lambda e:chr(e), rng)
from random import sample
- return reduce(lambda e1, e2: e1 + e2,
- sample(char_sequence, 16))
+ return ''.join(sample(char_sequence, 16))
def get_os_info():
if os.name == 'nt':
@@ -946,7 +945,7 @@ def reduce_chars_newlines(text, max_chars = 0, max_lines = 0):
if lines:
lines = map(lambda e: _cut_if_long(e), lines)
if lines:
- reduced_text = reduce(lambda e, e1: e + '\n' + e1, lines)
+ reduced_text = '\n'.join(lines)
if reduced_text != text:
reduced_text += '...'
else:
diff --git a/src/common/nslookup.py b/src/common/nslookup.py
index 0c0ec9bc9..9640d1dd8 100644
--- a/src/common/nslookup.py
+++ b/src/common/nslookup.py
@@ -208,7 +208,7 @@ class IdleCommand(IdleObject):
def _compose_command_line(self):
''' return one line representation of command and its arguments '''
- return reduce(lambda left, right: left + ' ' + right, self._compose_command_args())
+ return ' '.join(self._compose_command_args())
def wait_child(self):
if self.pipe.poll() is None:
diff --git a/src/common/socks5.py b/src/common/socks5.py
index 9cdc33166..55cdc4369 100644
--- a/src/common/socks5.py
+++ b/src/common/socks5.py
@@ -609,7 +609,7 @@ class Socks5:
struct.unpack('!BBBB', buff[:4])
if host_type == 0x01:
host_arr = struct.unpack('!iiii', buff[4:8])
- host, = reduce(lambda e1, e2: str(e1) + "." + str(e2), host_arr)
+ host, = '.'.join(str(s) for s in host_arr)
host_len = len(host)
elif host_type == 0x03:
host_len, = struct.unpack('!B' , buff[4])
diff --git a/src/gajim.py b/src/gajim.py
index 02f58a534..230de2f20 100755
--- a/src/gajim.py
+++ b/src/gajim.py
@@ -1570,8 +1570,7 @@ class Interface:
# 'Subject' and 'Snippet' field
if cnt >=5:
break
- senders = reduce(lambda b, a: a + ',\n ' + b,
- gmessage['From'])
+ senders = ',\n '.join(reversed(gmessage['From']))
text += _('\n\nFrom: %(from_address)s\nSubject: %(subject)s\n%(snippet)s') % \
{'from_address': senders, 'subject': gmessage['Subject'],
'snippet': gmessage['Snippet']}
diff --git a/src/ipython_view.py b/src/ipython_view.py
index 37b8213ad..8ee34b294 100644
--- a/src/ipython_view.py
+++ b/src/ipython_view.py
@@ -212,25 +212,22 @@ class IterableIPShell:
'''
split_line = self.complete_sep.split(line)
possibilities = self.IP.complete(split_line[-1])
+
+ try:
+ __builtins__.all
+ except AttributeError:
+ def all(iterable):
+ for element in iterable:
+ if not element:
+ return False
+ return True
+
+ def common_prefix(seq):
+ """Returns the common prefix of a sequence of strings"""
+ return "".join(c for i, c in enumerate(seq[0])
+ if all(s.startswith(c, i) for s in seq))
if possibilities:
- def _commonPrefix(str1, str2):
- '''
- Reduction function. returns common prefix of two given strings.
-
- @param str1: First string.
- @type str1: string
- @param str2: Second string
- @type str2: string
-
- @return: Common prefix to both strings.
- @rtype: string
- '''
- for i in range(len(str1)):
- if not str2.startswith(str1[:i+1]):
- return str1[:i]
- return str1
- common_prefix = reduce(_commonPrefix, possibilities)
- completed = line[:-len(split_line[-1])]+common_prefix
+ completed = line[:-len(split_line[-1])]+common_prefix(possibilities)
else:
completed = line
return completed, possibilities