Skip to content
This repository was archived by the owner on Aug 26, 2021. It is now read-only.

Commit e335a3d

Browse files
committed
initial checkin
0 parents  commit e335a3d

File tree

9 files changed

+929
-0
lines changed

9 files changed

+929
-0
lines changed

README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lime is an async HTTP/1.[01] engine.

app.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import re
2+
class Application:
3+
def __init__(self, urls):
4+
self._urls = urls
5+
6+
def delegate(self, url, method, http):
7+
params = []
8+
try:
9+
url_part1, url_rest = ['/'+u for u in url.split('/',2) if u != '']
10+
except:
11+
url_part1 = url_rest = url
12+
for u in self._urls:
13+
key = u
14+
if u != '/':
15+
u = ['/'+u for u in u.split('/',2) if u != ''][0]
16+
m = re.match('%s$' % u, url_part1)
17+
if m: break
18+
if not m:
19+
return 'method not found'
20+
21+
user_method = self._urls[key]
22+
if isinstance(user_method, Application):
23+
return user_method.delegate(url_rest, method, http)
24+
else:
25+
m = None
26+
for u in self._urls:
27+
#print 'matching %s with %s' % (u, url)
28+
m = re.match('%s$' % u, url)
29+
if m: break
30+
if not m:
31+
return 'method not found'
32+
params = m.groups()
33+
user_method = self._urls[key].get(method)
34+
return user_method(http, *params)

example_app.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from lime import HttpPool
2+
from app import Application
3+
4+
def some_method(http, id):
5+
return 'hello this some method %s' % id
6+
7+
def method1(http, id, id2):
8+
return 'hello, this is method1 with id %s %s' % (id, id2)
9+
10+
#module 1
11+
module1_urls = {
12+
'/some_method/(\d+)/(\d+)': {'GET': method1}
13+
}
14+
15+
module1 = Application(module1_urls)
16+
17+
main_urls = {
18+
'/(\d*)': {'GET': some_method},
19+
'/test2': module1
20+
}
21+
22+
#main module
23+
main_module = Application(main_urls)
24+
25+
pool = HttpPool(main_module)
26+
pool.listen(bind_address='127.0.0.1', port=8080)

0 commit comments

Comments
 (0)