Exemple #1
0
 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
Exemple #2
0
 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
Exemple #3
0
 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()
Exemple #4
0
 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)
Exemple #5
0
 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)
Exemple #6
0
Fichier : job.py Projet : dsc/trowl
 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)
Exemple #7
0
 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()
Exemple #8
0
    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
Exemple #9
0
    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
Exemple #10
0
 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')
Exemple #11
0
 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')
Exemple #12
0
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