Module AjaxStub :: Class AjaxStub
[show private | hide private]
[frames | no frames]

Type AjaxStub

      object --+    
               |    
AjaxStubDispatch --+
                   |
                  AjaxStub


Create a stub interface for JavaScript.
Method Summary
  __init__(self, type, methodClassInstance)
Call the constructor of the base class passing it the encoding type.
  getCGIMethod(self)
Return the default CGI method.
  getCGIValue(self, key)
Get the raw CGI value of the provided key.
  getMethodMaps(self)
Get a tuple of the function and method dictionaries.
  getStubMethodNameList(self)
Get a list of the registered functions and/or methods to be turned into JavaScript stubs.
  hasCGIKey(self, key)
Test if the CGI name exists.
  includeTraceback(self)
Enables the including of the traceback in the error result.
  register(self, *args)
Register the functions.
  setCGIMethod(self, method)
Set the CGI method to either 'GET' or 'POST'.
  unregister(self, name)
Remove the object mapped to by the method name from the StubContainer.
  __findCGIMethod(self, methodObj)
Find if the class method has a CGI method defined.
  __getNextStub(self, mmap)
A generator returning a stub string.
  __getStub(self, stub)
Get the JavaScript stub by name.
  __getStubs(self, mmap)
Iterate through the provided map adding the stubs to a srting variable.
  __isValidCGIMethod(self, method)
Check if method is a valid CGI method.
  __makeTraceback(self)
Create an HTML compliant traceback.
  __register(self, mmap, args)
Iterate through args for each stub, test for an instance of a Tuple.
  __registerMethods(self)
Register the class object methods.
  _exportAjaxStubArgsJS(self)
Return the two JavaScript variables that need to be set prior to instantiating the JavaScript AjaxStub class.
  _exportStubsJS(self)
Create the stubs and return them as a string.
  _handleClientRequest(self)
Handle the request from the client and execute the method/function requested from the client.
    Inherited from AjaxStubDispatch
  addContentType(self, typeMap)
Add new content types to the defaults. (Class method)
  dispatchJavascript(self)
Dispatch the JavaScript request code, of your choice, plus the stubs to standard out.
  initRequest(self)
Send the content type to the client.
  processClientRequest(self)
Print to standard out the results of the requested function or method call.
  _encodeHTML(self, data)
Encode HTML for sending to the client.
  _encodeJSON(self, data)
Encode JSON to send to the client.
  _encodeXML(self, data)
Encode XML to send to the client.
  _getContentType(self)
Returns the content type.
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __repr__(x)
x.__repr__() <==> repr(x)
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)

Class Variable Summary
str ARGUMENT = 'arg'
str COMMAND = 'cmd'
str GET = 'GET'
str POST = 'POST'
str _AjaxStub__CALLBACK = 'CB'
list _AjaxStub__cgiMethods = ['GET', 'POST']
SRE_Pattern _AjaxStub__REGEX = [ \n\r\t]+
str _FAILURE = 'failure'
str _RESULT = 'result'
str _STATUS = 'status'
str _SUCCESS = 'success'
    Inherited from AjaxStubDispatch
str HTML = 'HTML'
str JSON = 'JSON'
str XML = 'XML'
dict _AjaxStubDispatch__CONTENT_TYPE = {'XML': 'text/xml', 'J...

Instance Method Details

__init__(self, type='HTML', methodClassInstance=None)
(Constructor)

  1. Call the constructor of the base class passing it the encoding type.
  2. Save to a private member object the instantiated class instance of the methods in the public API.
  3. Create the CGI FieldStorage instance.
  4. Set the default CGI method to 'GET'.
  5. Create the function map.
  6. Create the method map.
  7. Register the class methods.
Parameters:
type - The transport encoding type. (ie. HTML, JSON, XML)
methodClassInstance - The instance object of the class holding your public API.
Overrides:
AjaxStub.AjaxStubDispatch.__init__

getCGIMethod(self)

Return the default CGI method.
Returns:
The default CGI method.

getCGIValue(self, key)

Get the raw CGI value of the provided key.
Parameters:
key - The CGI name.
Returns:
The CGI value.

getMethodMaps(self)

Get a tuple of the function and method dictionaries.
Returns:
Tuple (method map, function map)

getStubMethodNameList(self)

Get a list of the registered functions and/or methods to be turned into JavaScript stubs.
Returns:
List of functions and/or methods.

hasCGIKey(self, key)

Test if the CGI name exists.
Parameters:
key - The CGI name.
Returns:
True if the name exists else False.

includeTraceback(self)

Enables the including of the traceback in the error result.

register(self, *args)

Register the functions.
Parameters:
args - List of function objects which can be tuples in the form of (object instance, cgiMethod) or just the method object.

setCGIMethod(self, method='GET')

Set the CGI method to either 'GET' or 'POST'.
Parameters:
method - The CGI method.

unregister(self, name)

Remove the object mapped to by the method name from the StubContainer.

NOTE: Only functions can be unregistered.
Parameters:
name - The name of the function to remove from the map.

__findCGIMethod(self, methodObj)

Find if the class method has a CGI method defined.

Warning: This way of getting the CGI method may be unreliable since it depends on the implementer to never use any of the CGI types for anything other than defining the CGI method.
Parameters:
methodObj - The method object.
Returns:
The CGI method.

__getNextStub(self, mmap)

A generator returning a stub string.
Parameters:
mmap - The next stub string.

__getStub(self, stub)

Get the JavaScript stub by name.
Parameters:
stub - If a tuple: (name, cgiMethod) or if a string then stub is the name of the function or method.
Returns:
The JavaScript stub.

__getStubs(self, mmap)

Iterate through the provided map adding the stubs to a srting variable.
Parameters:
mmap - The StubContainer to make the stubs from.
Returns:
The resulting string containing all the JavaScript stubs.

__isValidCGIMethod(self, method)

Check if method is a valid CGI method.
Returns:
If valid return True else False.

__makeTraceback(self)

Create an HTML compliant traceback.
Returns:
The formatted exception.

__register(self, mmap, args)

Iterate through args for each stub, test for an instance of a Tuple. If a Tuple check if the 2nd value is a valid CGI method if not raise an exception else put this stub and the CGI method in the provided map. If not a Tuple put just the stub in the provided map.
Parameters:
mmap - The StubContainer object to put the functions or methods in.
args - The functions or methods to put into the StubContainer.

__registerMethods(self)

Register the class object methods.

_exportAjaxStubArgsJS(self)

Return the two JavaScript variables that need to be set prior to instantiating the JavaScript AjaxStub class.
Returns:
The JavaScript variables set to the Content-Type and the list of stub names.

_exportStubsJS(self)

Create the stubs and return them as a string.
Returns:
A string representing the JavaScript stubs.

_handleClientRequest(self)

Handle the request from the client and execute the method/function requested from the client.
Returns:
The result of the client request.

Class Variable Details

ARGUMENT

Type:
str
Value:
'arg'                                                                  

COMMAND

Type:
str
Value:
'cmd'                                                                  

GET

Type:
str
Value:
'GET'                                                                  

POST

Type:
str
Value:
'POST'                                                                 

_AjaxStub__CALLBACK

Type:
str
Value:
'CB'                                                                   

_AjaxStub__cgiMethods

Type:
list
Value:
['GET', 'POST']                                                        

_AjaxStub__REGEX

Type:
SRE_Pattern
Value:
[ \n\r\t]+                                                             

_FAILURE

Type:
str
Value:
'failure'                                                              

_RESULT

Type:
str
Value:
'result'                                                               

_STATUS

Type:
str
Value:
'status'                                                               

_SUCCESS

Type:
str
Value:
'success'                                                              

Generated by Epydoc 2.1 on Fri Aug 3 23:25:20 2007 http://epydoc.sf.net