python的taco模块
taco的Python项目详细描述
简介
taco是一个连接脚本语言的系统。 它的目标是允许您从 另一个。 它通过在子进程中运行第二语言解释器来实现这一点, 以及传递有关要在该解释器内执行的操作的消息。
原则上,要与脚本语言交互,最好是 将一个的解释器作为另一个的扩展嵌入。 但是这可能不方便也不可能, 每种语言的组合都需要重复。 相反,taco只需要一个“client”模块和“server”脚本 对于每种语言,都应该很容易安装, 它的消息被设计成通用的 可以在任何语言组合之间使用。
有关玉米卷的更多信息,请参见 Taco Homepage。
示例
下面是不同类型响应的示例 可能是因为打了个玉米卷电话:
函数结果
If you find that you need the weighted ^{tt1}$ function from the Acme::Dice Perl module, you can import it and call the function as follows:
>>> from taco import Taco >>> taco = Taco(lang='perl') >>> taco.import_module('Acme::Dice', 'roll_dice') >>> taco.call_function('roll_dice', dice=1, sides=6, favor=6, bias=100) 6
In this example, instantiating a ^{tt2}$ object starts a sub-process running a Perl script. This “server” script then handles the instructions to import a module and call one of its functions, returning the value 6.
对象引用
To allow the use of object-oriented modules such as Acme::PricelessMethods, references to objects are returned as instances of the ^{tt3}$ class.
>>> taco.import_module('Acme::PricelessMethods') >>> pm = taco.construct_object('Acme::PricelessMethods') >>> type(pm) <class 'taco.object.TacoObject'>
These objects can be used to invoke further actions:
>>> pm.call_method('is_machine_on') 1
例外情况
^{tt1}$ raises an exception if we try to roll more than 100 dice. The exception is caught and re-raised on the “client” side:
>>> taco.call_function('roll_dice', dice=1000) Traceback (most recent call last): ... taco.error.TacoReceivedError: ... Really? Roll 1000 dice? ...
安装
可以使用setup.py脚本安装模块:
python setup.py install
在此之前,您可能需要运行单元测试:
PYTHONPATH=lib python -m unittest -v
对于python 2,可能需要包含命令discover 在unittest模块名之后。 如果成功了,您应该会看到许多测试用例正在运行。
集成测试
这个包还包括进一步的集成测试 整个系统。 这些测试存储在名为ti_*.py的文件中以避免它们 由unittestdiscovery找到,默认为 参数. 它们都使用python“client”模块,但是有很多 “服务器”脚本。
Python
使用python“服务器”脚本的测试可以直接从 套餐:
PYTHONPATH=lib python -m unittest discover -v -s 'ti-python' -p 'ti_*.py'
其他语言
以下测试都需要一个taco“服务器”脚本 要在搜索路径中安装的相应语言。
Perl
PYTHONPATH=lib python -m unittest discover -v -s 'ti-perl' -p 'ti_*.py'
许可证
此程序是免费软件:您可以重新分发和/或修改 根据由 自由软件基金会,或者许可证的第3版,或者 (由您选择)任何更高版本。
这个程序的发布是希望它能有用, 但没有任何保证;甚至没有 适销性或适合某一特定目的的适销性。见 GNU通用公共许可证了解更多详细信息。
你应该收到GNU通用公共许可证的副本 还有这个节目。如果没有,请参见<;http://www.gnu.org/licenses/>;。