Anchor management: list and remove anchors.

This commit is contained in:
Aldo Cortesi 2012-04-29 12:15:25 +12:00
parent 2d88d88f8c
commit f03ce81070
4 changed files with 33 additions and 18 deletions

View File

@ -86,19 +86,35 @@ class PathodApp(tornado.web.Application):
def __init__(self, application, request, **settings):
Pathod.__init__(self, spec, application, request, **settings)
FixedPathod.spec = spec
FixedPathod.pattern = pattern
l.insert(0, tornado.web.URLSpec(pattern, FixedPathod, self.appsettings))
def get_anchors(self, pattern, spec):
def get_anchors(self):
"""
Anchors are added to the beginning of the handlers.
"""
pass
l = self.handlers[0][1]
a = []
for i in l:
if i.handler_class.__name__ == "FixedPathod":
a.append(
(
i.handler_class.pattern,
i.handler_class.spec
)
)
return a
def remove_anchor(self, pattern, spec):
"""
Anchors are added to the beginning of the handlers.
"""
pass
l = self.handlers[0][1]
for i, h in enumerate(l):
if h.handler_class.__name__ == "FixedPathod":
if (h.handler_class.pattern, h.handler_class.spec) == (pattern, spec):
del l[i]
return
# begin nocover

10
notes
View File

@ -33,16 +33,10 @@ Examples:
200:b1k:xr
Sequences:
200 * 2 | !forever
200 | 404 | 200,b:500g
Anchors:
Passed on command-line?
--anchor /foo/bar 200:!/foo
Passed on command-line:
-a "/foo/bar=200:!/foo"
Built-in help

View File

@ -6,7 +6,13 @@ class uApplication(libpry.AutoTree):
def test_anchors(self):
a = app.PathodApp(staticdir=None)
a.add_anchor("/foo", "200")
assert a.handlers[0][1][0].handler_class.__name__ == "FixedPathod"
assert a.get_anchors() == [("/foo", "200")]
a.add_anchor("/bar", "400")
assert a.get_anchors() == [("/bar", "400"), ("/foo", "200")]
a.remove_anchor("/bar", "400")
assert a.get_anchors() == [("/foo", "200")]
a.remove_anchor("/oink", "400")
assert a.get_anchors() == [("/foo", "200")]
class uPages(libpry.AutoTree):

9
todo
View File

@ -1,6 +1,5 @@
- Anchors
- Disconnect or pause at specified byte offset
- Logs
- API
- Logs, log reset, log retrieval
- Add anchors programmatically?
- Sequences
- Anchor management