Add option to specify craft anchor point.
This commit is contained in:
parent
97fe026c32
commit
eb1f2c3fc4
|
@ -83,8 +83,8 @@ class PathodHandler(tcp.BaseHandler):
|
||||||
if i[0].match(path):
|
if i[0].match(path):
|
||||||
return self.serve_crafted(i[1], request_log)
|
return self.serve_crafted(i[1], request_log)
|
||||||
|
|
||||||
if not self.server.nocraft and path.startswith(self.server.prefix):
|
if not self.server.nocraft and path.startswith(self.server.craftanchor):
|
||||||
spec = urllib.unquote(path)[len(self.server.prefix):]
|
spec = urllib.unquote(path)[len(self.server.craftanchor):]
|
||||||
try:
|
try:
|
||||||
crafted = rparse.parse_response(self.server.request_settings, spec)
|
crafted = rparse.parse_response(self.server.request_settings, spec)
|
||||||
except rparse.ParseException, v:
|
except rparse.ParseException, v:
|
||||||
|
@ -149,14 +149,14 @@ class PathodHandler(tcp.BaseHandler):
|
||||||
class Pathod(tcp.TCPServer):
|
class Pathod(tcp.TCPServer):
|
||||||
LOGBUF = 500
|
LOGBUF = 500
|
||||||
def __init__( self,
|
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
|
sizelimit=None, noweb=False, nocraft=False, noapi=False
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
addr: (address, port) tuple. If port is 0, a free port will be
|
addr: (address, port) tuple. If port is 0, a free port will be
|
||||||
automatically chosen.
|
automatically chosen.
|
||||||
ssloptions: a dictionary containing certfile and keyfile specifications.
|
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.
|
staticdir: path to a directory of static resources, or None.
|
||||||
anchors: A list of (regex, spec) tuples, or None.
|
anchors: A list of (regex, spec) tuples, or None.
|
||||||
sizelimit: Limit size of served data.
|
sizelimit: Limit size of served data.
|
||||||
|
@ -164,7 +164,7 @@ class Pathod(tcp.TCPServer):
|
||||||
tcp.TCPServer.__init__(self, addr)
|
tcp.TCPServer.__init__(self, addr)
|
||||||
self.ssloptions = ssloptions
|
self.ssloptions = ssloptions
|
||||||
self.staticdir = staticdir
|
self.staticdir = staticdir
|
||||||
self.prefix = prefix
|
self.craftanchor = craftanchor
|
||||||
self.sizelimit = sizelimit
|
self.sizelimit = sizelimit
|
||||||
self.noweb, self.nocraft, self.noapi = noweb, nocraft, noapi
|
self.noweb, self.nocraft, self.noapi = noweb, nocraft, noapi
|
||||||
if not noapi:
|
if not noapi:
|
||||||
|
|
5
pathod
5
pathod
|
@ -10,6 +10,10 @@ if __name__ == "__main__":
|
||||||
"-a", dest='anchors', default=[], type=str, action="append", metavar="ANCHOR",
|
"-a", dest='anchors', default=[], type=str, action="append", metavar="ANCHOR",
|
||||||
help='Add an anchor. Specified as a string with the form pattern=pagespec'
|
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(
|
parser.add_argument(
|
||||||
"-d", dest='staticdir', default=None, type=str,
|
"-d", dest='staticdir', default=None, type=str,
|
||||||
help='Directory for static files.'
|
help='Directory for static files.'
|
||||||
|
@ -89,6 +93,7 @@ if __name__ == "__main__":
|
||||||
try:
|
try:
|
||||||
pd = pathod.Pathod(
|
pd = pathod.Pathod(
|
||||||
(args.address, args.port),
|
(args.address, args.port),
|
||||||
|
craftanchor = args.craftanchor,
|
||||||
ssloptions = ssl,
|
ssloptions = ssl,
|
||||||
staticdir = args.staticdir,
|
staticdir = args.staticdir,
|
||||||
anchors = alst,
|
anchors = alst,
|
||||||
|
|
Loading…
Reference in New Issue