Finished converting server/ and server/portal to google-style docstrings as per #709.

This commit is contained in:
Griatch 2015-06-23 15:20:32 +02:00
parent ccae355175
commit 19bfaae8a6
15 changed files with 906 additions and 268 deletions

View file

@ -2,9 +2,8 @@
Telnet OOB (Out of band communication)
This implements the following telnet oob protocols:
MSDP (Mud Server Data Protocol)
GMCP (Generic Mud Communication Protocol)
This implements the following telnet oob protocols: MSDP (Mud Server
Data Protocol) GMCP (Generic Mud Communication Protocol)
This implements the MSDP protocol as per
http://tintin.sourceforge.net/msdp/ and the GMCP protocol as per
@ -14,9 +13,9 @@ Following the lead of KaVir's protocol snippet, we first check if
client supports MSDP and if not, we fallback to GMCP with a MSDP
header where applicable.
OOB manages out-of-band
communication between the client and server, for updating health bars
etc. See also GMCP which is another standard doing the same thing.
OOB manages out-of-band communication between the client and server,
for updating health bars etc. See also GMCP which is another standard
doing the same thing.
"""
import re
@ -63,9 +62,12 @@ class TelnetOOB(object):
def __init__(self, protocol):
"""
Initiates by storing the protocol
on itself and trying to determine
if the client supports MSDP.
Initiates by storing the protocol on itself and trying to
determine if the client supports MSDP.
Args:
protocol (Protocol): The active protocol.
"""
self.protocol = protocol
self.protocol.protocol_flags['OOB'] = False
@ -80,23 +82,46 @@ class TelnetOOB(object):
self.oob_reported = {}
def no_msdp(self, option):
"No msdp supported or wanted"
"""
Client reports No msdp supported or wanted.
Args:
options (Option): Not used.
"""
# no msdp, check GMCP
self.protocol.handshake_done()
def do_msdp(self, option):
"MSDP supported by client"
"""
Client reports that it supports msdp.
Args:
option (Option): Not used.
"""
self.MSDP = True
self.protocol.protocol_flags['OOB'] = True
self.protocol.handshake_done()
def no_gmcp(self, option):
"Neither MSDP nor GMCP supported"
"""
If this is reached, it means neither MSDP nor GMCP is
supported.
Args:
option (Option): Not used.
"""
self.protocol.handshake_done()
def do_gmcp(self, option):
"""
Called when client confirms that it can do MSDP or GMCP.
Args:
option (Option): Not used.
"""
self.GMCP = True
self.protocol.protocol_flags['OOB'] = True
@ -106,17 +131,19 @@ class TelnetOOB(object):
def encode_msdp(self, cmdname, *args, **kwargs):
"""
handle return data from cmdname by converting it to
a proper msdp structure. These are the combinations we
support:
handle return data from cmdname by converting it to a proper
msdp structure. These are the combinations we support:
cmdname string -> cmdname string
cmdname *args -> cmdname MSDP_ARRAY
cmdname **kwargs -> cmdname MSDP_TABLE
Args:
cmdname (str): Name of OOB command.
args, kwargs (any): Arguments to OOB command.
# send 'raw' data structures
MSDP_ARRAY *args -> MSDP_ARRAY
MSDP_TABLE **kwargs -> MSDP_TABLE
Examples:
cmdname string -> cmdname string
cmdname *args -> cmdname MSDP_ARRAY
cmdname **kwargs -> cmdname MSDP_TABLE
MSDP_ARRAY *args -> MSDP_ARRAY
MSDP_TABLE **kwargs -> MSDP_TABLE
"""
msdp_string = ""
@ -138,14 +165,21 @@ class TelnetOOB(object):
def encode_gmcp(self, cmdname, *args, **kwargs):
"""
Gmcp messages are on one of the following outgoing forms:
Encode GMCP messages.
cmdname string -> cmdname string
cmdname *args -> cmdname [arg, arg, arg, ...]
cmdname **kwargs -> cmdname {key:arg, key:arg, ...}
Args:
cmdname (str): GMCP OOB command name.
args, kwargs (any): Arguments to OOB command.
cmdname is generally recommended to be a string on the form
Module.Submodule.Function
Notes:
Gmcp messages are on one of the following outgoing forms:
- cmdname string -> cmdname string
- cmdname *args -> cmdname [arg, arg, arg, ...]
- cmdname **kwargs -> cmdname {key:arg, key:arg, ...}
cmdname is generally recommended to be a string on the form
Module.Submodule.Function
"""
if cmdname in ("SEND", "REPORT", "UNREPORT", "LIST"):
# we wrap the standard MSDP commands in a MSDP.submodule
@ -165,11 +199,15 @@ class TelnetOOB(object):
def decode_msdp(self, data):
"""
Decodes incoming MSDP data
Decodes incoming MSDP data.
cmdname var --> cmdname arg
cmdname array --> cmdname *args
cmdname table --> cmdname **kwargs
Args:
data (str or list): MSDP data.
Notes:
cmdname var --> cmdname arg
cmdname array --> cmdname *args
cmdname table --> cmdname **kwargs
"""
tables = {}
@ -211,11 +249,15 @@ class TelnetOOB(object):
def decode_gmcp(self, data):
"""
Decodes incoming GMCP data on the form 'varname <structure>'
Decodes incoming GMCP data on the form 'varname <structure>'.
cmdname string -> cmdname arg
cmdname [arg, arg,...] -> cmdname *args
cmdname {key:arg, key:arg, ...} -> cmdname **kwargs
Args:
data (str or list): GMCP data.
Notes:
cmdname string -> cmdname arg
cmdname [arg, arg,...] -> cmdname *args
cmdname {key:arg, key:arg, ...} -> cmdname **kwargs
"""
if hasattr(data, "__iter__"):
@ -248,6 +290,11 @@ class TelnetOOB(object):
def data_out(self, cmdname, *args, **kwargs):
"""
Return a msdp-valid subnegotiation across the protocol.
Args:
cmdname (str): OOB-command name.
args, kwargs (any): Arguments to OOB command.
"""
#print "data_out:", encoded_oob
if self.MSDP: