From fc46f2618332037a8c1b58fbce5d616033bff1c9 Mon Sep 17 00:00:00 2001
From: Dan Klein <danklei@cisco.com>
Date: Wed, 26 Aug 2015 15:05:58 +0300
Subject: Rearranged files and external libraries in two different locations,
 one for cpp (trex-core/external_libs) and one for python
 (trex-core/scripts/external_libs)

---
 scripts/external_libs/zmq/utils/jsonapi.py | 59 ++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100644 scripts/external_libs/zmq/utils/jsonapi.py

(limited to 'scripts/external_libs/zmq/utils/jsonapi.py')

diff --git a/scripts/external_libs/zmq/utils/jsonapi.py b/scripts/external_libs/zmq/utils/jsonapi.py
new file mode 100644
index 00000000..865ca6d5
--- /dev/null
+++ b/scripts/external_libs/zmq/utils/jsonapi.py
@@ -0,0 +1,59 @@
+"""Priority based json library imports.
+
+Always serializes to bytes instead of unicode for zeromq compatibility
+on Python 2 and 3.
+
+Use ``jsonapi.loads()`` and ``jsonapi.dumps()`` for guaranteed symmetry.
+
+Priority: ``simplejson`` > ``jsonlib2`` > stdlib ``json``
+
+``jsonapi.loads/dumps`` provide kwarg-compatibility with stdlib json.
+
+``jsonapi.jsonmod`` will be the module of the actual underlying implementation.
+"""
+
+# Copyright (C) PyZMQ Developers
+# Distributed under the terms of the Modified BSD License.
+
+from zmq.utils.strtypes import bytes, unicode
+
+jsonmod = None
+
+priority = ['simplejson', 'jsonlib2', 'json']
+for mod in priority:
+    try:
+        jsonmod = __import__(mod)
+    except ImportError:
+        pass
+    else:
+        break
+
+def dumps(o, **kwargs):
+    """Serialize object to JSON bytes (utf-8).
+    
+    See jsonapi.jsonmod.dumps for details on kwargs.
+    """
+    
+    if 'separators' not in kwargs:
+        kwargs['separators'] = (',', ':')
+    
+    s = jsonmod.dumps(o, **kwargs)
+    
+    if isinstance(s, unicode):
+        s = s.encode('utf8')
+    
+    return s
+
+def loads(s, **kwargs):
+    """Load object from JSON bytes (utf-8).
+    
+    See jsonapi.jsonmod.loads for details on kwargs.
+    """
+    
+    if str is unicode and isinstance(s, bytes):
+        s = s.decode('utf8')
+    
+    return jsonmod.loads(s, **kwargs)
+
+__all__ = ['jsonmod', 'dumps', 'loads']
+
-- 
cgit