예제 #1
0
def abbrtask(S, max):
    if S is None:
        return "???"
    if len(S) > max:
        module, _, cls = rpartition(S, ".")
        module = abbr(module, max - len(cls), False)
        return module + "[.]" + cls
    return S
예제 #2
0
def abbrtask(S, max):
    if S is None:
        return "???"
    if len(S) > max:
        module, _, cls = rpartition(S, ".")
        module = abbr(module, max - len(cls), False)
        return module + "[.]" + cls
    return S
예제 #3
0
def resolve_loader(loader):
    loader = LOADER_ALIASES.get(loader, loader)
    loader_module_name, _, loader_cls_name = rpartition(loader, ".")
    if first_letter(loader_cls_name) not in string.uppercase:
        warnings.warn(DeprecationWarning(
            "CELERY_LOADER now needs loader class name, e.g. %s.%s" % (
                loader, _DEFAULT_LOADER_CLASS_NAME)))
        return loader, _DEFAULT_LOADER_CLASS_NAME
    return loader_module_name, loader_cls_name
예제 #4
0
파일: __init__.py 프로젝트: berg/celery
def get_cls_by_name(name, aliases={}, imp=None):
    """Get class by name.

    The name should be the full dot-separated path to the class::

        modulename.ClassName

    Example::

        celery.concurrency.processes.TaskPool
                                    ^- class name

    If ``aliases`` is provided, a dict containing short name/long name
    mappings, the name is looked up in the aliases first.

    Examples:

        >>> get_cls_by_name("celery.concurrency.processes.TaskPool")
        <class 'celery.concurrency.processes.TaskPool'>

        >>> get_cls_by_name("default", {
        ...     "default": "celery.concurrency.processes.TaskPool"})
        <class 'celery.concurrency.processes.TaskPool'>

        # Does not try to look up non-string names.
        >>> from celery.concurrency.processes import TaskPool
        >>> get_cls_by_name(TaskPool) is TaskPool
        True

    """
    if imp is None:
        imp = importlib.import_module

    if not isinstance(name, basestring):
        return name                                 # already a class

    name = aliases.get(name) or name
    module_name, _, cls_name = rpartition(name, ".")
    module = imp(module_name)
    return getattr(module, cls_name)
예제 #5
0
def get_cls_by_name(name, aliases={}):
    """Get class by name.

    The name should be the full dot-separated path to the class::

        modulename.ClassName

    Example::

        celery.concurrency.processes.TaskPool
                                    ^- class name

    If ``aliases`` is provided, a dict containing short name/long name
    mappings, the name is looked up in the aliases first.

    Examples:

        >>> get_cls_by_name("celery.concurrency.processes.TaskPool")
        <class 'celery.concurrency.processes.TaskPool'>

        >>> get_cls_by_name("default", {
        ...     "default": "celery.concurrency.processes.TaskPool"})
        <class 'celery.concurrency.processes.TaskPool'>

        # Does not try to look up non-string names.
        >>> from celery.concurrency.processes import TaskPool
        >>> get_cls_by_name(TaskPool) is TaskPool
        True

    """

    if not isinstance(name, basestring):
        return name  # already a class

    name = aliases.get(name) or name
    module_name, _, cls_name = rpartition(name, ".")
    module = importlib.import_module(module_name)
    return getattr(module, cls_name)
예제 #6
0
 def test_emergency_error(self):
     sio = StringIO()
     emergency_error(sio, "Testing emergency error facility")
     self.assertEqual(rpartition(sio.getvalue(), ":")[2].strip(),
                          "Testing emergency error facility")
예제 #7
0
 def test_rpartition_unicode(self):
     s = u'hi mom !'
     self.assertEqual(utils.rpartition(s, ' '), (u'hi mom', u' ', u'!'))
예제 #8
0
 def test_rpartition_unicode(self):
     s = u'hi mom !'
     self.assertEqual(utils.rpartition(s, ' '), (u'hi mom', u' ', u'!'))
예제 #9
0
def resolve_backend(backend=None):
    backend = BACKEND_ALIASES.get(backend, backend)
    backend_module_name, _, backend_cls_name = rpartition(backend, ".")
    return backend_module_name, backend_cls_name
예제 #10
0
def resolve_backend(backend=None):
    backend = BACKEND_ALIASES.get(backend, backend)
    backend_module_name, _, backend_cls_name = rpartition(backend, ".")
    return backend_module_name, backend_cls_name