Пример #1
0
 def get_suggested_type_for_sequence_component(self, value, suggested_type, **kwargs):
     if suggested_type is None:
         return None
     if is_array_type(suggested_type):
         return get_component_type(suggested_type)
     else:
         raise AbortConversion("parent of value is a sequence, but the suggested type is not an array type", obj=value)
Пример #2
0
 def get_suggested_type_for_sequence_component(self, value, suggested_type,
                                               **kwargs):
     if suggested_type is None:
         return None
     if is_array_type(suggested_type):
         return get_component_type(suggested_type)
     else:
         raise AbortConversion(
             "parent of value is a sequence, but the suggested type is not an array type",
             obj=value)
Пример #3
0
    def categorise_object(self, node, suggested_type, **kwargs):

        from xml.dom import Node

        if node is None:
            number_of_nodes = 0
            null_value = True
        elif isinstance(node, types.StringTypes):
            number_of_nodes = -1  # Means "no-node type".
            null_value = not node
        else:
            number_of_nodes = len(node.childNodes)
            null_value = not number_of_nodes

        # This is a bit ambiguous - how on earth are we meant to determine
        # this? We'll see whether an explicit type is given here, otherwise
        # we'll have to just guess.
        if null_value:
            if suggested_type == 'mapping':
                return MAPPING_TYPE
            elif is_array_type(suggested_type):
                return SEQUENCE_TYPE

            # If the suggested type is atomic, then we inform them that
            # it is an atomic object. Some atomic types make sense with
            # no nodes (like an empty string). Some don't, of course
            # (like an integer), but never mind. It's better to inform
            # the caller code that it is an atom if the desired type is
            # an atom - otherwise for empty strings, we will get None
            # instead.
            elif is_java_return_type(suggested_type):
                # We'll assume it is just an atom. It can't be an object
                # without an object ID.
                return ATOM_TYPE

            # Oh well, let's just say it's null then.
            else:
                return NULL_TYPE

        if number_of_nodes == -1:
            return ATOM_TYPE

        if number_of_nodes == 1 and node.firstChild.nodeType == Node.TEXT_NODE:
            return ATOM_TYPE

        if number_of_nodes and node.firstChild.nodeName == 'ENTRY':
            return SEQUENCE_TYPE

        if suggested_type == 'mapping':
            return MAPPING_TYPE

        return OBJECT_TYPE
Пример #4
0
    def categorise_object(self, node, suggested_type, **kwargs):

        from xml.dom import Node

        if node is None:
            number_of_nodes = 0
            null_value = True
        elif isinstance(node, types.StringTypes):
            number_of_nodes = -1 # Means "no-node type".
            null_value = not node
        else:
            number_of_nodes = len(node.childNodes)
            null_value = not number_of_nodes

        # This is a bit ambiguous - how on earth are we meant to determine
        # this? We'll see whether an explicit type is given here, otherwise
        # we'll have to just guess.
        if null_value:
            if suggested_type == 'mapping':
                return MAPPING_TYPE
            elif is_array_type(suggested_type):
                return SEQUENCE_TYPE

            # If the suggested type is atomic, then we inform them that
            # it is an atomic object. Some atomic types make sense with
            # no nodes (like an empty string). Some don't, of course
            # (like an integer), but never mind. It's better to inform
            # the caller code that it is an atom if the desired type is
            # an atom - otherwise for empty strings, we will get None
            # instead.
            elif is_java_return_type(suggested_type):
                # We'll assume it is just an atom. It can't be an object
                # without an object ID.
                return ATOM_TYPE

            # Oh well, let's just say it's null then.
            else:
                return NULL_TYPE

        if number_of_nodes == -1:
            return ATOM_TYPE

        if number_of_nodes == 1 and node.firstChild.nodeType == Node.TEXT_NODE:
            return ATOM_TYPE

        if number_of_nodes and node.firstChild.nodeName == 'ENTRY':
            return SEQUENCE_TYPE

        if suggested_type == 'mapping':
            return MAPPING_TYPE

        return OBJECT_TYPE