Ejemplo n.º 1
0
 def testFindRequestHandler(self):
     dispatcher = Dispatcher()
     self.createAnonRoute('/')
     self.createAnonRoute('/bar')
     self.assertTrue(dispatcher.find_request_handler('/') != None)
     self.assertTrue(dispatcher.find_request_handler('/bar') != None)
     self.assertTrue(dispatcher.find_request_handler('/baz') == None)
Ejemplo n.º 2
0
"""
Main pyroutes module

This module handles all the dispatching services for pyroutes.
"""

from pyroutes.route import Route
from pyroutes.middleware.errors import *
import pyroutes.settings as settings
from pyroutes.dispatcher import Dispatcher

from wsgiref.util import shift_path_info

__request__handlers__ = {}

dispatcher = Dispatcher()


def route(path, *args, **kwargs):
    """
    Routes define which methods handles requests to certain paths, and are defined
    using the `@route`-decorator. The decorator takes one argument that defines which
    path the method is used for. The decorated function recieves one argument from pyroutes
    containing a `Request`-instance with all the information for that particular request.

    **Defining routes**

    This is a simple example route ::

      from pyroutes import route
      from pyroutes.http.response import Response