Skip to content

Commit

Permalink
Merge pull request #315 from sepalani/gs_query
Browse files Browse the repository at this point in the history
Cleaned: gamespy/gs_query.py
  • Loading branch information
AdmiralCurtiss committed Jul 31, 2016
2 parents f3339f8 + 78d5624 commit 9e84456
Showing 1 changed file with 9 additions and 24 deletions.
33 changes: 9 additions & 24 deletions gamespy/gs_query.py
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2014 polaris-
Copyright (C) 2014 ToadKing
Copyright (C) 2014 AdmiralCurtiss
Copyright (C) 2015 Sepalani
Copyright (C) 2016 Sepalani
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
Expand All @@ -19,8 +19,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

import copy


def parse_gamespy_message(message):
"""Parse a GameSpy message."""
Expand Down Expand Up @@ -65,40 +63,27 @@ def parse_gamespy_message(message):
return stack, msg


def create_gamespy_message_from_dict(messages_orig):
def create_gamespy_message_from_dict(messages):
"""Generate a list based on the input dictionary.
The main command must also be stored in __cmd__ for it to put the
parameter at the beginning.
"""
# Deep copy the dictionary because we don't want the original to be
# modified
messages = copy.deepcopy(messages_orig)

if "__cmd__" in messages:
cmd = messages['__cmd__']
messages.pop('__cmd__', None)
else:
cmd = ""

if "__cmd_val__" in messages:
cmd_val = messages['__cmd_val__']
messages.pop('__cmd_val__', None)
else:
cmd_val = ""

if cmd in messages:
messages.pop(cmd, None)
cmd = messages.get("__cmd__", "")
cmd_val = messages.get("__cmd_val__", "")

l = [("__cmd__", cmd), ("__cmd_val__", cmd_val)]
l.extend([(message, messages[message]) for message in messages])
l.extend([
(key, value)
for key, value in messages.items()
if key not in (cmd, "__cmd__", "__cmd_val__")
])

return l


def create_gamespy_message_from_list(messages):
"""Generate a string based on the input list."""
d = {}
cmd = ""
cmd_val = ""

Expand Down

0 comments on commit 9e84456

Please sign in to comment.