@@ -59,6 +59,12 @@ class UndefinedOpenIDNamespace(ValueError):
5959 """Raised if the generic OpenID namespace is accessed when there
6060 is no OpenID namespace set for this message."""
6161
62+ class InvalidOpenIDNamespace (ValueError ):
63+ """Raised if openid.ns is not a recognized value.
64+
65+ For recognized values, see L{Message.allowed_openid_namespaces}
66+ """
67+
6268# Sentinel used for Message implementation to indicate that getArg
6369# should raise an exception instead of returning a default.
6470no_default = object ()
@@ -113,7 +119,11 @@ class Message(object):
113119 allowed_openid_namespaces = [OPENID1_NS , OPENID2_NS ]
114120
115121 def __init__ (self , openid_namespace = None ):
116- """Create an empty Message"""
122+ """Create an empty Message.
123+
124+ @raises InvalidOpenIDNamespace: if openid_namespace is not in
125+ L{Message.allowed_openid_namespaces}
126+ """
117127 self .args = {}
118128 self .namespaces = NamespaceMap ()
119129 if openid_namespace is None :
@@ -122,7 +132,9 @@ def __init__(self, openid_namespace=None):
122132 self .setOpenIDNamespace (openid_namespace )
123133
124134 def fromPostArgs (cls , args ):
125- """Construct a Message containing a set of POST arguments"""
135+ """Construct a Message containing a set of POST arguments.
136+
137+ """
126138 self = cls ()
127139
128140 # Partition into "openid." args and bare args
@@ -150,7 +162,11 @@ def fromPostArgs(cls, args):
150162 fromPostArgs = classmethod (fromPostArgs )
151163
152164 def fromOpenIDArgs (cls , openid_args ):
153- """Construct a Message from a parsed KVForm message"""
165+ """Construct a Message from a parsed KVForm message.
166+
167+ @raises InvalidOpenIDNamespace: if openid.ns is not in
168+ L{Message.allowed_openid_namespaces}
169+ """
154170 self = cls ()
155171 self ._fromOpenIDArgs (openid_args )
156172 return self
@@ -203,11 +219,16 @@ def _fromOpenIDArgs(self, openid_args):
203219 self .setArg (ns_uri , ns_key , value )
204220
205221 def setOpenIDNamespace (self , openid_ns_uri ):
222+ """Set the OpenID namespace URI used in this message.
223+
224+ @raises InvalidOpenIDNamespace: if the namespace is not in
225+ L{Message.allowed_openid_namespaces}
226+ """
206227 if openid_ns_uri == THE_OTHER_OPENID1_NS :
207228 # It's better this way, really.
208229 openid_ns_uri = OPENID1_NS
209230 if openid_ns_uri not in self .allowed_openid_namespaces :
210- raise ValueError ( 'Invalid null namespace: %r' % ( openid_ns_uri ,) )
231+ raise InvalidOpenIDNamespace ( openid_ns_uri )
211232
212233 self .namespaces .addAlias (openid_ns_uri , NULL_NAMESPACE )
213234 self ._openid_ns_uri = openid_ns_uri
0 commit comments