Ejemplo n.º 1
0
def RestoreListTypeWithWsdl(response, service_type_map,
                            operation_return_types):
    """Restores list types within given response which were overwritten by SOAPpy.

  Args:
    response: tuple Response data object.
    service_type_map: dict Information on WSDL-defined types in one service.
    operation_return_types: list Data types this operation returns, in order.

  Returns:
    tuple Responses, each with list types restored.
  """
    holder = []
    if (len(operation_return_types) == 1
            and not Utils.IsXsdOrSoapenc(operation_return_types[0])
            and service_type_map[operation_return_types[0]]['soap_type']
            == 'array'):
        holder.extend(
            _RestoreListTypesForResponse(list(response),
                                         operation_return_types[0],
                                         service_type_map))
    else:
        for i in range(len(response)):
            holder.append(
                _RestoreListTypesForResponse(response[i],
                                             operation_return_types[i],
                                             service_type_map))
    return tuple(holder)
Ejemplo n.º 2
0
def _SanityCheckArray(wsdl_types, obj, xsi_type):
    """Validates a list representing an array type against its WSDL definition.

  Args:
    wsdl_types: dict WSDL-defined types in the same service as the given type.
    obj: list List representing the given array type.
    xsi_type: str The array type name defined in the WSDL.
  """
    ValidateTypes(((obj, list), ))
    if Utils.IsXsdOrSoapenc(wsdl_types[xsi_type]['base_type']):
        for item in obj:
            if item is None: continue
            ValidateTypes(((item, (str, unicode)), ))
    else:
        for item in obj:
            if item is None: continue
            NewSanityCheck(wsdl_types, item, wsdl_types[xsi_type]['base_type'])
Ejemplo n.º 3
0
def _SanityCheckComplexType(wsdl_types, obj, xsi_type):
    """Validates a dict representing a complex type against its WSDL definition.

  Args:
    wsdl_types: dict WSDL-defined types in the same service as the given type.
    obj: dict Object that should represent an instance of the given type.
    xsi_type: str The complex type name defined in the WSDL.

  Raises:
    ValidationError: The given object is not an acceptable representation of the
                     given WSDL-defined complex type.
  """
    ValidateTypes(((obj, dict), ))
    obj_contained_type, contained_type_key = Utils.GetExplicitType(
        wsdl_types, obj, xsi_type)

    if obj_contained_type and not obj_contained_type == xsi_type:
        if not IsSuperType(wsdl_types, obj_contained_type, xsi_type):
            raise ValidationError(
                'Expecting type of \'%s\' but given type of class '
                '\'%s\'.' % (xsi_type, obj_contained_type))
        xsi_type = obj_contained_type

    parameters = Utils.GenParamOrder(wsdl_types, xsi_type)
    for key in obj:
        if obj[key] is None or (obj_contained_type
                                and key == contained_type_key):
            continue
        found = False
        for parameter, param_type in parameters:
            if parameter == key:
                found = True
                if Utils.IsXsdOrSoapenc(param_type):
                    ValidateTypes(((obj[key], (str, unicode)), ))
                else:
                    NewSanityCheck(wsdl_types, obj[key], param_type)
                break
        if not found:
            raise ValidationError('Field \'%s\' is not in type \'%s\'.' %
                                  (key, xsi_type))
Ejemplo n.º 4
0
def _RestoreListTypesForResponse(response, xsi_type, service_type_map):
    """Restores list types for an individual response object.

  Args:
    response: obj An individual object returned by the webservice. May be a
              dictionary, list, or string depending on what it represents.
    xsi_type: str The WSDL-defined type of this response.
    service_type_map: dict Information on WSDL-defined types in one service.

  Returns:
    obj The response in its proper format. May be a dictionary, list, or string
    depending on what was input. Not guaranteed to output the same data type
    that was input - may output a list instead.
  """
    if isinstance(response, dict):
        if not response: return response
        for param, param_type in Utils.GenParamOrder(service_type_map,
                                                     xsi_type):
            if not param in response or Utils.IsXsdOrSoapenc(param_type):
                continue
            value = response[param]
            if (service_type_map[param_type]['soap_type'] == 'array'
                    and not isinstance(response[param], list)):
                value = [value]
            response[param] = _RestoreListTypesForResponse(
                value, param_type, service_type_map)
        return response
    elif isinstance(response, list):
        lst = []
        for item in response:
            if item is None: continue
            lst.append(
                _RestoreListTypesForResponse(
                    item, service_type_map[xsi_type]['base_type'],
                    service_type_map))
        return lst
    else:
        return response