Example #1
0
File: srv.py Project: t0z/tuby
def serv_module(modname=None):
    log.debug('%s: %s', request.method, modname)
    if modname is None:
        args = request_parser(request)
        modname = args._
    modname = modname.decode('utf8').strip().replace(u'.', u'_')
    if modname == '_':
        path = Path.join(basepath, 'tuby', 'core.py')
        if not Path.exists(path):
            return Err.file_not_found, 404
        return Response(mini(readfile(path)), mimetype=MIME_RESPONSE)
    path = None
    for storepath in [modpath, Path.abspath(Path.join(basepath, Path.pardir,
                                                      'smodule'))]:
        path = Path.join(storepath, u'%s.py' % modname)
        if not Path.exists(path):
            continue
        content = readfile(path)
        if content is not None:
            return Response(mini(content), mimetype=MIME_RESPONSE)
    log.error('File not found: %s', path)
    return Err.file_not_found
Example #2
0
try:
    TUBY = TUBY  # @UndefinedVariable
except Exception:
    from tuby.core import TubyStream
    TUBY = TubyStream()
from tuby.mini import mini

TUBY.stdout.write(mini(''.join(l for l in TUBY.stdin)))