PEP 8 coding, whitespace, docstring/comment edits

Marking debug code, fix typo in docstring
This commit is contained in:
BlauFeuer 2017-03-03 18:08:47 -05:00 committed by GitHub
parent 42b41a6889
commit 0af6f2498e

View file

@ -32,12 +32,12 @@ from evennia.utils.utils import to_str
# MSDP-relevant telnet cmd/opt-codes # MSDP-relevant telnet cmd/opt-codes
MSDP = chr(69) MSDP = chr(69)
MSDP_VAR = chr(1) #^A MSDP_VAR = chr(1) # ^A
MSDP_VAL = chr(2) #^B MSDP_VAL = chr(2) # ^B
MSDP_TABLE_OPEN = chr(3) #^C MSDP_TABLE_OPEN = chr(3) # ^C
MSDP_TABLE_CLOSE = chr(4) #^D MSDP_TABLE_CLOSE = chr(4) # ^D
MSDP_ARRAY_OPEN = chr(5) #^E MSDP_ARRAY_OPEN = chr(5) # ^E
MSDP_ARRAY_CLOSE = chr(6) #^F MSDP_ARRAY_CLOSE = chr(6) # ^F
# GMCP # GMCP
GMCP = chr(201) GMCP = chr(201)
@ -51,13 +51,15 @@ force_str = lambda inp: to_str(inp, force_string=True)
# pre-compiled regexes # pre-compiled regexes
# returns 2-tuple # returns 2-tuple
msdp_regex_table = re.compile(r"%s\s*(\w*?)\s*%s\s*%s(.*?)%s" % (MSDP_VAR, MSDP_VAL, msdp_regex_table = re.compile(r"%s\s*(\w*?)\s*%s\s*%s(.*?)%s"
MSDP_TABLE_OPEN, % (MSDP_VAR, MSDP_VAL,
MSDP_TABLE_CLOSE)) MSDP_TABLE_OPEN,
MSDP_TABLE_CLOSE))
# returns 2-tuple # returns 2-tuple
msdp_regex_array = re.compile(r"%s\s*(\w*?)\s*%s\s*%s(.*?)%s" % (MSDP_VAR, MSDP_VAL, msdp_regex_array = re.compile(r"%s\s*(\w*?)\s*%s\s*%s(.*?)%s"
MSDP_ARRAY_OPEN, % (MSDP_VAR, MSDP_VAL,
MSDP_ARRAY_CLOSE)) MSDP_ARRAY_OPEN,
MSDP_ARRAY_CLOSE))
msdp_regex_var = re.compile(r"%s" % MSDP_VAR) msdp_regex_var = re.compile(r"%s" % MSDP_VAR)
msdp_regex_val = re.compile(r"%s" % MSDP_VAL) msdp_regex_val = re.compile(r"%s" % MSDP_VAL)
@ -67,9 +69,8 @@ EVENNIA_TO_GMCP = {"client_options": "Core.Supports.Get",
"repeat": "Char.Repeat.Update", "repeat": "Char.Repeat.Update",
"monitor": "Char.Monitor.Update"} "monitor": "Char.Monitor.Update"}
# Msdp object handler
class TelnetOOB(object): class TelnetOOB(object): # Msdp object handler
""" """
Implements the MSDP and GMCP protocols. Implements the MSDP and GMCP protocols.
""" """
@ -100,7 +101,7 @@ class TelnetOOB(object):
Client reports No msdp supported or wanted. Client reports No msdp supported or wanted.
Args: Args:
options (Option): Not used. option (Option): Not used.
""" """
# no msdp, check GMCP # no msdp, check GMCP
@ -173,7 +174,7 @@ class TelnetOOB(object):
if not (args or kwargs): if not (args or kwargs):
return msdp_cmdname return msdp_cmdname
#print "encode_msdp in:", cmdname, args, kwargs # print("encode_msdp in:", cmdname, args, kwargs) # DEBUG
msdp_args = '' msdp_args = ''
if args: if args:
@ -182,30 +183,30 @@ class TelnetOOB(object):
msdp_args += args[0] msdp_args += args[0]
else: else:
msdp_args += "{msdp_array_open}" \ msdp_args += "{msdp_array_open}" \
"{msdp_args}" \ "{msdp_args}" \
"{msdp_array_close}".format( "{msdp_array_close}".format(
msdp_array_open=MSDP_ARRAY_OPEN, msdp_array_open=MSDP_ARRAY_OPEN,
msdp_array_close=MSDP_ARRAY_CLOSE, msdp_array_close=MSDP_ARRAY_CLOSE,
msdp_args= "".join("%s%s" % ( msdp_args="".join("%s%s"
MSDP_VAL, json.dumps(val)) % (MSDP_VAL, json.dumps(val))
for val in args)) for val in args))
msdp_kwargs = "" msdp_kwargs = ""
if kwargs: if kwargs:
msdp_kwargs = msdp_cmdname msdp_kwargs = msdp_cmdname
msdp_kwargs += "{msdp_table_open}" \ msdp_kwargs += "{msdp_table_open}" \
"{msdp_kwargs}" \ "{msdp_kwargs}" \
"{msdp_table_close}".format( "{msdp_table_close}".format(
msdp_table_open=MSDP_TABLE_OPEN, msdp_table_open=MSDP_TABLE_OPEN,
msdp_table_close=MSDP_TABLE_CLOSE, msdp_table_close=MSDP_TABLE_CLOSE,
msdp_kwargs = "".join("%s%s%s%s" % ( msdp_kwargs="".join("%s%s%s%s"
MSDP_VAR, key, MSDP_VAL, json.dumps(val)) % (MSDP_VAR, key, MSDP_VAL,
for key, val in kwargs.iteritems())) json.dumps(val))
for key, val in kwargs.iteritems()))
msdp_string = msdp_args + msdp_kwargs msdp_string = msdp_args + msdp_kwargs
#print "msdp_string:", msdp_string # print("msdp_string:", msdp_string) # DEBUG
return msdp_string return msdp_string
def encode_gmcp(self, cmdname, *args, **kwargs): def encode_gmcp(self, cmdname, *args, **kwargs):
@ -238,10 +239,10 @@ class TelnetOOB(object):
gmcp_string = "%s %s" % (cmdname, json.dumps([args, kwargs])) gmcp_string = "%s %s" % (cmdname, json.dumps([args, kwargs]))
else: else:
gmcp_string = "%s %s" % (cmdname, json.dumps(args)) gmcp_string = "%s %s" % (cmdname, json.dumps(args))
else: # only kwargs else: # only kwargs
gmcp_string = "%s %s" % (cmdname, json.dumps(kwargs)) gmcp_string = "%s %s" % (cmdname, json.dumps(kwargs))
#print "gmcp string", gmcp_string # print("gmcp string", gmcp_string) # DEBUG
return gmcp_string return gmcp_string
def decode_msdp(self, data): def decode_msdp(self, data):
@ -271,7 +272,7 @@ class TelnetOOB(object):
if hasattr(data, "__iter__"): if hasattr(data, "__iter__"):
data = "".join(data) data = "".join(data)
#print "decode_msdp in:", data # print("decode_msdp in:", data) # DEBUG
tables = {} tables = {}
arrays = {} arrays = {}
@ -279,7 +280,7 @@ class TelnetOOB(object):
# decode tables # decode tables
for key, table in msdp_regex_table.findall(data): for key, table in msdp_regex_table.findall(data):
tables[key] = {} if not key in tables else tables[key] tables[key] = {} if key not in tables else tables[key]
for varval in msdp_regex_var.split(table)[1:]: for varval in msdp_regex_var.split(table)[1:]:
var, val = msdp_regex_val.split(varval, 1) var, val = msdp_regex_val.split(varval, 1)
if var: if var:
@ -288,7 +289,7 @@ class TelnetOOB(object):
# decode arrays from all that was not a table # decode arrays from all that was not a table
data_no_tables = msdp_regex_table.sub("", data) data_no_tables = msdp_regex_table.sub("", data)
for key, array in msdp_regex_array.findall(data_no_tables): for key, array in msdp_regex_array.findall(data_no_tables):
arrays[key] = [] if not key in arrays else arrays[key] arrays[key] = [] if key not in arrays else arrays[key]
parts = msdp_regex_val.split(array) parts = msdp_regex_val.split(array)
if len(parts) == 2: if len(parts) == 2:
arrays[key].append(parts[1]) arrays[key].append(parts[1])
@ -326,10 +327,9 @@ class TelnetOOB(object):
for key, var in variables.iteritems(): for key, var in variables.iteritems():
cmds[key] = [[var], {}] cmds[key] = [[var], {}]
#print "msdp data in:", cmds # print("msdp data in:", cmds) # DEBUG
self.protocol.data_in(**cmds) self.protocol.data_in(**cmds)
def decode_gmcp(self, data): def decode_gmcp(self, data):
""" """
Decodes incoming GMCP data on the form 'varname <structure>'. Decodes incoming GMCP data on the form 'varname <structure>'.
@ -353,7 +353,7 @@ class TelnetOOB(object):
if hasattr(data, "__iter__"): if hasattr(data, "__iter__"):
data = "".join(data) data = "".join(data)
#print "decode_gmcp in:", data # print("decode_gmcp in:", data) # DEBUG
if data: if data:
try: try:
cmdname, structure = data.split(None, 1) cmdname, structure = data.split(None, 1)
@ -368,7 +368,7 @@ class TelnetOOB(object):
args, kwargs = [], {} args, kwargs = [], {}
if hasattr(structure, "__iter__"): if hasattr(structure, "__iter__"):
if isinstance(structure, dict): if isinstance(structure, dict):
kwargs = {key: value for key, value in structure.iteritems() if key } kwargs = {key: value for key, value in structure.iteritems() if key}
else: else:
args = list(structure) args = list(structure)
else: else: