mirror of https://github.com/scrapy/scrapy.git
Account for mangling when serializing requests with private callbacks
This commit is contained in:
parent
a3d38041e2
commit
e667ca7682
|
|
@ -75,7 +75,11 @@ def _find_method(obj, func):
|
|||
pass
|
||||
else:
|
||||
if func_self is obj:
|
||||
return six.get_method_function(func).__name__
|
||||
name = six.get_method_function(func).__name__
|
||||
if name.startswith('__'):
|
||||
classname = obj.__class__.__name__.lstrip('_')
|
||||
name = '_%s%s' % (classname, name)
|
||||
return name
|
||||
raise ValueError("Function %s is not a method of: %s" % (func, obj))
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -68,6 +68,12 @@ class RequestSerializationTest(unittest.TestCase):
|
|||
errback=self.spider.handle_error)
|
||||
self._assert_serializes_ok(r, spider=self.spider)
|
||||
|
||||
def test_private_callback_serialization(self):
|
||||
r = Request("http://www.example.com",
|
||||
callback=self.spider._TestSpider__parse_item_private,
|
||||
errback=self.spider.handle_error)
|
||||
self._assert_serializes_ok(r, spider=self.spider)
|
||||
|
||||
def test_unserializable_callback1(self):
|
||||
r = Request("http://www.example.com", callback=lambda x: x)
|
||||
self.assertRaises(ValueError, request_to_dict, r)
|
||||
|
|
@ -87,6 +93,9 @@ class TestSpider(Spider):
|
|||
def handle_error(self, failure):
|
||||
pass
|
||||
|
||||
def __parse_item_private(self, response):
|
||||
pass
|
||||
|
||||
|
||||
class CustomRequest(Request):
|
||||
pass
|
||||
|
|
|
|||
Loading…
Reference in New Issue