From 80c55f19a143d8938ced81a599100259509567a1 Mon Sep 17 00:00:00 2001 From: Mikhail Korobov Date: Thu, 21 Jan 2016 18:31:58 +0500 Subject: [PATCH 1/2] PY3 fixed scrapy bench command --- scrapy/utils/benchserver.py | 8 ++++---- tests/test_commands.py | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/scrapy/utils/benchserver.py b/scrapy/utils/benchserver.py index 4385d72a9..a9a2c938e 100644 --- a/scrapy/utils/benchserver.py +++ b/scrapy/utils/benchserver.py @@ -16,15 +16,15 @@ class Root(Resource): total = _getarg(request, 'total', 100, int) show = _getarg(request, 'show', 10, int) nlist = [random.randint(1, total) for _ in range(show)] - request.write("") + request.write(b"") args = request.args.copy() for nl in nlist: args['n'] = nl argstr = urlencode(args, doseq=True) request.write("follow {1}
" - .format(argstr, nl)) - request.write("") - return '' + .format(argstr, nl).encode('utf8')) + request.write(b"") + return b'' def _getarg(request, name, default=None, type=str): diff --git a/tests/test_commands.py b/tests/test_commands.py index 5755b3881..057112d12 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -72,7 +72,7 @@ class StartprojectTest(ProjectTest): self.assertEqual(1, self.call('startproject', self.project_name)) self.assertEqual(1, self.call('startproject', 'wrong---project---name')) self.assertEqual(1, self.call('startproject', 'sys')) - + class StartprojectTemplatesTest(ProjectTest): @@ -80,7 +80,7 @@ class StartprojectTemplatesTest(ProjectTest): super(StartprojectTemplatesTest, self).setUp() self.tmpl = join(self.temp_path, 'templates') self.tmpl_proj = join(self.tmpl, 'project') - + def test_startproject_template_override(self): copytree(join(scrapy.__path__[0], 'templates'), self.tmpl) os.mknod(join(self.tmpl_proj, 'root_template')) @@ -276,3 +276,4 @@ class BenchCommandTest(CommandTest): '-s', 'CLOSESPIDER_TIMEOUT=0.01') log = to_native_str(p.stderr.read()) self.assertIn('INFO: Crawled', log) + self.assertNotIn('Unhandled Error', log) From a18dc24471f121ed85d1bee4281d43c3a3728162 Mon Sep 17 00:00:00 2001 From: Mikhail Korobov Date: Thu, 21 Jan 2016 18:44:37 +0500 Subject: [PATCH 2/2] correctly process arguments for bench server --- scrapy/utils/benchserver.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scrapy/utils/benchserver.py b/scrapy/utils/benchserver.py index a9a2c938e..5bbda6e27 100644 --- a/scrapy/utils/benchserver.py +++ b/scrapy/utils/benchserver.py @@ -13,8 +13,8 @@ class Root(Resource): return self def render(self, request): - total = _getarg(request, 'total', 100, int) - show = _getarg(request, 'show', 10, int) + total = _getarg(request, b'total', 100, int) + show = _getarg(request, b'show', 10, int) nlist = [random.randint(1, total) for _ in range(show)] request.write(b"") args = request.args.copy()