Commits

William Pitcock committed 7fadc97

Update tests.

Comments (0)

Files changed (1)

 """
 
 import json
-from .pbkdf2 import pbkdf2_hex
+from pbkdf2 import pbkdf2_hex
 
 class Message(object):
     """
     def signature(self):
         return pbkdf2_hex(self.payload_json(), self.secret, keylen=64)
 
-    def dumps(self):
+    def dumps(self, pretty_print=False):
         envelope = self.obj
         envelope['signature'] = self.signature()
+
+        if pretty_print:
+            return json.dumps(envelope, indent=4, separators=(',', ': '))
+
         return json.dumps(envelope)
 
     def validate(self):
 
         return (self.signature() == self.expected_hash)
 
-    def payload(self)
+    def payload(self):
         return self.obj
 
 class InvalidSignatureException(Exception):
 
     signature = envelope.pop('signature', None)
     if signature is None:
-        except InvalidSignatureException()
+        raise InvalidSignatureException()
 
     message = Message(envelope, secret, signature)
     if message.validate() is not True:
-        except InvalidSignatureException()
+        raise InvalidSignatureException()
 
     return message.payload()
 
-def dumps(obj, secret):
+def dumps(obj, secret, pretty_print=False):
     '''Pack a dictionary into an Edia RPC message.'''
-    return Message(obj, secret).dumps()
+    return Message(obj, secret).dumps(pretty_print)
+
+if __name__ == '__main__':
+    secret = 'YNvngbwbWgjh4gbjh'
+    message = { 'message': 'doStuff', 'params': [1, 2, 3] }
 
+    print dumps(message, secret, True)