예제 #1
0
파일: command.py 프로젝트: xmnr/atk
    def load(self, arguments):
        """
        Looks through the arguments to find directives specifying the message
        (ie, -M, --stdin, etc). If none are found, the defaultRequest/
        defaultResponse are used.
        """

        request = arguments.messageType == REQUEST
        type = "request" if request else "response"
        if arguments.message:
            if request: message = parseRequest(arguments.message)
            else: message = parseResponse(arguments.message)
        elif arguments.stdin:
            info(
                "Reading {} from stdin".format(type),
                arguments.verbose
            )
            if request: message = readRequest()
            else: message = self.readResponse()
        elif arguments.file:
            info(
                "Reading {} from {}".format(type, arguments.file),
                arguments.verbose
            )
            f = open(arguments.file, "r")
            if request: message = readRequest(f)
            else: message = self.readResponse(f)
        else:
            if request: message = self.defaultRequest
            else: message = self.defaultResponse

        return message
예제 #2
0
    def testParsingResponsesWithSpaceInReason(self):

        r = "\r\n".join((
            "HTTP/1.1 404 NOT FOUND",
            "Content-type: text/plain",
            "",
            "No idea."
        ))
        self.assertEqual(
            parseResponse(r),
            {
                "version": "HTTP/1.1",
                "status": "404",
                "reason": "NOT FOUND",
                "headers": (
                    ("Content-type", "text/plain"),
                ),
                "entity": "No idea."
            }
        )
예제 #3
0
    def testParsingResponses(self):

        r = "\r\n".join((
            "HTTP/1.1 200 OK",
            "Content-type: text/plain",
            "heaDer: vAlue",
            "",
            "B"
        ))
        self.assertEqual(
            parseResponse(r),
            {
                "version": "HTTP/1.1",
                "status": "200",
                "reason": "OK",
                "entity": "B",
                "headers": (
                    ("Content-type", "text/plain"),
                    ("heaDer", "vAlue")
                )
            }
        )
예제 #4
0
파일: __init__.py 프로젝트: xmnr/atk
def readResponse(file=stdin):
    """
    Reads an entire file & parses it as a response.
    """

    return parseResponse(file.read())