def post(self):
        try:
            """ Send notifications """
            if not self.can("send_notification"):
                self.send_response(FORBIDDEN, dict(error="No permission to send notification"))
                return

            # if request body is json entity
            data = self.json_decode(self.request.body)

            data = self.validate_data(data)

            # Hook
            if 'extra' in data:
                if data['extra'] in 'processor':
                    try:
                        proc = import_module('hooks.' + data['extra']['processor'])
                        data = proc.process_pushnotification_payload(data)
                    except Exception as ex:
                        self.send_response(BAD_REQUEST, dict(error=str(ex)))

            if not self.token:
                self.token = data.get('token', None)

            # application specific data
            extra = data.get('extra', {})

            device = data.get('device', DEVICE_TYPE_IOS).lower()
            channel = data.get('channel', 'default')
            token = self.db.tokens.find_one({'token': self.token})

            if not token:
                token = EntityBuilder.build_token(self.token, device, self.appname, channel)
                if not self.can("create_token"):
                    self.send_response(BAD_REQUEST, dict(error="Unknow token and you have no permission to create"))
                    return
                try:
                    # TODO check permission to insert
                    self.db.tokens.insert(token, safe=True)
                except Exception as ex:
                    self.send_response(INTERNAL_SERVER_ERROR, dict(error=str(ex)))

            if device == DEVICE_TYPE_SMS:
                data.setdefault('sms', {})
                data['sms'].setdefault('to', data.get('token', ''))
                data['sms'].setdefault('message', data.get('message', ''))
                sms = self.smsconnections[self.app['shortname']][0]
                sms.process(token=data['token'], alert=data['alert'], extra=extra, sms=data['sms'])
                self.send_response(ACCEPTED)
            elif device == DEVICE_TYPE_IOS:
                # Use sliptlines trick to remove line ending (only for iOs).
                if type(data['alert']) is not dict:
                    alert = ''.join(data['alert'].splitlines())
                else:
                    alert = data['alert']
                data.setdefault('apns', {})
                data['apns'].setdefault('badge', data.get('badge', None))
                data['apns'].setdefault('sound', data.get('sound', None))
                data['apns'].setdefault('custom', data.get('custom', None))
                self.get_apns_conn().process(token=self.token, alert=alert, extra=extra, apns=data['apns'])
                self.send_response(ACCEPTED)
            elif device == DEVICE_TYPE_ANDROID:
                data.setdefault('gcm', {})
                try:
                    gcm = self.gcmconnections[self.app['shortname']][0]
                    response = gcm.process(token=[self.token], alert=data['alert'], extra=data['extra'], gcm=data['gcm'])
                    responsedata = response.json()
                    if responsedata['failure'] == 0:
                        self.send_response(ACCEPTED)
                except GCMUpdateRegIDsException as ex:
                    self.send_response(ACCEPTED)
                except GCMInvalidRegistrationException as ex:
                    self.send_response(BAD_REQUEST, dict(error=str(ex), regids=ex.regids))
                except GCMNotRegisteredException as ex:
                    self.send_response(BAD_REQUEST, dict(error=str(ex), regids=ex.regids))
                except GCMException as ex:
                    self.send_response(INTERNAL_SERVER_ERROR, dict(error=str(ex)))
            elif device == DEVICE_TYPE_WNS:
                data.setdefault('wns', {})
                wns = self.wnsconnections[self.app['shortname']][0]
                wns.process(token=data['token'], alert=data['alert'], extra=extra, wns=data['wns'])
                self.send_response(ACCEPTED)
            elif device == DEVICE_TYPE_MPNS:
                data.setdefault('mpns', {})
                mpns = self.mpnsconnections[self.app['shortname']][0]
                mpns.process(token=data['token'], alert=data['alert'], extra=extra, mpns=data['mpns'])
                self.send_response(ACCEPTED)
            else:
                self.send_response(BAD_REQUEST, dict(error='Invalid device type'))
            logmessage = 'Message length: %s, Access key: %s' %(len(data['alert']), self.appkey)
            self.add_to_log('%s notification' % self.appname, logmessage)
        except Exception as ex:
            import traceback
            traceback.print_exc()
            self.send_response(INTERNAL_SERVER_ERROR, dict(error=str(ex)))
dataset/ETHPy150Open airnotifier/airnotifier/api/push.py/PushHandler.post/swapped operands of `in`