def serializer(self, req):
<EOL>content_types = self.method.serializers.get_types()<EOL>content_type = req.accept.best_match(content_types)<EOL>if content_type is None:<EOL><INDENT>raise webob.exc.HTTPNotAcceptable()<EOL><DEDENT>try:<EOL><INDENT>serializer = self.method.serializers(content_type)<EOL><DEDENT>except KeyError:<EOL><INDENT>raise webob.exc.HTTPNotAcceptable()<EOL><DEDENT>if hasattr(serializer, '<STR_LIT>'):<EOL><INDENT>for ext in reversed(self.extensions):<EOL><INDENT>try:<EOL><INDENT>serializer.attach(ext.serializers(content_type))<EOL><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT>return content_type, serializer<EOL>
Selects and returns the serializer to use, based on the
serializers declared on the action method and its extensions.
The returned content type is selected based on the types
available and the best match generated from the HTTP `Accept`
header.  Raises `HTTPNotAcceptable` if the request cannot be
serialized to an acceptable media type.  Returns a tuple of
the content type and the serializer.