Пример #1
0
def wrap_list(value, length, delim_lines=',\n', delim_entries=', '):
    def _counter(item, buffer):
        return len(item) + sum(imap(len, buffer)) + 2 * len(buffer) > length

    wrapped = accumulate(value, [], _counter, add_fun=lambda x, y: x + [y])
    return str.join(delim_lines,
                    imap(lambda x: str.join(delim_entries, x), wrapped))
Пример #2
0
def parse_parameter_option(option):
	# first token is variable / tuple - rest is option specifier: "a option" or "(a,b) option"
	tokens = list(split_brackets(option.lower()))
	if len(tokens) and '(' in tokens[0]:
		# parse tuple in as general way as possible
		result = [tuple(accumulate(tokens[0], '',
			do_emit=lambda i, b: not is_valid_parameter_char(i),
			do_add=lambda i, b: is_valid_parameter_char(i)))]
		if tokens[1:]:
			result.append(str.join('', tokens[1:]).strip())
	else:
		result = str.join('', tokens).strip().split(' ', 1)
	if len(result) == 1:
		result.append(None)
	return tuple(result)
Пример #3
0
def parse_parameter_option(option):
    # first token is variable / tuple - rest is option specifier: "a option" or "(a,b) option"
    tokens = list(split_brackets(option.lower()))
    if len(tokens) and '(' in tokens[0]:
        # parse tuple in as general way as possible
        result = [
            tuple(
                accumulate(tokens[0],
                           '',
                           do_emit=lambda i, b: not is_valid_parameter_char(i),
                           do_add=lambda i, b: is_valid_parameter_char(i)))
        ]
        if tokens[1:]:
            result.append(str.join('', tokens[1:]).strip())
    else:
        result = str.join('', tokens).strip().split(' ', 1)
    if len(result) == 1:
        result.append(None)
    return tuple(result)
Пример #4
0
def wrap_list(value, length, delim_lines=',\n', delim_entries=', '):
	def _counter(item, buffer):
		return len(item) + sum(imap(len, buffer)) + 2 * len(buffer) > length
	wrapped = accumulate(value, [], _counter, add_fun=lambda x, y: x + [y])
	return str.join(delim_lines, imap(lambda x: str.join(delim_entries, x), wrapped))