<commit_before># coding=utf-8

from pycolo import Resource
from pycolo.codes import codes
from pycolo import Response
from pycolo.codes import mediaCodes


class DefaultTest(Resource):
    """
    This resource implements a test of specification for the
    ETSI IoT CoAP Plugtests, Paris, France, 24 - 25 March 2012.
    """

    def __int__(self):

        self.title = "Default test resource"

    def performGET(self, request):

        # Check: Type, Code

        # create response
        response = Response(codes.RESP_CONTENT)

        payload =  "Type: %d (%s)\nCode: %d (%s)\nMID: %d" %\
                                     request.getType().ordinal(),\
                                     request.typeString(),\
                                     request.code,\
                                     request.MID

        if request.getToken().length > 0:
            payload.append("Token: ")
            payload.append(request.getTokenString())

        if len(payload) > 64:
            payload.delete(62, len(payload))
            payload.append('>>')


        # set payload
        response.payload = payload
        response.contentType = mediaCodes.text

        # complete the request
        request.respond(response)

    def performPOST(self, request):

        # Check: Type, Code, has Content-Type

        # create new response
        response = Response(codes.RESP_CREATED)

        payload = "Type: %d (%s)\nCode: %d (%s) MID: %d" %\
                                     request.type.ordinal(),\
                                     request.type,\
                                     request.code,\
                                     request.MID

        payload.join("\nCT: %d\nPL: %d" % request.getContentType(), request.payloadSize())

        if request.getToken():
            payload.append("\nTo: ")
            payload.append(request.getTokenString())

        if len(payload) > 64:
            payload.delete(62, payload.length())
            payload.append('>>')

        response.payload = str(payload)
        response.contentType = mediaCodes.TEXT_PLAIN

        response.setLocationPath("/nirvana")

        # complete the request
        request.respond(response)

    def performPUT(self, request):

        # Check: Type, Code, has Content-Type

        # create new response
        """

        :param request:
        """
        response = Response(codes.RESP_CHANGED)

        payload = "Type: %d (%s)\nCode: %d (%s)\nMID: %d" %\
                                     request.getType().ordinal(),\
                                     request.typeString(),\
                                     request.getCode(),\
                                     request.getMID()

        payload.append("\nCT: %d\nPL: %d" % request.getContentType(), request.payloadSize())

        if request.getToken().length > 0:
            payload.append("\nTo: ")
            payload.append(request.getTokenString())

        if payload.length() > 64:
            payload.delete(62, payload.length())
            payload.append('>>')

        response.payload = str(payload)
        response.contentType = mediaCodes.text


        # complete the request
        request.respond(response)


    def performDELETE(self, request):

        # Check: Type, Code, has Content-Type

        # create new response
        """

        :param request:
        """
        response = Response(codes.RESP_DELETED)

        payload = "Type: %d (%s)\nCode: %d (%s)\nMID: %d" %\
                                     request.getType().ordinal(),\
                                     request.typeString(),\<commit_msg>Correction<commit_after># coding=utf-8

from pycolo import Resource
from pycolo.codes import codes
from pycolo import Response
from pycolo.codes import mediaCodes


class DefaultTest(Resource):
    """
    This resource implements a test of specification for the
    ETSI IoT CoAP Plugtests, Paris, France, 24 - 25 March 2012.
    """

    def __init__(self):

        self.title = "Default test resource"

    def performGET(self, request):

        # Check: Type, Code

        # create response
        response = Response(codes.RESP_CONTENT)

        payload =  "Type: %d (%s)\nCode: %d (%s)\nMID: %d" %\
                                     request.getType().ordinal(),\
                                     request.typeString(),\
                                     request.code,\
                                     request.MID

        if request.getToken().length > 0:
            payload.append("Token: ")
            payload.append(request.getTokenString())

        if len(payload) > 64:
            payload.delete(62, len(payload))
            payload.append('>>')


        # set payload
        response.payload = payload
        response.contentType = mediaCodes.text

        # complete the request
        request.respond(response)

    def performPOST(self, request):

        # Check: Type, Code, has Content-Type

        # create new response
        response = Response(codes.RESP_CREATED)

        payload = "Type: %d (%s)\nCode: %d (%s) MID: %d" %\
                                     request.type.ordinal(),\
                                     request.type,\
                                     request.code,\
                                     request.MID

        payload.join("\nCT: %d\nPL: %d" % request.getContentType(), request.payloadSize())

        if request.getToken():
            payload.append("\nTo: ")
            payload.append(request.getTokenString())

        if len(payload) > 64:
            payload.delete(62, payload.length())
            payload.append('>>')

        response.payload = str(payload)
        response.contentType = mediaCodes.TEXT_PLAIN

        response.setLocationPath("/nirvana")

        # complete the request
        request.respond(response)

    def performPUT(self, request):

        # Check: Type, Code, has Content-Type

        # create new response
        """

        :param request:
        """
        response = Response(codes.RESP_CHANGED)

        payload = "Type: %d (%s)\nCode: %d (%s)\nMID: %d" %\
                                     request.getType().ordinal(),\
                                     request.typeString(),\
                                     request.getCode(),\
                                     request.getMID()

        payload.append("\nCT: %d\nPL: %d" % request.getContentType(), request.payloadSize())

        if request.getToken().length > 0:
            payload.append("\nTo: ")
            payload.append(request.getTokenString())

        if payload.length() > 64:
            payload.delete(62, payload.length())
            payload.append('>>')

        response.payload = str(payload)
        response.contentType = mediaCodes.text


        # complete the request
        request.respond(response)


    def performDELETE(self, request):
        response = Response(codes.RESP_DELETED)

        payload = "Type: %d (%s)\nCode: %d (%s)\nMID: %d" %\
                                     request.getType().ordinal(),\
                                     request.typeString(),\
{'fraction_non_alphanumeric': 0.1161001538676738, 'fraction_numerical': 0.006434466358931319, 'mean_word_length': 1.4991261796574624, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4186769', 'n_tokens_mistral': 1938, 'n_tokens_neox': 1803, 'n_words': 409}