Addresses requested changes + shim code
class variable name changes handled by shim
This commit is contained in:
parent
111b1c5136
commit
546927dd74
1 changed files with 44 additions and 44 deletions
|
|
@ -80,9 +80,10 @@ class MuxCommand(Command):
|
||||||
start with the switch indicator /.
|
start with the switch indicator /.
|
||||||
|
|
||||||
Optional variables to aid in parsing, if set:
|
Optional variables to aid in parsing, if set:
|
||||||
self.options = (tuple of valid /switches expected
|
self.switch_options - (tuple of valid /switches expected by this
|
||||||
by this command (without the /))
|
command (without the /))
|
||||||
self.split = Alternate string delimiter to separate left/right hand side.
|
self.rhs_split - Alternate string delimiter to separate
|
||||||
|
left/right hand sides.
|
||||||
|
|
||||||
This parser breaks self.args into its constituents and stores them in the
|
This parser breaks self.args into its constituents and stores them in the
|
||||||
following variables:
|
following variables:
|
||||||
|
|
@ -102,6 +103,18 @@ class MuxCommand(Command):
|
||||||
"""
|
"""
|
||||||
raw = self.args
|
raw = self.args
|
||||||
args = raw.strip()
|
args = raw.strip()
|
||||||
|
# Temporary code to use the old settings before renaming # #
|
||||||
|
if hasattr(self, "options"): #
|
||||||
|
self.switch_options = self.options #
|
||||||
|
if hasattr(self, "split") and not hasattr(self, "rhs_split"): #
|
||||||
|
self.rhs_split = self.split # # #
|
||||||
|
# Without explicitly setting these attributes, they assume default values:
|
||||||
|
if not hasattr(self, "switch_options"):
|
||||||
|
self.switch_options = None
|
||||||
|
if not hasattr(self, "rhs_split"):
|
||||||
|
self.rhs_split = "="
|
||||||
|
if not hasattr(self, "account_caller"):
|
||||||
|
self.account_caller = False
|
||||||
|
|
||||||
# split out switches
|
# split out switches
|
||||||
switches = []
|
switches = []
|
||||||
|
|
@ -114,17 +127,19 @@ class MuxCommand(Command):
|
||||||
else:
|
else:
|
||||||
args = ""
|
args = ""
|
||||||
switches = switches[0].split('/')
|
switches = switches[0].split('/')
|
||||||
# Parse mux options, comparing them against user-provided switches, expanding abbreviations.
|
# If user-provides switches, parse them with parser switch options.
|
||||||
if hasattr(self, "options") and self.options and switches:
|
if switches and self.switch_options:
|
||||||
# If specific options are known, test them against given switches.
|
|
||||||
valid_switches, unused_switches, extra_switches = [], [], []
|
valid_switches, unused_switches, extra_switches = [], [], []
|
||||||
for element in switches:
|
for element in switches:
|
||||||
option_check = [each for each in self.options if each.lower().startswith(element.lower())]
|
option_check = [each for each in self.switch_options
|
||||||
if len(option_check) > 1:
|
if each.lower() == element.lower() or
|
||||||
|
each.lower().startswith(element.lower())]
|
||||||
|
match_count = len(option_check)
|
||||||
|
if match_count > 1:
|
||||||
extra_switches += option_check # Either the option provided is ambiguous,
|
extra_switches += option_check # Either the option provided is ambiguous,
|
||||||
elif len(option_check) == 1:
|
elif match_count == 1:
|
||||||
valid_switches += option_check # or it is a valid option abbreviation,
|
valid_switches += option_check # or it is a valid option abbreviation,
|
||||||
elif len(option_check) == 0:
|
elif match_count == 0:
|
||||||
unused_switches += [element] # or an extraneous option to be ignored.
|
unused_switches += [element] # or an extraneous option to be ignored.
|
||||||
if extra_switches: # User provided switches
|
if extra_switches: # User provided switches
|
||||||
self.msg('|g%s|n: |wAmbiguous switch supplied: Did you mean /|C%s|w?' %
|
self.msg('|g%s|n: |wAmbiguous switch supplied: Did you mean /|C%s|w?' %
|
||||||
|
|
@ -138,21 +153,22 @@ class MuxCommand(Command):
|
||||||
|
|
||||||
# check for arg1, arg2, ... = argA, argB, ... constructs
|
# check for arg1, arg2, ... = argA, argB, ... constructs
|
||||||
lhs, rhs = args.strip(), None
|
lhs, rhs = args.strip(), None
|
||||||
lhslist, rhslist = [arg.strip() for arg in args.split(',')], []
|
best_split = self.rhs_split
|
||||||
if lhs:
|
if lhs:
|
||||||
if '=' in lhs: # Default delimiter has priority
|
if hasattr(self.rhs_split, '__iter__'):
|
||||||
# Parse to separate left into left/right sides using default delimiter
|
for this_split in self.rhs_split:
|
||||||
lhs, rhs = lhs.split('=', 1)
|
if this_split in lhs: # First delimiter to allow a successful
|
||||||
elif hasattr(self, "split") and self.split and self.split in lhs:
|
best_split = this_split # split is the best split.
|
||||||
# Parse to separate left into left/right sides using a custom delimiter, if provided.
|
break
|
||||||
lhs, rhs = lhs.split(self.split, 1) # At most, split once, into left and right parts.
|
# Parse to separate left into left/right sides using best_split delimiter string
|
||||||
# Trim user-injected whitespace
|
if best_split in lhs:
|
||||||
rhs = rhs.strip() if rhs is not None else None
|
lhs, rhs = lhs.split(best_split, 1)
|
||||||
lhs = lhs.strip()
|
# Trim user-injected whitespace
|
||||||
# Further split left/right sides by comma delimiter
|
rhs = rhs.strip() if rhs is not None else None
|
||||||
lhslist = [arg.strip() for arg in lhs.split(',')] if lhs is not None else ""
|
lhs = lhs.strip()
|
||||||
rhslist = [arg.strip() for arg in rhs.split(',')] if rhs is not None else ""
|
# Further split left/right sides by comma delimiter
|
||||||
|
lhslist = [arg.strip() for arg in lhs.split(',')] if lhs is not None else ""
|
||||||
|
rhslist = [arg.strip() for arg in rhs.split(',')] if rhs is not None else ""
|
||||||
# save to object properties:
|
# save to object properties:
|
||||||
self.raw = raw
|
self.raw = raw
|
||||||
self.switches = switches
|
self.switches = switches
|
||||||
|
|
@ -167,7 +183,7 @@ class MuxCommand(Command):
|
||||||
# sure that self.caller is always the account if possible. We also create
|
# sure that self.caller is always the account if possible. We also create
|
||||||
# a special property "character" for the puppeted object, if any. This
|
# a special property "character" for the puppeted object, if any. This
|
||||||
# is convenient for commands defined on the Account only.
|
# is convenient for commands defined on the Account only.
|
||||||
if hasattr(self, "account_caller") and self.account_caller:
|
if self.account_caller:
|
||||||
if utils.inherits_from(self.caller, "evennia.objects.objects.DefaultObject"):
|
if utils.inherits_from(self.caller, "evennia.objects.objects.DefaultObject"):
|
||||||
# caller is an Object/Character
|
# caller is an Object/Character
|
||||||
self.character = self.caller
|
self.character = self.caller
|
||||||
|
|
@ -203,10 +219,8 @@ class MuxCommand(Command):
|
||||||
string += "\nraw argument (self.raw): |w%s|n \n" % self.raw
|
string += "\nraw argument (self.raw): |w%s|n \n" % self.raw
|
||||||
string += "cmd args (self.args): |w%s|n\n" % self.args
|
string += "cmd args (self.args): |w%s|n\n" % self.args
|
||||||
string += "cmd switches (self.switches): |w%s|n\n" % self.switches
|
string += "cmd switches (self.switches): |w%s|n\n" % self.switches
|
||||||
if hasattr(self, "options"): # Optional
|
string += "cmd options (self.switch_options): |w%s|n\n" % self.switch_options
|
||||||
string += "cmd options (self.options): |w%s|n\n" % self.options
|
string += "cmd parse left/right using (self.rhs_split): |w%s|n\n" % self.rhs_split
|
||||||
if hasattr(self, "split"): # Optional
|
|
||||||
string += "cmd parse left/right using (self.split): |w%s|n\n" % self.split
|
|
||||||
string += "space-separated arg list (self.arglist): |w%s|n\n" % self.arglist
|
string += "space-separated arg list (self.arglist): |w%s|n\n" % self.arglist
|
||||||
string += "lhs, left-hand side of '=' (self.lhs): |w%s|n\n" % self.lhs
|
string += "lhs, left-hand side of '=' (self.lhs): |w%s|n\n" % self.lhs
|
||||||
string += "lhs, comma separated (self.lhslist): |w%s|n\n" % self.lhslist
|
string += "lhs, comma separated (self.lhslist): |w%s|n\n" % self.lhslist
|
||||||
|
|
@ -231,18 +245,4 @@ class MuxAccountCommand(MuxCommand):
|
||||||
character is actually attached to this Account and Session.
|
character is actually attached to this Account and Session.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def parse(self):
|
account_caller = True # Using MuxAccountCommand explicitly defaults the caller to an account
|
||||||
"""
|
|
||||||
We run the parent parser as usual, then fix the result
|
|
||||||
"""
|
|
||||||
super(MuxAccountCommand, self).parse()
|
|
||||||
|
|
||||||
if utils.inherits_from(self.caller, "evennia.objects.objects.DefaultObject"):
|
|
||||||
# caller is an Object/Character
|
|
||||||
self.character = self.caller
|
|
||||||
self.caller = self.caller.account
|
|
||||||
elif utils.inherits_from(self.caller, "evennia.accounts.accounts.DefaultAccount"):
|
|
||||||
# caller was already an Account
|
|
||||||
self.character = self.caller.get_puppet(self.session)
|
|
||||||
else:
|
|
||||||
self.character = None
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue