Exemplo n.º 1
0
 def test_010_presence_deserialise(self):
     inputJ = """
           {
             "parent": {
               "child": {}
             }
           }"""
     x = pbJ.loads(inputJ, bindings, "presence")
     self.assertIs(x.parent.child._present(), True)
Exemplo n.º 2
0
 def parse(self, data, model, model_name, path_helper=None):
     try:
         model = pbJ.loads(data, model, model_name, path_helper=path_helper)
     except Exception as e:
         logger.info(f"Could not parse model data")
         logger.debug(f"Invalid model - Exception: {e}")
         model = {}
     finally:
         return model
Exemplo n.º 3
0
 def test_010_presence_deserialise(self):
   inputJ = """
             {
               "parent": {
                 "child": {}
               }
             }"""
   x = pbJ.loads(inputJ, bindings, "presence")
   self.assertIs(x.parent.child._present(), True)
Exemplo n.º 4
0
def jsonToPyangObject(mappingDetails, jsonStr):
  loadedObject = pybindJSON.loads(jsonStr, mappingDetails['yangObj'], mappingDetails['mappingObj']['modelName'])
  return loadedObject
Exemplo n.º 5
0
import pprint
import pyangbind.lib.pybindJSON as pbJ
import sbindings
import os

pp = pprint.PrettyPrinter(indent=4)

# Load an instance from file using PyBind's native JSON format
loaded_object = pbJ.load(os.path.join("json", "simple-instance.json"),
                         sbindings, "simple_serialise")
pp.pprint(loaded_object.get(filter=True))

# Load an instance from a corresponding string using the native JSON format
string_to_load = open(os.path.join('json', 'simple-instance.json'), 'r')
string_to_load = string_to_load.read().replace('\n', '')
loaded_object_two = pbJ.loads(string_to_load, sbindings, "simple_serialise")
pp.pprint(loaded_object_two.get(filter=True))

# Load an instance from an IETF-JSON file
loaded_ietf_obj = \
            pbJ.load_ietf(os.path.join("json", "simple-instance-ietf.json"),
                              sbindings, "simple_serialise")
pp.pprint(loaded_ietf_obj.get(filter=True))

# Load an instance from an IETF-JSON string
string_to_load = open(os.path.join('json', 'simple-instance-ietf.json'), 'r')
string_to_load = string_to_load.read().replace('\n', '')

loaded_ietf_obj_two = pbJ.loads_ietf(string_to_load, sbindings,
                                     "simple_serialise")
pp.pprint(loaded_ietf_obj_two.get(filter=True))
Exemplo n.º 6
0
from __future__ import unicode_literals, print_function
import pprint
import pyangbind.lib.pybindJSON as pbJ
import sbindings
import os

pp = pprint.PrettyPrinter(indent=4)

# Load an instance from file using PyBind's native JSON format
loaded_object = pbJ.load(os.path.join("json", "simple-instance.json"), sbindings, "simple_serialise")
pp.pprint(loaded_object.get(filter=True))

# Load an instance from a corresponding string using the native JSON format
string_to_load = open(os.path.join("json", "simple-instance.json"), "r")
string_to_load = string_to_load.read().replace("\n", "")
loaded_object_two = pbJ.loads(string_to_load, sbindings, "simple_serialise")
pp.pprint(loaded_object_two.get(filter=True))

# Load an instance from an IETF-JSON file
loaded_ietf_obj = pbJ.load_ietf(os.path.join("json", "simple-instance-ietf.json"), sbindings, "simple_serialise")
pp.pprint(loaded_ietf_obj.get(filter=True))

# Load an instance from an IETF-JSON string
string_to_load = open(os.path.join("json", "simple-instance-ietf.json"), "r")
string_to_load = string_to_load.read().replace("\n", "")

loaded_ietf_obj_two = pbJ.loads_ietf(string_to_load, sbindings, "simple_serialise")
pp.pprint(loaded_ietf_obj_two.get(filter=True))

# Load into an existing instance
from pyangbind.lib.serialise import pybindJSONDecoder
Exemplo n.º 7
0
  for i in [(-452.6729, False), (-444.44, True), (-443.22, False),
            (-330, True), (-222.21, False), (111.2, False), (111.1, True),
            (446.56, True), (555.55559282, False)]:
    passed = False
    try:
      q.container.dec64LeafWithRange = i[0]
      passed = True
    except ValueError, m:
      pass
    assert passed == i[1], \
        "decimal64 leaf with range was not correctly set (%f -> %s != %s)" \
            % (i[0], passed, i[1])

  testdata = '''
{
    "container": {
        "d1": 12.34
    }
}
'''
  import pyangbind.lib.pybindJSON as pbj
  doc = pbj.loads(testdata, bindings, 'decimal')
  print pbj.dumps(doc)

  if not k:
    os.system("/bin/rm %s/bindings.py" % this_dir)
    os.system("/bin/rm %s/bindings.pyc" % this_dir)

if __name__ == '__main__':
  main()