def send(self, test=None):
        # Has one of the messages caused an inactive recipient error?
        inactive_recipient = False

        # Check messages for completeness prior to attempting to send
        self._check_values()

        # If test is not specified, attempt to read the Django setting
        if test is None:
            try:
                from django.conf import settings as django_settings
                test = getattr(django_settings, "POSTMARK_TEST_MODE", None)
            except ImportError:
                pass

        # Split up into groups of 500 messages for sending
        for messages in _chunks(self.messages, PMBatchMail.MAX_MESSAGES):
            json_message = []
            for message in messages:
                json_message.append(message.to_json_message())

            req = Request(
                __POSTMARK_URL__ + 'email/batch',
                json.dumps(json_message, cls=PMJSONEncoder).encode('utf8'),
                {
                    'Accept': 'application/json',
                    'Content-Type': 'application/json',
                    'X-Postmark-Server-Token': self.__api_key,
                    'User-agent': self.__user_agent
                }
            )

            # If this is a test, just print the message
            if test:
                print('JSON message is:\n%s' % json.dumps(json_message, cls=PMJSONEncoder))
                continue

            # Attempt send
            try:
                result = urlopen(req)
                jsontxt = result.read().decode()
                result.close()
                if result.code == 200:
                    results = json.loads(jsontxt)
                    for i, res in enumerate(results):
                        self.__messages[i].message_id = res.get("MessageID", None)
                else:
                    raise PMMailSendException((result.code, result.msg) % 'Return code %d: %s')
            except HTTPError as err:
                if err.code == 401:
                    raise PMMailUnauthorizedException('Sending Unauthorized - incorrect API key.', err)
                elif err.code == 422:
                    try:
                        jsontxt = err.read().decode()
                        jsonobj = json.loads(jsontxt)
                        desc = jsonobj['Message']
                        error_code = jsonobj['ErrorCode']
                    except KeyError:
                        raise PMMailUnprocessableEntityException('Unprocessable Entity: Description not given')

                    if error_code == 406:
                        # One of the message recipients was inactive. Postmark still sends the
                        # rest of the messages that have active recipients. Continue sending
                        # the rest of the chunks.
                        inactive_recipient = True
                        continue

                    raise PMMailUnprocessableEntityException('Unprocessable Entity: %s' % desc)
                elif err.code == 500:
                    raise PMMailServerErrorException('Internal server error at Postmark. Admins have been alerted.', err)
            except URLError as err:
                if hasattr(err, 'reason'):
                    raise PMMailURLException('URLError: Failed to reach the server: %s (See "inner_exception" for details)' % err.reason, err)
                elif hasattr(err, 'code'):
                    raise PMMailURLException('URLError: %d: The server couldn\'t fufill the request. (See "inner_exception" for details)' % err.code, err)
                else:
                    raise PMMailURLException('URLError: The server couldn\'t fufill the request. (See "inner_exception" for details)', err)

        if inactive_recipient:
            raise PMMailInactiveRecipientException('You tried to send email to a recipient that has been marked as inactive.')

        return True
dataset/ETHPy150Open themartorana/python-postmark/postmark/core.py/PMBatchMail.send/swapped operands of `%`