__author__ = 'aarongary'

class Lispify():
    def __init__(self, obj):
        if(obj is None):
            raise ValueError("Please provide an object")

        self.obj = obj

    def to_lisp(self):
        if type(self.obj) is unicode:
            return self.lispify(str(self.obj))
        else:
            return self.lispify(self.obj)

    def lispify(self, L, indra_statement=False):
        "Convert a Python object L to a lisp representation."
        if (isinstance(L, str)
            or isinstance(L, float)
            or isinstance(L, int)):

            if indra_statement:
                return '"%s"' % L
            else:
                return L

        elif (isinstance(L, list)
              or isinstance(L, tuple)):
            s = []
            for element in L:
                s += [self.lispify(element)]
            return '(' + ' '.join(s) + ')'
        elif isinstance(L, dict):
            s = []
            for key in L:
                #print "key: " + key
                #print L[key]
                tmp_key = str(key)
                if not tmp_key.isalnum():
                    tmp_key = '"%s"' % tmp_key
                if key == "INDRA statement":
                    s += [":{0} {1}".format("INDRA_statement", self.lispify(L[key], True))]# tmp_key, self.lispify(L[key], True))]
                else:
                    s += [":{0} {1}".format(tmp_key, self.lispify(L[key], False))]
            return '(' + ' '.join(s) + ')'
        elif isinstance(L, unicode):
            if indra_statement:
                return '"%s"' % str(L)
            else:
                return str(L)
        else:
            return L

@@ -956,75 +956,8 @@
  L:%0A
-                #print %22key: %22 + key%0A                #print L%5Bkey%5D%0A
     
@@ -1010,19 +1010,22 @@
  if 
-not
+%22 %22 in
  tmp_key
 .isa
@@ -1024,18 +1024,8 @@
 _key
-.isalnum()
 :%0A  
@@ -1056,24 +1056,33 @@
 y = 
-'%22%25s%22' %25 tmp_key
+%22_%22.join(tmp_key.split())
 %0A   
@@ -1122,16 +1122,54 @@
 tement%22:
+  # Indra statements need to be quoted
 %0A       
@@ -1248,47 +1248,8 @@
 ey%5D,
- True))%5D# tmp_key, self.lispify(L%5Bkey%5D,
  Tru

Fix issue with lispifying return messages (KQML) where keys have spaces.