[thorstenp] replace reduce instances
This commit is contained in:
parent
73aee40542
commit
2ffad66473
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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])
|
||||
|
|
|
@ -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']}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue