def from_URI(cls, URI=None): URI = URI or pmxbot.config.get('database', 'sqlite:pmxbot.sqlite') candidates = reversed(list(iter_subclasses(cls))) if hasattr(cls, 'scheme'): candidates = itertools.chain([cls], candidates) matches = (cls for cls in candidates if cls.uri_matches(URI)) return next(matches)(URI)
def get_valid_managers(cls, location): """ Get the valid RepoManagers for this location. """ def by_priority_attr(c): return getattr(c, 'priority', 0) classes = sorted(iter_subclasses(cls), key=by_priority_attr, reverse=True) all_managers = (c(location) for c in classes) return (mgr for mgr in all_managers if mgr.is_valid())