<commit_before>from itertools import izip

from vistrails.core.modules.vistrails_module import Module, ModuleError
from vistrails.core.interpreter.base import AbortExecution
from vistrails.core import debug

class vtkObjectBase(Module):
    @staticmethod
    def get_set_method_info(port_name):
        return None

    @staticmethod
    def get_get_method_info(port_name):
        return None

    def call_set_method(self, vtk_obj, port_name, params):
        print "CALLING SET", port_name, params
        info = self.get_set_method_info(port_name)
        if info is None:
            raise ModuleError(self, 
                              'Internal error: cannot find '
                              'port "%s"' % port_name)
        method_name, shape, other_params, translator = info

        if isinstance(params, tuple):
            params = list(params)
        elif not isinstance(params, list):
            params = [params]
        if translator is not None:
            params = [translator(p) for p in params]
        method = getattr(vtk_obj, method_name)
        if shape is not None:
            def reshape_params(p, s):
                out = []
                for elt in s:
                    if isinstance(elt, list):
                        out.append(reshape_params(p, elt))
                    else:
                        for i in xrange(elt):
                            out.append(p.pop(0))
                return out
            params = reshape_params(params, shape)
        try:
            print "  calling", method_name, other_params + params
            method(*(other_params + params))
        except Exception, e:
            raise ModuleError(self,
                              "VTK Exception: %s" % debug.format_exception(e))

    def call_get_method(self, vtk_obj, port_name):
        print "CALLING GET", port_name
        info = self.get_get_method_info(port_name)
        if info is None:
            raise ModuleError(self, 
                              'Internal error: cannot find '
                              'port "%s"' % port_name)
        method_name, other_params = info<commit_msg>Fixed enums<commit_after>from itertools import izip

from vistrails.core.modules.vistrails_module import Module, ModuleError
from vistrails.core.interpreter.base import AbortExecution
from vistrails.core import debug

class vtkObjectBase(Module):
    @staticmethod
    def get_set_method_info(port_name):
        return None

    @staticmethod
    def get_get_method_info(port_name):
        return None

    def call_set_method(self, vtk_obj, port_name, params):
        print "CALLING SET", port_name, params
        info = self.get_set_method_info(port_name)
        if info is None:
            raise ModuleError(self, 
                              'Internal error: cannot find '
                              'port "%s"' % port_name)
        method_name, shape, other_params, translator = info

        if isinstance(params, tuple):
            params = list(params)
        elif not isinstance(params, list):
            params = [params]
        if translator is not None:
            params = [translator(p) for p in params]
        # handle enums
        spec = self.input_specs[port_name]
        if len(spec.items) == 1 and spec.items[0].entry_type == 'enum':
            # Append enum name to function name and delete params
            method_name += params[0]
            params = []
        method = getattr(vtk_obj, method_name)
        if shape is not None:
            def reshape_params(p, s):
                out = []
                for elt in s:
                    if isinstance(elt, list):
                        out.append(reshape_params(p, elt))
                    else:
                        for i in xrange(elt):
                            out.append(p.pop(0))
                return out
            params = reshape_params(params, shape)
        try:
            print "  calling", method_name, other_params + params
            method(*(other_params + params))
        except Exception, e:
            raise ModuleError(self,
                              "VTK Exception: %s" % debug.format_exception(e))

    def call_get_method(self, vtk_obj, port_name):
        print "CALLING GET", port_name
        info = self.get_get_method_info(port_name)
        if info is None:
            raise ModuleError(self, 
                              'Internal error: cannot find '
                              'port "%s"' % port_name)
        method_name, other_params = info
{'fraction_non_alphanumeric': 0.07732980832782552, 'fraction_numerical': 0.0011015642211940956, 'mean_word_length': 1.7088305489260143, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4129143', 'n_tokens_mistral': 1249, 'n_tokens_neox': 1206, 'n_words': 338}