#940: Convert some docstring as defined in PEP 257.
parent
bb685d9700
commit
9525724449
|
@ -25,25 +25,25 @@
|
|||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
'''
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
# pylint: disable=unused-wildcard-import,wildcard-import
|
||||
|
||||
|
||||
class ClientWorker(object):
|
||||
'''
|
||||
"""
|
||||
A ServerWorker is a server module that "works" for service
|
||||
Most method are invoked inside their own thread, except onActivation & onDeactivation.
|
||||
Most method are invoked inside their own thread, except onActivation & onDeactivation.
|
||||
This two methods are invoked inside main service thread, take that into account when creating them
|
||||
|
||||
|
||||
* You must provide a module name (override name on your class), so we can identify the module by a "valid" name.
|
||||
A valid name is like a valid python variable (do not use spaces, etc...)
|
||||
* The name of the module is used as REST message destination id:
|
||||
https://sampleserver:8888/[name]/....
|
||||
Remember that module names and REST path are case sensitive!!!
|
||||
|
||||
'''
|
||||
|
||||
"""
|
||||
name = None
|
||||
service = None
|
||||
|
||||
|
@ -51,15 +51,15 @@ class ClientWorker(object):
|
|||
self.service = service
|
||||
|
||||
def activate(self):
|
||||
'''
|
||||
"""
|
||||
Convenient method to wrap onActivation, so we can include easyly custom common logic for activation in a future
|
||||
'''
|
||||
"""
|
||||
self.onActivation()
|
||||
|
||||
def deactivate(self):
|
||||
'''
|
||||
"""
|
||||
Convenient method to wrap onActivation, so we can include easyly custom common logic for deactivation in a future
|
||||
'''
|
||||
"""
|
||||
self.onDeactivation()
|
||||
|
||||
def processMessage(self, message, params):
|
||||
|
@ -83,32 +83,31 @@ class ClientWorker(object):
|
|||
return operation(params)
|
||||
|
||||
def onActivation(self):
|
||||
'''
|
||||
"""
|
||||
Invoked by Service for activation.
|
||||
This MUST be overridden by modules!
|
||||
This method is invoked inside main thread, so if it "hangs", complete service will hang
|
||||
This should be no problem, but be advised about this
|
||||
'''
|
||||
"""
|
||||
pass
|
||||
|
||||
def onDeactivation(self):
|
||||
'''
|
||||
"""
|
||||
Invoked by Service before unloading service
|
||||
This MUST be overridden by modules!
|
||||
This method is invoked inside main thread, so if it "hangs", complete service will hang
|
||||
This should be no problem, but be advised about this
|
||||
'''
|
||||
"""
|
||||
pass
|
||||
|
||||
# *************************************
|
||||
# * Helper, convenient helper methods *
|
||||
# *************************************
|
||||
def sendServerMessage(self, message, data):
|
||||
'''
|
||||
"""
|
||||
Sends a message to connected ipc clients
|
||||
By convenience, it uses the "current" moduel name as destination module name also.
|
||||
If you need to send a message to a different module, you can use self.service.sendClientMessage(module, message, data) instead
|
||||
og this helmer
|
||||
'''
|
||||
"""
|
||||
self.service.ipc.sendMessage(self.name, message, data)
|
||||
|
|
@ -25,25 +25,25 @@
|
|||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
'''
|
||||
"""
|
||||
@author: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
'''
|
||||
"""
|
||||
# pylint: disable=unused-wildcard-import,wildcard-import
|
||||
|
||||
|
||||
class ServerWorker(object):
|
||||
'''
|
||||
"""
|
||||
A ServerWorker is a server module that "works" for service
|
||||
Most method are invoked inside their own thread, except onActivation & onDeactivation.
|
||||
Most method are invoked inside their own thread, except onActivation & onDeactivation.
|
||||
This two methods are invoked inside main service thread, take that into account when creating them
|
||||
|
||||
|
||||
* You must provide a module name (override name on your class), so we can identify the module by a "valid" name.
|
||||
A valid name is like a valid python variable (do not use spaces, etc...)
|
||||
* The name of the module is used as REST message destination id:
|
||||
https://sampleserver:8888/[name]/....
|
||||
Remember that module names and REST path are case sensitive!!!
|
||||
|
||||
'''
|
||||
|
||||
"""
|
||||
name = None
|
||||
service = None
|
||||
locked = False
|
||||
|
@ -52,43 +52,43 @@ class ServerWorker(object):
|
|||
self.service = service
|
||||
|
||||
def activate(self):
|
||||
'''
|
||||
"""
|
||||
Convenient method to wrap onActivation, so we can include easyly custom common logic for activation in a future
|
||||
'''
|
||||
"""
|
||||
self.onActivation()
|
||||
|
||||
def deactivate(self):
|
||||
'''
|
||||
"""
|
||||
Convenient method to wrap onActivation, so we can include easyly custom common logic for deactivation in a future
|
||||
'''
|
||||
"""
|
||||
self.onDeactivation()
|
||||
|
||||
def process(self, getParams, postParams, server):
|
||||
'''
|
||||
"""
|
||||
This method is invoked on a message received with an empty path (that means a message with only the module name, like in "http://example.com/Sample"
|
||||
Override it if you expect messages with that pattern
|
||||
|
||||
|
||||
Overriden method must return data that can be serialized to json (i.e. Ojects are not serializable to json, basic type are)
|
||||
'''
|
||||
"""
|
||||
raise NotImplementedError('Generic message processor is not supported')
|
||||
|
||||
def processServerMessage(self, path, getParams, postParams, server):
|
||||
'''
|
||||
"""
|
||||
This method can be overriden to provide your own message proccessor, or better you can
|
||||
implement a method that is called exactly as "process_" + path[0] (module name has been removed from path array) and this default processMessage will invoke it
|
||||
* Example:
|
||||
Imagine this invocation url (no matter if GET or POST): http://example.com:9999/Sample/mazinger/Z
|
||||
The HTTP Server will remove "Sample" from path, parse arguments and invoke this method as this:
|
||||
module.processMessage(["mazinger","Z"], getParams, postParams)
|
||||
|
||||
|
||||
This method will process "mazinguer", and look for a "self" method that is called "process_mazinger", and invoke it this way:
|
||||
return self.process_mazinger(["Z"], getParams, postParams)
|
||||
|
||||
|
||||
In the case path is empty (that is, the path is composed only by the module name, like in "http://example.com/Sample", the "process" method
|
||||
will be invoked directly
|
||||
|
||||
|
||||
The methods must return data that can be serialized to json (i.e. Ojects are not serializable to json, basic type are)
|
||||
'''
|
||||
"""
|
||||
if self.locked is True:
|
||||
raise Exception('system is busy')
|
||||
|
||||
|
@ -103,20 +103,20 @@ class ServerWorker(object):
|
|||
|
||||
|
||||
def processClientMessage(self, message, data):
|
||||
'''
|
||||
"""
|
||||
Invoked by Service when a client message is received (A message from user space Agent)
|
||||
|
||||
|
||||
This method can be overriden to provide your own message proccessor, or better you can
|
||||
implement a method that is called exactly "process_client_" + message (module name has been removed from path) and this default processMessage will invoke it
|
||||
* Example:
|
||||
We got a message from OGAgent "Mazinger", with json params
|
||||
module.processClientMessage("mazinger", jsonParams)
|
||||
|
||||
|
||||
This method will process "mazinguer", and look for a "self" method that is called "process_client_mazinger", and invoke it this way:
|
||||
self.process_client_mazinger(jsonParams)
|
||||
|
||||
|
||||
The methods returns nothing (client communications are done asynchronously)
|
||||
'''
|
||||
"""
|
||||
try:
|
||||
operation = getattr(self, 'process_client_' + message)
|
||||
except Exception:
|
||||
|
@ -128,52 +128,52 @@ class ServerWorker(object):
|
|||
|
||||
|
||||
def onActivation(self):
|
||||
'''
|
||||
"""
|
||||
Invoked by Service for activation.
|
||||
This MUST be overridden by modules!
|
||||
This method is invoked inside main thread, so if it "hangs", complete service will hang
|
||||
This should be no problem, but be advised about this
|
||||
'''
|
||||
"""
|
||||
pass
|
||||
|
||||
def onDeactivation(self):
|
||||
'''
|
||||
"""
|
||||
Invoked by Service before unloading service
|
||||
This MUST be overridden by modules!
|
||||
This method is invoked inside main thread, so if it "hangs", complete service will hang
|
||||
This should be no problem, but be advised about this
|
||||
'''
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def onLogin(self, user):
|
||||
'''
|
||||
"""
|
||||
Invoked by Service when an user login is detected
|
||||
This CAN be overridden by modules
|
||||
This method is invoked whenever the client (user space agent) notifies the server (Service) that a user has logged in.
|
||||
This method is run on its own thread
|
||||
'''
|
||||
"""
|
||||
pass
|
||||
|
||||
def onLogout(self, user):
|
||||
'''
|
||||
"""
|
||||
Invoked by Service when an user login is detected
|
||||
This CAN be overridden by modules
|
||||
This method is invoked whenever the client (user space agent) notifies the server (Service) that a user has logged in.
|
||||
This method is run on its own thread
|
||||
'''
|
||||
"""
|
||||
pass
|
||||
|
||||
# *************************************
|
||||
# * Helper, convenient helper methods *
|
||||
# *************************************
|
||||
def sendClientMessage(self, message, data):
|
||||
'''
|
||||
"""
|
||||
Sends a message to connected ipc clients
|
||||
By convenience, it uses the "current" moduel name as destination module name also.
|
||||
If you need to send a message to a different module, you can use self.service.sendClientMessage(module, message, data) instead
|
||||
og this helmer
|
||||
'''
|
||||
"""
|
||||
self.service.sendClientMessage(self.name, message, data)
|
||||
|
||||
def sendScriptMessage(self, script):
|
||||
|
|
Loading…
Reference in New Issue