def extract(self, msg):
def normal(key):<EOL><INDENT>v = msg.get(key)<EOL>if v is None:<EOL><INDENT>return v<EOL><DEDENT>normalizer = self.normalizers.get(key, lambda x: x)<EOL>return normalizer(v)<EOL><DEDENT>def odict(keys):<EOL><INDENT>return collections.OrderedDict((k, normal(k)) for k in keys)<EOL><DEDENT>def match(m):<EOL><INDENT>return (msg.get(k) in v for k, v in m.items()) if m else ()<EOL><DEDENT>accept = all(match(self.accept))<EOL>reject = any(match(self.reject))<EOL>if reject or not accept:<EOL><INDENT>keys = ()<EOL><DEDENT>elif self.keys_by_type is None:<EOL><INDENT>keys = [k for k in msg.keys() if k not in self.omit]<EOL><DEDENT>else:<EOL><INDENT>keys = self.keys_by_type.get(msg.get('<STR_LIT:type>'))<EOL><DEDENT>return odict(keys)<EOL>
Yield an ordered dictionary if msg['type'] is in keys_by_type.