Package openid :: Module extension
[frames] | no frames]

Source Code for Module openid.extension

 1  from openid import message as message_module 
 2   
3 -class Extension(object):
4 """An interface for OpenID extensions. 5 6 @ivar ns_uri: The namespace to which to add the arguments for this 7 extension 8 """ 9 ns_uri = None 10 ns_alias = None 11
12 - def getExtensionArgs(self):
13 """Get the string arguments that should be added to an OpenID 14 message for this extension. 15 16 @returns: A dictionary of completely non-namespaced arguments 17 to be added. For example, if the extension's alias is 18 'uncle', and this method returns {'meat':'Hot Rats'}, the 19 final message will contain {'openid.uncle.meat':'Hot Rats'} 20 """ 21 raise NotImplementedError
22
23 - def toMessage(self, message=None):
24 """Add the arguments from this extension to the provided 25 message, or create a new message containing only those 26 arguments. 27 28 @returns: The message with the extension arguments added 29 """ 30 if message is None: 31 warnings.warn('Passing None to Extension.toMessage is deprecated. ' 32 'Creating a message assuming you want OpenID 2.', 33 DeprecationWarning, stacklevel=2) 34 message = message_module.Message(message_module.OPENID2_NS) 35 36 implicit = message.isOpenID1() 37 38 try: 39 message.namespaces.addAlias(self.ns_uri, self.ns_alias, 40 implicit=implicit) 41 except KeyError: 42 if message.namespaces.getAlias(self.ns_uri) != self.ns_alias: 43 raise 44 45 message.updateArgs(self.ns_uri, self.getExtensionArgs()) 46 return message
47