Panda3D

- Main Page
- Packages
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Public Attributes | Static Public Attributes

# WebRequestDispatcher Class Reference

List of all members.

## Public Member Functions
def | __init__
def | __new__
def | enableLandingPage
def | getBodyTag
def | getHeadTag
def | handleGET
def | invalidURI
def | listenOnPort
def | poll
def | pollHTTPTask
def | registerGETHandler
def | startCheckingIncomingHTTP
def | stopCheckingIncomingHTTP
def | unregisterGETHandler
## Public Attributes
| landingPage
## Static Public Attributes
| listenPort = None
| notify = notify
float | requestTimeout = 10.0
dictionary | uriToHandler = {}

## Detailed Description

    Request dispatcher for HTTP requests.
    Contains registration and dispatching functionality.

    Single-state class--multiple instances share all data.
    This is because we're wrapping a singleton webserver.

    How to use:

    w = WebRequestDispatcher()
    w.listenOnPort(8888)
    def test(replyTo,**kw):
        print 'test got called with these options: %s' % str(kw)
        replyTo.respond('<html><body>Thank you for the yummy arguments: %s' % str(kw))
    w.registerGETHandler('test',test)
    while 1:
        w.poll()

    Browse to http://localhost:8888/test?foo=bar and see the result!

## Constructor & Destructor Documentation

def __init__ | ( |  | self,
|  |  | wantLandingPage = `True`
| ) |  |

## Member Function Documentation

def __new__ | ( |  | self,
|  |  | a,
|  |  | kw
| ) |  |

def enableLandingPage | ( |  | self,
|  |  | enable
| ) |  |

def getBodyTag | ( |  | self | ) |

def getHeadTag | ( |  | self | ) |

def handleGET | ( |  | self,
|  |  | req
| ) |  |

    Parse and dispatch a single GET request.
    Expects to receive a WebRequest object.

def invalidURI | ( |  | self,
|  |  | replyTo,
|  |  | kw
| ) |  |

def listenOnPort | ( |  | self,
|  |  | listenPort
| ) |  |

    Start the web server listening if it isn't already.
    Singleton server, so ignore multiple listen requests.

def poll | ( |  | self | ) |

    Pump the web server, handle any incoming requests.
    This function should be called regularly, about 2-4
    calls/sec for current applications is a good number.

def pollHTTPTask | ( |  | self,
|  |  | task
| ) |  |

def registerGETHandler | ( |  | self,
|  |  | uri,
|  |  | handler,
|  |  | returnsResponse = `False`,
|  |  | autoSkin = `False`
| ) |  |

    Call this function to register a handler function to
    be called in response to a query to the given URI.

    GET options are translated into **kw arguments.
    Handler function should accept **kw in order to handle
    arbitrary queries.

    If returnsResponse is False, the request is left open after
    handler returns--handler or tasks it creates are responsible
    for fulfilling the query now or in the future.  Argument
    replyTo (a WebRequest) is guaranteed to be passed to the
    handler, and replyTo.respond must be called with an HTML
    response string to fulfill the query and close the socket.

    If returnsResponse is True, WebRequestDispatcher expects the
    handler to return its response string, and we will route the
    response and close the socket ourselves.  No replyTo argument
    is provided to the handler in this case.

def startCheckingIncomingHTTP | ( |  | self,
|  |  | interval = `0.3`
| ) |  |

def stopCheckingIncomingHTTP | ( |  | self | ) |

def unregisterGETHandler | ( |  | self,
|  |  | uri
| ) |  |

## Member Data Documentation

landingPage

listenPort = None`[static]`

notify = notify`[static]`

float requestTimeout = 10.0`[static]`

dictionary uriToHandler = {}`[static]`

All Classes Namespaces Functions Variables Enumerations Enumerator Properties