@@ -112,14 +112,31 @@ def array_or_singleton(claim_spec, values):
112112
113113
114114def _is_subset (a , b ):
115+ # Is 'a' a subset of 'b'
115116 if isinstance (a , list ):
116117 if isinstance (b , list ):
117- return set (b ).issubset (set (a ))
118+ return set (a ).issubset (set (b ))
118119 elif isinstance (b , list ):
119120 return a in b
120121 else :
121122 return a == b
122123
124+ def _intersection (a , b ):
125+ res = None
126+ if isinstance (a , list ):
127+ if isinstance (b , list ):
128+ res = list (set (a ).intersection (set (b )))
129+ else :
130+ if b in a :
131+ res = b
132+ else :
133+ res = []
134+ elif isinstance (b , list ):
135+ if a in b :
136+ res = [a ]
137+ else :
138+ res = []
139+ return res
123140
124141def preferred_to_registered (prefers : dict , supported : dict ,
125142 registration_response : Optional [dict ] = None ):
@@ -136,10 +153,19 @@ def preferred_to_registered(prefers: dict, supported: dict,
136153 if registration_response :
137154 for key , val in registration_response .items ():
138155 if key in REGISTER2PREFERRED :
139- if _is_subset (val , supported .get (REGISTER2PREFERRED [key ])):
156+ # Is the response value with in what this instance supports
157+ _supports = supported .get (REGISTER2PREFERRED [key ])
158+ if _is_subset (val , _supports ):
140159 registered [key ] = val
141160 else :
142- logger .warning (f'OP tells me to do something I do not support: { key } = { val } ' )
161+ logger .warning (
162+ f'OP tells me to do something I do not support: (key) = { val } not within '
163+ f'{ _supports } ' )
164+ _val = _intersection (val , _supports )
165+ if _val :
166+ registered [key ] = _val
167+ else :
168+ raise ValueError ('Not able to support the OPs choice' )
143169 else :
144170 registered [key ] = val # Should I just accept with the OP says ??
145171
0 commit comments