示例#1
0
 def _groups(self, response, start=None, extra_bools=None):
     """Returns a group of dicts from `response`.
     If `start` is specified, items prior to this will be discarded,
     and each group will be starting with this.
     `extra_bools` allows custom keys to be booleaned"""
     group = []
     for k, v in self.__pairs_from(response):
         if k == start:
             if group:
                 yield dict(group)
             group = [(k, stronger(k, v, extra_bools))]
         else:
             if group or not start:
                 group.append((k, stronger(k, v, extra_bools)))
     yield dict(group)
示例#2
0
 def _groups(self, response, start=None, extra_bools=None):
     """Returns a series of dicts from `response`.
     If `start` is specified, items prior to this will be discarded,
     and each dict will be grouped starting with this key.
     `extra_bools` allows custom keys to be booleaned"""
     groups = []
     for k, v in self.__pairs_from(response):
         if k == start:
             if groups:
                 yield dict(groups)
             # New group starts here
             groups = [(k, stronger(k, v, extra_bools))]
         else:
             if groups or not start:
                 groups.append((k, stronger(k, v, extra_bools)))
     if groups:
         yield dict(groups)
示例#3
0
 def _groups(self, response: str, start_key: str = None, extra_bools=None):
     """Generator to yield a series of dicts from `response`.
     If `start` is specified, items prior to this will be discarded,
     and each dict will be grouped starting with this key.
     `extra_bools` allows custom keys to be booleaned"""
     groups = []
     started = False
     for k, v in self.__pairs_from(response):
         if k == start_key or " count" in k:
             if groups:
                 yield dict(groups)
                 groups = []
             started = True
             # New group starts here
             if " count" not in k:
                 groups = [(k, stronger(k, v, extra_bools))]
         else:
             if started or not start_key:
                 groups.append((k, stronger(k, v, extra_bools)))
     if groups:
         yield dict(groups)
示例#4
0
 def test_full(self):
     for (k, v), exp in [(('canpoweroff', '1'), True),
                         (('hasitems', '0'), False),
                         (('duration', '0.0'), 0.0),
                         (('foo', 'bar'), 'bar')]:
         assert stronger(k, v) == exp