@lru_cache(maxsize=<NUM_LIT:200>)<EOL><INDENT>def selectPolicy(self, origin, request_method=None):<DEDENT>
ret_origin = None<EOL>policyname = None<EOL>if self.matchstrategy in ("<STR_LIT>", "<STR_LIT>"):<EOL><INDENT>for pol in self.activepolicies:<EOL><INDENT>policy=self.policies[pol]<EOL>ret_origin = None<EOL>policyname = policy.name<EOL>if policyname == "<STR_LIT>":<EOL><INDENT>break<EOL><DEDENT>if self.matchstrategy == "<STR_LIT>":<EOL><INDENT>if policy.methods != "<STR_LIT:*>" and not CORS.matchlist(request_method, policy.methods, case_sensitive=True):<EOL><INDENT>continue<EOL><DEDENT><DEDENT>if origin and policy.match:<EOL><INDENT>if CORS.matchlist(origin, policy.match):<EOL><INDENT>ret_origin = origin<EOL><DEDENT><DEDENT>elif policy.origin == "<STR_LIT>":<EOL><INDENT>ret_origin = origin<EOL><DEDENT>elif policy.origin:<EOL><INDENT>ret_origin = policy.origin<EOL><DEDENT>if ret_origin:<EOL><INDENT>break<EOL><DEDENT><DEDENT><DEDENT>return policyname, ret_origin<EOL>
Based on the matching strategy and the origin and optionally the requested method a tuple of policyname and origin to pass back is returned.