WebKit.JSONRPCServlet
index
/root/instaladores_rar/Webware-andes/WebKit/JSONRPCServlet.py

JSON-RPC servlet base class
 
Written by Jean-Francois Pieronne

 
Modules
       
traceback

 
Classes
       
WebKit.HTTPContent.HTTPContent(WebKit.HTTPServlet.HTTPServlet)
JSONRPCServlet

 
class JSONRPCServlet(WebKit.HTTPContent.HTTPContent)
    A superclass for Webware servlets using JSON-RPC techniques.
 
JSONRPCServlet can be used to make coding JSON-RPC applications easier.
 
Subclasses should override the method json_methods() which returns a list
of method names. These method names refer to Webware Servlet methods that
are able to be called by an JSON-RPC-enabled web page. This is very similar
in functionality to Webware's actions.
 
Some basic security measures against JavaScript hijacking are taken     by
default which can be deactivated if you're not dealing with sensitive data.
You can further increase security by adding shared secret mechanisms.
 
 
Method resolution order:
JSONRPCServlet
WebKit.HTTPContent.HTTPContent
WebKit.HTTPServlet.HTTPServlet
WebKit.Servlet.Servlet
WebKit.Object.Object
__builtin__.object
MiscUtils.NamedValueAccess.NamedValueAccess

Methods defined here:
__init__(self)
actions(self)
defaultAction(self)
exposedMethods(self)
jsonCall(self)
Execute method with arguments on the server side.
 
Returns Javascript function to be executed by the client immediately.
respondToGet(self, transaction)
writeError(self, msg)
writeResult(self, data)

Methods inherited from WebKit.HTTPContent.HTTPContent:
application(self)
The `Application` instance we're using.
awake(self, transaction)
Let servlet awake.
 
Makes instance variables from the transaction. This is
where Page becomes unthreadsafe, as the page is tied to
the transaction. This is also what allows us to
implement functions like `write`, where you don't
need to pass in the transaction or response.
callMethodOfServlet(self, url, method, *args, **kwargs)
Call a method of another servlet.
 
See `Application.callMethodOfServlet` for details.
The main difference is that here you don't have
to pass in the transaction as the first argument.
canBeThreaded(self)
Declares whether servlet can be threaded.
 
Returns 0 because of the instance variables we set up in `awake`.
endResponse(self)
End response.
 
When this method is called during `awake` or
`respond`, servlet processing will end immediately,
and the accumulated response will be sent.
 
Note that `sleep` will still be called, providing a
chance to clean up or free any resources.
forward(self, url)
Forward request.
 
Forwards this request to another servlet.
See `Application.forward` for details.
The main difference is that here you don't have
to pass in the transaction as the first argument.
handleAction(self, action)
Handle action.
 
Invoked by `_respond` when a legitimate action has
been found in a form. Invokes `preAction`, the actual
action method and `postAction`.
 
Subclasses rarely override this method.
includeURL(self, url)
Include output from other servlet.
 
Includes the response of another servlet
in the current servlet's response.
See `Application.includeURL` for details.
The main difference is that here you don't have
to pass in the transaction as the first argument.
methodNameForAction(self, name)
Return method name for an action name.
 
Invoked by _respond() to determine the method name for a given action
name which has been derived as the value of an ``_action_`` field.
Since this is usually the label of an HTML submit button in a form,
it is often needed to transform it in order to get a valid method name
(for instance, blanks could be replaced by underscores and the like).
This default implementation of the name transformation is the identity,
it simply returns the name. Subclasses should override this method
when action names don't match their method names; they could "mangle"
the action names or look the method names up in a dictionary.
postAction(self, actionName)
Things to do after action.
 
Invoked by self after invoking a action method.
Subclasses may override to
customize and may or may not invoke super as they see
fit. The `actionName` is passed to this method,
although it seems a generally bad idea to rely on
this. However, it's still provided just in case you
need that hook.
 
By default this does nothing.
preAction(self, actionName)
Things to do before action.
 
Invoked by self prior to invoking a action method.
The `actionName` is passed to this method,
although it seems a generally bad idea to rely on
this. However, it's still provided just in case you
need that hook.
 
By default this does nothing.
request(self)
The request (`HTTPRequest`) we're handling.
respondToPost(self, transaction)
Respond to POST.
 
Invoked in response to a POST request method. All methods
are passed to `_respond`.
response(self)
The response (`HTTPResponse`) we're handling.
sendRedirectAndEnd(self, url, status=None)
Send redirect and end.
 
Sends a redirect back to the client and ends the response.
This is a very popular pattern.
sendRedirectPermanentAndEnd(self, url)
Send permanent redirect and end.
sendRedirectSeeOtherAndEnd(self, url)
Send redirect to a URL to be retrieved with GET and end.
 
This is the proper method for the Post/Redirect/Get pattern.
sendRedirectTemporaryAndEnd(self, url)
Send temporary redirect and end.
session(self)
The session object.
 
This provides a state for the current user
(associated with a browser instance, really).
If no session exists, then a session will be created.
sessionEncode(self, url=None)
Utility function to access `Session.sessionEncode`.
 
Takes a url and adds the session ID as a parameter.
This is for cases where you don't know if the client
will accepts cookies.
sleep(self, transaction)
Let servlet sleep again.
 
We unset some variables. Very boring.
transaction(self)
The `Transaction` we're currently handling.
urlDecode(self, s)
Alias for `WebUtils.Funcs.urlDecode`.
 
Turns special % characters into actual characters.
urlEncode(self, s)
Alias for `WebUtils.Funcs.urlEncode`.
 
Quotes special characters using the % substitutions.
write(self, *args)
Write to output.
 
Writes the arguments, which are turned to strings (with `str`)
and concatenated before being written to the response.
Unicode strings must be encoded before they can be written.
writeExceptionReport(self, handler)
Write extra information to the exception report.
 
The `handler` argument is the exception handler, and
information is written there (using `writeTitle`,
`write`, and `writeln`).  This information is added
to the exception report.
 
See `WebKit.ExceptionHandler` for more information.
writeln(self, *args)
Write to output with newline.
 
Writes the arguments (like `write`), adding a newline after.
Unicode strings must be encoded before they can be written.

Methods inherited from WebKit.HTTPServlet.HTTPServlet:
lastModified(self, trans)
Get time of last modification.
 
Return this object's Last-Modified time (as a float),
or None (meaning don't know or not applicable).
notImplemented(self, trans)
respond(self, trans)
Respond to a request.
 
Invokes the appropriate respondToSomething() method depending on the
type of request (e.g., GET, POST, PUT, ...).
respondToHead(self, trans)
Respond to a HEAD request.
 
A correct but inefficient implementation.

Methods inherited from WebKit.Servlet.Servlet:
canBeReused(self)
Returns whether a single servlet instance can be reused.
 
The default is True, but subclasses con override to return False.
Keep in mind that performance may seriously be degraded if instances
can't be reused. Also, there's no known good reasons not to reuse
an instance. Remember the awake() and sleep() methods are invoked
for every transaction. But just in case, your servlet can refuse
to be reused.
close(self)
log(self, message)
Log a message.
 
This can be invoked to print messages concerning the servlet.
This is often used by self to relay important information back
to developers.
name(self)
Return the name which is simple the name of the class.
 
Subclasses should *not* override this method.
It is used for logging and debugging.
open(self)
runMethodForTransaction(self, trans, method, *args, **kw)
runTransaction(self, trans)
serverSidePath(self, path=None)
Return the filesystem path of the page on the server.
setFactory(self, factory)

Methods inherited from WebKit.Object.Object:
deprecated(self, method)
Output a deprecation warning.
 
The implementation of WebKit sometimes invokes this method which prints
a warning that the method you are using has been deprecated.
This method expects that deprecated methods say so at the beginning of
their doc string and terminate that msg with @. For example:
 
        DEPRECATED: Class.foo() on 01/24/01 in ver 0.5. Use Class.bar() instead. @
 
Putting this information in the doc string is important for accuracy
in the generated docs.
 
Example call:
        self.deprecated(self.foo)

Data descriptors inherited from WebKit.Object.Object:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Methods inherited from MiscUtils.NamedValueAccess.NamedValueAccess:
handleUnknownSetKey(self, key)
hasValueForKey(self, key)
Check whether key is available.
 
Returns true if the key is available, although that does not guarantee
that there will not be errors caused by retrieving the key.
hasValueForName(self, keysString)
Check whether name is available.
resetKeyBindings(self)
Rest all key bindings, releasing alreaedy referenced values.
setValueForKey(self, key, value)
Set value for a given key.
 
Suppose key is 'foo'.
This method sets the value with the following precedence:
        1. Public attributes before private attributes
        2. Methods before non-methods
 
More specifically, this method then uses one of the following:
        @@ 2000-03-04 ce: fill in
 
... or invokes handleUnknownSetKey().
valueForKey(self, key, default=<class MiscUtils.NoDefault>)
Get value for given key.
 
Suppose key is 'foo'.
This method returns the value with the following precedence:
        1. Methods before non-methods
        2. Public attributes before private attributes
 
More specifically, this method then returns one of the following:
        * self.foo()
        * self._foo()
        * self.foo
        * self._foo
 
... or default, if it was specified,
otherwise invokes and returns result of valueForUnknownKey().
Note that valueForUnknownKey() normally returns an exception.
 
See valueForName() which is a more advanced version of this method
that allows multiple, qualified keys.
valueForKeySequence(self, listOfKeys, default=None)
Get the value for the given list of keys.
valueForName(self, keysString, default=None)
Get the value for the given keysString.
 
This is the more advanced version of valueForKey(), which can only
handle single names. This method can handle
        'foo', 'foo1.foo2', 'a.b.c.d', etc.
It will traverse dictionaries if needed.
valueForUnknownKey(self, key, default)
valuesForNames(self, keys, default=None, defaults=None, forgive=0, includeNames=0)
Get all values for given names.
 
Returns a list of values that match the given keys, each of which is
passed through valueForName() and so could be of the form 'a.b.c'.
 
keys and defaults are sequences.
default is any kind of object.
forgive and includeNames are flags.
 
If default is not None, then it is substituted when a key is not found.
Otherwise, if defaults is not None, then its corresponding/parallel
value for the current key is substituted when a key is not found.
Otherwise, if forgive is true, then unknown keys simply don't produce
any values.
Otherwise, if default and defaults are None, and forgive is false,
then the unknown keys will probably raise an exception through
self.valueForUnknownKey() although that method can always return
a final, default value.
if keys is None, then None is returned.
If keys is an empty list, then None is returned.
Often these last four arguments are specified by key.
Examples:
        names = ['origin.x', 'origin.y', 'size.width', 'size.height']
        obj.valuesForNames(names)
        obj.valuesForNames(names, default=0.0)
        obj.valuesForNames(names, defaults=[0.0, 0.0, 100.0, 100.0])
        obj.valuesForNames(names, forgive=0)
@@ 2000-03-04 ce: includeNames is only supported when forgive=1.
        It should be supported for the other cases.
        It should be documented.
        It should be included in the test cases.

 
Functions
       
StringIO(...)
StringIO([s]) -- Return a StringIO-like stream for reading or writing