# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is the Python XPCOM language bindings.
#
# The Initial Developer of the Original Code is
# ActiveState Tool Corp.
# Portions created by the Initial Developer are Copyright (C) 2000, 2001
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Mark Hammond <MarkH@ActiveState.com> (original author)
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
# 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"
class PythonTestComponent:
# Note we only list the "child" interface, not our intermediate interfaces
# (which we must, by definition, also support)
self.interface_value = None
self.isupports_value = None
if verbose:
print "Python.TestComponent: __del__ method called - object is destructing"
# 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);
ret = ""
# wstring do_wstring(in wstring p1, inout wstring p2, out wstring p3);
ret = u""
# 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)
# 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
#
# 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:
return results
#void MultiplyEachItemInIntegerArrayAndAppend(
# in PRInt32 val,
# inout PRUint32 count,
# [array, size_is(count)] inout PRInt32 valueArray);
results = valueArray[:]
for item in valueArray:
return results
# void DoubleStringArray(inout PRUint32 count,
# [array, size_is(count)] inout string valueArray);
results = []
for item in valueArray:
return results
# void ReverseStringArray(in PRUint32 count,
# [array, size_is(count)] inout string valueArray);
return 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 DoubleString(inout PRUint32 count,
# [size_is(count)] inout string str);
return val * 2
# 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
# 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
# void DoubleString4([size_is(count)] in string in_str, inout PRUint32 count, [size_is(count)] out string out_str);
return val * 2
# // 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)] inout string in_str,
# [size_is(count)]out string out_str);
# 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!
return val * 2
return val * 2
return val * 2
return val * 2
return v
return v.encode("utf8")
# 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);
return u"A" * count
# 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.
# void UpOctetArray(inout PRUint32 count,
# [array, size_is(count)] inout PRUint8 data);
# void UpOctetArray2(inout PRUint32 count,
# [array, size_is(count)] inout PRUint8 data);
# This time we return a list of integers.
# Arrays of 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
return a
# void GetInterfaceArray(out PRUint32 count,
# [array, size_is(count)] out nsISupports data);
# void ExtendInterfaceArray(inout PRUint32 count,
# [array, size_is(count)] inout nsISupports data);
return data * 2
# Arrays of IIDs
# void CheckIIDArray(in PRUint32 count,
# [array, size_is(count)] in nsIIDRef data,
# [retval] out PRBool all_mine);
ret = 1
for i in data:
ret = 0
break
return ret
# void GetIIDArray(out PRUint32 count,
# [array, size_is(count)] out nsIIDRef 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.
# void SumArrays(in PRUint32 count, [array, size_is(count)]in array1, [array, size_is(count)]in array2, [retval]result);
print "SumArrays - not expecting different lengths!"
result = 0
for i in array1:
for i in array2:
return result
# Test our count param can be shared as an "out" param.
# 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
# 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.
# 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.
# void CopyAndDoubleArray(inout PRUint32 count, [array, size_is(count)]in array1, [array, size_is(count)]out 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 array1, [array, size_is(count)]inout array2);
if array2 is not None:
return rc
# Test nsIVariant support
for v in invar[1:]:
invar_use += v
else:
for v in inresult[1:]:
inresult_use += v
else:
if inresult_use is None and invar_use is None:
return None
return inresult_use + invar_use
return invar
return None
for v in variants[1:]:
result += v
return result
# Some tests for the "new" (Feb-2001) DOMString type.
# Result: DOMString &
if length == -1:
return None
return "P" * length
# Result: DOMString &
if length == -1:
return None
return "y" * length
# Result: uint32
# In: param0: DOMString &
if param0 is None: return -1
# Result: uint32
# In: param0: DOMString &
if param0 is None: return -1
# Result: uint32
# In: param0: DOMString *
if param0 is None: return -1
# Result: void - None
# In: param0: DOMString &
# In: param1: DOMString &
# Out: DOMString &
# Result: DOMString &
return self.domstring_value
# Result: void - None
# In: param0: DOMString &
# Result: DOMString &
return self.domstring_value