webfaction and repo.or.cz deployment done
[worddb.git] / libs / openid / extension.py
blobd48bbb2f0ecd04986a503cd4c104390ead47a55d
1 from openid import message as message_module
3 class Extension(object):
4 """An interface for OpenID extensions.
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
12 def getExtensionArgs(self):
13 """Get the string arguments that should be added to an OpenID
14 message for this extension.
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
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.
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)
36 implicit = message.isOpenID1()
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
45 message.updateArgs(self.ns_uri, self.getExtensionArgs())
46 return message