diff options
-rw-r--r-- | libpathod/pathoc.py | 22 | ||||
-rwxr-xr-x | pathoc | 25 | ||||
-rwxr-xr-x | pathod | 2 | ||||
-rw-r--r-- | test/test_rparse.py | 1 |
4 files changed, 48 insertions, 2 deletions
diff --git a/libpathod/pathoc.py b/libpathod/pathoc.py new file mode 100644 index 00000000..5ad1bd26 --- /dev/null +++ b/libpathod/pathoc.py @@ -0,0 +1,22 @@ +from netlib import tcp, http +import rparse + + +class PathocError(Exception): pass + + +class Pathoc(tcp.TCPClient): + def __init__(self, ssl, host, port, clientcert): + try: + tcp.TCPClient.__init__(self, ssl, host, port, clientcert) + except tcp.NetLibError, v: + raise PathocError(v) + + def request(self, spec): + r = rparse.parse_request({}, spec) + r.serve(self.wfile) + self.wfile.flush() + + line = self.rfile.readline() + print line + @@ -0,0 +1,25 @@ +#!/usr/bin/env python +import argparse, sys +from libpathod import pathoc, version + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='A perverse HTTP client.') + parser.add_argument('--port', type=int, default=None, help="Port. Defaults to 80, or 443 if SSL is active.") + parser.add_argument('--ssl', action="store_true", default=False, help="Connect with SSL.") + parser.add_argument('host', type=str, help='Host to connect to') + parser.add_argument('request', type=str, nargs="+", help='Request specification') + + args = parser.parse_args() + + if args.port is None: + port = 443 if args.ssl else 80 + else: + port = args.port + + try: + p = pathoc.Pathoc(args.ssl, args.host, port, None) + for i in args.request: + p.request(i) + except pathoc.PathocError, v: + print >> sys.stderr, str(v) + sys.exit(1) @@ -3,7 +3,7 @@ import argparse, sys from libpathod import pathod, utils, version if __name__ == "__main__": - parser = argparse.ArgumentParser(description='Process some integers.') + parser = argparse.ArgumentParser(description='A pathological HTTP/S daemon.') parser.add_argument("-p", dest='port', default=9999, type=int, help='Port. Specify 0 to pick an arbitrary empty port.') parser.add_argument("-l", dest='address', default="0.0.0.0", type=str, help='Listening address.') parser.add_argument( diff --git a/test/test_rparse.py b/test/test_rparse.py index a25bbc74..9f330f51 100644 --- a/test/test_rparse.py +++ b/test/test_rparse.py @@ -211,7 +211,6 @@ class TestParseRequest: assert str(r) - class TestParseResponse: def test_parse_err(self): tutils.raises(rparse.ParseException, rparse.parse_response, {}, "400:msg,b:") |