File: python.xml

package info (click to toggle)
virtuoso-opensource 7.2.5.1%2Bdfsg1-0.3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 285,240 kB
  • sloc: ansic: 641,220; sql: 490,413; xml: 269,570; java: 83,893; javascript: 79,900; cpp: 36,927; sh: 31,653; cs: 25,702; php: 12,690; yacc: 10,227; lex: 7,601; makefile: 7,129; jsp: 4,523; awk: 1,697; perl: 1,013; ruby: 1,003; python: 326
file content (130 lines) | stat: -rw-r--r-- 5,176 bytes parent folder | download | duplicates (2)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
 -  
 -  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
 -  project.
 -  
 -  Copyright (C) 1998-2018 OpenLink Software
 -  
 -  This project is free software; you can redistribute it and/or modify it
 -  under the terms of the GNU General Public License as published by the
 -  Free Software Foundation; only version 2 of the License, dated June 1991.
 -  
 -  This program is distributed in the hope that it will be useful, but
 -  WITHOUT ANY WARRANTY; without even the implied warranty of
 -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 -  General Public License for more details.
 -  
 -  You should have received a copy of the GNU General Public License along
 -  with this program; if not, write to the Free Software Foundation, Inc.,
 -  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 -  
 -  
-->
<sect1 id="pythonhosting"><title>Python Hosting</title>

<para>Virtuoso functionality can be enhanced through external libraries by
loading shared objects or DLLs.  The new functions are written in a language of
choice and compiled to produce a shared library appropriate to the operating
system.  The path to the shared library must be declared in the Virtuoso INI
file and the server restarted before it can be used.</para>

<para>The Python language is hosted within Virtuoso in this way.
<computeroutput>hosting_python.so</computeroutput> (or
<computeroutput>hosting_python.dll</computeroutput>) is the library used.</para>

<para>The Python hosting module requires the Python library, version 2.2.2 or above,
to build and use the module, which then must be installed in the Plugins-Load-path
defined in the Virtuoso ini file.  The source code and build script
(<computeroutput>build.py</computeroutput>) for building the
<computeroutput>hosting_python.so</computeroutput> module are included in the Unix
distribution in the  <computeroutput>custom/hosting/python</computeroutput>
directory.  The Unix installer will offer to build it near the end of the
installation process.  The build.py is a kind of Makefile.  On unix it requires
<computeroutput>libtool</computeroutput> and <computeroutput>cc</computeroutput>
in the path.  On windows it requires <computeroutput>cl.exe</computeroutput>
in the path.</para>

<para>The Virtuoso INI file uses a [Plugins] configuration section for listing
shared libraries for the server to load upon startup.  An example of this is:</para>

<programlisting><![CDATA[
[Plugins]
LoadPath = /home/virtuoso/hosting
Load1 = Hosting, hosting_python.so
..
]]></programlisting>

<para>The "Hosting" type defines the entry points for initialization of the runtime
hosting environment, destruction of the user environment and execution of a
file or string containing commands in the hosted language.  It also returns a
list of file extensions that it is capable of processing.  Virtuoso
dynamically defines memory-resident (no disk image) HTTP server handlers for
each specified type. </para>

<para>The Python hosting plugin supports the 'py' extension.  Hence, upon
initialization of the hosting plugin, Virtuoso defines the
<function>__http_handler_py(..)</function>  function according to the API for
file type handlers in the Virtuoso HTTP server.  With this handler in place,
each hit on a .py file (file system or WebDAV) with appropriate execute
permissions will cause the HTTP server to execute the code within it and return
the result instead of simple the file contents.</para>

<para>The python interpreter has a global lock unrelated to the Virtuoso hosting
module, thus no more than one thread can run python code at a time.</para>

<para>The handler will call the __hosting_http_handler VSE with a special set
of parameters to represent the HTTP environment correctly.  Virtuoso will, by
default call the plugin to memory as required, and expel it when finished.
This behavior can be controlled by the INI file parameter:</para>

<programlisting><![CDATA[
[HTTPServer]
PersistentHostingModules = 1/0 default 0
]]></programlisting>

<para>Setting <computeroutput>PersistentHostingModules</computeroutput> to "1"
prevents Virtuoso from removing the interpreters from the HTTP threads after
each request.</para>

<tip><title>See Also:</title>
  <para><link linkend="vseplugins">VSEI Plugins</link></para></tip>

<example id="ex_hostingsharedobjectspy"><title>Using the Python Plugin</title>

<para>Executing Python code directly:</para>

<programlisting><![CDATA[
select __hosting_http_handler ('py', 'print "hello world"; ', '', vector (), 'helloworld.py');
]]></programlisting>

<programlisting><![CDATA[
returns : hello world
]]></programlisting>

<para>Executing a python script file (python/test_print.py in the Virtuoso
working directory):</para>

<programlisting><![CDATA[
python/test_print.py
-------------------
#!/usr/bin/python
print "hello world file";
]]></programlisting>

<programlisting><![CDATA[
select __hosting_http_handler ('py', 'python/test_print.py');
]]></programlisting>

<programlisting><![CDATA[
returns : hello world file
]]></programlisting>
</example>

</sect1>


<!--
aix needs readline
-->