From 87f655b9fd09c77b168f90139239f88fad7576eb Mon Sep 17 00:00:00 2001 From: Jeremy Stanley Date: Sat, 29 Jul 2017 03:56:25 +0000 Subject: [PATCH] Switch quoting styles to reduce escaped quotes In an effort to address leaning toothpick syndrome, adjust quoting styles where possible to avoid escaping quote marks without increasing ambiguity. --- mudpy/misc.py | 96 ++++++++++++++++++++++++------------------------- mudpy/tests/selftest.py | 52 +++++++++++++-------------- share/menu.yaml | 2 +- 3 files changed, 75 insertions(+), 75 deletions(-) diff --git a/mudpy/misc.py b/mudpy/misc.py index 822beeb..59bef18 100644 --- a/mudpy/misc.py +++ b/mudpy/misc.py @@ -404,7 +404,7 @@ class Universe: inactive_avatars.append(self.contents[avatar]) except KeyError: pending_loglines.append(( - "Missing avatar \"%s\", possible data corruption" % + 'Missing avatar "%s", possible data corruption' % avatar, 6)) for user in self.userlist: if user.avatar in inactive_avatars: @@ -961,7 +961,7 @@ class User: try: avatars.append(universe.contents[avatar].get("name")) except KeyError: - log("Missing avatar \"%s\", possible data corruption." % + log('Missing avatar "%s", possible data corruption.' % avatar, 6) return avatars @@ -1977,8 +1977,8 @@ def command_help(actor, parameters): else: output += " $(grn)" output += item + "$(nrm) - " + description + "$(eol)" - output += ("$(eol)Enter \"help COMMAND\" for help on a command " - "named \"COMMAND\".") + output += ('$(eol)Enter "help COMMAND" for help on a command ' + 'named "COMMAND".') # send the accumulated output to the user actor.send(output) @@ -2008,13 +2008,13 @@ def command_say(actor, parameters): # if the message is wrapped in quotes, remove them and leave contents # intact - if parameters.startswith("\"") and parameters.endswith("\""): + if parameters.startswith('"') and parameters.endswith('"'): message = parameters[1:-1] literal = True # otherwise, get rid of stray quote marks on the ends of the message else: - message = parameters.strip("\"'`") + message = parameters.strip('''"'`''') literal = False # the user entered a message @@ -2072,9 +2072,9 @@ def command_say(actor, parameters): # tell the area if message: actor.echo_to_location( - actor.get("name") + " " + action + "s, \"" + message + "\"" + actor.get("name") + " " + action + 's, "' + message + '"' ) - actor.send("You " + action + ", \"" + message + "\"") + actor.send("You " + action + ', "' + message + '"') # there was no message else: @@ -2125,8 +2125,8 @@ def command_show(actor, parameters): if len(arguments) != 2: message = "You must specify one category." elif arguments[1] in universe.categories: - message = ("These are the elements in the \"" + arguments[1] - + "\" category:$(eol)") + message = ('These are the elements in the "' + arguments[1] + + '" category:$(eol)') elements = [ ( universe.categories[arguments[1]][x].key @@ -2136,27 +2136,27 @@ def command_show(actor, parameters): for element in elements: message += "$(eol) $(grn)" + element + "$(nrm)" else: - message = "Category \"" + arguments[1] + "\" does not exist." + message = 'Category "' + arguments[1] + '" does not exist.' elif arguments[0] == "file": if len(arguments) != 2: message = "You must specify one file." elif arguments[1] in universe.files: - message = ("These are the elements in the \"" + arguments[1] - + "\" file:$(eol)") + message = ('These are the elements in the "' + arguments[1] + + '" file:$(eol)') elements = universe.files[arguments[1]].data.keys() elements.sort() for element in elements: message += "$(eol) $(grn)" + element + "$(nrm)" else: - message = "Category \"" + arguments[1] + "\" does not exist." + message = 'Category "' + arguments[1] + '" does not exist.' elif arguments[0] == "element": if len(arguments) != 2: message = "You must specify one element." elif arguments[1].strip(".") in universe.contents: element = universe.contents[arguments[1].strip(".")] - message = ("These are the properties of the \"" + arguments[1] - + "\" element (in \"" + element.origin.filename - + "\"):$(eol)") + message = ('These are the properties of the "' + arguments[1] + + '" element (in "' + element.origin.filename + + '"):$(eol)') facets = element.facets() for facet in sorted(facets): if element.old_style: @@ -2166,7 +2166,7 @@ def command_show(actor, parameters): message += ("$(eol) $(grn)%s: $(red)%s$(nrm)" % (facet, str(facets[facet]))) else: - message = "Element \"" + arguments[1] + "\" does not exist." + message = 'Element "' + arguments[1] + '" does not exist.' elif arguments[0] == "result": if len(arguments) < 2: message = "You need to specify an expression." @@ -2207,7 +2207,7 @@ def command_show(actor, parameters): message = ("When specified, level must be 0-9 (default 1), " "start and stop must be >=1 (default 10 and 1).") else: - message = "I don't know what \"" + parameters + "\" is." + message = '''I don't know what "''' + parameters + '" is.' actor.send(message) @@ -2224,10 +2224,10 @@ def command_create(actor, parameters): if len(arguments) == 2: element, filename = arguments if element in universe.contents: - message = "The \"" + element + "\" element already exists." + message = 'The "' + element + '" element already exists.' else: - message = ("You create \"" + - element + "\" within the universe.") + message = ('You create "' + + element + '" within the universe.') logline = actor.owner.account.get( "name" ) + " created an element: " + element @@ -2235,7 +2235,7 @@ def command_create(actor, parameters): logline += " in file " + filename if filename not in universe.files: message += ( - " Warning: \"" + filename + "\" is not yet " + ' Warning: "' + filename + '" is not yet ' "included in any other file and will not be read " "on startup unless this is remedied.") Element(element, universe, filename, old_style=True) @@ -2252,11 +2252,11 @@ def command_destroy(actor, parameters): message = "You must specify an element to destroy." else: if parameters not in universe.contents: - message = "The \"" + parameters + "\" element does not exist." + message = 'The "' + parameters + '" element does not exist.' else: universe.contents[parameters].destroy() - message = ("You destroy \"" + parameters - + "\" within the universe.") + message = ('You destroy "' + parameters + + '" within the universe.') log( actor.owner.account.get( "name" @@ -2273,28 +2273,28 @@ def command_set(actor, parameters): else: arguments = parameters.split(" ", 2) if len(arguments) == 1: - message = ("What facet of element \"" + arguments[0] - + "\" would you like to set?") + message = ('What facet of element "' + arguments[0] + + '" would you like to set?') elif len(arguments) == 2: - message = ("What value would you like to set for the \"" + - arguments[1] + "\" facet of the \"" + arguments[0] - + "\" element?") + message = ('What value would you like to set for the "' + + arguments[1] + '" facet of the "' + arguments[0] + + '" element?') else: element, facet, value = arguments if element not in universe.contents: - message = "The \"" + element + "\" element does not exist." + message = 'The "' + element + '" element does not exist.' else: try: universe.contents[element].set(facet, value) except ValueError: - message = ("Value \"%s\" of type \"%s\" cannot be coerced " - "to the correct datatype for facet \"%s\"." % + message = ('Value "%s" of type "%s" cannot be coerced ' + 'to the correct datatype for facet "%s".' % (value, type(value), facet)) else: - message = ("You have successfully (re)set the \"" + facet - + "\" facet of element \"" + element - + "\". Try \"show element " + - element + "\" for verification.") + message = ('You have successfully (re)set the "' + facet + + '" facet of element "' + element + + '". Try "show element ' + + element + '" for verification.') actor.send(message) @@ -2305,23 +2305,23 @@ def command_delete(actor, parameters): else: arguments = parameters.split(" ") if len(arguments) == 1: - message = ("What facet of element \"" + arguments[0] - + "\" would you like to delete?") + message = ('What facet of element "' + arguments[0] + + '" would you like to delete?') elif len(arguments) != 2: message = "You may only specify an element and a facet." else: element, facet = arguments if element not in universe.contents: - message = "The \"" + element + "\" element does not exist." + message = 'The "' + element + '" element does not exist.' elif facet not in universe.contents[element].facets(): - message = ("The \"" + element + "\" element has no \"" + facet - + "\" facet.") + message = ('The "' + element + '" element has no "' + facet + + '" facet.') else: universe.contents[element].remove_facet(facet) - message = ("You have successfully deleted the \"" + facet - + "\" facet of element \"" + element - + "\". Try \"show element " + - element + "\" for verification.") + message = ('You have successfully deleted the "' + facet + + '" facet of element "' + element + + '". Try "show element ' + + element + '" for verification.') actor.send(message) @@ -2330,7 +2330,7 @@ def command_error(actor, input_data): # 90% of the time use a generic error if random.randrange(10): - message = "I'm not sure what \"" + input_data + "\" means..." + message = '''I'm not sure what "''' + input_data + '''" means...''' # 10% of the time use the classic diku error else: diff --git a/mudpy/tests/selftest.py b/mudpy/tests/selftest.py index 7251b90..d8f5106 100644 --- a/mudpy/tests/selftest.py +++ b/mudpy/tests/selftest.py @@ -10,7 +10,7 @@ import time test_account0_setup = ( (0, "Identify yourself:", "luser0"), (0, "Enter your choice:", "n"), - (0, "Enter a new password for \"luser0\":", "Test123"), + (0, 'Enter a new password for "luser0":', "Test123"), (0, "Enter the same new password again:", "Test123"), (0, r"What would you like to do\?", "c"), (0, "Pick a birth gender for your new avatar:", "f"), @@ -22,7 +22,7 @@ test_account0_setup = ( test_account1_setup = ( (1, "Identify yourself:", "luser1"), (1, "Enter your choice:", "n"), - (1, "Enter a new password for \"luser1\":", "Test456"), + (1, 'Enter a new password for "luser1":', "Test456"), (1, "Enter the same new password again:", "Test456"), (1, r"What would you like to do\?", "c"), (1, "Pick a birth gender for your new avatar:", "m"), @@ -41,18 +41,18 @@ test_explicit_punctuation = ( (1, r'exclaims, "Hello there\!"', "say And you are?"), (1, r'You ask, "And you are\?"', ""), (0, r'asks, "And you are\?"', "say I'm me, of course."), - (0, r'You say, "I\'m me, of course\."', ""), - (1, r'says, "I\'m me, of course\."', "say I wouldn't be so sure..."), - (1, r'You muse, "I wouldn\'t be so sure\.\.\."', ""), - (0, r'muses, "I wouldn\'t be so sure\.\.\."', "say You mean,"), + (0, r'''You say, "I'm me, of course\."''', ""), + (1, r'''says, "I'm me, of course\."''', "say I wouldn't be so sure..."), + (1, r'''You muse, "I wouldn't be so sure\.\.\."''', ""), + (0, r'''muses, "I wouldn't be so sure\.\.\."''', "say You mean,"), (0, 'You begin, "You mean,"', ""), (1, 'begins, "You mean,"', "say I know-"), (1, 'You begin, "I know-"', ""), (0, 'begins, "I know-"', "say Don't interrupt:"), - (0, r'You begin, "Don\'t interrupt:"', ""), - (1, r'begins, "Don\'t interrupt:"', "say I wasn't interrupting;"), - (1, r'You begin, "I wasn\'t interrupting;"', ""), - (0, r'begins, "I wasn\'t interrupting;"', ""), + (0, r'''You begin, "Don't interrupt:"''', ""), + (1, r'''begins, "Don't interrupt:"''', "say I wasn't interrupting;"), + (1, r'''You begin, "I wasn't interrupting;"''', ""), + (0, r'''begins, "I wasn't interrupting;"''', ""), ) test_implicit_punctuation = ( @@ -63,20 +63,20 @@ test_implicit_punctuation = ( test_typo_replacement = ( (1, '> ', "say That's what i think."), - (1, r'You say, "That\'s what I think\."', ""), - (0, r'says, "That\'s what I think\."', "say You know what i'd like."), - (0, r'You say, "You know what I\'d like\."', ""), - (1, r'says, "You know what I\'d like\."', "say Then i'll tell you."), - (1, r'You say, "Then I\'ll tell you\."', ""), - (0, r'says, "Then I\'ll tell you\."', "say Now i'm ready."), - (0, r'You say, "Now I\'m ready\."', ""), - (1, r'says, "Now I\'m ready\."', "say That's teh idea."), - (1, r'You say, "That\'s the idea\."', ""), - (0, r'says, "That\'s the idea\."', "say It's what theyre saying."), - (0, r'You say, "It\'s what they\'re saying\."', ""), - (1, r'says, "It\'s what they\'re saying\."', "say Well, youre right."), - (1, r'You say, "Well, you\'re right\."', ""), - (0, r'says, "Well, you\'re right\."', ""), + (1, r'''You say, "That's what I think\."''', ""), + (0, r'''says, "That's what I think\."''', "say You know what i'd like."), + (0, r'''You say, "You know what I'd like\."''', ""), + (1, r'''says, "You know what I'd like\."''', "say Then i'll tell you."), + (1, r'''You say, "Then I'll tell you\."''', ""), + (0, r'''says, "Then I'll tell you\."''', "say Now i'm ready."), + (0, r'''You say, "Now I'm ready\."''', ""), + (1, r'''says, "Now I'm ready\."''', "say That's teh idea."), + (1, r'''You say, "That's the idea\."''', ""), + (0, r'''says, "That's the idea\."''', "say It's what theyre saying."), + (0, r'''You say, "It's what they're saying\."''', ""), + (1, r'''says, "It's what they're saying\."''', "say Well, youre right."), + (1, r'''You say, "Well, you're right\."''', ""), + (0, r'''says, "Well, you're right\."''', ""), ) test_sentence_capitalization = ( @@ -133,7 +133,7 @@ test_account1_teardown = ( test_admin_setup = ( (2, "Identify yourself:", "admin"), (2, "Enter your choice:", "n"), - (2, "Enter a new password for \"admin\":", "Test789"), + (2, 'Enter a new password for "admin":', "Test789"), (2, "Enter the same new password again:", "Test789"), (2, r"What would you like to do\?", "c"), (2, "Pick a birth gender for your new avatar:", "m"), @@ -176,7 +176,7 @@ test_custom_loglevel = ( test_invalid_loglevel = ( (2, "> ", "set account:admin loglevel two"), - (2, r'Value "two" of type "" cannot be coerced .*> ', ""), + (2, r'''Value "two" of type "" cannot be coerced .*> ''', ""), ) test_log_no_errors = ( diff --git a/share/menu.yaml b/share/menu.yaml index 9735aec..afc4808 100644 --- a/share/menu.yaml +++ b/share/menu.yaml @@ -94,7 +94,7 @@ menu:entering_account_name: menu:entering_new_password: echo: off error_weak: That is a weak password... Try something at least 7 characters long with a combination of mixed-case letters, numbers and punctuation/spaces. - prompt: "Enter a new password for \"$(account)\":" + prompt: 'Enter a new password for "$(account)":' error_differs: The two passwords did not match. Try again... menu:initial: -- 2.11.0