Esempio n. 1
0
    def _getAndCheckNUS(self,
                        subscription: Resource,
                        newJson: dict = None,
                        previousNus: List[str] = None,
                        originator: str = None) -> Tuple[List[str], int, str]:
        newNus = []
        if newJson is None:  # If there is no new JSON structure, get the one from the subscription to work with
            newJson = subscription.asJSON()

        # Resolve the URI's in the previousNus.
        if previousNus is not None:
            if (previousNus := self._getNotificationURLs(
                    previousNus, originator)) is None:
                # Fail if any of the NU's cannot be retrieved
                return None, C.rcSubscriptionVerificationInitiationFailed, 'cannot retrieve all previous nu' 's'
Esempio n. 2
0
    def _sendRequest(self,
                     nu: str,
                     ri: str,
                     jsn: dict,
                     reason: int = None,
                     resource: Resource = None,
                     originator: str = None) -> bool:
        Utils.setXPath(jsn, 'm2m:sgn/sur', Utils.fullRI(ri))

        # Add some values to the notification
        # TODO: switch statement:  (x is not None and bla())
        if reason is not None:
            Utils.setXPath(jsn, 'm2m:sgn/nev/net', reason)
        if resource is not None:
            Utils.setXPath(jsn, 'm2m:sgn/nev/rep', resource.asJSON())
        if originator is not None:
            Utils.setXPath(jsn, 'm2m:sgn/cr', originator)

        _, rc, _ = CSE.httpServer.sendCreateRequest(
            nu, Configuration.get('cse.csi'), data=json.dumps(jsn))
        return rc in [C.rcOK]