Ejemplo n.º 1
0
    def __init__(self, declaring_type, name, payload, original_name=None):
        self._name = name
        original_name = original_name or name
        self._declaring_type = weakref.ref(declaring_type)
        self._meta_values = None

        if callable(payload):
            if isinstance(payload, specs.FunctionDefinition):
                self._body = payload
            else:
                self._body = yaql_integration.get_function_definition(
                    payload, weakref.proxy(self), original_name)
            self._arguments_scheme = None
            if any(
                (helpers.inspect_is_static(declaring_type.extension_class,
                                           original_name),
                 helpers.inspect_is_classmethod(declaring_type.extension_class,
                                                original_name))):
                self._usage = self._body.meta.get(
                    constants.META_USAGE, dsl_types.MethodUsages.Static)
                if self._usage not in dsl_types.MethodUsages.StaticMethods:
                    raise ValueError('Invalid Usage for static method ' +
                                     self.name)
            else:
                self._usage = (self._body.meta.get(constants.META_USAGE)
                               or dsl_types.MethodUsages.Runtime)
                if self._usage not in dsl_types.MethodUsages.InstanceMethods:
                    raise ValueError('Invalid Usage for instance method ' +
                                     self.name)
            if (self._body.name.startswith('#')
                    or self._body.name.startswith('*')):
                raise ValueError(
                    'Import of special yaql functions is forbidden')
            self._meta = meta.MetaData(
                self._body.meta.get(constants.META_MPL_META),
                dsl_types.MetaTargets.Method, declaring_type)
        else:
            payload = payload or {}
            self._body = macros.MethodBlock(payload.get('Body'), name)
            self._usage = payload.get(
                'Usage') or dsl_types.MethodUsages.Runtime
            arguments_scheme = helpers.list_value(payload.get('Arguments'))
            if isinstance(arguments_scheme, dict):
                arguments_scheme = [{
                    key: value
                } for key, value in six.iteritems(arguments_scheme)]
            self._arguments_scheme = collections.OrderedDict()
            for record in arguments_scheme:
                if (not isinstance(record, dict) or len(record) > 1):
                    raise ValueError()
                name = list(record.keys())[0]
                self._arguments_scheme[name] = MuranoMethodArgument(
                    self, self.name, name, record[name])
            self._meta = meta.MetaData(payload.get('Meta'),
                                       dsl_types.MetaTargets.Method,
                                       declaring_type)

        self._instance_stub, self._static_stub = \
            yaql_integration.build_stub_function_definitions(
                weakref.proxy(self))
Ejemplo n.º 2
0
    def __init__(self, murano_class, name, payload):
        self._name = name
        self._murano_class = weakref.ref(murano_class)

        if callable(payload):
            if isinstance(payload, specs.FunctionDefinition):
                self._body = payload
            else:
                self._body = yaql_integration.get_function_definition(payload)
            self._arguments_scheme = None
            self._usage = (self._body.meta.get('usage')
                           or self._body.meta.get('Usage')
                           or MethodUsages.Runtime)
            if (self._body.name.startswith('#')
                    or self._body.name.startswith('*')):
                raise ValueError(
                    'Import of special yaql functions is forbidden')
        else:
            payload = payload or {}
            self._body = macros.MethodBlock(payload.get('Body') or [], name)
            self._usage = payload.get('Usage') or MethodUsages.Runtime
            arguments_scheme = payload.get('Arguments') or []
            if isinstance(arguments_scheme, types.DictionaryType):
                arguments_scheme = [{
                    key: value
                } for key, value in arguments_scheme.iteritems()]
            self._arguments_scheme = collections.OrderedDict()
            for record in arguments_scheme:
                if (not isinstance(record, types.DictionaryType)
                        or len(record) > 1):
                    raise ValueError()
                name = record.keys()[0]
                self._arguments_scheme[name] = typespec.ArgumentSpec(
                    self.name, name, record[name], self.murano_class)
        self._yaql_function_definition = \
            yaql_integration.build_wrapper_function_definition(self)
Ejemplo n.º 3
0
    def __init__(self,
                 declaring_type,
                 name,
                 payload,
                 original_name=None,
                 ephemeral=False):
        self._name = name
        original_name = original_name or name
        self._declaring_type = weakref.ref(declaring_type)
        self._meta_values = None
        self_ref = self if ephemeral else weakref.proxy(self)

        if callable(payload):
            if isinstance(payload, specs.FunctionDefinition):
                self._body = payload
            else:
                self._body = yaql_integration.get_function_definition(
                    payload, self_ref, original_name)
            self._arguments_scheme = None
            self._scope = self._body.meta.get(constants.META_SCOPE)
            if declaring_type.extension_class and any(
                (helpers.inspect_is_static(declaring_type.extension_class,
                                           original_name),
                 helpers.inspect_is_classmethod(declaring_type.extension_class,
                                                original_name))):
                self._usage = self._body.meta.get(
                    constants.META_USAGE, dsl_types.MethodUsages.Static)
                if self._usage not in dsl_types.MethodUsages.StaticMethods:
                    raise ValueError('Invalid Usage for static method ' +
                                     self.name)
            else:
                self._usage = (self._body.meta.get(constants.META_USAGE)
                               or dsl_types.MethodUsages.Runtime)
                if self._usage not in dsl_types.MethodUsages.InstanceMethods:
                    raise ValueError('Invalid Usage for instance method ' +
                                     self.name)
                self._resolve_usage_and_scope()
            if self._scope is None:
                self._scope = dsl_types.MethodScopes.Session
            if (self._body.name.startswith('#')
                    or self._body.name.startswith('*')):
                raise ValueError(
                    'Import of special yaql functions is forbidden')
            self._meta = meta.MetaData(
                self._body.meta.get(constants.META_MPL_META),
                dsl_types.MetaTargets.Method, declaring_type)
        else:
            payload = payload or {}
            self._body = macros.MethodBlock(payload.get('Body'), name)
            self._usage = payload.get(
                'Usage') or dsl_types.MethodUsages.Runtime
            self._scope = payload.get('Scope')
            self._resolve_usage_and_scope()
            if self._scope is None:
                self._scope = dsl_types.MethodScopes.Session
            arguments_scheme = helpers.list_value(payload.get('Arguments'))
            if isinstance(arguments_scheme, dict):
                arguments_scheme = [{
                    key: value
                } for key, value in arguments_scheme.items()]
            self._arguments_scheme = collections.OrderedDict()
            seen_varargs = False
            seen_kwargs = False
            args_order_error = False
            for record in arguments_scheme:
                if not isinstance(record, dict) or len(record) > 1:
                    raise exceptions.DslSyntaxError(
                        'Invalid arguments declaration')
                name = list(record.keys())[0]
                argument = MuranoMethodArgument(self, self.name, name,
                                                record[name])
                usage = argument.usage
                if (usage == dsl_types.MethodArgumentUsages.Standard
                        and (seen_kwargs or seen_varargs)):
                    args_order_error = True
                elif usage == dsl_types.MethodArgumentUsages.VarArgs:
                    if seen_kwargs or seen_varargs:
                        args_order_error = True
                    seen_varargs = True
                elif usage == dsl_types.MethodArgumentUsages.KwArgs:
                    if seen_kwargs:
                        args_order_error = True
                    seen_kwargs = True

                if args_order_error:
                    raise exceptions.DslSyntaxError(
                        'Invalid argument order in method {0}'.format(
                            self.name))
                else:
                    self._arguments_scheme[name] = argument

            self._meta = meta.MetaData(payload.get('Meta'),
                                       dsl_types.MetaTargets.Method,
                                       declaring_type)

        self._instance_stub, self._static_stub = \
            yaql_integration.build_stub_function_definitions(self_ref)
Ejemplo n.º 4
0
 def _prepare_body(self, body, name):
     return macros.MethodBlock(body, name)