Commits

Marcin Kasperski committed 0eb958e

Using ordered dictionary for parsed params to preserve their order

Comments (0)

Files changed (4)

 """
 
 from setuptools import setup, find_packages
-import os
+import os, sys
 execfile(os.path.join(os.path.dirname(__file__), "src", "mekk", "fics", "version.py"))
 
 long_description = open("README.txt").read()
 
 license = "Artistic" # or MPL 1.1
 
+requirements = [
+    'Twisted',
+]
+if sys.version < (2,7,0):
+    requirements.append('ordereddict')
+
 setup(name='mekk.fics',
       version=VERSION,
       description="FICS client library.",
       test_suite = 'nose.collector',
       include_package_data = True,
       zip_safe=False,
-      install_requires=[
-        'Twisted',
-      ],
+      install_requires=requirements,
       tests_require=[
         'nose',
         'dict_compare',

src/mekk/fics/tell_commands/command_parser.py

 import re, logging
 from mekk.fics.tell_commands.shortcut_resolver import ShortcutResolver
 from mekk.fics.tell_commands import tell_errors
+from mekk.fics.tell_commands.odict import OrderedDict
 
 logger = logging.getLogger("fics.lib")
 
         Parse given text. In case it can not be parsed,
         throws exception.
 
-        :returns: command name, args, kwargs
+        :returns: command name, args, kwargs (the latter as OrderedDict)
         """
         words = re_spaces.split(text.strip(' \r\n'))
 
             raise tell_errors.UnknownCommand(e.bad_keyword, e.known_keywords)
 
         args = []
-        kwargs = {}
+        kwargs = OrderedDict
         for word in words:
             m = re_eq.search(word)
             if m:

src/mekk/fics/tell_commands/fics_client_mixin_tell_commands.py

         :type player: PlayerType
         :param args: list of positional arguments (guaranteed to satisfy positional_parameters_count requirement)
         :type args: [str]
-        :param named_args: keyword arguments (resolved against list of known params - if specified by named_parameters)
-        :type named_args: dict
+        :param named_args: keyword arguments (resolved against list of known params - if specified
+            by named_parameters)
+        :type named_args: OrderedDict
         :return: deferred signalling end of processing, or string if it is over immediately. If string is non-empty (or
             deferred is fired with non-empty string as parameter), the string is treated as result to be told to the player issuing
             the command

src/mekk/fics/tell_commands/odict.py

+# -*- coding: utf-8 -*-
+
+try:
+    from collections import OrderedDict
+except ImportError:
+    # pip install ordereddict
+    from ordereddict import OrderedDict
+