示例#1
0
def make_app():
    application = URLDispatcher()
    js_app = DirectoryApp(os.path.join(here, 'static/js'))
    css_app = DirectoryApp(os.path.join(here, 'static/css'))
    img_app = DirectoryApp(os.path.join(here, 'static/img'))

    application.add_url('js', '/js/*', js_app)
    application.add_url('css', '/css/*', css_app)
    application.add_url('img', '/img/*', img_app)
    application.add_url('page', '/{page_name}', page_view)
    application.add_url('page_edit', '/{page_name}/edit', page_edit)
    application.add_url('top', '/', HTTPFound(location='FrontPage'))
    return application
示例#2
0
def make_app():
    application = URLDispatcher()
    js_app = DirectoryApp(os.path.join(here, 'static/js'))
    css_app = DirectoryApp(os.path.join(here, 'static/css'))
    img_app = DirectoryApp(os.path.join(here, 'static/img'))

    application.add_url('js', '/js/*', js_app)
    application.add_url('css', '/css/*', css_app)
    application.add_url('img', '/img/*', img_app)
    application.add_url('page', '/{page_name}', page_view)
    application.add_url('page_edit', '/{page_name}/edit', page_edit)
    application.add_url('top', '/', HTTPFound(location='FrontPage'))
    return application
示例#3
0
from webdispatch import URLDispatcher
from webob.dec import wsgify

@wsgify
def top(request):
    return request.environ['webdispatch.urlgenerator'].generate('top')

app = URLDispatcher()
app.add_url('top', '/', top)

示例#4
0
from webob import Request
from webob.dec import wsgify
from webdispatch import URLDispatcher
from webdispatch.mixins import URLMapperMixin


class MyRequest(Request, URLMapperMixin):
    pass


app = URLDispatcher()


@wsgify(RequestClass=MyRequest)
def index(request):
    url = request.generate_url("hello", xname="webdispatch")
    return '<a href="%s">Hello</a>' % (url,)


@wsgify(RequestClass=MyRequest)
def hello(request):
    return "Hello %s" % request.urlvars["xname"]


app.add_url("home", "/", index)
app.add_url("hello", "/hello/{xname}", hello)

if __name__ == "__main__":
    from wsgiref.simple_server import make_server

    httpd = make_server("0.0.0.0", 8080, app)
示例#5
0
    if address == "NONE":
        return [b"Hi"]

    if int(address) > 0 and int(address) < 255:
        call_powerwake(address)
        return [b'success to wake']

    return [b"fail to wake"]


def call_powerwake(octed):

    args = shlex.split(CMD_LINE + octed)
    # print (args)
    subprocess.call(args)
    return


def run():
    server = simple_server.make_server('', SERVER_PORT, app)
    server.serve_forever()
    return


from webdispatch import URLDispatcher
app = URLDispatcher()

app.add_url(INDEX_NAME, '/' + INDEX_NAME, query_parse)

run()
示例#6
0
def hello(environ, start_response):
    start_response("200 OK",
        [('Content-type', 'text/plain')])
    return ["hello"]

def goodbye(environ, start_response):
    start_response("200 OK",
        [('Content-type', 'text/plain')])
    return ["goodby %s" % environ['wsgiorg.routing_args'][1]['name']]

from webdispatch import URLDispatcher
application = URLDispatcher()
application.add_url('hello', '/hello', hello)
application.add_url('goodbye', '/good-bye', goodbye)

from wsgiref.simple_server import make_server

httpd = make_server('0.0.0.0', 8080, application)
httpd.serve_forever()
示例#7
0
from webdispatch import URLDispatcher
from webob.dec import wsgify

@wsgify
def slug(request):
    slug = request.urlvars['slug']
    return slug

app = URLDispatcher()
app.add_url('slug', '/{slug}', slug)