Scrapy, a fast high-level web crawling & scraping framework for Python.
py3 fetch command: it may actually be better to try to print bytes as-is
Konstantin Lopuhinc6d013ec8574
diff --git a/scrapy/commands/fetch.py b/scrapy/commands/fetch.pyindex 3888da210..49fa18ab2 100644--- a/scrapy/commands/fetch.py+++ b/scrapy/commands/fetch.py@@ -1,11 +1,11 @@from __future__ import print_function+import sys, sixfrom w3lib.url import is_urlfrom scrapy.commands import ScrapyCommandfrom scrapy.http import Requestfrom scrapy.exceptions import UsageErrorfrom scrapy.utils.spider import spidercls_for_request, DefaultSpider-from scrapy.utils.python import to_unicodeclass Command(ScrapyCommand):@@ -29,10 +29,10 @@ class Command(ScrapyCommand):help="print response HTTP headers instead of body")def _print_headers(self, headers, prefix):+ prefix = prefix.encode()for key, values in headers.items():for value in values:- print('%s %s: %s' % (- prefix, to_unicode(key), to_unicode(value)))+ self._print_bytes(prefix + b' ' + key + b': ' + value)def _print_response(self, response, opts):if opts.headers:@@ -40,7 +40,11 @@ class Command(ScrapyCommand):print('>')self._print_headers(response.headers, '<')else:- print(to_unicode(response.body))+ self._print_bytes(response.body)++ def _print_bytes(self, bytes_):+ bytes_writer = sys.stdout if six.PY2 else sys.stdout.buffer+ bytes_writer.write(bytes_ + b'\n')def run(self, args, opts):if len(args) != 1 or not is_url(args[0]):