<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def select_formatter(self, request, resource):
 """ Select appropriate formatter based on the request. :param request: the HTTP request :param resource: the invoked resource """


        # 1. get from resource
        if resource.mapper:
            return resource.mapper
        # 2. get from url
        mapper_name = self._get_name_from_url(request)
        if mapper_name:
            return self._get_mapper(mapper_name)
        # 3. get from accept header
        mapper_name = self._get_name_from_accept(request)
        if mapper_name:
            return self._get_mapper(mapper_name)
        # 4. use resource's default
        if resource.default_mapper:
            return resource.default_mapper
        # 5. use manager's default
        return self._get_default_mapper()