in api/handler.py [0:0]
def application(environ, start_response):
"""
This is the main handler. Every API call goes through here.
Checks against the pages library, and if submod found, runs
it and returns the output.
"""
path = environ.get('PATH_INFO', '')
for regex, function in urls:
m = re.match(regex, path)
if m:
callback = WarbleAPIWrapper(path, function)
session = plugins.session.WarbleSession(DB, environ, config)
a = 0
for bucket in callback(environ, start_response, session):
if a == 0:
session.headers.append(bucket)
try:
start_response("200 Okay", session.headers)
except:
pass
a += 1
# WSGI prefers byte strings, so convert if regular py3 string
if isinstance(bucket, str):
yield bytes(bucket, encoding = 'utf-8')
elif isinstance(bucket, bytes):
yield bucket
return
for bucket in fourohfour(environ, start_response):
yield bytes(bucket, encoding = 'utf-8')