def encode(self, string):
        """Encode a_string as per the canonicalisation encoding rules.

        See the AWS dev reference page 186 (2009-11-30 version).
        @return: a_string encoded.
        """
        if isinstance(string, unicode):
            string = string.encode("utf-8")
        return quote(string, safe="~")