<commit_before># -*- test-case-name: vumi.transports.infobip.tests.test_infobip_ussd -*-
"""Infobip USSD transport."""

import json

from twisted.internet.defer import inlineCallbacks
from vumi.message import TransportUserMessage
from vumi.transports.httprpc import HttpRpcTransport


class InfobipUssdTransport(HttpRpcTransport):
    """Infobip USSD transport."""

    METHOD_TO_EVENT = {
        "status": TransportUserMessage.SESSION_NONE,
        "start": TransportUserMessage.SESSION_NEW,
        "response": TransportUserMessage.SESSION_RESUME,
        "end": TransportUserMessage.SESSION_CLOSE,
        }

    def handle_raw_inbound_message(self, msgid, request):
        parts = request.path.split('/')
        ussd_session_id = parts[-2]
        session_method = parts[-1]
        session_event = self.METHOD_TO_EVENT.get(session_method,
                                             TransportUserMessage.SESSION_NONE)
        req_data = json.load(request.content)
        msisdn = req_data["msisdn"]
        content = req_data["text"]
        to_addr = req_data["shortCode"]

        transport_metadata = {'session_id': ussd_session_id}

        self.publish_message(
            message_id=msgid,
            content=content,
            to_addr=to_addr,
            from_addr=msisdn,
            session_event=session_event,
            transport_name=self.transport_name,
            transport_type=self.config.get('transport_type', 'ussd'),
            transport_metadata=transport_metadata,
        )

    def handle_outbound_message(self, message):
        if message.payload.get('in_reply_to') and 'content' in message.payload:
            should_close = (message['session_event']
                            == TransportUserMessage.SESSION_CLOSE)
            response_data = {
                "shouldClose": should_close,
                "ussdMenu": message['content'],
                "responseExitCode": 200,
                "responseMessage": "",
                }
            self.finishRequest(
                    message['in_reply_to'],
                    json.dumps(response_data))
<commit_msg>undoing infobip specific change<commit_after># -*- test-case-name: vumi.transports.infobip.tests.test_infobip_ussd -*-
"""Infobip USSD transport."""

import json

from twisted.internet.defer import inlineCallbacks
from vumi.message import TransportUserMessage
from vumi.transports.httprpc import HttpRpcTransport


class InfobipUssdTransport(HttpRpcTransport):
    """Infobip USSD transport."""

    METHOD_TO_EVENT = {
        "status": TransportUserMessage.SESSION_NONE,
        "start": TransportUserMessage.SESSION_NEW,
        "response": TransportUserMessage.SESSION_RESUME,
        "end": TransportUserMessage.SESSION_CLOSE,
        }

    def handle_raw_inbound_message(self, msgid, request):
        parts = request.path.split('/')
        ussd_session_id = parts[-2]
        session_method = parts[-1]
        session_event = self.METHOD_TO_EVENT.get(session_method,
                                             TransportUserMessage.SESSION_NONE)
        req_data = json.load(request.content)
        msisdn = req_data["msisdn"]
        content = req_data["text"]
        to_addr = req_data["shortCode"]
        provider = req_data.get("unknown", "")  # TODO: fill-in field

        transport_metadata = {'session_id': ussd_session_id}
        self.publish_message(
                message_id=msgid,
                content=content,
                to_addr=to_addr,
                from_addr=msisdn,
                provider=provider,
                session_event=session_event,
                transport_name=self.transport_name,
                transport_type=self.config.get('transport_type'),
                transport_metadata=transport_metadata,
                )

    def handle_outbound_message(self, message):
        if message.payload.get('in_reply_to') and 'content' in message.payload:
            should_close = (message['session_event']
                            == TransportUserMessage.SESSION_CLOSE)
            response_data = {
                "shouldClose": should_close,
                "ussdMenu": message['content'],
                "responseExitCode": 200,
                "responseMessage": "",
                }
            self.finishRequest(
                    message['in_reply_to'],
                    json.dumps(response_data))

{'fraction_non_alphanumeric': 0.09581247155211653, 'fraction_numerical': 0.002275830678197542, 'mean_word_length': 2.2411504424778763, 'pattern_counts': {'":': 16, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1872481', 'n_tokens_mistral': 1217, 'n_tokens_neox': 1167, 'n_words': 190}