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