
from superdesk.io.feed_parsers.nitf import NITFFeedParser
from superdesk.io import register_feed_parser


class PAFeedParser(NITFFeedParser):
    """
    NITF Parser extension for Press Association, it maps the category meta tag to an anpa category
    """
    NAME = 'pa_nitf'

    def _category_mapping(self, elem):
        """
        Map the category supplied by PA to a best guess anpa_category in the system
        :param elem:
        :return: anpa category list qcode
        """
        category = elem.get('content')[:1].upper()
        if category in ('S', 'R', 'F'):
            return [{'qcode': 'S'}]
        if category == 'Z':
            return [{'qcode': 'V'}]
        return [{'qcode': 'I'}]

    def __init__(self):
        self.MAPPING = {'anpa_category': {'xpath': "head/meta/[@name='category']", 'filter': self._category_mapping}}
        super().__init__()

register_feed_parser(PAFeedParser.NAME, PAFeedParser())


from superdesk.io.feed_parsers.nitf import NITFFeedParser
from superdesk.io import register_feed_parser


class PAFeedParser(NITFFeedParser):
    """
    NITF Parser extension for Press Association, it maps the category meta tag to an anpa category
    """
    NAME = 'pa_nitf'

    def _category_mapping(self, elem):
        """
        Map the category supplied by PA to a best guess anpa_category in the system
        :param elem:
        :return: anpa category list qcode
        """
        if elem.get('content') is not None:
            category = elem.get('content')[:1].upper()
            if category in {'S', 'R', 'F'}:
                return [{'qcode': 'S'}]
            if category == 'Z':
                return [{'qcode': 'V'}]
        return [{'qcode': 'I'}]

    def __init__(self):
        self.MAPPING = {'anpa_category': {'xpath': "head/meta/[@name='category']", 'filter': self._category_mapping}}
        super().__init__()

register_feed_parser(PAFeedParser.NAME, PAFeedParser())

Use a set for comparison
Use a set for comparison

  
  from superdesk.io.feed_parsers.nitf import NITFFeedParser
  from superdesk.io import register_feed_parser
  
  
  class PAFeedParser(NITFFeedParser):
      """
      NITF Parser extension for Press Association, it maps the category meta tag to an anpa category
      """
      NAME = 'pa_nitf'
  
      def _category_mapping(self, elem):
          """
          Map the category supplied by PA to a best guess anpa_category in the system
          :param elem:
          :return: anpa category list qcode
          """
+         if elem.get('content') is not None:
-         category = elem.get('content')[:1].upper()
+             category = elem.get('content')[:1].upper()
-         if category in ('S', 'R', 'F'):
+             if category in {'S', 'R', 'F'}:
-             return [{'qcode': 'S'}]
+                 return [{'qcode': 'S'}]
-         if category == 'Z':
+             if category == 'Z':
-             return [{'qcode': 'V'}]
+                 return [{'qcode': 'V'}]
          return [{'qcode': 'I'}]
  
      def __init__(self):
          self.MAPPING = {'anpa_category': {'xpath': "head/meta/[@name='category']", 'filter': self._category_mapping}}
          super().__init__()
  
  register_feed_parser(PAFeedParser.NAME, PAFeedParser())
  
Use a set for comparison
## Code Before:

from superdesk.io.feed_parsers.nitf import NITFFeedParser
from superdesk.io import register_feed_parser


class PAFeedParser(NITFFeedParser):
    """
    NITF Parser extension for Press Association, it maps the category meta tag to an anpa category
    """
    NAME = 'pa_nitf'

    def _category_mapping(self, elem):
        """
        Map the category supplied by PA to a best guess anpa_category in the system
        :param elem:
        :return: anpa category list qcode
        """
        category = elem.get('content')[:1].upper()
        if category in ('S', 'R', 'F'):
            return [{'qcode': 'S'}]
        if category == 'Z':
            return [{'qcode': 'V'}]
        return [{'qcode': 'I'}]

    def __init__(self):
        self.MAPPING = {'anpa_category': {'xpath': "head/meta/[@name='category']", 'filter': self._category_mapping}}
        super().__init__()

register_feed_parser(PAFeedParser.NAME, PAFeedParser())

## Instruction:
Use a set for comparison
## Code After:

from superdesk.io.feed_parsers.nitf import NITFFeedParser
from superdesk.io import register_feed_parser


class PAFeedParser(NITFFeedParser):
    """
    NITF Parser extension for Press Association, it maps the category meta tag to an anpa category
    """
    NAME = 'pa_nitf'

    def _category_mapping(self, elem):
        """
        Map the category supplied by PA to a best guess anpa_category in the system
        :param elem:
        :return: anpa category list qcode
        """
        if elem.get('content') is not None:
            category = elem.get('content')[:1].upper()
            if category in {'S', 'R', 'F'}:
                return [{'qcode': 'S'}]
            if category == 'Z':
                return [{'qcode': 'V'}]
        return [{'qcode': 'I'}]

    def __init__(self):
        self.MAPPING = {'anpa_category': {'xpath': "head/meta/[@name='category']", 'filter': self._category_mapping}}
        super().__init__()

register_feed_parser(PAFeedParser.NAME, PAFeedParser())
