PEP 8 coding, whitespace, docstring/comment edits
Marking debug code, fix typo in docstring
This commit is contained in:
parent
42b41a6889
commit
0af6f2498e
1 changed files with 41 additions and 41 deletions
|
|
@ -51,11 +51,13 @@ 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_VAR, MSDP_VAL,
|
||||||
MSDP_TABLE_OPEN,
|
MSDP_TABLE_OPEN,
|
||||||
MSDP_TABLE_CLOSE))
|
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_VAR, MSDP_VAL,
|
||||||
MSDP_ARRAY_OPEN,
|
MSDP_ARRAY_OPEN,
|
||||||
MSDP_ARRAY_CLOSE))
|
MSDP_ARRAY_CLOSE))
|
||||||
msdp_regex_var = re.compile(r"%s" % MSDP_VAR)
|
msdp_regex_var = re.compile(r"%s" % MSDP_VAR)
|
||||||
|
|
@ -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:
|
||||||
|
|
@ -186,11 +187,10 @@ class TelnetOOB(object):
|
||||||
"{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
|
||||||
|
|
@ -199,13 +199,14 @@ class TelnetOOB(object):
|
||||||
"{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,
|
||||||
|
json.dumps(val))
|
||||||
for key, val in kwargs.iteritems()))
|
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):
|
||||||
|
|
@ -241,7 +242,7 @@ class TelnetOOB(object):
|
||||||
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)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue