From bac46ba438a1dac5cabcaba8ed085a475ff406b6 Mon Sep 17 00:00:00 2001 From: Pablo Hoffman Date: Mon, 2 May 2011 01:11:19 -0300 Subject: [PATCH] make sure Request.method is always str --- scrapy/http/request/__init__.py | 2 +- scrapy/tests/test_http_request.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/scrapy/http/request/__init__.py b/scrapy/http/request/__init__.py index 9f2161674..7fd034890 100644 --- a/scrapy/http/request/__init__.py +++ b/scrapy/http/request/__init__.py @@ -25,7 +25,7 @@ class Request(object_ref): dont_filter=False, errback=None): self._encoding = encoding # this one has to be set first - self.method = method.upper() + self.method = str(method).upper() self._set_url(url) self._set_body(body) self.priority = priority diff --git a/scrapy/tests/test_http_request.py b/scrapy/tests/test_http_request.py index e9da2d3b3..841568ed8 100644 --- a/scrapy/tests/test_http_request.py +++ b/scrapy/tests/test_http_request.py @@ -162,6 +162,10 @@ class RequestTest(unittest.TestCase): self.assertEqual(r4.meta, {}) assert r4.dont_filter is False + def test_method_always_str(self): + r = self.request_class("http://www.example.com", method=u"POST") + assert isinstance(r.method, str) + def test_weakref_slots(self): """Check that classes are using slots and are weak-referenceable""" x = self.request_class('http://www.example.com')