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
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
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)
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)
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")
def test_rpartition_unicode(self): s = u'hi mom !' self.assertEqual(utils.rpartition(s, ' '), (u'hi mom', u' ', u'!'))
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