Esempio n. 1
0
 def test_makeBranchTrailingSlash(self):
     """makeBranch creates a mirrored branch even if the URL ends with /.
     """
     uri = URI(self.factory.getUniqueURL())
     expected_name = self.popup.getBranchNameFromURL(
         str(uri.ensureNoSlash()))
     branch = self.popup.makeBranchFromURL(str(uri.ensureSlash()))
     self.assertEqual(str(uri.ensureNoSlash()), branch.url)
     self.assertEqual(expected_name, branch.name)
 def test_makeBranchTrailingSlash(self):
     """makeBranch creates a mirrored branch even if the URL ends with /.
     """
     uri = URI(self.factory.getUniqueURL())
     expected_name = self.popup.getBranchNameFromURL(
         str(uri.ensureNoSlash()))
     branch = self.popup.makeBranchFromURL(str(uri.ensureSlash()))
     self.assertEqual(str(uri.ensureNoSlash()), branch.url)
     self.assertEqual(expected_name, branch.name)
Esempio n. 3
0
def web_root_for_service_root(service_root):
    """Turn a service root URL into a web root URL.

    This is done heuristically, not with a lookup.
    """
    service_root = lookup_service_root(service_root)
    web_root_uri = URI(service_root)
    web_root_uri.path = ""
    web_root_uri.host = web_root_uri.host.replace("api.", "", 1)
    web_root = str(web_root_uri.ensureSlash())
    return web_root
Esempio n. 4
0
def web_root_for_service_root(service_root):
    """Turn a service root URL into a web root URL.

    This is done heuristically, not with a lookup.
    """
    service_root = lookup_service_root(service_root)
    web_root_uri = URI(service_root)
    web_root_uri.path = ""
    web_root_uri.host = web_root_uri.host.replace("api.", "", 1)
    web_root = str(web_root_uri.ensureSlash())
    return web_root
Esempio n. 5
0
    def get_token_and_login(cls, consumer_name,
                            service_root=uris.STAGING_SERVICE_ROOT,
                            cache=None, timeout=None, proxy_info=None,
                            authorizer_class=AuthorizeRequestTokenWithBrowser,
                            allow_access_levels=[], max_failed_attempts=3,
                            version=DEFAULT_VERSION):
        """Get credentials from Launchpad and log into the service root.

        This is a convenience method which will open up the user's preferred
        web browser and thus should not be used by most applications.
        Applications should, instead, use Credentials.get_request_token() to
        obtain the authorization URL and
        Credentials.exchange_request_token_for_access_token() to obtain the
        actual OAuth access token.

        This method will negotiate an OAuth access token with the service
        provider, but to complete it we will need the user to log into
        Launchpad and authorize us, so we'll open the authorization page in
        a web browser and ask the user to come back here and tell us when they
        finished the authorization process.

        :param consumer_name: The consumer name, as appropriate for the
            `Consumer` constructor
        :type consumer_name: string
        :param service_root: The URL to the root of the web service.
        :type service_root: string
        :return: The web service root
        :rtype: `Launchpad`
        """
        credentials = Credentials(consumer_name)
        service_root = uris.lookup_service_root(service_root)
        web_root_uri = URI(service_root)
        web_root_uri.path = ""
        web_root_uri.host = web_root_uri.host.replace("api.", "", 1)
        web_root = str(web_root_uri.ensureSlash())
        authorization_json = credentials.get_request_token(
            web_root=web_root, token_format=Credentials.DICT_TOKEN_FORMAT)
        authorizer = authorizer_class(
            web_root, authorization_json['oauth_token_consumer'],
            authorization_json['oauth_token'], allow_access_levels,
            max_failed_attempts)
        authorizer()
        credentials.exchange_request_token_for_access_token(web_root)
        return cls(credentials, service_root, cache, timeout, proxy_info,
                   version)
Esempio n. 6
0
    def normalize(self, input):
        """See `IURIField`."""
        if input is None:
            return input

        try:
            uri = URI(input)
        except InvalidURIError as exc:
            raise LaunchpadValidationError(str(exc))
        # If there is a policy for whether trailing slashes are
        # allowed at the end of the path segment, ensure that the
        # URI conforms.
        if self.trailing_slash is not None:
            if self.trailing_slash:
                uri = uri.ensureSlash()
            else:
                uri = uri.ensureNoSlash()
        input = unicode(uri)
        return input
Esempio n. 7
0
    def normalize(self, input):
        """See `IURIField`."""
        if input is None:
            return input

        try:
            uri = URI(input)
        except InvalidURIError as exc:
            raise LaunchpadValidationError(str(exc))
        # If there is a policy for whether trailing slashes are
        # allowed at the end of the path segment, ensure that the
        # URI conforms.
        if self.trailing_slash is not None:
            if self.trailing_slash:
                uri = uri.ensureSlash()
            else:
                uri = uri.ensureNoSlash()
        input = unicode(uri)
        return input