#940: Convert some docstring as defined in PEP 257.

remotes/github/python3
Ramón M. Gómez 2020-07-07 13:46:35 +02:00
parent bb685d9700
commit 9525724449
2 changed files with 51 additions and 52 deletions

View File

@ -25,14 +25,14 @@
# 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.
This two methods are invoked inside main service thread, take that into account when creating them
@ -43,7 +43,7 @@ class ClientWorker(object):
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)

View File

@ -25,14 +25,14 @@
# 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.
This two methods are invoked inside main service thread, take that into account when creating them
@ -43,7 +43,7 @@ class ServerWorker(object):
https://sampleserver:8888/[name]/....
Remember that module names and REST path are case sensitive!!!
'''
"""
name = None
service = None
locked = False
@ -52,28 +52,28 @@ 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:
@ -88,7 +88,7 @@ class ServerWorker(object):
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,7 +103,7 @@ 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
@ -116,7 +116,7 @@ class ServerWorker(object):
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):