def test_safe_str_to_class(self): from pyres import safe_str_to_class assert safe_str_to_class('tests.Basic') == Basic self.assertRaises(ImportError, safe_str_to_class, 'test.Mine') self.assertRaises(ImportError, safe_str_to_class, 'tests.World') # test that we'll use the class name as a module name if no # module name is provided (for Ruby compatibility) assert safe_str_to_class('tests') == tests
def perform(self): payload_class_str = self._payload["class"] payload_class = safe_str_to_class(payload_class_str) args = self._payload.get("args", None) if args: return payload_class.perform(*args) else: return payload_class.perform()
def test_safe_str_to_class(self): from pyres import safe_str_to_class from pyres import safe_str_to_class_v2 from tests.a import b assert safe_str_to_class('tests.Basic') == Basic self.assertRaises(ImportError, safe_str_to_class, 'test.Mine') self.assertRaises(ImportError, safe_str_to_class, 'tests.World') self.assertRaises(ImportError, safe_str_to_class, '{}.{}'.format(b.__module__, b.__name__)) self.assertEqual(safe_str_to_class_v2('{}.{}'.format(b.__module__, b.__name__)), b)
def test_safe_str_to_class(self): from pyres import safe_str_to_class from pyres import safe_str_to_class_v2 from tests.a import b assert safe_str_to_class('tests.Basic') == Basic self.assertRaises(ImportError, safe_str_to_class, 'test.Mine') self.assertRaises(ImportError, safe_str_to_class, 'tests.World') self.assertRaises(ImportError, safe_str_to_class, '{}.{}'.format(b.__module__, b.__name__)) self.assertEqual( safe_str_to_class_v2('{}.{}'.format(b.__module__, b.__name__)), b)
def __init__(self, url, filter=None, **env): if not filter: self.filter = None elif filter.startswith('regex:'): print "Filter from pattern: %s" % filter[6:] self.filter = re.compile(filter[6:]).search elif filter.startswith('class:'): self.filter = pyres.safe_str_to_class(filter[6:])(url, env) super(Spider, self).__init__(url, filter=filter, **env)
def perform(self): """This method converts payload into args and calls the **perform** method on the payload class. """ payload_class_str = self._payload["class"] payload_class = safe_str_to_class(payload_class_str) payload_class.resq = self.resq args = self._payload.get("args", None) if args: return payload_class.perform(*args) else: return payload_class.perform()
def perform(self): """This method converts payload into args and calls the ``perform`` method on the payload class. """ payload_class_str = self._payload["class"] payload_class = safe_str_to_class(payload_class_str) payload_class.resq = self.resq args = self._payload.get("args", None) try: return payload_class.perform(*args) except: if not self.retry(payload_class, args): raise
def test_safe_str_to_class(self): from pyres import safe_str_to_class assert safe_str_to_class('tests.Basic') == Basic self.assertRaises(ImportError, safe_str_to_class, 'test.Mine') self.assertRaises(ImportError, safe_str_to_class, 'tests.World')
def test_safe_str_to_class(): from pyres import safe_str_to_class assert safe_str_to_class('tests.Basic') == Basic assert safe_str_to_class('test.Mine') == None assert safe_str_to_class('hello.World') == None