@@ -140,14 +140,16 @@ def return_response(self, method, path, data, headers, response):
140140 if req_action == 'Subscribe' and response .status_code < 400 :
141141 response_data = xmltodict .parse (response .content )
142142 topic_arn = (req_data .get ('TargetArn' ) or req_data .get ('TopicArn' ))[0 ]
143+ filter_policy = (req_data .get ('FilterPolicy' ) or [None ])[0 ]
143144 attributes = get_subscribe_attributes (req_data )
144145 sub_arn = response_data ['SubscribeResponse' ]['SubscribeResult' ]['SubscriptionArn' ]
145146 do_subscribe (
146147 topic_arn ,
147148 req_data ['Endpoint' ][0 ],
148149 req_data ['Protocol' ][0 ],
149150 sub_arn ,
150- attributes
151+ attributes ,
152+ filter_policy
151153 )
152154 if req_action == 'CreateTopic' and response .status_code < 400 :
153155 response_data = xmltodict .parse (response .content )
@@ -173,7 +175,7 @@ def publish_message(topic_arn, req_data, subscription_arn=None):
173175 for subscriber in SNS_SUBSCRIPTIONS .get (topic_arn , []):
174176 if subscription_arn not in [None , subscriber ['SubscriptionArn' ]]:
175177 continue
176- filter_policy = json .loads (subscriber .get ('FilterPolicy' , '{}' ) )
178+ filter_policy = json .loads (subscriber .get ('FilterPolicy' ) or '{}' )
177179 message_attributes = get_message_attributes (req_data )
178180 if not check_filter_policy (filter_policy , message_attributes ):
179181 continue
@@ -231,7 +233,7 @@ def do_delete_topic(topic_arn):
231233 SNS_SUBSCRIPTIONS .pop (topic_arn , None )
232234
233235
234- def do_subscribe (topic_arn , endpoint , protocol , subscription_arn , attributes ):
236+ def do_subscribe (topic_arn , endpoint , protocol , subscription_arn , attributes , filter_policy = None ):
235237 # An endpoint may only be subscribed to a topic once. Subsequent
236238 # subscribe calls do nothing (subscribe is idempotent).
237239 for existing_topic_subscription in SNS_SUBSCRIPTIONS .get (topic_arn , []):
@@ -244,6 +246,7 @@ def do_subscribe(topic_arn, endpoint, protocol, subscription_arn, attributes):
244246 'Endpoint' : endpoint ,
245247 'Protocol' : protocol ,
246248 'SubscriptionArn' : subscription_arn ,
249+ 'FilterPolicy' : filter_policy
247250 }
248251 subscription .update (attributes )
249252 SNS_SUBSCRIPTIONS [topic_arn ].append (subscription )
@@ -379,7 +382,7 @@ def create_sqs_message_attributes(subscriber, attributes):
379382 if value ['Type' ] == 'Binary' :
380383 attribute ['BinaryValue' ] = value ['Value' ]
381384 else :
382- attribute ['StringValue' ] = value ['Value' ]
385+ attribute ['StringValue' ] = str ( value ['Value' ])
383386 message_attributes [key ] = attribute
384387
385388 return message_attributes
@@ -400,6 +403,9 @@ def get_message_attributes(req_data):
400403 elif binary_value is not None :
401404 attribute ['Value' ] = binary_value
402405
406+ if attribute ['Type' ] == 'Number' :
407+ attribute ['Value' ] = float (attribute ['Value' ])
408+
403409 attributes [name ] = attribute
404410 x += 1
405411 else :
0 commit comments