Example #1
0
def get_actor_class(actor):
    """Returns a Class Reference to an Actor by string name.

    Args:
        actor: String name of the actor to find.

    Returns:
        <Class Ref to Actor>
    """
    expected_exceptions = (AttributeError, ImportError, TypeError)

    try:
        # Try to load our local actors up first. Assume that the
        # 'kingpin.actors.' prefix was not included in the name.
        full_actor = 'kingpin.actors.%s' % actor
        ref = utils.str_to_class(full_actor)
    except expected_exceptions as e:
        log.warning('Could not import %s: %s' % (full_actor, e))
        try:
            ref = utils.str_to_class(actor)
        except expected_exceptions:
            log.critical('Could not import %s: %s' % (actor, e))
            msg = 'Unable to import "%s" as a valid Actor.' % actor
            raise exceptions.InvalidActor(msg)

    return ref
Example #2
0
    def test_str_to_class(self):
        class_string_name = 'tornado.testing.AsyncTestCase'
        returned_class = utils.str_to_class(class_string_name)
        self.assertEqual(testing.AsyncTestCase, returned_class)

        class_string_name = 'kingpin.actors.misc.Sleep'
        returned_class = utils.str_to_class(class_string_name)
        self.assertEqual(misc.Sleep, returned_class)
Example #3
0
    def test_str_to_class(self):
        class_string_name = 'tornado.testing.AsyncTestCase'
        returned_class = utils.str_to_class(class_string_name)
        self.assertEquals(testing.AsyncTestCase, returned_class)

        class_string_name = 'misc.Sleep'
        returned_class = utils.str_to_class(class_string_name)
        self.assertEquals(misc.Sleep, returned_class)
Example #4
0
def get_actor_class(actor):
    """Returns a Class Reference to an Actor by string name.

    Args:
        actor: String name of the actor to find.

    Returns:
        <Class Ref to Actor>
    """
    expected_exceptions = (AttributeError, ImportError, TypeError)

    # Try to load our local actors up first. Assume that the
    # 'kingpin.actors.' prefix was not included in the name.
    for prefix in ['kingpin.actors.', '', 'actors.']:
        full_actor = prefix + actor
        try:
            return utils.str_to_class(full_actor)
        except expected_exceptions as e:
            log.debug('Tried importing "%s" but failed: %s' % (full_actor, e))

    msg = 'Unable to import "%s" as a valid Actor.' % actor
    raise exceptions.InvalidActor(msg)
Example #5
0
def get_actor_class(actor):
    """Returns a Class Reference to an Actor by string name.

    Args:
        actor: String name of the actor to find.

    Returns:
        <Class Ref to Actor>
    """
    expected_exceptions = (AttributeError, ImportError, TypeError)

    # Try to load our local actors up first. Assume that the
    # 'kingpin.actors.' prefix was not included in the name.
    for prefix in ['kingpin.actors.', '', 'actors.']:
        full_actor = prefix + actor
        try:
            return utils.str_to_class(full_actor)
        except expected_exceptions as e:
            log.debug('Tried importing "%s" but failed: %s' % (full_actor, e))

    msg = 'Unable to import "%s" as a valid Actor.' % actor
    raise exceptions.InvalidActor(msg)
Example #6
0
 def _execute(self):
     exc = utils.str_to_class(self.option('exception'))
     raise exc
Example #7
0
 def _execute(self):
     exc = utils.str_to_class(self.option('exception'))
     raise exc