/*******************************************************************************
 * (c) Copyright 2016 Hewlett-Packard Development Company, L.P.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Apache License v2.0 which accompany this distribution.
 *
 * The Apache License is available at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 *******************************************************************************/
package io.cloudslang.lang.runtime.bindings.scripts;

import io.cloudslang.lang.entities.bindings.values.Value;
import io.cloudslang.lang.entities.bindings.values.ValueFactory;
import io.cloudslang.runtime.api.python.PythonRuntimeService;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author Bonczidai Levente
 * @since 1/19/2016
 */
@Component
public class ScriptExecutor extends ScriptProcessor {
    @Autowired
    private PythonRuntimeService pythonRuntimeService;

    public Map<String, Value> executeScript(String script, Map<String, Value> callArguments) {
        return executeScript(Collections.<String>emptySet(), script, callArguments);
    }

    public Map<String, Value> executeScript(Set<String> dependencies, String script, Map<String, Value> callArguments) {
        Map<String, Serializable> executionResult = pythonRuntimeService
                .exec(dependencies, script, createPythonContext(callArguments)).getExecutionResult();
        Map<String, Value> result = new HashMap<>();
        for (Map.Entry<String, Serializable> entry : executionResult.entrySet()) {
            Value callArgumenet = callArguments.get(entry.getKey());
            Value value = ValueFactory.create(entry.getValue(), callArgumenet != null && callArgumenet.isSensitive());
            result.put(entry.getKey(), value);
        }
        return result;
    }
}

@@ -728,239 +728,332 @@
 ort 
-java.io.Serializable;%0Aimport java.util.Collections;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0Aimport java.util.Set;%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.stereotype.Componen
+org.python.core.PyList;%0Aimport org.python.core.PyObject;%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.stereotype.Component;%0A%0Aimport java.io.Serializable;%0Aimport java.util.ArrayList;%0Aimport java.util.Collections;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0Aimport java.util.Se
 t;%0A%0A
@@ -1949,58 +1949,637 @@
     
-Value value = ValueFactory.create(entry.getValue()
+Serializable theValue;%0A            if (entry.getValue() instanceof PyList) %7B%0A                ArrayList%3CString%3E localList = new ArrayList%3C%3E();%0A                PyList pyList = (PyList) entry.getValue();%0A                for (Object next : pyList) %7B%0A                    localList.add(next == null ? null : next.toString());%0A                %7D%0A                theValue = localList;%0A            %7D else if (entry.getValue() instanceof PyObject) %7B%0A                theValue = entry.getValue().toString();%0A            %7D else %7B%0A                theValue = entry.getValue();%0A            %7D%0A            Value value = ValueFactory.create(theValue
 , ca

Replace PyList with ArrayList due to security issues with PyList deserialization