Ejemplo n.º 1
0
    def setValues(self, type_uri, values):
        """Set the values for the given attribute type. This replaces
        any values that have already been set for this attribute.

        @param type_uri: The URI for the attribute

        @param values: A list of values to send for this attribute. Values which are not text, will be converted.
        @type values: List[Any]
        """

        self.data[type_uri] = [force_text(v) for v in values]
Ejemplo n.º 2
0
    def addValue(self, type_uri, value):
        """Add a single value for the given attribute type to the
        message. If there are already values specified for this type,
        this value will be sent in addition to the values already
        specified.

        @param type_uri: The URI for the attribute

        @param value: The value to add to the response to the relying party for this attribute. It the value is not
            a text, it will be converted.
        @type value: Any

        @returns: None
        """
        try:
            values = self.data[type_uri]
        except KeyError:
            values = self.data[type_uri] = []

        values.append(force_text(value))
Ejemplo n.º 3
0
    def extractResponse(cls, request, data):
        """Take a C{L{SRegRequest}} and a dictionary of simple
        registration values and create a C{L{SRegResponse}}
        object containing that data.

        @param request: The simple registration request object
        @type request: SRegRequest

        @param data: The simple registration data for this response, as a mapping of unqualified simple registration
            field name to value. For instance, the nickname should be stored under the key 'nickname'. If the value is
            missing or None, it will be skipped. If the value is not a text, it will be converted.
        @type data: Dict[six.text_type, Any]

        @returns: a simple registration response object
        @rtype: SRegResponse
        """
        self = cls()
        self.ns_uri = request.ns_uri
        for field in request.allRequestedFields():
            value = data.get(field)
            if value is not None:
                self.data[field] = force_text(value)
        return self
Ejemplo n.º 4
0
    def extractResponse(cls, request, data):
        """Take a C{L{SRegRequest}} and a dictionary of simple
        registration values and create a C{L{SRegResponse}}
        object containing that data.

        @param request: The simple registration request object
        @type request: SRegRequest

        @param data: The simple registration data for this response, as a mapping of unqualified simple registration
            field name to value. For instance, the nickname should be stored under the key 'nickname'. If the value is
            missing or None, it will be skipped. If the value is not a text, it will be converted.
        @type data: Dict[six.text_type, Any]

        @returns: a simple registration response object
        @rtype: SRegResponse
        """
        self = cls()
        self.ns_uri = request.ns_uri
        for field in request.allRequestedFields():
            value = data.get(field)
            if value is not None:
                self.data[field] = force_text(value)
        return self
Ejemplo n.º 5
0
 def test_objects(self):
     self.assertEqual(force_text(None), 'None')
     self.assertEqual(force_text(14), '14')
     self.assertEqual(force_text(True), 'True')
     self.assertEqual(force_text(False), 'False')
Ejemplo n.º 6
0
 def test_bytes(self):
     self.assertEqual(force_text(b''), '')
     self.assertEqual(force_text(b'ascii'), 'ascii')
     self.assertEqual(force_text('ůňíčóďé'.encode('utf-8')), 'ůňíčóďé')
Ejemplo n.º 7
0
 def test_text(self):
     self.assertEqual(force_text(''), '')
     self.assertEqual(force_text('ascii'), 'ascii')
     self.assertEqual(force_text('ůňíčóďé'), 'ůňíčóďé')
Ejemplo n.º 8
0
 def test_objects(self):
     self.assertEqual(force_text(None), 'None')
     self.assertEqual(force_text(14), '14')
     self.assertEqual(force_text(True), 'True')
     self.assertEqual(force_text(False), 'False')
Ejemplo n.º 9
0
 def test_bytes(self):
     self.assertEqual(force_text(b''), '')
     self.assertEqual(force_text(b'ascii'), 'ascii')
     self.assertEqual(force_text('ůňíčóďé'.encode('utf-8')), 'ůňíčóďé')
Ejemplo n.º 10
0
 def test_text(self):
     self.assertEqual(force_text(''), '')
     self.assertEqual(force_text('ascii'), 'ascii')
     self.assertEqual(force_text('ůňíčóďé'), 'ůňíčóďé')