1+ # -*- test-case-name: openid.test.test_ax -*-
12"""Implements the OpenID attribute exchange specification, version 1.0
23as of svn revision 370 from svn.openid.net.
34
@@ -567,16 +568,22 @@ class FetchResponse(AXKeyValueMessage):
567568 """
568569 mode = 'fetch_response'
569570
570- def __init__ (self , update_url = None ):
571+ def __init__ (self , request = None , update_url = None ):
572+ """
573+ @param request: When supplied, I will use namespace aliases
574+ that match those in this request. I will also check to
575+ make sure I do not respond with attributes that were not
576+ requested.
577+
578+ @param update_url: By default, C{update_url} is taken from the
579+ request. But if you do not supply the request, you may set
580+ the C{update_url} here.
581+ """
571582 AXKeyValueMessage .__init__ (self )
572583 self .update_url = update_url
584+ self .request = request
573585
574- # This takes an argument, when base getExtensionArgs
575- # doesn't. That's by design. If you call it with the base
576- # arguments, it'll work as expected.
577- # XXX Document what happens with the request set
578- #pylint:disable-msg=W0221
579- def getExtensionArgs (self , request = None ):
586+ def getExtensionArgs (self ):
580587 """Serialize this object into arguments in the attribute
581588 exchange namespace
582589
@@ -589,19 +596,19 @@ def getExtensionArgs(self, request=None):
589596
590597 zero_value_types = []
591598
592- if request is not None :
599+ if self . request is not None :
593600 # Validate the data in the context of the request (the
594601 # same attributes should be present in each, and the
595602 # counts in the response must be no more than the counts
596603 # in the request)
597604
598605 for type_uri in self .data :
599- if type_uri not in request :
606+ if type_uri not in self . request :
600607 raise KeyError (
601608 'Response attribute not present in request: %r'
602609 % (type_uri ,))
603610
604- for attr_info in request .iterAttrs ():
611+ for attr_info in self . request .iterAttrs ():
605612 # Copy the aliases from the request so that reading
606613 # the response in light of the request is easier
607614 if attr_info .alias is None :
@@ -634,7 +641,8 @@ def getExtensionArgs(self, request=None):
634641 kv_args ['type.' + alias ] = attr_info .type_uri
635642 kv_args ['count.' + alias ] = '0'
636643
637- update_url = (request and request .update_url ) or self .update_url
644+ update_url = ((self .request and self .request .update_url )
645+ or self .update_url )
638646
639647 if update_url :
640648 ax_args ['update_url' ] = update_url
0 commit comments