File: python_resolver.go

package info (click to toggle)
golang-github-hydrogen18-stalecucumber 0.0~git20180226.6de214d-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 280 kB
  • sloc: python: 71; makefile: 2
file content (35 lines) | stat: -rw-r--r-- 898 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package stalecucumber

import "errors"

// A type to convert to a GLOBAL opcode to something meaningful in golang
type PythonResolver interface {
	Resolve(module string, name string, args []interface{}) (interface{}, error)
}

var ErrUnresolvablePythonGlobal = errors.New("Unresolvable Python global value")

type PythonResolverChain []PythonResolver

func MakePythonResolverChain(args... PythonResolver) PythonResolverChain{
	if len(args) == 0 {
		panic("Cannot make chain of length zero")
	}
	return PythonResolverChain(args)
}

func (this PythonResolverChain) Resolve(module string, name string, args []interface{})(interface{}, error){
	var err error
	for _, resolver := range this {
		var result interface{}
		result, err = resolver.Resolve(module, name, args)
		if err == nil {
			return result, nil
		}
		if err != ErrUnresolvablePythonGlobal {
			return nil, err
		}
	}

	return nil, err
}