Exemplo n.º 1
0
    def print_pipelined_requests(self, specs, showreq, showresp, explain, hexdump, ignorecodes, ignoretimeout, fp=sys.stdout):
        """
            Performs a series of pipelined requests, and prints results to the specified
            file descriptor.

            spec: A request specification
            showreq: Print requests
            showresp: Print responses
            explain: Print request explanation
            hexdump: When printing requests or responses, use hex dump output
            ignorecodes: Sequence of return codes to ignore

            Returns True if we have a non-ignored response.
        """
        if explain:
            r = r.freeze(self.settings, self.host)

        if showreq:
            self.wfile.start_log()
        if showresp:
            self.rfile.start_log()

        # write all the requests
        parsed_requests = {}  # spec -> r, req
        for spec in specs:
            try:
                r = language.parse_request(self.settings, spec)
            except language.ParseException, v:
                print >> fp, "Error parsing request spec: %s"%v.msg
                print >> fp, v.marked()
                return
            except language.FileAccessDenied, v:
                print >> fp, "File access error: %s"%v
                return
Exemplo n.º 2
0
    def _preview(is_request):
        if is_request:
            template = "request_preview.html"
        else:
            template = "response_preview.html"

        spec = request.args["spec"]

        args = dict(
            spec = spec,
            section = "main",
            syntaxerror = None,
            error = None,
        )
        if not spec.strip():
            args["error"] = "Can't parse an empty spec."
            return render(template, False, **args)

        try:
            if is_request:
                r = language.parse_request(app.config["pathod"].request_settings, spec)
            else:
                r = language.parse_response(app.config["pathod"].request_settings, spec)
        except language.ParseException, v:
            args["syntaxerror"] = str(v)
            args["marked"] = v.marked()
            return render(template, False, **args)
Exemplo n.º 3
0
    def print_request(self,
                      spec,
                      showreq,
                      showresp,
                      explain,
                      showssl,
                      hexdump,
                      ignorecodes,
                      ignoretimeout,
                      fp=sys.stdout):
        """
            Performs a series of requests, and prints results to the specified
            file descriptor.

            spec: A request specification
            showreq: Print requests
            showresp: Print responses
            explain: Print request explanation
            showssl: Print info on SSL connection
            hexdump: When printing requests or responses, use hex dump output
            ignorecodes: Sequence of return codes to ignore

            Returns True if we have a non-ignored response.
        """
        try:
            r = language.parse_request(self.settings, spec)
        except language.ParseException, v:
            print >> fp, "Error parsing request spec: %s" % v.msg
            print >> fp, v.marked()
            return
Exemplo n.º 4
0
    def _preview(is_request):
        if is_request:
            template = "request_preview.html"
        else:
            template = "response_preview.html"

        spec = request.args["spec"]

        args = dict(
            spec=spec,
            section="main",
            syntaxerror=None,
            error=None,
        )
        if not spec.strip():
            args["error"] = "Can't parse an empty spec."
            return render(template, False, **args)

        try:
            if is_request:
                r = language.parse_request(
                    app.config["pathod"].request_settings, spec)
            else:
                r = language.parse_response(
                    app.config["pathod"].request_settings, spec)
        except language.ParseException, v:
            args["syntaxerror"] = str(v)
            args["marked"] = v.marked()
            return render(template, False, **args)
Exemplo n.º 5
0
    def request(self, spec):
        """
            Return an (httpversion, code, msg, headers, content) tuple.

            May raise language.ParseException, netlib.http.HttpError or
            language.FileAccessDenied.
        """
        r = language.parse_request(self.settings, spec)
        ret = language.serve(r, self.wfile, self.settings, self.host)
        self.wfile.flush()
        return Response(*http.read_response(self.rfile, r.method, None))
Exemplo n.º 6
0
    def request(self, spec):
        """
            Return a PathocResult namedtuple.

            May raise language.ParseException, netlib.http.HttpError or
            language.FileAccessDenied.
        """
        r = language.parse_request(self.settings, spec)
        ret = language.serve(r, self.wfile, self.settings, self.host)
        self.wfile.flush()
        return PathocResult._make(http.read_response(self.rfile, r.method, None))
Exemplo n.º 7
0
    def request(self, spec):
        """
            Return an (httpversion, code, msg, headers, content) tuple.

            May raise language.ParseException, netlib.http.HttpError or
            language.FileAccessDenied.
        """
        r = language.parse_request(self.settings, spec)
        language.serve(r, self.wfile, self.settings, self.address.host)
        self.wfile.flush()
        ret = list(http.read_response(self.rfile, r.method.string(), None))
        ret.append(self.sslinfo)
        return Response(*ret)
Exemplo n.º 8
0
    def print_request(self, spec, showreq, showresp, explain, hexdump, ignorecodes, ignoretimeout, fp=sys.stdout):
        """
            Performs a series of requests, and prints results to the specified
            file descriptor.

            spec: A request specification
            showreq: Print requests
            showresp: Print responses
            explain: Print request explanation
            hexdump: When printing requests or responses, use hex dump output
            ignorecodes: Sequence of return codes to ignore

            Returns True if we have a non-ignored response.
        """
        try:
            r = language.parse_request(self.settings, spec)
        except language.ParseException, v:
            print >> fp, "Error parsing request spec: %s"%v.msg
            print >> fp, v.marked()
            return
Exemplo n.º 9
0
    def pipelined_requests(self, specs):
        """
            Return a list of PathocResult namedtuple's.
            The requests defined by the list of spec are sent using http pipelining.

            May raise language.ParseException, netlib.http.HttpError or
            language.FileAccessDenied.
        """
        parsed_specs = {}  # spec -> r, ret
        for spec in specs:
            r = language.parse_request(self.settings, spec)
            ret = language.serve(r, self.wfile, self.settings, self.host)
            parsed_specs[spec] = r, ret
        self.wfile.flush()
        rval = []
        for spec in specs:
            r, ret = parsed_specs[spec]
            result = PathocResult._make(http.read_response(self.rfile, r.method, None))
            rval.append(result)
        return rval