Panda3D
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
WebRequestDispatcher Class Reference
Inheritance diagram for WebRequestDispatcher:

Public Member Functions

def __init__ (self, wantLandingPage=True)
 
def __new__ (self, a, kw)
 
def enableLandingPage (self, enable)
 
def getBodyTag (self)
 
def getHeadTag (self)
 
def handleGET (self, req)
 
def invalidURI (self, replyTo, kw)
 
def listenOnPort (self, listenPort)
 
def poll (self)
 
def pollHTTPTask (self, task)
 
def registerGETHandler (self, uri, handler, returnsResponse=False, autoSkin=False)
 
def startCheckingIncomingHTTP (self, interval=0.3)
 
def stopCheckingIncomingHTTP (self)
 
def unregisterGETHandler (self, uri)
 

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

◆ __init__()

def __init__ (   self,
  wantLandingPage = True 
)

Member Function Documentation

◆ __new__()

def __new__ (   self,
  a,
  kw 
)

◆ enableLandingPage()

def enableLandingPage (   self,
  enable 
)

◆ getBodyTag()

def getBodyTag (   self)

◆ getHeadTag()

def getHeadTag (   self)

◆ handleGET()

def handleGET (   self,
  req 
)
Parse and dispatch a single GET request.
Expects to receive a WebRequest object.

◆ invalidURI()

def invalidURI (   self,
  replyTo,
  kw 
)

◆ listenOnPort()

def listenOnPort (   self,
  listenPort 
)
Start the web server listening if it isn't already.
Singleton server, so ignore multiple listen requests.

◆ poll()

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.

◆ pollHTTPTask()

def pollHTTPTask (   self,
  task 
)

◆ registerGETHandler()

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.

◆ startCheckingIncomingHTTP()

def startCheckingIncomingHTTP (   self,
  interval = 0.3 
)

◆ stopCheckingIncomingHTTP()

def stopCheckingIncomingHTTP (   self)

◆ unregisterGETHandler()

def unregisterGETHandler (   self,
  uri 
)

Member Data Documentation

◆ landingPage

landingPage

◆ listenPort

listenPort = None
static

◆ notify

notify = notify
static

◆ requestTimeout

float requestTimeout = 10.0
static

◆ uriToHandler

dictionary uriToHandler = {}
static