From ba2f5db4f0944d0b3e8ef99c316f81ff9f182a26 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 21 May 2015 10:03:13 +0530 Subject: [PATCH] ... --- src/calibre/srv/opts.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/calibre/srv/opts.py b/src/calibre/srv/opts.py index 38b1b6d7dc..4d4be3998d 100644 --- a/src/calibre/srv/opts.py +++ b/src/calibre/srv/opts.py @@ -6,6 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import, __license__ = 'GPL v3' __copyright__ = '2015, Kovid Goyal ' +from itertools import izip_longest from collections import namedtuple, OrderedDict from operator import attrgetter @@ -69,13 +70,16 @@ raw_options = ( ' worse overall performance when sending multiple small packets. It' ' prevents the TCP stack from aggregating multiple small TCP packets.', ) +assert len(raw_options) % 4 == 0 options = [] -i = 0 -while i + 3 < len(raw_options): - shortdoc, name, default, doc = raw_options[i:i+4] - i += 4 +def grouper(n, iterable, fillvalue=None): + "grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx" + args = [iter(iterable)] * n + return izip_longest(*args, fillvalue=fillvalue) + +for shortdoc, name, default, doc in grouper(4, raw_options): choices = None if isinstance(default, Choices): choices = default