def groupfinder(userid, request):
    user = request.db.query(User).filter_by(id=userid).first()
if user is not None:
    sites = user.allowed_sites
return [('site:%d' % s.id) for s in sites]


class SiteFactory(object):

    def __init__(self, request):
        self.request = request

def __getitem__(self, key):
    site = self.request.db.query(Site).filter_by(id=key).first()
if site is None:
    raise KeyError
site.__parent__ = self
site.__name__ = key
site.__acl__ = [(Allow, 'site:%d' % site.id, 'view')]
return site
Как элегантно обрабатывать сложные URL-адреса?