def encode_message(self, message): """Encode a message using parameter prefix. Args: message: Message to URL Encode. Returns: URL encoded message. """ return protourlencode.encode_message(message, prefix=self.__parameter_prefix)
def testParameterPrefix(self): """Test using the 'prefix' parameter to encode_message.""" class MyMessage(messages.Message): number = messages.IntegerField(1) names = messages.StringField(2, repeated=True) message = MyMessage() message.number = 10 message.names = [u'Fred', u'Lisa'] encoded_message = protourlencode.encode_message(message, prefix='prefix-') self.assertEquals({'prefix-number': ['10'], 'prefix-names-0': ['Fred'], 'prefix-names-1': ['Lisa'], }, cgi.parse_qs(encoded_message)) self.assertEquals(message, protourlencode.decode_message(MyMessage, encoded_message, prefix='prefix-'))
def testParameterPrefix(self): """Test using the 'prefix' parameter to encode_message.""" class MyMessage(messages.Message): number = messages.IntegerField(1) names = messages.StringField(2, repeated=True) message = MyMessage() message.number = 10 message.names = [u'Fred', u'Lisa'] encoded_message = protourlencode.encode_message(message, prefix='prefix-') self.assertEquals( { 'prefix-number': ['10'], 'prefix-names-0': ['Fred'], 'prefix-names-1': ['Lisa'], }, cgi.parse_qs(encoded_message)) self.assertEquals( message, protourlencode.decode_message(MyMessage, encoded_message, prefix='prefix-'))