Exemplo n.º 1
0
    def _decodeRepetitiveInterval(decoder):
        """
        Decode the input as an NDN-TLV RepetitiveInterval.

        :param TlvDecoder decoder: The decoder with the input to decode.
        :return: A new RepetitiveInterval with the decoded result.
        :rtype: RepetitiveInterval
        """
        endOffset = decoder.readNestedTlvsStart(Tlv.Encrypt_RepetitiveInterval)

        # Use Blob to convert UTF8 to a string.
        startDate = Schedule.fromIsoString(
            str(Blob(decoder.readBlobTlv(Tlv.Encrypt_StartDate), True)))
        endDate = Schedule.fromIsoString(
            str(Blob(decoder.readBlobTlv(Tlv.Encrypt_EndDate), True)))
        startHour = decoder.readNonNegativeIntegerTlv(
            Tlv.Encrypt_IntervalStartHour)
        endHour = decoder.readNonNegativeIntegerTlv(
            Tlv.Encrypt_IntervalEndHour)
        nRepeats = decoder.readNonNegativeIntegerTlv(Tlv.Encrypt_NRepeats)

        # The RepeatUnit enum has the same values as the encoding.
        repeatUnit = decoder.readNonNegativeIntegerTlv(Tlv.Encrypt_RepeatUnit)

        decoder.finishNestedTlvs(endOffset)
        return RepetitiveInterval(startDate, endDate, startHour, endHour,
                                  nRepeats, repeatUnit)
Exemplo n.º 2
0
    def getCoveringInterval(self, timeStamp):
        """
        Get the interval that covers the time stamp. This iterates over the two
        repetitive interval sets and find the shortest interval that allows a
        group member to access the data. If there is no interval covering the
        time stamp, this returns False for isPositive and a negative interval.

        :param float timeStamp: The time stamp as milliseconds since Jan 1,
          1970 UTC.
        :return: An object with fields "isPositive" and "interval" where
          isPositive is True if the returned interval is positive or False if
          negative, and interval is the Interval covering the time stamp, or a
          negative interval if not found.
        :rtype: Schedule.Result
        """
        blackPositiveResult = Interval(True)
        whitePositiveResult = Interval(True)

        blackNegativeResult = Interval()
        whiteNegativeResult = Interval()

        # Get the black result.
        Schedule._calculateIntervalResult(self._blackIntervalList, timeStamp,
                                          blackPositiveResult,
                                          blackNegativeResult)

        # If the black positive result is not empty, then isPositive must be False.
        if not blackPositiveResult.isEmpty():
            return Schedule.Result(False, blackPositiveResult)

        # Get the whiteResult.
        Schedule._calculateIntervalResult(self._whiteIntervalList, timeStamp,
                                          whitePositiveResult,
                                          whiteNegativeResult)

        if whitePositiveResult.isEmpty() and not whiteNegativeResult.isValid():
            # There is no white interval covering the time stamp.
            # Return False and a 24-hour interval.
            timeStampDateOnly = RepetitiveInterval._toDateOnlyMilliseconds(
                timeStamp)
            return Schedule.Result(
                False,
                Interval(
                    timeStampDateOnly, timeStampDateOnly +
                    RepetitiveInterval.MILLISECONDS_IN_DAY))

        if not whitePositiveResult.isEmpty():
            # There is white interval covering the time stamp.
            # Return True and calculate the intersection.
            if blackNegativeResult.isValid():
                return Schedule.Result(
                    True,
                    whitePositiveResult.intersectWith(blackNegativeResult))
            else:
                return Schedule.Result(True, whitePositiveResult)
        else:
            # There is no white interval covering the time stamp.
            # Return False.
            return Schedule.Result(False, whiteNegativeResult)
Exemplo n.º 3
0
    def getCoveringInterval(self, timeStamp):
        """
        Get the interval that covers the time stamp. This iterates over the two
        repetitive interval sets and find the shortest interval that allows a
        group member to access the data. If there is no interval covering the
        time stamp, this returns False for isPositive and a negative interval.

        :param float timeStamp: The time stamp as milliseconds since Jan 1,
          1970 UTC.
        :return: An object with fields "isPositive" and "interval" where
          isPositive is True if the returned interval is positive or False if
          negative, and interval is the Interval covering the time stamp, or a
          negative interval if not found.
        :rtype: Schedule.Result
        """
        blackPositiveResult = Interval(True)
        whitePositiveResult = Interval(True)

        blackNegativeResult = Interval()
        whiteNegativeResult = Interval()

        # Get the black result.
        Schedule._calculateIntervalResult(
          self._blackIntervalList, timeStamp, blackPositiveResult,
          blackNegativeResult)

        # If the black positive result is not empty, then isPositive must be False.
        if not blackPositiveResult.isEmpty():
            return Schedule.Result(False, blackPositiveResult)

        # Get the whiteResult.
        Schedule._calculateIntervalResult(
          self._whiteIntervalList, timeStamp, whitePositiveResult,
          whiteNegativeResult)

        if whitePositiveResult.isEmpty() and not whiteNegativeResult.isValid():
            # There is no white interval covering the time stamp.
            # Return False and a 24-hour interval.
            timeStampDateOnly = RepetitiveInterval._toDateOnlyMilliseconds(
              timeStamp)
            return Schedule.Result(False, Interval(
              timeStampDateOnly,
              timeStampDateOnly + RepetitiveInterval.MILLISECONDS_IN_DAY))

        if not whitePositiveResult.isEmpty():
            # There is white interval covering the time stamp.
            # Return True and calculate the intersection.
            if blackNegativeResult.isValid():
                return Schedule.Result(
                  True, whitePositiveResult.intersectWith(blackNegativeResult))
            else:
                return Schedule.Result(True, whitePositiveResult)
        else:
            # There is no white interval covering the time stamp.
            # Return False.
            return Schedule.Result(False, whiteNegativeResult)