def _create_api_key_properties_(self, pair):
        assert_true(len(pair) == 2, 'application_href userInfo segment must consist' +
                                    ' of the following format: apiKeyId:apiKeySecret')

        properties = {'apiKey.id' : urllib.parse.unquote(pair[0]), 'apiKey.secret' : urllib.parse.unquote(pair[1])}

        return yaml.dump(properties)
    def build(self):
        """
        Builds a Client and Application wrapper instance based on the configured
        *set_application_href*. See the Class-level docstring for usage scenarios.

        :returns a Client and Application wrapper instance based on the configured *set_application_href*.
        """

        assert_not_none(self.application_href, "'application_href' property must be specified when using this builder implementation.")

        cleaned_href = self.application_href[0:len(self.application_href)] #just returning a copy

        at_sigh_index = cleaned_href.find('@')

        if at_sigh_index > 0: #otherwise an apiKey File/YAML/etc for the API Key is required

            parts = self._get_href_with_user_info_(cleaned_href, at_sigh_index)

            cleaned_href = parts[0] + parts[2]

            parts = parts[1].split(':', 1)

            api_key_properties = self._create_api_key_properties_(parts)

            self.set_api_key_properties(api_key_properties)

        assert_true(cleaned_href.find('http') == 0 and cleaned_href.find('://') > 0, 'Invalid application href URL')

        client = self._build_client_()

        application = client.data_store.get_resource(cleaned_href, Application)

        return ClientApplication(client, application)
    def _get_href_with_user_info_(self, href, at_sign_index):
        assert_instance(href, str, 'href')
        assert_instance(at_sign_index, int, 'at_sign_index')

        double_slash_index = href.find('//')

        assert_true(double_slash_index > 0, 'Invalid application href URL')

        parts = {}
        parts[0] = href[0:double_slash_index + 2] #up to and including the double slash
        parts[1] = href[double_slash_index + 2:at_sign_index] #raw user info
        parts[2] = href[at_sign_index + 1:len(href)] #after the @ character

        return parts
    def save(self, resource, clazz = None):

        assert_instance(resource, Resource, "resource")

        href = resource.href
        assert_true(href, "save may only be called on objects that have already been persisted (i.e. they have an existing href).")

        href = self._qualify_(href) if self._needs_to_be_fully_qualified_(href) else href

        clazz = clazz if clazz else resource.__class__

        returned_resource = self._save_(href, resource, clazz)

        # ensure the caller's argument is updated with what is returned from the server:
        resource.set_properties(returned_resource.properties)

        return returned_resource
    def _to_simple_reference_(self, property_name, resource_properties):

        href_prop_name = Resource.HREF_PROP_NAME
        assert_true(resource_properties and href_prop_name in resource_properties, "Nested resource {} must have an 'href' property".format(property_name))

        return {href_prop_name : resource_properties[href_prop_name]}