Skip to content

Commit

Permalink
added _very basic_ support for search queries, and example2.py to demo
Browse files Browse the repository at this point in the history
  • Loading branch information
lojikil committed Oct 28, 2014
1 parent 042d644 commit f2b26fc
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
13 changes: 12 additions & 1 deletion chasha.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ def __str__(self):
return '\r\n'.join(res)


class Request(object):

def __init__(self, descriptor=None, search=None):
self.descriptor = descriptor
self.search = search


class Chasha(object):

def __init__(self):
Expand All @@ -82,6 +89,7 @@ def __init__(self):
# defaults down below...
self.port = 7070
self.host = '0.0.0.0'
self.request = None

def add_route(self, descriptor, callback):
if ':' in descriptor:
Expand Down Expand Up @@ -166,7 +174,10 @@ def run(self, **kwargs):
desc = desc.strip()
print "[!] client sent data..."
try:
handler = self.router(desc)
descparts = desc.split('\t')
self.request = Request(cget(descparts, 0),
cget(descparts, 1))
handler = self.router(descparts[0])
print "[!] router matched said data..."
print "[!] type of handler: ", type(handler)
if isinstance(handler, tuple):
Expand Down
45 changes: 45 additions & 0 deletions example2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from chasha import Chasha, Directory

app = Chasha()


@app.route('/foo')
def foo():
return """Test\r
Data\r
Check if multiline...\r
Works\r\n"""


@app.route('/bar')
def bar():
d = Directory("/bar")
d.add_child("This is an empty directory")
d.add_child("it exists simply to illustrate & test nested directories")
d.add_child("and further, it is just neat")
return d


@app.route('/blah/<bar:int>')
def blah(bar):
ret = """
bar is {0}\r
descriptor is {1}\r
search is {2}\r\n""".format(bar, app.request.descriptor, app.request.search)
return ret


@app.default()
def default():
d = Directory("/")
d.add_child("Dynamic routing example; /blah/ accepts an integer")
d.add_child([0, "Foo bar industries", "/foo", "127.0.0.1", "7070"])
d.add_child("Some test info here...")
d.add_child("Some more test info...")
d.add_child(Directory("/bar", port=7070, name="FooBar Testing"))
d.add_child([0, "Test blah 10", "/blah/10", "127.0.0.1", "7070"])
d.add_child([0, "Test blah 20", "/blah/20", "127.0.0.1", "7070"])
d.add_child([0, "Test blab 30", "/blah/30", "127.0.0.1", "7070"])
return d

app.run()

0 comments on commit f2b26fc

Please sign in to comment.