def get_repo_and_action(request): """Determines the repo and action for a request. The action is the part of the URL path after the repo, with no leading or trailing slashes.""" scheme, netloc, path, _, _ = urlparse.urlsplit(request.url) parts = path.lstrip('/').split('/') # TODO(kpy): Remove support for legacy URLs in mid-January 2012. import legacy_redirect if legacy_redirect.get_subdomain(request): repo = legacy_redirect.get_subdomain(request) action = '/'.join(parts) return repo, action # Depending on whether we're serving from appspot directly or # google.org/personfinder we could have /global or /personfinder/global # as the 'global' prefix. if parts[0] == 'personfinder': parts.pop(0) repo = parts and parts.pop(0) or None action = '/'.join(parts) if repo == 'global': repo = None return repo, action
def test_get_subdomain(self): self.init('/', 'japan.personfinder.appspot.com') assert 'japan' == legacy_redirect.get_subdomain(self.handler.request)
def test_get_subdomain(self): self.init("/", "japan.personfinder.appspot.com") assert "japan" == legacy_redirect.get_subdomain(self.handler.request)