Twisted 15.3.0 does not raises expected exception serializing lambda functions

This commit is contained in:
Daniel Graña 2015-08-05 20:33:25 -03:00
parent 2bca27ef2c
commit c5ffa1a59f
2 changed files with 15 additions and 0 deletions

View File

@ -1,4 +1,5 @@
import sys
from six.moves import copyreg
if sys.version_info[0] == 2:
from urlparse import urlparse
@ -12,3 +13,13 @@ if sys.version_info[0] == 2:
if urlparse('s3://bucket/key?key=value').query != 'key=value':
from urlparse import uses_query
uses_query.append('s3')
# Undo what Twisted's perspective broker adds to pickle register
# to prevent bugs like Twisted#7989 while serializing requests
import twisted.persisted.styles # NOQA
# Remove only entries with twisted serializers for non-twisted types.
for k, v in frozenset(copyreg.dispatch_table.items()):
if not getattr(k, '__module__', '').startswith('twisted') \
and getattr(v, '__module__', '').startswith('twisted'):
copyreg.dispatch_table.pop(k)

View File

@ -31,6 +31,8 @@ class MarshalFifoDiskQueueTest(t.FifoDiskQueueTest):
self.assertEqual(q.pop(), {'a': 'dict'})
def test_nonserializable_object(self):
# Trigger Twisted bug #7989
import twisted.persisted.styles # NOQA
q = self.queue()
self.assertRaises(ValueError, q.push, lambda x: x)
@ -109,6 +111,8 @@ class MarshalLifoDiskQueueTest(t.LifoDiskQueueTest):
self.assertEqual(q.pop(), 'a')
def test_nonserializable_object(self):
# Trigger Twisted bug #7989
import twisted.persisted.styles # NOQA
q = self.queue()
self.assertRaises(ValueError, q.push, lambda x: x)