Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
def __iter__(self):
"""
- Makes the object iterable by going through each line
+ Makes the object iterable by going through each block
"""
- return iter(self.body)
+ block = []
+
+ for line in self.body:
+ # Convert to string
+ for charset in ("utf-8", "latin1"):
+ try:
+ line = line.decode(charset)
+ except UnicodeDecodeError:
+ continue
+ else:
+ break
+
+ # Strip line-endings
+ line = line.strip()
+
+ if line:
+ block.append(line)
+ continue
+
+ # End the block on an empty line
+ yield block
+
+ # Reset the block
+ block = []
@property
def headers(self):
print("Downloading %s..." % url)
with d.request(url) as r:
- for line in r:
- print(line)
+ for block in r:
+ for line in block:
+ print(line)
+ print()