First checkin of the Python XPCOM bindings.
git-svn-id: svn://10.0.0.236/trunk@87331 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -0,0 +1,149 @@
|
||||
<!-- Copyright (c) 2000-2001 ActiveState Tool Corporation. -->
|
||||
<!-- See the file LICENSE.txt for licensing information. -->
|
||||
|
||||
<center><b><font size=+2>Python Component Sample</font></b>
|
||||
|
||||
<p>
|
||||
<br>
|
||||
Last modified
|
||||
<script>
|
||||
document.write(document.lastModified);
|
||||
</script>
|
||||
</center>
|
||||
|
||||
<p>XPConnect allows JavaScript
|
||||
to transparantly access and manipulate XPCOM objects;
|
||||
|
||||
<p>Big Deal, I hear you say! But it also works for Python!!!
|
||||
|
||||
<p>
|
||||
This sample demonstrates accessing a XPCOM object through XPConnect.
|
||||
The JavaScript executed when this page loads creates an instance
|
||||
of the Python object by
|
||||
using the <tt>Components</tt> object, then accesses it through
|
||||
the <a href="py_test_component.idl">nsISample</a> interface by calling <tt>QueryInterface</tt>:
|
||||
<br>
|
||||
<pre>
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
var sample = Components.classes["component://mozilla/sample/sample-world"].createInstance();
|
||||
sample = sample.QueryInterface(Components.interfaces.nsISample);
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
The buttons on the form are connected to JavaScript event handlers which
|
||||
call the methods defined in Python
|
||||
|
||||
|
||||
<p><b><a name="Compiling">Compiling the idl</b>
|
||||
|
||||
<p>The XPIDL compiler (xpidl on Unix, xpidl.exe on Windows, and a CodeWarrior plugin on Mac)
|
||||
is compiled at build time (except on Mac) thus
|
||||
you will have to build mozilla in order to test this out. If you
|
||||
have already built mozilla then the compiler will be located at <tt>mozilla\dist\WIN32_D.OBJ\bin\xpidl.exe</tt>.
|
||||
|
||||
<p>Once you have the XPIDL compiler enter the following command at your
|
||||
prompt:
|
||||
<br><tt>D:\whereever\xpcom\test\test_component>d:\mozilla\dist\WIN32_D.OBJ\bin\xpidl -I
|
||||
d:\mozilla\dist\idl -m typelib py_test_component.idl</tt>. You must then copy the generated .xpt file
|
||||
to the mozilla component directory.
|
||||
|
||||
<p>The <tt>-I d:\mozilla\dist\idl</tt> points the compiler to the folder
|
||||
containing the other idl files, needed because nsISample.idl inherits from
|
||||
nsISupports.idl. The <tt>-m typelib</tt> instruction tells the compiler
|
||||
to build the .XPT typelib file.</tt>.
|
||||
|
||||
<p>
|
||||
For more information on compilation see the <a href="http://www.mozilla.org/scriptable/xpidl/">xpidl
|
||||
compiler page</a>.
|
||||
|
||||
<p><b>Running the sample</b>
|
||||
<p><b>NOTE: This doesnt work for me - I get an access denied error using XPConnect!</b>
|
||||
<p>Using Mozilla, load this file. Pay attention
|
||||
to the console when clicking "write".
|
||||
|
||||
<!-- XXX keep in sync with stuff in pre tag below -->
|
||||
<script>
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
var sample = Components.classes["Python.TestComponent"].createInstance();
|
||||
sample = sample.QueryInterface(Components.interfaces.nsIPythonTestInterface);
|
||||
dump("sample = " + sample + "\n");
|
||||
|
||||
function get()
|
||||
{
|
||||
var field = document.getElementById('Value');
|
||||
field.value = sample.str_value;
|
||||
}
|
||||
|
||||
function set()
|
||||
{
|
||||
var field = document.getElementById('Value');
|
||||
sample.str_value = field.value;
|
||||
}
|
||||
|
||||
function poke()
|
||||
{
|
||||
var field = document.getElementById('Value');
|
||||
sample.poke(field.value);
|
||||
}
|
||||
|
||||
function write()
|
||||
{
|
||||
sample.writeValue("here is what I'm writing: ");
|
||||
}
|
||||
</script>
|
||||
|
||||
<p>
|
||||
<form name="form">
|
||||
<input type="button" value="Get" onclick="get();">
|
||||
<input type="button" value="Set" onclick="set();">
|
||||
<input type="button" value="Poke" onclick="poke();">
|
||||
<input type="text" id="Value">
|
||||
<input type="button" value="Write" onclick="write();">
|
||||
<form>
|
||||
|
||||
<hr>
|
||||
|
||||
<p>
|
||||
JavaScript and form source:
|
||||
|
||||
<!-- XXX keep in sync with actual script -->
|
||||
<pre>
|
||||
<script>
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
var sample = Components.classes["component://Python.TestComponent"].createInstance();
|
||||
sample = sample.QueryInterface(Components.interfaces.nsIPythonTestInterface);
|
||||
dump("sample = " + sample + "\n");
|
||||
|
||||
function get()
|
||||
{
|
||||
var field = document.getElementById('Value');
|
||||
field.value = sample.str_value;
|
||||
}
|
||||
|
||||
function set()
|
||||
{
|
||||
var field = document.getElementById('Value');
|
||||
sample.str_value = field.value;
|
||||
}
|
||||
|
||||
function poke()
|
||||
{
|
||||
var field = document.getElementById('Value');
|
||||
sample.poke(field.value);
|
||||
}
|
||||
|
||||
function write()
|
||||
{
|
||||
sample.writeValue("here is what I'm writing: ");
|
||||
}
|
||||
</script>
|
||||
|
||||
<form name="form">
|
||||
<input type="button" value="Get" onclick="get();">
|
||||
<input type="button" value="Set" onclick="set();">
|
||||
<input type="button" value="Poke" onclick="poke();">
|
||||
<input type="text" id="Value">
|
||||
<input type="button" value="Write" onclick="write();">
|
||||
<form>
|
||||
|
||||
</pre>
|
||||
@@ -0,0 +1,183 @@
|
||||
/* Copyright (c) 2000-2001 ActiveState Tool Corporation.
|
||||
See the file LICENSE.txt for licensing information. */
|
||||
|
||||
// NOTE: This is a TEST interface, not a DEMO interface :-)
|
||||
// We try to get as many data-types etc exposed, meaning this
|
||||
// doesnt really make a good demo of a "simple component"
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(1ECAED4F-E4D5-4ee7-ABF0-7D72AE1441D7)]
|
||||
interface nsIPythonTestInterface : nsISupports
|
||||
{
|
||||
// Some constants for us to test - one for every type supported by xpidl
|
||||
const short One = 1;
|
||||
const long Two = 2;
|
||||
const long MinusOne = -1;
|
||||
const long BigLong = 0x7FFFFFFF;
|
||||
const long BigULong = 0xFFFFFFFF;
|
||||
|
||||
// Declare every type supported as an attribute.
|
||||
attribute boolean boolean_value; // PRBool
|
||||
attribute octet octet_value; // PRUint8
|
||||
attribute short short_value; // PRInt16
|
||||
attribute unsigned short ushort_value; // PRUint16
|
||||
attribute long long_value; // PRInt32
|
||||
attribute unsigned long ulong_value; // PRUint32
|
||||
attribute long long long_long_value; // PRInt64
|
||||
attribute unsigned long long ulong_long_value; // PRUint64
|
||||
attribute float float_value; // float
|
||||
attribute double double_value; // double
|
||||
attribute char char_value; // char
|
||||
attribute wchar wchar_value; // PRUnichar
|
||||
attribute string string_value; // char *
|
||||
attribute wstring wstring_value; // PRUnichar*
|
||||
attribute nsIIDRef iid_value; // an IID
|
||||
attribute nsIPythonTestInterface interface_value; // A specific interface
|
||||
attribute nsISupports isupports_value; // A generic interface
|
||||
|
||||
// Declare every type supported as a method with an "in", "in/out" and "out" params
|
||||
boolean do_boolean(in boolean p1, inout boolean p2, out boolean p3);
|
||||
octet do_octet(in octet p1, inout octet p2, out octet p3);
|
||||
short do_short(in short p1, inout short p2, out short p3);
|
||||
unsigned short do_unsigned_short(in unsigned short p1, inout unsigned short p2, out unsigned short p3);
|
||||
long do_long(in long p1, inout long p2, out long p3);
|
||||
unsigned long do_unsigned_long(in unsigned long p1, inout unsigned long p2, out unsigned long p3);
|
||||
long long do_long_long(in long long p1, inout long long p2, out long long p3);
|
||||
unsigned long long do_unsigned_long_long(in unsigned long long p1, inout unsigned long long p2, out unsigned long long p3);
|
||||
float do_float(in float p1, inout float p2, out float p3);
|
||||
double do_double(in double p1, inout double p2, out double p3);
|
||||
char do_char(in char p1, inout char p2, out char p3);
|
||||
wchar do_wchar(in wchar p1, inout wchar p2, out wchar p3);
|
||||
string do_string(in string p1, inout string p2, out string p3);
|
||||
wstring do_wstring(in wstring p1, inout wstring p2, out wstring p3);
|
||||
nsIIDRef do_nsIIDRef(in nsIIDRef p1, inout nsIIDRef p2, out nsIIDRef p3);
|
||||
nsIPythonTestInterface do_nsIPythonTestInterface(in nsIPythonTestInterface p1, inout nsIPythonTestInterface p2, out nsIPythonTestInterface p3);
|
||||
nsISupports do_nsISupports(in nsISupports p1, inout nsISupports p2, out nsISupports p3);
|
||||
void do_nsISupportsIs(in nsIIDRef iid, [iid_is(iid),retval] out nsQIResult result);
|
||||
// Do I really need these??
|
||||
// void do_nsISupportsIs2(inout nsIIDRef iid, [iid_is(iid)] inout nsQIResult result);
|
||||
// void do_nsISupportsIs3(out nsIIDRef iid, [iid_is(iid)] inout nsQIResult result);
|
||||
// void do_nsISupportsIs4(out nsIIDRef iid, [iid_is(iid)] out nsQIResult result);
|
||||
};
|
||||
|
||||
// Another interface - we use another interface purely for testing purposes -
|
||||
// We ensure that the entire interface hierarcy is available correctly.
|
||||
[scriptable, uuid(B38D1538-FE92-42c3-831F-285242EDEEA4)]
|
||||
interface nsIPythonTestInterfaceExtra : nsIPythonTestInterface
|
||||
{
|
||||
// These were copied from the XPCOM test 'xpctest.idl'
|
||||
// (and a few extras added)
|
||||
void MultiplyEachItemInIntegerArray(
|
||||
in PRInt32 val,
|
||||
in PRUint32 count,
|
||||
[array, size_is(count)] inout PRInt32 valueArray);
|
||||
void MultiplyEachItemInIntegerArrayAndAppend(
|
||||
in PRInt32 val,
|
||||
inout PRUint32 count,
|
||||
[array, size_is(count)] inout PRInt32 valueArray);
|
||||
|
||||
// Note that this method shares a single "size_is" between 2 params!
|
||||
void CompareStringArrays([array, size_is(count)] in string arr1,
|
||||
[array, size_is(count)] in string arr2,
|
||||
in unsigned long count,
|
||||
[retval] out short result);
|
||||
|
||||
void DoubleStringArray(inout PRUint32 count,
|
||||
[array, size_is(count)] inout string valueArray);
|
||||
void ReverseStringArray(in PRUint32 count,
|
||||
[array, size_is(count)] inout string valueArray);
|
||||
|
||||
// One count, one inout array.
|
||||
void DoubleString(inout PRUint32 count,
|
||||
[size_is(count)] inout string str);
|
||||
// One in count and in array, plus out count and out array
|
||||
void DoubleString2(in PRUint32 in_count, [size_is(in_count)] in string in_str,
|
||||
out PRUint32 out_count, [size_is(out_count)] out string out_str);
|
||||
// As per DoubleString2, but out string also marked retval
|
||||
void DoubleString3(in PRUint32 in_count, [size_is(in_count)] in string in_str,
|
||||
out PRUint32 out_count, [size_is(out_count), retval] out string out_str);
|
||||
// One in array, one out array, one share inout count.
|
||||
void DoubleString4([size_is(count)] in string in_str, inout PRUint32 count, [size_is(count)] out string out_str);
|
||||
// UpString defines the count as only "in" - meaning the result must be the same size
|
||||
void UpString(in PRUint32 count,
|
||||
[size_is(count)] inout string str);
|
||||
// UpString2 defines count as only "in", and a string as only "out"
|
||||
void UpString2(in PRUint32 count,
|
||||
[size_is(count)] in string in_str,
|
||||
[size_is(count)]out string out_str);
|
||||
// Test we can get an "out" array with an "in" size (and the size is not used anywhere as a size for an in!)
|
||||
void GetFixedString(in PRUint32 count, [size_is(count)]out string out_str);
|
||||
|
||||
void DoubleWideString(inout PRUint32 count,
|
||||
[size_is(count)] inout wstring str);
|
||||
void DoubleWideString2(in PRUint32 in_count, [size_is(in_count)] in wstring in_str,
|
||||
out PRUint32 out_count, [size_is(out_count)] out wstring out_str);
|
||||
void DoubleWideString3(in PRUint32 in_count, [size_is(in_count)] in wstring in_str,
|
||||
out PRUint32 out_count, [size_is(out_count), retval] out wstring out_str);
|
||||
void DoubleWideString4([size_is(count)] in wstring in_str, inout PRUint32 count, [size_is(count)] out wstring out_str);
|
||||
// UpWideString defines the count as only "in" - meaning the result must be the same size
|
||||
void UpWideString(in PRUint32 count,
|
||||
[size_is(count)] inout wstring str);
|
||||
// UpWideString2 defines count as only "in", and a string as only "out"
|
||||
void UpWideString2(in PRUint32 count,
|
||||
[size_is(count)] in wstring in_str,
|
||||
[size_is(count)]out wstring out_str);
|
||||
// Test we can get an "out" array with an "in" size (and the size is not used anywhere as a size for an in!)
|
||||
void GetFixedWideString(in PRUint32 count, [size_is(count)]out string out_str);
|
||||
|
||||
void GetStrings(out PRUint32 count,
|
||||
[retval, array, size_is(count)] out string str);
|
||||
|
||||
void UpOctetArray(inout PRUint32 count,
|
||||
[array, size_is(count)] inout PRUint8 data);
|
||||
|
||||
void UpOctetArray2(inout PRUint32 count,
|
||||
[array, size_is(count)] inout PRUint8 data);
|
||||
|
||||
// Arrays of interfaces
|
||||
void CheckInterfaceArray(in PRUint32 count,
|
||||
[array, size_is(count)] in nsISupports data,
|
||||
[retval] out PRBool all_non_null);
|
||||
void GetInterfaceArray(out PRUint32 count,
|
||||
[array, size_is(count)] out nsISupports data);
|
||||
void ExtendInterfaceArray(inout PRUint32 count,
|
||||
[array, size_is(count)] inout nsISupports data);
|
||||
|
||||
// Arrays of IIDs
|
||||
void CheckIIDArray(in PRUint32 count,
|
||||
[array, size_is(count)] in nsIIDRef data,
|
||||
[retval] out PRBool all_mine);
|
||||
void GetIIDArray(out PRUint32 count,
|
||||
[array, size_is(count)] out nsIIDRef data);
|
||||
void ExtendIIDArray(inout PRUint32 count,
|
||||
[array, size_is(count)] inout nsIIDRef data);
|
||||
|
||||
// More specific tests.
|
||||
// Test our count param can be shared as an "in" param.
|
||||
void SumArrays(in PRUint32 count, [array, size_is(count)]in PRInt32 array1, [array, size_is(count)]in PRInt32 array2, [retval]out PRInt32 result);
|
||||
// Test our count param can be shared as an "out" param.
|
||||
void GetArrays(out PRUint32 count, [array, size_is(count)]out PRInt32 array1, [array, size_is(count)]out PRInt32 array2);
|
||||
// Test we can get an "out" array with an "in" size (and the size is not used anywhere as a size for an in!)
|
||||
void GetFixedArray(in PRUint32 count, [array, size_is(count)]out PRInt32 array1);
|
||||
// Test our "in" count param can be shared as one "in", plus one "out" param.
|
||||
void CopyArray(in PRUint32 count, [array, size_is(count)]in PRInt32 array1, [array, size_is(count)]out PRInt32 array2);
|
||||
// Test our "in-out" count param can be shared as one "in", plus one "out" param.
|
||||
void CopyAndDoubleArray(inout PRUint32 count, [array, size_is(count)]in PRInt32 array1, [array, size_is(count)]out PRInt32 array2);
|
||||
// Test our "in-out" count param can be shared as one "in", plus one "in-out" param.
|
||||
void AppendArray(inout PRUint32 count, [array, size_is(count)]in PRInt32 array1, [array, size_is(count)]inout PRInt32 array2);
|
||||
};
|
||||
|
||||
// DOM String support is a "recent" (01/2001) addition to XPCOM. These test
|
||||
// have their own interface for no real good reason ;-)
|
||||
[scriptable, uuid(657ae651-a973-4818-8c06-f4b948b3d758)]
|
||||
interface nsIPythonTestInterfaceDOMStrings : nsIPythonTestInterfaceExtra
|
||||
{
|
||||
DOMString GetDOMStringResult();
|
||||
void GetDOMStringOut([retval] out DOMString s);
|
||||
PRUint32 GetDOMStringLength(in DOMString s);
|
||||
PRUint32 GetDOMStringRefLength(in DOMStringRef s);
|
||||
PRUint32 GetDOMStringPtrLength(in DOMStringPtr s);
|
||||
void ConcatDOMStrings(in DOMString s1, in DOMString s2, out DOMString ret);
|
||||
attribute DOMString domstring_value;
|
||||
readonly attribute DOMString domstring_value_ro;
|
||||
};
|
||||
@@ -0,0 +1,344 @@
|
||||
# Copyright (c) 2000-2001 ActiveState Tool Corporation.
|
||||
# See the file LICENSE.txt for licensing information.
|
||||
|
||||
# NOTE: This is a TEST interface, not a DEMO interface :-)
|
||||
# We try to get as many data-types etc exposed, meaning this
|
||||
# doesnt really make a good demo of a "simple component"
|
||||
|
||||
|
||||
from xpcom import components, verbose
|
||||
|
||||
class PythonTestComponent:
|
||||
# Note we only list the "child" interface, not our intermediate interfaces
|
||||
# (which we must, by definition, also support)
|
||||
_com_interfaces_ = components.interfaces.nsIPythonTestInterfaceDOMStrings
|
||||
_reg_clsid_ = "{7EE4BDC6-CB53-42c1-A9E4-616B8E012ABA}"
|
||||
_reg_contractid_ = "Python.TestComponent"
|
||||
def __init__(self):
|
||||
self.boolean_value = 1
|
||||
self.octet_value = 2
|
||||
self.short_value = 3
|
||||
self.ushort_value = 4
|
||||
self.long_value = 5
|
||||
self.ulong_value = 6
|
||||
self.long_long_value = 7
|
||||
self.ulong_long_value = 8
|
||||
self.float_value = 9.0
|
||||
self.double_value = 10.0
|
||||
self.char_value = "a"
|
||||
self.wchar_value = "b"
|
||||
self.string_value = "cee"
|
||||
self.wstring_value = "dee"
|
||||
self.iid_value = self._reg_clsid_
|
||||
self.interface_value = None
|
||||
self.isupports_value = None
|
||||
self.domstring_value = "dom"
|
||||
|
||||
def __del__(self):
|
||||
if verbose:
|
||||
print "Python.TestComponent: __del__ method called - object is destructing"
|
||||
|
||||
def do_boolean(self, p1, p2):
|
||||
# boolean do_boolean(in boolean p1, inout boolean p2, out boolean p3);
|
||||
ret = p1 ^ p2
|
||||
return ret, not ret, ret
|
||||
|
||||
def do_octet(self, p1, p2):
|
||||
# octet do_octet(in octet p1, inout octet p2, out octet p3);
|
||||
return p1+p2, p1-p2, p1*p2
|
||||
|
||||
def do_short(self, p1, p2):
|
||||
# short do_short(in short p1, inout short p2, out short p3);
|
||||
return p1+p2, p1-p2, p1*p2
|
||||
|
||||
def do_unsigned_short(self, p1, p2):
|
||||
# unsigned short do_unsigned_short(in unsigned short p1, inout unsigned short p2, out unsigned short p3);
|
||||
return p1+p2, p1-p2, p1*p2
|
||||
def do_long(self, p1, p2):
|
||||
# long do_long(in long p1, inout long p2, out long p3);
|
||||
return p1+p2, p1-p2, p1*p2
|
||||
|
||||
def do_unsigned_long(self, p1, p2):
|
||||
# unsigned long do_unsigned_long(in unsigned long p1, inout unsigned long p2, out unsigned long p3);
|
||||
return p1+p2, p1-p2, p1*p2
|
||||
def do_long_long(self, p1, p2):
|
||||
# long long do_long_long(in long long p1, inout long long p2, out long long p3);
|
||||
return p1+p2, p1-p2, p1*p2
|
||||
def do_unsigned_long_long(self, p1, p2):
|
||||
# unsigned long long do_unsigned_long_long(in unsigned long long p1, inout unsigned long long p2, out unsigned long long p3);
|
||||
return p1+p2, p1-p2, p1*p2
|
||||
def do_float(self, p1, p2):
|
||||
# float do_float(in float p1, inout float p2, out float p3);
|
||||
return p1+p2, p1-p2, p1*p2
|
||||
def do_double(self, p1, p2):
|
||||
# double do_double(in double p1, inout double p2, out double p3);
|
||||
return p1+p2, p1-p2, p1*p2
|
||||
def do_char(self, p1, p2):
|
||||
# char do_char(in char p1, inout char p2, out char p3);
|
||||
return chr(ord(p1)+ord(p2)), p2, p1
|
||||
def do_wchar(self, p1, p2):
|
||||
# wchar do_wchar(in wchar p1, inout wchar p2, out wchar p3);
|
||||
return chr(ord(p1)+ord(p2)), p2, p1
|
||||
def do_string(self, p1, p2):
|
||||
# string do_string(in string p1, inout string p2, out string p3);
|
||||
ret = ""
|
||||
if p1 is not None: ret = ret + p1
|
||||
if p2 is not None: ret = ret + p2
|
||||
return ret, p1, p2
|
||||
def do_wstring(self, p1, p2):
|
||||
# wstring do_wstring(in wstring p1, inout wstring p2, out wstring p3);
|
||||
ret = u""
|
||||
if p1 is not None: ret = ret + p1
|
||||
if p2 is not None: ret = ret + p2
|
||||
return ret, p1, p2
|
||||
def do_nsIIDRef(self, p1, p2):
|
||||
# nsIIDRef do_nsIIDRef(in nsIIDRef p1, inout nsIIDRef p2, out nsIIDRef p3);
|
||||
return p1, self._reg_clsid_, p2
|
||||
def do_nsIPythonTestInterface(self, p1, p2):
|
||||
# nsIPythonTestInterface do_nsIPythonTestInterface(in nsIPythonTestInterface p1, inout nsIPythonTestInterface p2, out nsIPythonTestInterface p3);
|
||||
return p2, p1, self
|
||||
def do_nsISupports(self, p1, p2):
|
||||
# nsISupports do_nsISupports(in nsISupports p1, inout nsISupports p2, out nsISupports p3);
|
||||
return self, p1, p2
|
||||
def do_nsISupportsIs(self, iid):
|
||||
# void do_nsISupportsIs(in nsIIDRef iid, [iid_is(iid),retval] out nsQIResult result)
|
||||
# Note the framework does the QI etc on us, so there is no real point me doing it.
|
||||
# (However, user code _should_ do the QI - otherwise any errors are deemed "internal" (as they
|
||||
# are raised by the C++ framework), and therefore logged to the console, etc.
|
||||
# A user QI allows the user to fail gracefully, whatever gracefully means for them!
|
||||
return self
|
||||
# Do I really need these??
|
||||
## def do_nsISupportsIs2(self, iid, interface):
|
||||
## # void do_nsISupportsIs2(inout nsIIDRef iid, [iid_is(iid),retval] inout nsQIResult result);
|
||||
## return iid, interface
|
||||
## def do_nsISupportsIs3(self, interface):
|
||||
## # void do_nsISupportsIs3(out nsIIDRef iid, [iid_is(iid)] inout nsQIResult result);
|
||||
## return self._com_interfaces_, interface
|
||||
## def do_nsISupportsIs4(self):
|
||||
## # void do_nsISupportsIs4(out nsIIDRef iid, [iid_is(iid)] out nsQIResult result);
|
||||
## return self._com_interfaces_, self
|
||||
|
||||
# Methods from the nsIPythonTestInterfaceExtra interface
|
||||
#
|
||||
def MultiplyEachItemInIntegerArray(self, val, valueArray):
|
||||
# void MultiplyEachItemInIntegerArray(
|
||||
# in PRInt32 val,
|
||||
# in PRUint32 count,
|
||||
# [array, size_is(count)] inout PRInt32 valueArray);
|
||||
# NOTE - the "sizeis" params are never passed to or returned from Python!
|
||||
results = []
|
||||
for item in valueArray:
|
||||
results.append(item * val)
|
||||
return results
|
||||
def MultiplyEachItemInIntegerArrayAndAppend(self, val, valueArray):
|
||||
#void MultiplyEachItemInIntegerArrayAndAppend(
|
||||
# in PRInt32 val,
|
||||
# inout PRUint32 count,
|
||||
# [array, size_is(count)] inout PRInt32 valueArray);
|
||||
results = valueArray[:]
|
||||
for item in valueArray:
|
||||
results.append(item * val)
|
||||
return results
|
||||
def DoubleStringArray(self, valueArray):
|
||||
# void DoubleStringArray(inout PRUint32 count,
|
||||
# [array, size_is(count)] inout string valueArray);
|
||||
results = []
|
||||
for item in valueArray:
|
||||
results.append(item * 2)
|
||||
return results
|
||||
|
||||
def ReverseStringArray(self, valueArray):
|
||||
# void ReverseStringArray(in PRUint32 count,
|
||||
# [array, size_is(count)] inout string valueArray);
|
||||
valueArray.reverse()
|
||||
return valueArray
|
||||
|
||||
# Note that this method shares a single "size_is" between 2 params!
|
||||
def CompareStringArrays(self, ar1, ar2):
|
||||
# void CompareStringArrays([array, size_is(count)] in string arr1,
|
||||
# [array, size_is(count)] in string arr2,
|
||||
# in unsigned long count,
|
||||
# [retval] out short result);
|
||||
return cmp(ar1, ar2)
|
||||
|
||||
def DoubleString(self, val):
|
||||
# void DoubleString(inout PRUint32 count,
|
||||
# [size_is(count)] inout string str);
|
||||
return val * 2
|
||||
def DoubleString2(self, val):
|
||||
# void DoubleString2(in PRUint32 in_count, [size_is(in_count)] in string in_str,
|
||||
# out PRUint32 out_count, [size_is(out_count)] out string out_str);
|
||||
return val * 2
|
||||
def DoubleString3(self, val):
|
||||
# void DoubleString3(in PRUint32 in_count, [size_is(in_count)] in string in_str,
|
||||
# out PRUint32 out_count, [size_is(out_count), retval] string out_str);
|
||||
return val * 2
|
||||
def DoubleString4(self, val):
|
||||
# void DoubleString4([size_is(count)] in string in_str, inout PRUint32 count, [size_is(count)] out string out_str);
|
||||
return val * 2
|
||||
def UpString(self, val):
|
||||
# // UpString defines the count as only "in" - meaning the result must be the same size
|
||||
# void UpString(in PRUint32 count,
|
||||
# [size_is(count)] inout string str);
|
||||
return val.upper()
|
||||
UpString2 = UpString
|
||||
# // UpString2 defines count as only "in", and a string as only "out"
|
||||
# void UpString2(in PRUint32 count,
|
||||
# [size_is(count)] inout string in_str,
|
||||
# [size_is(count)]out string out_str);
|
||||
|
||||
def GetFixedString(self, count):
|
||||
# void GetFixedString(in PRUint32 count, [size_is(count)out string out_str);
|
||||
return "A" * count
|
||||
|
||||
# DoubleWideString functions are identical to DoubleString, except use wide chars!
|
||||
def DoubleWideString(self, val):
|
||||
return val * 2
|
||||
def DoubleWideString2(self, val):
|
||||
return val * 2
|
||||
def DoubleWideString3(self, val):
|
||||
return val * 2
|
||||
def DoubleWideString4(self, val):
|
||||
return val * 2
|
||||
def UpWideString(self, val):
|
||||
return val.upper()
|
||||
UpWideString2 = UpWideString
|
||||
|
||||
# Test we can get an "out" array with an "in" size (and the size is not used anywhere as a size for an in!)
|
||||
def GetFixedWideString(self, count):
|
||||
# void GetFixedWideString(in PRUint32 count, [size_is(count)out string out_str);
|
||||
return u"A" * count
|
||||
|
||||
def GetStrings(self):
|
||||
# void GetStrings(out PRUint32 count,
|
||||
# [retval, array, size_is(count)] out string str);
|
||||
return "Hello from the Python test component".split()
|
||||
# Some tests for our special "PRUint8" support.
|
||||
def UpOctetArray( self, data ):
|
||||
# void UpOctetArray(inout PRUint32 count,
|
||||
# [array, size_is(count)] inout PRUint8 data);
|
||||
return data.upper()
|
||||
|
||||
def UpOctetArray2( self, data ):
|
||||
# void UpOctetArray2(inout PRUint32 count,
|
||||
# [array, size_is(count)] inout PRUint8 data);
|
||||
data = data.upper()
|
||||
# This time we return a list of integers.
|
||||
return map( ord, data )
|
||||
|
||||
# Arrays of interfaces
|
||||
def CheckInterfaceArray(self, interfaces):
|
||||
# void CheckInterfaceArray(in PRUint32 count,
|
||||
# [array, size_is(count)] in nsISupports data,
|
||||
# [retval] out PRBool all_non_null);
|
||||
ret = 1
|
||||
for i in interfaces:
|
||||
if i is None:
|
||||
ret = 0
|
||||
break
|
||||
return ret
|
||||
def GetInterfaceArray(self):
|
||||
# void GetInterfaceArray(out PRUint32 count,
|
||||
# [array, size_is(count)] out nsISupports data);
|
||||
return self, self, self, None
|
||||
def ExtendInterfaceArray(self, data):
|
||||
# void ExtendInterfaceArray(inout PRUint32 count,
|
||||
# [array, size_is(count)] inout nsISupports data);
|
||||
return data * 2
|
||||
|
||||
# Arrays of IIDs
|
||||
def CheckIIDArray(self, data):
|
||||
# void CheckIIDArray(in PRUint32 count,
|
||||
# [array, size_is(count)] in nsIIDRef data,
|
||||
# [retval] out PRBool all_mine);
|
||||
ret = 1
|
||||
for i in data:
|
||||
if i!= self._com_interfaces_ and i != self._reg_clsid_:
|
||||
ret = 0
|
||||
break
|
||||
return ret
|
||||
def GetIIDArray(self):
|
||||
# void GetIIDArray(out PRUint32 count,
|
||||
# [array, size_is(count)] out nsIIDRef data);
|
||||
return self._com_interfaces_, self._reg_clsid_
|
||||
def ExtendIIDArray(self, data):
|
||||
# void ExtendIIDArray(inout PRUint32 count,
|
||||
# [array, size_is(count)] inout nsIIDRef data);
|
||||
return data * 2
|
||||
|
||||
# Test our count param can be shared as an "in" param.
|
||||
def SumArrays(self, array1, array2):
|
||||
# void SumArrays(in PRUint32 count, [array, size_is(count)]in array1, [array, size_is(count)]in array2, [retval]result);
|
||||
if len(array1)!=len(array2):
|
||||
print "SumArrays - not expecting different lengths!"
|
||||
result = 0
|
||||
for i in array1:
|
||||
result = result + i
|
||||
for i in array2:
|
||||
result = result+i
|
||||
return result
|
||||
|
||||
# Test our count param can be shared as an "out" param.
|
||||
def GetArrays(self):
|
||||
# void GetArrays(out PRUint32 count, [array, size_is(count)]out array1, [array, size_is(count)]out array2);
|
||||
return (1,2,3), (4,5,6)
|
||||
# Test we can get an "out" array with an "in" size
|
||||
def GetFixedArray(self, size):
|
||||
# void GetFixedArray(in PRUint32 count, [array, size_is(count)]out PRInt32 array1]);
|
||||
return 0 * size
|
||||
|
||||
# Test our "in" count param can be shared as one "in", plus one "out" param.
|
||||
def CopyArray(self, array1):
|
||||
# void CopyArray(in PRUint32 count, [array, size_is(count)]in array1, [array, size_is(count)]out array2);
|
||||
return array1
|
||||
# Test our "in-out" count param can be shared as one "in", plus one "out" param.
|
||||
def CopyAndDoubleArray(self, array):
|
||||
# void CopyAndDoubleArray(inout PRUint32 count, [array, size_is(count)]in array1, [array, size_is(count)]out array2);
|
||||
return array + array
|
||||
# Test our "in-out" count param can be shared as one "in", plus one "in-out" param.
|
||||
def AppendArray(self, array1, array2):
|
||||
# void AppendArray(inout PRUint32 count, [array, size_is(count)]in array1, [array, size_is(count)]inout array2);
|
||||
rc = array1
|
||||
if array2 is not None:
|
||||
rc.extend(array2)
|
||||
return rc
|
||||
|
||||
# Some tests for the "new" (Feb-2001) DOMString type.
|
||||
def GetDOMStringResult( self ):
|
||||
# Result: DOMString &
|
||||
return "A DOM String"
|
||||
def GetDOMStringOut( self ):
|
||||
# Result: DOMString &
|
||||
return "Another DOM String"
|
||||
def GetDOMStringLength( self, param0 ):
|
||||
# Result: uint32
|
||||
# In: param0: DOMString &
|
||||
return len(param0)
|
||||
|
||||
def GetDOMStringRefLength( self, param0 ):
|
||||
# Result: uint32
|
||||
# In: param0: DOMString &
|
||||
return len(param0)
|
||||
|
||||
def GetDOMStringPtrLength( self, param0 ):
|
||||
# Result: uint32
|
||||
# In: param0: DOMString *
|
||||
return len(param0)
|
||||
|
||||
def ConcatDOMStrings( self, param0, param1 ):
|
||||
# Result: void - None
|
||||
# In: param0: DOMString &
|
||||
# In: param1: DOMString &
|
||||
# Out: DOMString &
|
||||
return param0 + param1
|
||||
def get_domstring_value( self ):
|
||||
# Result: DOMString &
|
||||
return self.domstring_value
|
||||
def set_domstring_value( self, param0 ):
|
||||
# Result: void - None
|
||||
# In: param0: DOMString &
|
||||
self.domstring_value = param0
|
||||
|
||||
def get_domstring_value_ro( self ):
|
||||
# Result: DOMString &
|
||||
return self.domstring_value
|
||||
Reference in New Issue
Block a user