From eb1f2c3fc40ccfc0db60776412add6a35af93bf9 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Tue, 24 Jul 2012 21:51:43 +1200 Subject: [PATCH] Add option to specify craft anchor point. --- libpathod/pathod.py | 10 +++++----- pathod | 5 +++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/libpathod/pathod.py b/libpathod/pathod.py index 90064581c..0ab7e9157 100644 --- a/libpathod/pathod.py +++ b/libpathod/pathod.py @@ -83,8 +83,8 @@ class PathodHandler(tcp.BaseHandler): if i[0].match(path): return self.serve_crafted(i[1], request_log) - if not self.server.nocraft and path.startswith(self.server.prefix): - spec = urllib.unquote(path)[len(self.server.prefix):] + if not self.server.nocraft and path.startswith(self.server.craftanchor): + spec = urllib.unquote(path)[len(self.server.craftanchor):] try: crafted = rparse.parse_response(self.server.request_settings, spec) except rparse.ParseException, v: @@ -149,14 +149,14 @@ class PathodHandler(tcp.BaseHandler): class Pathod(tcp.TCPServer): LOGBUF = 500 def __init__( self, - addr, ssloptions=None, prefix="/p/", staticdir=None, anchors=None, + addr, ssloptions=None, craftanchor="/p/", staticdir=None, anchors=None, sizelimit=None, noweb=False, nocraft=False, noapi=False ): """ addr: (address, port) tuple. If port is 0, a free port will be automatically chosen. ssloptions: a dictionary containing certfile and keyfile specifications. - prefix: string specifying the prefix at which to anchor response generation. + craftanchor: string specifying the path under which to anchor response generation. staticdir: path to a directory of static resources, or None. anchors: A list of (regex, spec) tuples, or None. sizelimit: Limit size of served data. @@ -164,7 +164,7 @@ class Pathod(tcp.TCPServer): tcp.TCPServer.__init__(self, addr) self.ssloptions = ssloptions self.staticdir = staticdir - self.prefix = prefix + self.craftanchor = craftanchor self.sizelimit = sizelimit self.noweb, self.nocraft, self.noapi = noweb, nocraft, noapi if not noapi: diff --git a/pathod b/pathod index a5cc02cad..df044ae73 100755 --- a/pathod +++ b/pathod @@ -10,6 +10,10 @@ if __name__ == "__main__": "-a", dest='anchors', default=[], type=str, action="append", metavar="ANCHOR", help='Add an anchor. Specified as a string with the form pattern=pagespec' ) + parser.add_argument( + "-c", dest='craftanchor', default="/p/", type=str, + help='Anchorpoint for URL crafting commands.' + ) parser.add_argument( "-d", dest='staticdir', default=None, type=str, help='Directory for static files.' @@ -89,6 +93,7 @@ if __name__ == "__main__": try: pd = pathod.Pathod( (args.address, args.port), + craftanchor = args.craftanchor, ssloptions = ssl, staticdir = args.staticdir, anchors = alst,