Beispiel #1
0
    def deserialize(cls, assoc_s):
        """
        Parse an association as stored by serialize().

        inverse of serialize

        @param assoc_s: Association as serialized by serialize()
        @type assoc_s: bytes

        @return: instance of this class
        """
        pairs = kvform.kvToSeq(assoc_s, strict=True)
        keys = []
        values = []
        for k, v in pairs:
            keys.append(k)
            values.append(v)

        if keys != cls.assoc_keys:
            raise ValueError('Unexpected key values: %r', keys)

        version, handle, secret, issued, lifetime, assoc_type = values
        if version != '2':
            raise ValueError('Unknown version: %r' % version)
        issued = int(issued)
        lifetime = int(lifetime)
        secret = oidutil.fromBase64(secret)
        return cls(handle, secret, issued, lifetime, assoc_type)
    def deserialize(cls, assoc_s):
        """
        Parse an association as stored by serialize().

        inverse of serialize


        @param assoc_s: Association as serialized by serialize()
        @type assoc_s: six.text_type, six.binary_type is deprecated

        @return: instance of this class
        """
        pairs = kvform.kvToSeq(string_to_text(
            assoc_s,
            "Binary values for assoc_s are deprecated. Use text input instead."
        ),
                               strict=True)
        keys = []
        values = []
        for k, v in pairs:
            keys.append(k)
            values.append(v)

        if keys != cls.assoc_keys:
            raise ValueError('Unexpected key values: %r', keys)

        version, handle, secret, issued, lifetime, assoc_type = values
        if version != '2':
            raise ValueError('Unknown version: %r' % version)
        issued = int(issued)
        lifetime = int(lifetime)
        secret = oidutil.fromBase64(secret)
        return cls(handle, secret, issued, lifetime, assoc_type)
Beispiel #3
0
    def deserialize(cls, assoc_s):
        """
        Parse an association as stored by serialize().

        inverse of serialize

        @param assoc_s: Association as serialized by serialize()
        @type assoc_s: bytes

        @return: instance of this class
        """
        pairs = kvform.kvToSeq(assoc_s, strict=True)
        keys = []
        values = []
        for k, v in pairs:
            keys.append(k)
            values.append(v)

        if keys != cls.assoc_keys:
            raise ValueError("Unexpected key values: %r", keys)

        version, handle, secret, issued, lifetime, assoc_type = values
        if version != "2":
            raise ValueError("Unknown version: %r" % version)
        issued = int(issued)
        lifetime = int(lifetime)
        secret = oidutil.fromBase64(secret)
        return cls(handle, secret, issued, lifetime, assoc_type)
Beispiel #4
0
    def runTest(self):
        # seq serializes to expected kvform
        actual = kvform.seqToKV(self.seq)
        self.failUnlessEqual(self.kvform, actual)

        # Parse back to sequence. Expected to be unchanged, except
        # stripping whitespace from start and end of values
        # (i. e. ordering, case, and internal whitespace is preserved)
        seq = kvform.kvToSeq(actual)
        clean_seq = self.cleanSeq(seq)

        self.failUnlessEqual(seq, clean_seq)
Beispiel #5
0
    def runTest(self):
        # seq serializes to expected kvform
        actual = kvform.seqToKV(self.seq)
        self.failUnlessEqual(self.kvform, actual)
        self.failUnless(type(actual) is str)

        # Parse back to sequence. Expected to be unchanged, except
        # stripping whitespace from start and end of values
        # (i. e. ordering, case, and internal whitespace is preserved)
        seq = kvform.kvToSeq(actual)
        clean_seq = self.cleanSeq(seq)

        self.failUnlessEqual(seq, clean_seq)
        self.checkWarnings(self.expected_warnings)
Beispiel #6
0
    def runTest(self):
        for kv_data, result, expected_warnings in kvseq_cases:
            # seq serializes to expected kvform
            with LogCapture() as logbook:
                actual = kvform.seqToKV(kv_data)
            self.assertEqual(actual, result)
            self.assertIsInstance(actual, str)

            # Parse back to sequence. Expected to be unchanged, except
            # stripping whitespace from start and end of values
            # (i. e. ordering, case, and internal whitespace is preserved)
            seq = kvform.kvToSeq(actual)
            clean_seq = self.cleanSeq(seq)

            self.assertEqual(seq, clean_seq)
            self.assertEqual(len(logbook.records), expected_warnings,
                             "Invalid warnings for {}: {}".format(kv_data, [r.getMessage() for r in logbook.records]))
Beispiel #7
0
    def runTest(self):
        for kv_data, result, expected_warnings in kvseq_cases:
            # seq serializes to expected kvform
            with LogCapture() as logbook:
                actual = kvform.seqToKV(kv_data)
            self.assertEqual(actual, result)
            self.assertIsInstance(actual, six.text_type)

            # Parse back to sequence. Expected to be unchanged, except
            # stripping whitespace from start and end of values
            # (i. e. ordering, case, and internal whitespace is preserved)
            seq = kvform.kvToSeq(actual)
            clean_seq = self.cleanSeq(seq)

            self.assertEqual(seq, clean_seq)
            self.assertEqual(len(logbook.records), expected_warnings,
                             "Invalid warnings for {}: {}".format(kv_data, [r.getMessage() for r in logbook.records]))
Beispiel #8
0
    def runTest(self):
        # seq serializes to expected kvform
        actual = kvform.seqToKV(self.seq)
        if isinstance(self.kvform, str):
            kvform_bytes = bytes(self.kvform, encoding="utf-8")
        else:
            kvform_bytes = self.kvform
        self.assertEqual(kvform_bytes, actual)
        self.assertTrue(isinstance(actual, bytes))

        # Parse back to sequence. Expected to be unchanged, except
        # stripping whitespace from start and end of values
        # (i. e. ordering, case, and internal whitespace is preserved)
        seq = kvform.kvToSeq(actual)
        clean_seq = self.cleanSeq(seq)

        self.assertEqual(seq, clean_seq)
        self.checkWarnings(self.expected_warnings)