コード例 #1
0
ファイル: test_Json.py プロジェクト: asuiu/pyxtension
    def test_copy(self):
        class MyMutableObject(object):
            def __init__(self):
                self.attribute = None

        foo = MyMutableObject()
        foo.attribute = True

        a = Json()
        a.immutable = 42
        a.mutable = foo

        b = a.copy()

        # immutable object should not change
        b.immutable = 21
        self.assertEqual(a.immutable, 42)

        # mutable object should change
        b.mutable.attribute = False
        self.assertEqual(a.mutable.attribute, b.mutable.attribute)

        # changing child of b should not affect a
        b.child = "new stuff"
        self.assertTrue(isinstance(a.child, Json))
コード例 #2
0
ファイル: test_Json.py プロジェクト: asuiu/pyxtension
 def test_to_dict_with_tuple(self):
     nested = {"a": ({"a": 0}, {2: 0})}
     prop = Json(nested)
     regular = prop.toOrig()
     self.assertDictEqual(regular, prop)
     self.assertDictEqual(regular, nested)
     self.assertIsInstance(regular["a"], tuple)
     self.assertNotIsInstance(regular["a"][0], Json)
コード例 #3
0
ファイル: parser.py プロジェクト: asuiu/pyNLP
 def toJson(self):
     """
     :return:
     :rtype: Json
     """
     j = Json()
     j.text = self._text
     j.tree = self._tree.toJson()
     j.dependencies = self.dependencies.toJson()
コード例 #4
0
ファイル: test_Json.py プロジェクト: asuiu/pyxtension
    def test_to_dict(self):
        nested = {"a": [{"a": 0}, 2], "b": {}, "c": 2}
        prop = Json(nested)
        regular = prop.toOrig()
        self.assertDictEqual(regular, prop)
        self.assertDictEqual(regular, nested)
        self.assertNotIsInstance(regular, Json)
        with self.assertRaises(AttributeError):
            regular.a

        def get_attr_deep():
            return regular["a"][0].a

        self.assertRaises(AttributeError, get_attr_deep)
コード例 #5
0
def bridgeHook(hook):
    # This function does all the magic

    # The event key is used to determine the type of event
    # e.g. repo:push, issue:created, etc.
    event = request.headers.get('X-Event-Key')

    # The template folder is searched for a template file
    # that matches thee event-key, (: replaced by -), e.g.
    # repo-push
    template_file_name = event.replace(":", "-")
    template_file = template_folder + template_file_name
    if (os.path.exists(template_file)):
        # Parse the json data from the webhook
        data = Json(request.get_json())

        # Read the template file and render it using the
        # data from the webhook
        template = Template(open(template_file, 'r').read())
        output = template.render(data=data)

        # Submit the new, bridged, webhook to the mattermost
        # incoming webhook
        submitHook(config.webhook_url + hook, output)
        return "Done"
    else:
        # In case there's no templat for the event
        # throw an error
        return "Couldn't handle this event", HTTP_500_INTERNAL_SERVER_ERROR
コード例 #6
0
def bridge_hook(hook):
    # This function does all the magic

    # The event key is used to determine the type of event
    # e.g. repo:push, issue:created, etc.
    event = request.headers.get('X-Event-Key')

    # The template folder is searched for a template file
    # that matches thee event-key, (: replaced by -), e.g.
    # repo-push
    payload_name = event.replace(":", "_")
    payload_func = getattr(payload, payload_name, None)

    if payload_func:
        # Parse the json data from the webhook
        data = Json(request.get_json())
        output = payload_func(data)
        # Submit the new, bridged, webhook to the mattermost
        # incoming webhook
        submit_hook(config.webhook_url + hook, output)
        return "Done"
    else:
        # In case there's no templat for the event
        # throw an error
        print(event)
        return "Couldn't handle this event", 501
コード例 #7
0
ファイル: test_Json.py プロジェクト: asuiu/pyxtension
    def test_update(self):
        old = Json()
        old.child.a = "old a"
        old.child.b = "old b"
        old.foo = "no dict"

        new = Json()
        new.child.b = "new b"
        new.child.c = "new c"
        new.foo.now_my_papa_is_a_dict = True

        old.update(new)

        reference = {"foo": {"now_my_papa_is_a_dict": True}, "child": {"c": "new c", "b": "new b"}}

        self.assertDictEqual(old, reference)
コード例 #8
0
ファイル: test_Json.py プロジェクト: asuiu/pyxtension
    def test_update_with_lists(self):
        org = Json()
        org.a = [1, 2, {"a": "superman"}]
        someother = Json()
        someother.b = [{"b": 123}]
        org.update(someother)

        correct = {"a": [1, 2, {"a": "superman"}], "b": [{"b": 123}]}

        org.update(someother)
        self.assertDictEqual(org, correct)
        self.assertIsInstance(org.b[0], Json)
コード例 #9
0
ファイル: test_Json.py プロジェクト: asuiu/pyxtension
    def test_toOrigNominal(self):
        j = Json()
        j.a = Json({"b": "c"})
        j.toString()
        j.toOrig()
        repr(j)
        d = j.toOrig()

        self.assertIsInstance(d, sdict)
        self.assertDictEqual(d, {"a": {"b": "c"}})
コード例 #10
0
    def write(self, reason, value):
        status = True
        if reason == 'LISTNR':
            var.listnr = value
            var.row = str(var.dataL[value])
            #publish.single(MQTT_TOPIC_01, msgData, hostname=MQTT_SERVER);
            temp = Json(str(var.row))
            var.setGas1 = temp.gas1
            var.setGas2 = temp.gas2
            var.setPgas1 = temp.pgas1
            var.setPgas2 = temp.pgas2
            var.setSetpoint = temp.setpoint
        elif reason == 'COPY' and str(var.row) != "":
            temp = Json(str(var.row))
            var.setGas1 = temp.gas1
            var.setGas2 = temp.gas2
            var.setPgas1 = temp.pgas1
            var.setPgas2 = temp.pgas2
            var.setSetpoint = temp.setpoint
        elif reason == 'SET.IC':
            var.setIc = value
        elif reason == 'SET.GAS1':
            var.setGas1 = var.elementToNumber(value)
            #print(var.setGas1);
        elif reason == 'SET.GAS2':
            var.setGas2 = var.elementToNumber(value)
            #print(var.setGas2);
        elif reason == 'SET.PGAS1':
            var.setPgas1 = value
            var.setPgas2 = 100 - value
        elif reason == 'SET.PGAS2':
            var.setPgas2 = value
        elif reason == 'SET.CYCLE':
            var.setCycle = value
        elif reason == 'SET.SETPOINT':
            var.setSetpoint = value

        elif reason == 'ELEMENT.G1':
            var.elementSelectedGas1 = value
            var.setGas1 = value
        elif reason == 'ELEMENT.G2':
            var.elementSelectedGas2 = value
            var.setGas2 = value

        elif reason == 'SEND':
            var.sendMsg = Json(('ic', var.setIc), ('gas1', var.setGas1),
                               ('gas2', var.setGas2), ('pgas1', var.setPgas1),
                               ('pgas2', var.setPgas2),
                               ('zyklus', var.setCycle),
                               ('sollwert', var.setSetpoint))
            #print(str(var.setGas1))
            #print(str(var.setGas2))
            publish.single(var.MQTT_TOPIC_05,
                           str(var.sendMsg),
                           hostname=var.MQTT_SERVER)

        elif reason == 'STOP':
            publish.single(var.MQTT_TOPIC_07, "1", hostname=var.MQTT_SERVER)
        elif reason == 'START':
            publish.single(var.MQTT_TOPIC_08, "1", hostname=var.MQTT_SERVER)
        elif reason == 'STARTEVAC':
            publish.single(var.MQTT_TOPIC_09, "1", hostname=var.MQTT_SERVER)
        elif reason == 'SETPOINT.PC':
            var.setpointPC = value
            publish.single(var.MQTT_TOPIC_10,
                           var.setpointPC,
                           hostname=var.MQTT_SERVER)

            #DATAV
        elif reason == 'V1':
            var.V1 = value
            msg = Json(('V1', var.V1), ('V2', var.V2), ('V3', var.V3),
                       ('V4', var.V4), ('V5', var.V5), ('V6', var.V6),
                       ('V7', var.V7), ('V8', var.V8))
            publish.single(var.MQTT_TOPIC_06,
                           str(msg),
                           hostname=var.MQTT_SERVER)
        elif reason == 'V2':
            var.V2 = value
            msg = Json(('V1', var.V1), ('V2', var.V2), ('V3', var.V3),
                       ('V4', var.V4), ('V5', var.V5), ('V6', var.V6),
                       ('V7', var.V7), ('V8', var.V8))
            publish.single(var.MQTT_TOPIC_06,
                           str(msg),
                           hostname=var.MQTT_SERVER)
        elif reason == 'V3':
            var.V3 = value
            msg = Json(('V1', var.V1), ('V2', var.V2), ('V3', var.V3),
                       ('V4', var.V4), ('V5', var.V5), ('V6', var.V6),
                       ('V7', var.V7), ('V8', var.V8))
            publish.single(var.MQTT_TOPIC_06,
                           str(msg),
                           hostname=var.MQTT_SERVER)
        elif reason == 'V4':
            var.V4 = value
            msg = Json(('V1', var.V1), ('V2', var.V2), ('V3', var.V3),
                       ('V4', var.V4), ('V5', var.V5), ('V6', var.V6),
                       ('V7', var.V7), ('V8', var.V8))
            publish.single(var.MQTT_TOPIC_06,
                           str(msg),
                           hostname=var.MQTT_SERVER)
        elif reason == 'V5':
            var.V5 = value
            msg = Json(('V1', var.V1), ('V2', var.V2), ('V3', var.V3),
                       ('V4', var.V4), ('V5', var.V5), ('V6', var.V6),
                       ('V7', var.V7), ('V8', var.V8))
            publish.single(var.MQTT_TOPIC_06,
                           str(msg),
                           hostname=var.MQTT_SERVER)
        elif reason == 'V6':
            var.V6 = value
            msg = Json(('V1', var.V1), ('V2', var.V2), ('V3', var.V3),
                       ('V4', var.V4), ('V5', var.V5), ('V6', var.V6),
                       ('V7', var.V7), ('V8', var.V8))
            publish.single(var.MQTT_TOPIC_06,
                           str(msg),
                           hostname=var.MQTT_SERVER)
        elif reason == 'V7':
            var.V7 = value
            msg = Json(('V1', var.V1), ('V2', var.V2), ('V3', var.V3),
                       ('V4', var.V4), ('V5', var.V5), ('V6', var.V6),
                       ('V7', var.V7), ('V8', var.V8))
            publish.single(var.MQTT_TOPIC_06,
                           str(msg),
                           hostname=var.MQTT_SERVER)
        elif reason == 'V8':
            var.V8 = value
            msg = Json(('V1', var.V1), ('V2', var.V2), ('V3', var.V3),
                       ('V4', var.V4), ('V5', var.V5), ('V6', var.V6),
                       ('V7', var.V7), ('V8', var.V8))
            publish.single(var.MQTT_TOPIC_06,
                           str(msg),
                           hostname=var.MQTT_SERVER)

#DATAFB
        elif reason == 'V1FB':
            var.V1FB = value
            msg = Json(('V1FB', var.V1FB), ('V2FB', var.V2FB),
                       ('V3FB', var.V3FB), ('V4FB', var.V4FB),
                       ('V5FB', var.V5FB), ('V6FB', var.V6FB),
                       ('V7FB', var.V7FB), ('V8FB', var.V8FB))
            publish.single(var.MQTT_TOPIC_12,
                           str(msg),
                           hostname=var.MQTT_SERVER)
        elif reason == 'V2FB':
            var.V2FB = value
            msg = Json(('V1FB', var.V1FB), ('V2FB', var.V2FB),
                       ('V3FB', var.V3FB), ('V4FB', var.V4FB),
                       ('V5FB', var.V5FB), ('V6FB', var.V6FB),
                       ('V7FB', var.V7FB), ('V8FB', var.V8FB))
            publish.single(var.MQTT_TOPIC_12,
                           str(msg),
                           hostname=var.MQTT_SERVER)
        elif reason == 'V3FB':
            var.V3FB = value
            msg = Json(('V1FB', var.V1FB), ('V2FB', var.V2FB),
                       ('V3FB', var.V3FB), ('V4FB', var.V4FB),
                       ('V5FB', var.V5FB), ('V6FB', var.V6FB),
                       ('V7FB', var.V7FB), ('V8FB', var.V8FB))
            publish.single(var.MQTT_TOPIC_12,
                           str(msg),
                           hostname=var.MQTT_SERVER)
        elif reason == 'V4FB':
            var.V4FB = value
            msg = Json(('V1FB', var.V1FB), ('V2FB', var.V2FB),
                       ('V3FB', var.V3FB), ('V4FB', var.V4FB),
                       ('V5FB', var.V5FB), ('V6FB', var.V6FB),
                       ('V7FB', var.V7FB), ('V8FB', var.V8FB))
            publish.single(var.MQTT_TOPIC_12,
                           str(msg),
                           hostname=var.MQTT_SERVER)
        elif reason == 'V5FB':
            var.V5FB = value
            msg = Json(('V1FB', var.V1FB), ('V2FB', var.V2FB),
                       ('V3FB', var.V3FB), ('V4FB', var.V4FB),
                       ('V5FB', var.V5FB), ('V6FB', var.V6FB),
                       ('V7FB', var.V7FB), ('V8FB', var.V8FB))
            publish.single(var.MQTT_TOPIC_12,
                           str(msg),
                           hostname=var.MQTT_SERVER)
        elif reason == 'V6FB':
            var.V6FB = value
            msg = Json(('V1FB', var.V1FB), ('V2FB', var.V2FB),
                       ('V3FB', var.V3FB), ('V4FB', var.V4FB),
                       ('V5FB', var.V5FB), ('V6FB', var.V6FB),
                       ('V7FB', var.V7FB), ('V8FB', var.V8FB))
            publish.single(var.MQTT_TOPIC_12,
                           str(msg),
                           hostname=var.MQTT_SERVER)
        elif reason == 'V7FB':
            var.V7FB = value
            msg = Json(('V1FB', var.V1FB), ('V2FB', var.V2FB),
                       ('V3FB', var.V3FB), ('V4FB', var.V4FB),
                       ('V5FB', var.V5FB), ('V6FB', var.V6FB),
                       ('V7FB', var.V7FB), ('V8FB', var.V8FB))
            publish.single(var.MQTT_TOPIC_12,
                           str(msg),
                           hostname=var.MQTT_SERVER)
        elif reason == 'V8FB':
            var.V8FB = value
            msg = Json(('V1FB', var.V1FB), ('V2FB', var.V2FB),
                       ('V3FB', var.V3FB), ('V4FB', var.V4FB),
                       ('V5FB', var.V5FB), ('V6FB', var.V6FB),
                       ('V7FB', var.V7FB), ('V8FB', var.V8FB))
            publish.single(var.MQTT_TOPIC_12,
                           str(msg),
                           hostname=var.MQTT_SERVER)

#publish.single(MQTT_TOPIC_02, msgTest, hostname=MQTT_SERVER);

#elif reason == 'TEST': global msgTest; msgTest = value; publish.single(MQTT_TOPIC_02, msgTest, hostname=MQTT_SERVER);
#elif reason == 'FILL': global msgFill; msgFill = value; publish.single(MQTT_TOPIC_03, msgFill, hostname=MQTT_SERVER);
#elif reason == 'RECEIPT':
#		global receipt, msgGas1, msgGas2, msgPGas1, msgPGas2, energy, coresponding;
#		receipt = value;
#		temp = Json(msgDataC);
#		msgGas1 = str(temp.dataC.pcGM[receipt].gas1);
#		msgGas2 = str(temp.dataC.pcGM[receipt].gas2);
#		msgPGas1 = int(temp.dataC.pcGM[receipt].pgas1)
#		msgPGas2 = int(temp.dataC.pcGM[receipt].pgas2)
#		energy = str(temp.dataC.pcGM[receipt].Energy)
#		coresponding = str(temp.dataC.pcGM[receipt].Coresponding)

        if status:
            self.setParam(reason, value)
        return status
コード例 #11
0
    def read(self, reason):

        #DATAV
        if reason == 'V1': value = var.V1
        elif reason == 'V2': value = var.V2
        elif reason == 'V3': value = var.V3
        elif reason == 'V4': value = var.V4
        elif reason == 'V5': value = var.V5
        elif reason == 'V6': value = var.V6
        elif reason == 'V7': value = var.V7
        elif reason == 'V8':
            value = var.V8

            #DATAP
        elif reason == 'PPC':
            value = var.ppc
        elif reason == 'PPV':
            value = var.ppv
        elif reason == 'SP.PC':
            value = var.sppc

            #DATAC
        elif reason == 'IC':
            value = var.ic
        elif reason == 'GAS1':
            value = var.numberToElement(var.gas1)
        elif reason == 'GAS2':
            value = var.numberToElement(var.gas2)
        elif reason == 'PGAS1':
            value = var.pgas1
        elif reason == 'PGAS2':
            value = var.pgas2
        elif reason == 'CYCLE':
            value = var.cycle
        elif reason == 'ACTCYCLE':
            value = var.actcycle
        elif reason == 'STATUS':
            value = var.status
        elif reason == 'SETPOINT':
            value = var.setpoint

            #DATAL
        elif reason == 'ROW':
            value = str(var.dataL[var.listnr])
            var.row = value
        elif reason == 'LISTNR':
            value = var.listnr
        elif reason == 'DATAL.CORESPONDING' and str(var.row) != "":
            temp = Json(str(var.row))
            value = str(temp.Coresponding)
        elif reason == 'DATAL.ENERGY' and str(var.row) != "":
            temp = Json(str(var.row))
            value = str(temp.Energy)
        elif reason == 'DATAL.GAS1' and str(var.row) != "":
            temp = Json(str(var.row))
            value = str(var.numberToElement(int(temp.gas1)))
        elif reason == 'DATAL.GAS2' and str(var.row) != "":
            temp = Json(str(var.row))
            value = str(var.numberToElement(int(temp.gas2)))
        elif reason == 'DATAL.PGAS1' and str(var.row) != "":
            temp = Json(str(var.row))
            value = str(temp.pgas1)
        elif reason == 'DATAL.PGAS2' and str(var.row) != "":
            temp = Json(str(var.row))
            value = str(temp.pgas2)
        elif reason == 'DATAL.SOLLWERT' and str(var.row) != "":
            temp = Json(str(var.row))
            value = temp.setpoint

            #DATASET
        elif reason == 'SET.IC':
            value = var.setIc
        elif reason == 'SET.GAS1':
            value = str(var.numberToElement(var.setGas1))
        elif reason == 'SET.GAS2':
            value = str(var.numberToElement(var.setGas2))
        elif reason == 'SET.PGAS1':
            value = var.setPgas1
        elif reason == 'SET.PGAS2':
            value = var.setPgas2
        elif reason == 'SET.CYCLE':
            value = var.setCycle
        elif reason == 'SET.SETPOINT':
            value = var.setSetpoint

            #DATAFB
        elif reason == 'V1FB':
            value = var.V1FB
        elif reason == 'V2FB':
            value = var.V2FB
        elif reason == 'V3FB':
            value = var.V3FB
        elif reason == 'V4FB':
            value = var.V4FB
        elif reason == 'V5FB':
            value = var.V5FB
        elif reason == 'V6FB':
            value = var.V6FB
        elif reason == 'V7FB':
            value = var.V7FB
        elif reason == 'V8FB':
            value = var.V8FB

            #OTHERS
        elif reason == 'ELEMENT.G1':
            value = var.elementSelectedGas1
        elif reason == 'ELEMENT.G2':
            value = var.elementSelectedGas2
        elif reason == 'SETPOINT.PC':
            value = var.setpointPC

        else:
            value = self.getParam(reason)
        return value
コード例 #12
0
ファイル: test_Json.py プロジェクト: asuiu/pyxtension
 def test_serializeDeserialize(self):
     serialized = '{"command":"put","details":{"cookie":"cookie1","platform":"fb"}}'
     j = Json(serialized)
     self.assertEqual(serialized, j.toString())
コード例 #13
0
ファイル: test_Json.py プロジェクト: asuiu/pyxtension
 def test_complex_nested_structure(self):
     prop = Json()
     prop.a = [[Json(), 2], [[]], [1, [2, 3], 0]]
     self.assertDictEqual(prop, {"a": [[{}, 2], [[]], [1, [2, 3], 0]]})
コード例 #14
0
ファイル: sentence_types.py プロジェクト: asuiu/pyNLP
 def toJson(self):
     j = Json()
     self.root.toJson()
     return j
コード例 #15
0
 def __init__(self, project):
     self.project = Json(project)
コード例 #16
0
ファイル: test_Json.py プロジェクト: asuiu/pyxtension
class JsonTestCase(unittest.TestCase):
    def setUp(self):
        self.d = Json((("a", 2), (3, 4), ("d", {"d2": 4})))

    def testConstructor(self):
        self.assertEqual(Json('{"a":2,"4":"5"}'), {"a": 2, "4": "5"})

    def testBase(self):
        self.assertEqual(self.d.a, 2)
        self.assertEqual(self.d["a"], 2)
        self.assertEqual(self.d.b.c, {})
        self.assertEqual(self.d.d.d2, 4)
        self.assertIsInstance(self.d.keys(), slist)
        self.assertIsInstance(self.d.iterkeys(), stream)
        self.assertIsInstance(self.d.itervalues(), stream)

    def test_strReturnsSortedMap(self):
        self.assertEqual('{"4":3,"a":"4"}', str(Json({"a": "4", 4: 3})))

    def test_strBasics(self):
        self.assertEqual(json.dumps({"a": "4"}, separators=(",", ":")), str(Json({"a": "4"})))
        self.assertEqual(
            json.dumps(dict((("a", 2), (3, 4), ("d", {"d2": 4}))), separators=(",", ":"), sort_keys=True),
            str(Json((("a", 2), (3, 4), ("d", {"d2": 4})))),
        )
        self.assertEqual(
            json.dumps(dict((("a", 2), (3, 4), ("d", {"d2": 4}))), separators=(",", ":"), sort_keys=True), str(self.d)
        )

    def test_repr_from_dict(self):
        d = {"a": "a"}
        j = Json(d)
        self.assertEqual(repr(j), repr(d))

    def test_repr_used_setattr(self):
        j = Json()
        j.a = "a"
        self.assertEqual(repr(j), repr({"a": "a"}))

    def test_forbiden_attrs(self):
        j = Json()
        with self.assertRaises(AttributeError):
            j.__methods__()

    def testUpdateItems(self):
        d = Json((("a", 2), (3, 4), ("d", {"d2": 4})))
        d.d.d2 = 3
        self.assertEqual(d.d.d2, 3)

    def testSpecialKeys(self):
        d = Json((("__init__", 2), (3, 4), ("d", {"d2": 4})))
        self.assertEqual(d["__init__"], 2)
        self.assertNotEquals(d.__init__, 2)
        self.assertIsInstance(d.__init__, types.MethodType)

    def testIteritems(self):
        b = self.d.iteritems().toList()
        self.assertEqual(self.d.iterkeys().toList(), self.d.toList())
        self.assertEqual(b[2][1].d2, 4)
        self.assertIsInstance(b[2][1], Json)
        self.assertIsInstance(self.d.iteritems(), stream)
        self.assertEqual(self.d.iteritems().toList(), [("a", 2), (3, 4), ("d", {"d2": 4})])
        self.assertEqual(self.d.iteritems()[2][1].d2, 4)
        self.assertIsInstance(self.d.iteritems(), stream)
        self.assertEquals(self.d.iteritems().sorted().toList(), [(3, 4), ("a", 2), ("d", {"d2": 4})])
        self.assertEqual(Json({1: 1, 2: 2, 3: 3}).itervalues().sum(), 6)

    def testJsonList(self):
        jlist = Json({"a": [1, 2, {"b": [{"c": 3}, {"d": 4}]}]})
        self.assertEqual(jlist.a[2], {"b": [{"c": 3}, {"d": 4}]})
        self.assertEqual(jlist.a[2].b[1].d, 4)

    def testJsonSetValues(self):
        self.d.c = "set"
        self.assertEqual(self.d.c, "set")

    def test_toOrigNominal(self):
        j = Json()
        j.a = Json({"b": "c"})
        j.toString()
        j.toOrig()
        repr(j)
        d = j.toOrig()

        self.assertIsInstance(d, sdict)
        self.assertDictEqual(d, {"a": {"b": "c"}})

    def test_NoneValueRemainsNone(self):
        j = Json({"a": None})
        self.assertIs(j.a, None)

    def test_ConvertSetToList(self):
        j = Json()
        j.st = set((1, 2))
        d = j.toOrig()
        self.assertIsInstance(d, sdict)
        self.assertDictEqual({"st": set([1, 2])}, d)

    def test_serializeDeserialize(self):
        serialized = '{"command":"put","details":{"cookie":"cookie1","platform":"fb"}}'
        j = Json(serialized)
        self.assertEqual(serialized, j.toString())
コード例 #17
0
ファイル: test_Json.py プロジェクト: asuiu/pyxtension
 def setUp(self):
     self.d = Json((("a", 2), (3, 4), ("d", {"d2": 4})))
コード例 #18
0
ファイル: test_Json.py プロジェクト: asuiu/pyxtension
 def test_dir_with_members(self):
     prop = Json({"__members__": 1})
     dir(prop)
     self.assertTrue("__members__" in prop.keys())
コード例 #19
0
ファイル: sentence_types.py プロジェクト: asuiu/pyNLP
 def toJson(self):
     return Json({'tag': self.tag})
コード例 #20
0
ファイル: test_Json.py プロジェクト: asuiu/pyxtension
 def test_ConvertSetToList(self):
     j = Json()
     j.st = set((1, 2))
     d = j.toOrig()
     self.assertIsInstance(d, sdict)
     self.assertDictEqual({"st": set([1, 2])}, d)
コード例 #21
0
ファイル: sentence_types.py プロジェクト: asuiu/pyNLP
 def toJson(self):
     return Json({'word': self.word, 'tag': self.tag, 'stemmed': self.stemmed})
コード例 #22
0
ファイル: test_Json.py プロジェクト: asuiu/pyxtension
 def test_forbiden_attrs(self):
     j = Json()
     with self.assertRaises(AttributeError):
         j.__methods__()
コード例 #23
0
ファイル: sentence_types.py プロジェクト: asuiu/pyNLP
 def toJson(self):
     return Json({'tag': self.tag, 'text': self.text})
コード例 #24
0
ファイル: test_Json.py プロジェクト: asuiu/pyxtension
 def test_set_one_level_property(self):
     prop = Json()
     prop.a = TEST_VAL
     self.assertDictEqual(prop, {"a": TEST_VAL})
コード例 #25
0
ファイル: test_Json.py プロジェクト: asuiu/pyxtension
 def test_repr_used_setattr(self):
     j = Json()
     j.a = "a"
     self.assertEqual(repr(j), repr({"a": "a"}))
コード例 #26
0
def on_message(client, userdata, msg):
    print(msg.topic + " " + str(msg.payload))

    #DATAP
    if msg.topic == var.MQTT_TOPIC_02:
        dataP = Json(str(msg.payload))
        var.ppc = float(dataP.dataP.pressurePC)
        var.ppv = float(dataP.dataP.pressurePV)
        var.sppc = float(dataP.dataP.setpointPC)

    #DATAV
    elif msg.topic == var.MQTT_TOPIC_01:
        dataV = Json(str(msg.payload))
        var.V1 = int(dataV.dataV.V1)
        var.V2 = int(dataV.dataV.V2)
        var.V3 = int(dataV.dataV.V3)
        var.V4 = int(dataV.dataV.V4)
        var.V5 = int(dataV.dataV.V5)
        var.V6 = int(dataV.dataV.V6)
        var.V7 = int(dataV.dataV.V7)
        var.V8 = int(dataV.dataV.V8)

    #DATAC
    elif msg.topic == var.MQTT_TOPIC_03:
        dataC = Json(str(msg.payload))
        var.ic = int(dataC.dataC.IC)
        var.gas1 = int(dataC.dataC.gas1)
        var.gas2 = int(dataC.dataC.gas2)
        var.pgas1 = int(dataC.dataC.pgas1)
        var.pgas2 = int(dataC.dataC.pgas2)
        var.cycle = int(dataC.dataC.zyklusnr)
        var.actcycle = int(dataC.dataC.actzyklus)
        var.status = int(dataC.dataC.status)
        var.setpoint = float(dataC.dataC.setpoint)

    #DATAL
    elif msg.topic == var.MQTT_TOPIC_04:
        dataL = Json(str(msg.payload))
        for x in range(len(dataL.dataL.pcGM)):
            var.dataL[x] = dataL.dataL.pcGM[x]

#DATAFB
    elif msg.topic == var.MQTT_TOPIC_11:
        dataFB = Json(str(msg.payload))
        var.V1FB = int(dataFB.dataFB.V1FB)
        var.V2FB = int(dataFB.dataFB.V2FB)
        var.V3FB = int(dataFB.dataFB.V3FB)
        var.V4FB = int(dataFB.dataFB.V4FB)
        var.V5FB = int(dataFB.dataFB.V5FB)
        var.V6FB = int(dataFB.dataFB.V6FB)
        var.V7FB = int(dataFB.dataFB.V7FB)
        var.V8FB = int(dataFB.dataFB.V8FB)

    #DATASET
    elif msg.topic == var.MQTT_TOPIC_05 or msg.topic == var.MQTT_TOPIC_06:
        print("sent data!")

    elif msg.topic == var.MQTT_TOPIC_07:
        print("STOP process")

    elif msg.topic == var.MQTT_TOPIC_08:
        print("START prcess")

    elif msg.topic == var.MQTT_TOPIC_09:
        print("START and EVACUATE process")

    elif msg.topic == var.MQTT_TOPIC_10:
        print("Set new PC setpoint")

    else:
        print("unknown topic: " + msg.topic)