Port PyUno to support Python 3
This commit is contained in:
committed by
Michael Meeks
parent
7cf799064f
commit
a09ce46818
@@ -1,9 +1,9 @@
|
|||||||
import uno
|
# -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||||
|
|
||||||
|
import uno
|
||||||
from com.sun.star.sdb.CommandType import COMMAND
|
from com.sun.star.sdb.CommandType import COMMAND
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
connectionString = "socket,host=localhost,port=2002"
|
connectionString = "socket,host=localhost,port=2002"
|
||||||
|
|
||||||
url = "uno:" + connectionString + ";urp;StarOffice.ComponentContext"
|
url = "uno:" + connectionString + ";urp;StarOffice.ComponentContext"
|
||||||
@@ -22,14 +22,15 @@ def main():
|
|||||||
|
|
||||||
rowset.execute();
|
rowset.execute();
|
||||||
|
|
||||||
print "Identifier\tAuthor"
|
print("Identifier\tAuthor")
|
||||||
|
|
||||||
id = rowset.findColumn("IDENTIFIER")
|
id = rowset.findColumn("IDENTIFIER")
|
||||||
author = rowset.findColumn("AUTHOR")
|
author = rowset.findColumn("AUTHOR")
|
||||||
while rowset.next():
|
while rowset.next():
|
||||||
print rowset.getString( id ) + "\t" + repr( rowset.getString( author ) )
|
print(rowset.getString(id) + "\t" + repr(rowset.getString(author)))
|
||||||
|
|
||||||
|
|
||||||
rowset.dispose();
|
rowset.dispose();
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
# vim:set shiftwidth=4 softtabstop=4 expandtab:
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
# -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||||
|
|
||||||
import uno
|
import uno
|
||||||
import unohelper
|
import unohelper
|
||||||
|
|
||||||
@@ -32,9 +34,10 @@ class HelloWorldJob( unohelper.Base, XJobExecutor ):
|
|||||||
# pythonloader looks for a static g_ImplementationHelper variable
|
# pythonloader looks for a static g_ImplementationHelper variable
|
||||||
g_ImplementationHelper = unohelper.ImplementationHelper()
|
g_ImplementationHelper = unohelper.ImplementationHelper()
|
||||||
|
|
||||||
#
|
|
||||||
g_ImplementationHelper.addImplementation( \
|
g_ImplementationHelper.addImplementation( \
|
||||||
HelloWorldJob, # UNO object class
|
HelloWorldJob, # UNO object class
|
||||||
"org.openoffice.comp.pyuno.demo.HelloWorld", # implemenation name
|
"org.openoffice.comp.pyuno.demo.HelloWorld", # implemenation name
|
||||||
("com.sun.star.task.Job",),) # list of implemented services
|
("com.sun.star.task.Job",),) # list of implemented services
|
||||||
# (the only service)
|
# (the only service)
|
||||||
|
|
||||||
|
# vim:set shiftwidth=4 softtabstop=4 expandtab:
|
||||||
|
@@ -6,7 +6,6 @@ PRJ=..
|
|||||||
|
|
||||||
ROOT=$(MISC)$/pyuno-doc
|
ROOT=$(MISC)$/pyuno-doc
|
||||||
|
|
||||||
|
|
||||||
FILES=\
|
FILES=\
|
||||||
$(ROOT)$/python-bridge.html \
|
$(ROOT)$/python-bridge.html \
|
||||||
$(ROOT)$/customized_setup.png \
|
$(ROOT)$/customized_setup.png \
|
||||||
@@ -22,7 +21,6 @@ FILES=\
|
|||||||
$(ROOT)$/samples$/hello_world_pyuno.zip
|
$(ROOT)$/samples$/hello_world_pyuno.zip
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$(MISC)$/pyuno-doc.zip : dirs $(FILES)
|
$(MISC)$/pyuno-doc.zip : dirs $(FILES)
|
||||||
-rm -f $@
|
-rm -f $@
|
||||||
cd $(MISC) && zip -r pyuno-doc.zip pyuno-doc
|
cd $(MISC) && zip -r pyuno-doc.zip pyuno-doc
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
# -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||||
|
|
||||||
import getopt,sys
|
import getopt,sys
|
||||||
import uno
|
import uno
|
||||||
from unohelper import Base,systemPathToFileUrl, absolutize
|
from unohelper import Base,systemPathToFileUrl, absolutize
|
||||||
@@ -21,7 +23,6 @@ class OutputStream( Base, XOutputStream ):
|
|||||||
def flush(self):
|
def flush(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
retVal = 0
|
retVal = 0
|
||||||
doc = None
|
doc = None
|
||||||
@@ -40,7 +41,7 @@ def main():
|
|||||||
if o == "--html":
|
if o == "--html":
|
||||||
filterName = "HTML (StarWriter)"
|
filterName = "HTML (StarWriter)"
|
||||||
|
|
||||||
print filterName
|
print(filterName)
|
||||||
if not len(args):
|
if not len(args):
|
||||||
usage()
|
usage()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
@@ -66,22 +67,22 @@ def main():
|
|||||||
doc = desktop.loadComponentFromURL(fileUrl , "_blank", 0, inProps)
|
doc = desktop.loadComponentFromURL(fileUrl , "_blank", 0, inProps)
|
||||||
|
|
||||||
if not doc:
|
if not doc:
|
||||||
raise UnoException( "Couldn't open stream for unknown reason", None )
|
raise UnoException("Could not open stream for unknown reason", None)
|
||||||
|
|
||||||
doc.storeToURL("private:stream", outProps)
|
doc.storeToURL("private:stream", outProps)
|
||||||
except IOException, e:
|
except IOException as e:
|
||||||
sys.stderr.write("Error during conversion: " + e.Message + "\n")
|
sys.stderr.write("Error during conversion: " + e.Message + "\n")
|
||||||
retVal = 1
|
retVal = 1
|
||||||
except UnoException, e:
|
except UnoException as e:
|
||||||
sys.stderr.write("Error (" + repr(e.__class__) + ") during conversion: " + e.Message + "\n")
|
sys.stderr.write("Error (" + repr(e.__class__) + ") during conversion: " + e.Message + "\n")
|
||||||
retVal = 1
|
retVal = 1
|
||||||
if doc:
|
if doc:
|
||||||
doc.dispose()
|
doc.dispose()
|
||||||
|
|
||||||
except UnoException, e:
|
except UnoException as e:
|
||||||
sys.stderr.write("Error (" + repr(e.__class__) + "): " + e.Message + "\n")
|
sys.stderr.write("Error (" + repr(e.__class__) + "): " + e.Message + "\n")
|
||||||
retVal = 1
|
retVal = 1
|
||||||
except getopt.GetoptError,e:
|
except getopt.GetoptError as e:
|
||||||
sys.stderr.write(str(e) + "\n")
|
sys.stderr.write(str(e) + "\n")
|
||||||
usage()
|
usage()
|
||||||
retVal = 1
|
retVal = 1
|
||||||
@@ -107,3 +108,5 @@ def usage():
|
|||||||
)
|
)
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
# vim:set shiftwidth=4 softtabstop=4 expandtab:
|
||||||
|
@@ -28,3 +28,5 @@ setenv LD_LIBRARY_PATH $OOOHOME/program:$LD_LIBRARY_PATH
|
|||||||
if( $?PYTHONHOME ) then
|
if( $?PYTHONHOME ) then
|
||||||
setenv PATH $PYTHONHOME/bin:$PATH
|
setenv PATH $PYTHONHOME/bin:$PATH
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# vim:set shiftwidth=4 softtabstop=4 expandtab:
|
||||||
|
@@ -1,8 +1,10 @@
|
|||||||
|
# -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||||
|
|
||||||
# bootstrap uno component context
|
# bootstrap uno component context
|
||||||
import uno
|
import uno
|
||||||
import unohelper
|
import unohelper
|
||||||
|
|
||||||
|
from com.sun.star.lang import IllegalArgumentException
|
||||||
|
|
||||||
# a UNO struct later needed to create a document
|
# a UNO struct later needed to create a document
|
||||||
from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK
|
from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK
|
||||||
@@ -46,10 +48,10 @@ table.initialize( 4,4)
|
|||||||
text.insertTextContent( cursor, table, 0 )
|
text.insertTextContent( cursor, table, 0 )
|
||||||
rows = table.Rows
|
rows = table.Rows
|
||||||
|
|
||||||
table.setPropertyValue( "BackTransparent", uno.Bool(0) )
|
table.setPropertyValue( "BackTransparent", False )
|
||||||
table.setPropertyValue( "BackColor", 13421823 )
|
table.setPropertyValue( "BackColor", 13421823 )
|
||||||
row = rows.getByIndex(0)
|
row = rows.getByIndex(0)
|
||||||
row.setPropertyValue( "BackTransparent", uno.Bool(0) )
|
row.setPropertyValue( "BackTransparent", False )
|
||||||
row.setPropertyValue( "BackColor", 6710932 )
|
row.setPropertyValue( "BackColor", 6710932 )
|
||||||
|
|
||||||
textColor = 16777215
|
textColor = 16777215
|
||||||
@@ -79,7 +81,7 @@ table.getCellByName("D4").setFormula("sum <A4:C4>")
|
|||||||
|
|
||||||
|
|
||||||
cursor.setPropertyValue( "CharColor", 255 )
|
cursor.setPropertyValue( "CharColor", 255 )
|
||||||
cursor.setPropertyValue( "CharShadowed", uno.Bool(1) )
|
cursor.setPropertyValue( "CharShadowed", True )
|
||||||
|
|
||||||
text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 )
|
text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 )
|
||||||
text.insertString( cursor, " This is a colored Text - blue with shadow\n" , 0 )
|
text.insertString( cursor, " This is a colored Text - blue with shadow\n" , 0 )
|
||||||
@@ -99,7 +101,8 @@ textInTextFrame.insertString( cursorInTextFrame, "\nWith this second line the he
|
|||||||
text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 )
|
text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 )
|
||||||
|
|
||||||
cursor.setPropertyValue( "CharColor", 65536 )
|
cursor.setPropertyValue( "CharColor", 65536 )
|
||||||
cursor.setPropertyValue( "CharShadowed", uno.Bool(0) )
|
cursor.setPropertyValue( "CharShadowed", False )
|
||||||
|
|
||||||
text.insertString( cursor, " That's all for now !!" , 0 )
|
text.insertString( cursor, " That's all for now!" , 0 )
|
||||||
|
|
||||||
|
# vim:set shiftwidth=4 softtabstop=4 expandtab:
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
# -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||||
|
|
||||||
# just a simple copy of the swriter.py demo, but implemented as a component. The advantage is,
|
# just a simple copy of the swriter.py demo, but implemented as a component. The advantage is,
|
||||||
# that the component may run within the office process which may give a performance improvement.
|
# that the component may run within the office process which may give a performance improvement.
|
||||||
|
|
||||||
@@ -26,7 +28,6 @@ class SWriterComp(XMain,unohelper.Base):
|
|||||||
|
|
||||||
# implementation for XMain.run( [in] sequence< any > )
|
# implementation for XMain.run( [in] sequence< any > )
|
||||||
def run( self,args ):
|
def run( self,args ):
|
||||||
|
|
||||||
ctx = self.ctx
|
ctx = self.ctx
|
||||||
smgr = ctx.ServiceManager
|
smgr = ctx.ServiceManager
|
||||||
desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",ctx)
|
desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",ctx)
|
||||||
@@ -102,11 +103,12 @@ class SWriterComp(XMain,unohelper.Base):
|
|||||||
cursor.setPropertyValue( "CharColor", 65536 )
|
cursor.setPropertyValue( "CharColor", 65536 )
|
||||||
cursor.setPropertyValue( "CharShadowed", uno.Bool(0) )
|
cursor.setPropertyValue( "CharShadowed", uno.Bool(0) )
|
||||||
|
|
||||||
text.insertString( cursor, " That's all for now !!" , 0 )
|
text.insertString( cursor, " That's all for now!" , 0 )
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
# pythonloader looks for a static g_ImplementationHelper variable
|
# pythonloader looks for a static g_ImplementationHelper variable
|
||||||
g_ImplementationHelper = unohelper.ImplementationHelper()
|
g_ImplementationHelper = unohelper.ImplementationHelper()
|
||||||
g_ImplementationHelper.addImplementation( \
|
g_ImplementationHelper.addImplementation( \
|
||||||
SWriterComp,"org.openoffice.comp.pyuno.swriter",("org.openoffice.demo.SWriter",),)
|
SWriterComp,"org.openoffice.comp.pyuno.swriter",("org.openoffice.demo.SWriter",),)
|
||||||
|
|
||||||
|
# vim:set shiftwidth=4 softtabstop=4 expandtab:
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
# instantiating
|
# -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||||
|
|
||||||
import uno
|
import uno
|
||||||
|
|
||||||
localContext = uno.getComponentContext()
|
localContext = uno.getComponentContext()
|
||||||
@@ -11,3 +12,4 @@ pyComp = remoteSmgr.createInstanceWithContext( "org.openoffice.demo.SWriter" , r
|
|||||||
|
|
||||||
pyComp.run( (), )
|
pyComp.run( (), )
|
||||||
|
|
||||||
|
# vim:set shiftwidth=4 softtabstop=4 expandtab:
|
||||||
|
@@ -45,8 +45,12 @@
|
|||||||
preconditions: python has been initialized before and
|
preconditions: python has been initialized before and
|
||||||
the global interpreter lock is held
|
the global interpreter lock is held
|
||||||
*/
|
*/
|
||||||
extern "C" PY_DLLEXPORT void SAL_CALL initpyuno();
|
extern "C" PY_DLLEXPORT
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
PyObject* SAL_CALL PyInit_pyuno();
|
||||||
|
#else
|
||||||
|
void SAL_CALL initpyuno();
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace pyuno
|
namespace pyuno
|
||||||
{
|
{
|
||||||
|
@@ -49,16 +49,16 @@ g_loadedComponents = {}
|
|||||||
def checkForPythonPathBesideComponent( url ):
|
def checkForPythonPathBesideComponent( url ):
|
||||||
path = unohelper.fileUrlToSystemPath( url+"/pythonpath.zip" );
|
path = unohelper.fileUrlToSystemPath( url+"/pythonpath.zip" );
|
||||||
if DEBUG == 1:
|
if DEBUG == 1:
|
||||||
print "checking for existence of " + encfile( path )
|
print("checking for existence of " + encfile( path ))
|
||||||
if 1 == os.access( encfile( path ), os.F_OK) and not path in sys.path:
|
if 1 == os.access( encfile( path ), os.F_OK) and not path in sys.path:
|
||||||
if DEBUG == 1:
|
if DEBUG == 1:
|
||||||
print "adding " + encfile( path ) + " to sys.path"
|
print("adding " + encfile( path ) + " to sys.path")
|
||||||
sys.path.append( path )
|
sys.path.append( path )
|
||||||
|
|
||||||
path = unohelper.fileUrlToSystemPath( url+"/pythonpath" );
|
path = unohelper.fileUrlToSystemPath( url+"/pythonpath" );
|
||||||
if 1 == os.access( encfile( path ), os.F_OK) and not path in sys.path:
|
if 1 == os.access( encfile( path ), os.F_OK) and not path in sys.path:
|
||||||
if DEBUG == 1:
|
if DEBUG == 1:
|
||||||
print "adding " + encfile( path ) + " to sys.path"
|
print("adding " + encfile( path ) + " to sys.path")
|
||||||
sys.path.append( path )
|
sys.path.append( path )
|
||||||
|
|
||||||
def encfile(uni):
|
def encfile(uni):
|
||||||
@@ -67,12 +67,12 @@ def encfile(uni):
|
|||||||
class Loader( XImplementationLoader, XServiceInfo, unohelper.Base ):
|
class Loader( XImplementationLoader, XServiceInfo, unohelper.Base ):
|
||||||
def __init__(self, ctx ):
|
def __init__(self, ctx ):
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print "pythonloader.Loader ctor"
|
print("pythonloader.Loader ctor")
|
||||||
self.ctx = ctx
|
self.ctx = ctx
|
||||||
|
|
||||||
def getModuleFromUrl( self, url ):
|
def getModuleFromUrl( self, url ):
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print "pythonloader: interpreting url " +url
|
print("pythonloader: interpreting url " + url)
|
||||||
protocol, dependent = splitUrl( url )
|
protocol, dependent = splitUrl( url )
|
||||||
if "vnd.sun.star.expand" == protocol:
|
if "vnd.sun.star.expand" == protocol:
|
||||||
exp = self.ctx.getValueByName( "/singletons/com.sun.star.util.theMacroExpander" )
|
exp = self.ctx.getValueByName( "/singletons/com.sun.star.util.theMacroExpander" )
|
||||||
@@ -80,7 +80,7 @@ class Loader( XImplementationLoader, XServiceInfo, unohelper.Base ):
|
|||||||
protocol,dependent = splitUrl( url )
|
protocol,dependent = splitUrl( url )
|
||||||
|
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print "pythonloader: after expansion " +protocol +":" + dependent
|
print("pythonloader: after expansion " + protocol + ":" + dependent)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if "file" == protocol:
|
if "file" == protocol:
|
||||||
@@ -104,7 +104,7 @@ class Loader( XImplementationLoader, XServiceInfo, unohelper.Base ):
|
|||||||
|
|
||||||
# compile and execute the module
|
# compile and execute the module
|
||||||
codeobject = compile( src, encfile(filename), "exec" )
|
codeobject = compile( src, encfile(filename), "exec" )
|
||||||
exec codeobject in mod.__dict__
|
exec(codeobject, mod.__dict__)
|
||||||
mod.__file__ = encfile(filename)
|
mod.__file__ = encfile(filename)
|
||||||
g_loadedComponents[url] = mod
|
g_loadedComponents[url] = mod
|
||||||
return mod
|
return mod
|
||||||
@@ -113,13 +113,13 @@ class Loader( XImplementationLoader, XServiceInfo, unohelper.Base ):
|
|||||||
else:
|
else:
|
||||||
raise RuntimeException( "PythonLoader: Unknown protocol " +
|
raise RuntimeException( "PythonLoader: Unknown protocol " +
|
||||||
protocol + " in url " +url, self )
|
protocol + " in url " +url, self )
|
||||||
except ImportError, e:
|
except ImportError as e:
|
||||||
raise RuntimeException( "Couldn't load " + url + " for reason " + str(e), None )
|
raise RuntimeException( "Couldn't load " + url + " for reason " + str(e), None )
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def activate( self, implementationName, dummy, locationUrl, regKey ):
|
def activate( self, implementationName, dummy, locationUrl, regKey ):
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print "pythonloader.Loader.activate"
|
print("pythonloader.Loader.activate")
|
||||||
|
|
||||||
mod = self.getModuleFromUrl( locationUrl )
|
mod = self.getModuleFromUrl( locationUrl )
|
||||||
implHelper = mod.__dict__.get( "g_ImplementationHelper" , None )
|
implHelper = mod.__dict__.get( "g_ImplementationHelper" , None )
|
||||||
@@ -130,7 +130,7 @@ class Loader( XImplementationLoader, XServiceInfo, unohelper.Base ):
|
|||||||
|
|
||||||
def writeRegistryInfo( self, regKey, dummy, locationUrl ):
|
def writeRegistryInfo( self, regKey, dummy, locationUrl ):
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
print "pythonloader.Loader.writeRegistryInfo"
|
print( "pythonloader.Loader.writeRegistryInfo" )
|
||||||
|
|
||||||
mod = self.getModuleFromUrl( locationUrl )
|
mod = self.getModuleFromUrl( locationUrl )
|
||||||
implHelper = mod.__dict__.get( "g_ImplementationHelper" , None )
|
implHelper = mod.__dict__.get( "g_ImplementationHelper" , None )
|
||||||
@@ -147,5 +147,3 @@ class Loader( XImplementationLoader, XServiceInfo, unohelper.Base ):
|
|||||||
|
|
||||||
def getSupportedServiceNames( self ):
|
def getSupportedServiceNames( self ):
|
||||||
return g_supportedServices
|
return g_supportedServices
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
/*nd '!=' comparisions are defined"126G -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
*
|
*
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
@@ -118,8 +118,26 @@ static void setPythonHome ( const OUString & pythonHome )
|
|||||||
OUString systemPythonHome;
|
OUString systemPythonHome;
|
||||||
osl_getSystemPathFromFileURL( pythonHome.pData, &(systemPythonHome.pData) );
|
osl_getSystemPathFromFileURL( pythonHome.pData, &(systemPythonHome.pData) );
|
||||||
OString o = rtl::OUStringToOString( systemPythonHome, osl_getThreadTextEncoding() );
|
OString o = rtl::OUStringToOString( systemPythonHome, osl_getThreadTextEncoding() );
|
||||||
rtl_string_acquire(o.pData); // leak this string (thats the api!)
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
// static because Py_SetPythonHome just copies the "wide" pointer
|
||||||
|
// PATH_MAX is defined in Python.h
|
||||||
|
static wchar_t wide[PATH_MAX + 1];
|
||||||
|
size_t len = mbstowcs(wide, o.pData->buffer, PATH_MAX + 1);
|
||||||
|
if(len == (size_t)-1)
|
||||||
|
{
|
||||||
|
PyErr_SetString(PyExc_SystemError, "invalid multibyte sequence in python home path");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(len == PATH_MAX + 1)
|
||||||
|
{
|
||||||
|
PyErr_SetString(PyExc_SystemError, "python home path is too long");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Py_SetPythonHome(wide);
|
||||||
|
#else
|
||||||
|
rtl_string_acquire(o.pData); // increase reference count
|
||||||
Py_SetPythonHome(o.pData->buffer);
|
Py_SetPythonHome(o.pData->buffer);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void prependPythonPath( const OUString & pythonPathBootstrap )
|
static void prependPythonPath( const OUString & pythonPathBootstrap )
|
||||||
@@ -178,7 +196,11 @@ Reference< XInterface > CreateInstance( const Reference< XComponentContext > & c
|
|||||||
|
|
||||||
if( pythonPath.getLength() )
|
if( pythonPath.getLength() )
|
||||||
prependPythonPath( pythonPath );
|
prependPythonPath( pythonPath );
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
PyImport_AppendInittab( "pyuno", PyInit_pyuno );
|
||||||
|
#else
|
||||||
|
PyImport_AppendInittab( "pyuno", initpyuno );
|
||||||
|
#endif
|
||||||
// initialize python
|
// initialize python
|
||||||
Py_Initialize();
|
Py_Initialize();
|
||||||
PyEval_InitThreads();
|
PyEval_InitThreads();
|
||||||
|
@@ -36,6 +36,7 @@ LINKFLAGSDEFS = # do not fail with missing symbols
|
|||||||
|
|
||||||
.INCLUDE : settings.mk
|
.INCLUDE : settings.mk
|
||||||
.IF "$(L10N_framework)"==""
|
.IF "$(L10N_framework)"==""
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
.IF "$(OS)$(COMEX)" == "SOLARIS4"
|
.IF "$(OS)$(COMEX)" == "SOLARIS4"
|
||||||
@@ -49,9 +50,6 @@ EXTRA_FRAMEWORK_FLAG=-framework Python
|
|||||||
.ENDIF # .IF "$(EXTRA_CFLAGS)"!=""
|
.ENDIF # .IF "$(EXTRA_CFLAGS)"!=""
|
||||||
|
|
||||||
.IF "$(GUI)" == "UNX"
|
.IF "$(GUI)" == "UNX"
|
||||||
# python expects modules without the lib prefix
|
|
||||||
# pyuno.so even on Mac OS X, because it is a python module
|
|
||||||
PYUNO_MODULE=$(DLLDEST)$/pyuno.so
|
|
||||||
PYUNORC=pyunorc
|
PYUNORC=pyunorc
|
||||||
.ELSE
|
.ELSE
|
||||||
.INCLUDE : pyversion.mk
|
.INCLUDE : pyversion.mk
|
||||||
@@ -85,7 +83,6 @@ NOOPTFILES= \
|
|||||||
$(SLO)$/pyuno_module.obj
|
$(SLO)$/pyuno_module.obj
|
||||||
.ENDIF # "$(COM)"=="GCC"
|
.ENDIF # "$(COM)"=="GCC"
|
||||||
|
|
||||||
|
|
||||||
SHL1STDLIBS= \
|
SHL1STDLIBS= \
|
||||||
$(CPPULIB) \
|
$(CPPULIB) \
|
||||||
$(CPPUHELPERLIB) \
|
$(CPPUHELPERLIB) \
|
||||||
@@ -110,7 +107,6 @@ DEFLIB1NAME=$(TARGET)
|
|||||||
ALLTAR : \
|
ALLTAR : \
|
||||||
$(DLLDEST)$/uno.py \
|
$(DLLDEST)$/uno.py \
|
||||||
$(DLLDEST)$/unohelper.py \
|
$(DLLDEST)$/unohelper.py \
|
||||||
$(PYUNO_MODULE) \
|
|
||||||
$(MISC)$/$(PYUNORC) \
|
$(MISC)$/$(PYUNORC) \
|
||||||
$(LB)$/lib$(TARGET).a
|
$(LB)$/lib$(TARGET).a
|
||||||
|
|
||||||
@@ -120,8 +116,8 @@ $(LB)$/lib$(TARGET).a: $(MISC)$/$(TARGET).def
|
|||||||
ALLTAR : \
|
ALLTAR : \
|
||||||
$(DLLDEST)$/uno.py \
|
$(DLLDEST)$/uno.py \
|
||||||
$(DLLDEST)$/unohelper.py \
|
$(DLLDEST)$/unohelper.py \
|
||||||
$(PYUNO_MODULE) \
|
$(MISC)$/$(PYUNORC) \
|
||||||
$(MISC)$/$(PYUNORC)
|
$(LB)$/$(TARGET)$(DLLPOST)
|
||||||
.ENDIF
|
.ENDIF
|
||||||
.ENDIF
|
.ENDIF
|
||||||
|
|
||||||
@@ -130,31 +126,6 @@ ALLTAR : \
|
|||||||
$(DLLDEST)$/%.py: %.py
|
$(DLLDEST)$/%.py: %.py
|
||||||
cp $? $@
|
cp $? $@
|
||||||
|
|
||||||
|
|
||||||
.IF "$(GUI)" == "UNX"
|
|
||||||
$(PYUNO_MODULE) : $(SLO)$/pyuno_dlopenwrapper.obj
|
|
||||||
.IF "$(OS)" == "LINUX"
|
|
||||||
@echo $(LINK) $(LINKFLAGS) $(LINKFLAGSRUNPATH_OOO) $(LINKFLAGSSHLCUI) -ldl -o $@ $(SLO)$/pyuno_dlopenwrapper.o > $(MISC)$/$(@:b).cmd
|
|
||||||
.ELIF "$(OS)" == "SOLARIS"
|
|
||||||
@echo ld -G -ldl -o $@ $(SLO)$/pyuno_dlopenwrapper.o > $(MISC)$/$(@:b).cmd
|
|
||||||
.ELIF "$(OS)" == "FREEBSD"
|
|
||||||
@echo ld -shared -o $@ $(SLO)$/pyuno_dlopenwrapper.o > $(MISC)$/$(@:b).cmd
|
|
||||||
.ELIF "$(OS)" == "NETBSD"
|
|
||||||
@echo $(LINK) $(LINKFLAGSSHLCUI) -o $@ $(SLO)$/pyuno_dlopenwrapper.o > $(MISC)$/$(@:b).cmd
|
|
||||||
.ELIF "$(OS)" == "OPENBSD"
|
|
||||||
@echo ld -shared -o $@ $(SLO)$/pyuno_dlopenwrapper.o > $(MISC)$/$(@:b).cmd
|
|
||||||
.ELIF "$(OS)" == "DRAGONFLY"
|
|
||||||
@echo ld -shared -o $@ $(SLO)$/pyuno_dlopenwrapper.o > $(MISC)$/$(@:b).cmd
|
|
||||||
.ELIF "$(OS)" == "MACOSX"
|
|
||||||
@echo $(CC) -bundle -ldl -o $@ $(SLO)$/pyuno_dlopenwrapper.o $(EXTRA_LINKFLAGS) $(EXTRA_FRAMEWORK_FLAG) > $(MISC)$/$(@:b).cmd
|
|
||||||
.ELSE
|
|
||||||
@echo $(LINK) $(LINKFLAGSSHLCUI) -o $@ $(SLO)$/pyuno_dlopenwrapper.o > $(MISC)$/$(@:b).cmd
|
|
||||||
.ENDIF
|
|
||||||
cat $(MISC)$/$(@:b).cmd
|
|
||||||
@+source $(MISC)$/$(@:b).cmd
|
|
||||||
.ENDIF
|
|
||||||
|
|
||||||
|
|
||||||
$(MISC)$/$(PYUNORC) : pyuno
|
$(MISC)$/$(PYUNORC) : pyuno
|
||||||
-rm -f $@
|
-rm -f $@
|
||||||
cat pyuno > $@
|
cat pyuno > $@
|
||||||
@@ -162,5 +133,12 @@ $(MISC)$/$(PYUNORC) : pyuno
|
|||||||
$(MISC)$/pyuno.flt : pyuno.flt
|
$(MISC)$/pyuno.flt : pyuno.flt
|
||||||
-rm -f $@
|
-rm -f $@
|
||||||
cat $? > $@
|
cat $? > $@
|
||||||
|
|
||||||
|
# python does not accept the "lib" prefix in the module library
|
||||||
|
$(LB)$/$(TARGET)$(DLLPOST) : $(LB)$/$(DLLPRE)$(TARGET)$(DLLPOST)
|
||||||
|
-rm -f $@
|
||||||
|
ln -s $? $@
|
||||||
|
|
||||||
.ENDIF # L10N_framework
|
.ENDIF # L10N_framework
|
||||||
|
|
||||||
|
# vim:set shiftwidth=4 softtabstop=4 expandtab:
|
||||||
|
@@ -135,13 +135,6 @@ OUString val2str( const void * pVal, typelib_TypeDescriptionReference * pTypeRef
|
|||||||
}
|
}
|
||||||
case typelib_TypeClass_UNION:
|
case typelib_TypeClass_UNION:
|
||||||
{
|
{
|
||||||
// typelib_TypeDescription * pTypeDescr = 0;
|
|
||||||
// TYPELIB_DANGER_GET( &pTypeDescr, pTypeRef );
|
|
||||||
// buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("{ ") );
|
|
||||||
// buf.append( val2str( (char *)pVal + ((typelib_UnionTypeDescription *)pTypeDescr)->nValueOffset,
|
|
||||||
// union_getSetType( pVal, pTypeDescr ) ) );
|
|
||||||
// buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" }") );
|
|
||||||
// TYPELIB_DANGER_RELEASE( pTypeDescr );
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case typelib_TypeClass_STRUCT:
|
case typelib_TypeClass_STRUCT:
|
||||||
@@ -600,11 +593,17 @@ int PyUNO_setattr (PyObject* self, char* name, PyObject* value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ensure object identity and struct equality
|
// ensure object identity and struct equality
|
||||||
static int PyUNO_cmp( PyObject *self, PyObject *that )
|
static PyObject* PyUNO_cmp( PyObject *self, PyObject *that, int op )
|
||||||
{
|
{
|
||||||
if( self == that )
|
if(op != Py_EQ && op != Py_NE)
|
||||||
|
{
|
||||||
|
PyErr_SetString(PyExc_TypeError, "only '==' and '!=' comparisions are defined");
|
||||||
return 0;
|
return 0;
|
||||||
int retDefault = self > that ? 1 : -1;
|
}
|
||||||
|
if( self == that )
|
||||||
|
{
|
||||||
|
return (op == Py_EQ ? Py_True : Py_False);
|
||||||
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Runtime runtime;
|
Runtime runtime;
|
||||||
@@ -624,13 +623,16 @@ static int PyUNO_cmp( PyObject *self, PyObject *that )
|
|||||||
Reference< XMaterialHolder > xMe( me->members->xInvocation,UNO_QUERY);
|
Reference< XMaterialHolder > xMe( me->members->xInvocation,UNO_QUERY);
|
||||||
Reference< XMaterialHolder > xOther( other->members->xInvocation,UNO_QUERY );
|
Reference< XMaterialHolder > xOther( other->members->xInvocation,UNO_QUERY );
|
||||||
if( xMe->getMaterial() == xOther->getMaterial() )
|
if( xMe->getMaterial() == xOther->getMaterial() )
|
||||||
return 0;
|
{
|
||||||
|
return (op == Py_EQ ? Py_True : Py_False);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if( tcMe == com::sun::star::uno::TypeClass_INTERFACE )
|
else if( tcMe == com::sun::star::uno::TypeClass_INTERFACE )
|
||||||
{
|
{
|
||||||
if( me->members->wrappedObject == other->members->wrappedObject )
|
if( me->members->wrappedObject == other->members->wrappedObject )
|
||||||
// if( me->members->xInvocation == other->members->xInvocation )
|
{
|
||||||
return 0;
|
return (op == Py_EQ ? Py_True : Py_False);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -639,13 +641,12 @@ static int PyUNO_cmp( PyObject *self, PyObject *that )
|
|||||||
{
|
{
|
||||||
raisePyExceptionWithAny( makeAny( e ) );
|
raisePyExceptionWithAny( makeAny( e ) );
|
||||||
}
|
}
|
||||||
return retDefault;
|
return Py_False;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyTypeObject PyUNOType =
|
static PyTypeObject PyUNOType =
|
||||||
{
|
{
|
||||||
PyObject_HEAD_INIT (&PyType_Type)
|
PyVarObject_HEAD_INIT( &PyType_Type, 0 )
|
||||||
0,
|
|
||||||
const_cast< char * >("pyuno"),
|
const_cast< char * >("pyuno"),
|
||||||
sizeof (PyUNO),
|
sizeof (PyUNO),
|
||||||
0,
|
0,
|
||||||
@@ -653,7 +654,7 @@ static PyTypeObject PyUNOType =
|
|||||||
(printfunc) 0,
|
(printfunc) 0,
|
||||||
(getattrfunc) PyUNO_getattr,
|
(getattrfunc) PyUNO_getattr,
|
||||||
(setattrfunc) PyUNO_setattr,
|
(setattrfunc) PyUNO_setattr,
|
||||||
(cmpfunc) PyUNO_cmp,
|
0,
|
||||||
(reprfunc) PyUNO_repr,
|
(reprfunc) PyUNO_repr,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
@@ -668,7 +669,7 @@ static PyTypeObject PyUNOType =
|
|||||||
NULL,
|
NULL,
|
||||||
(traverseproc)0,
|
(traverseproc)0,
|
||||||
(inquiry)0,
|
(inquiry)0,
|
||||||
(richcmpfunc)0,
|
(richcmpfunc) PyUNO_cmp,
|
||||||
0,
|
0,
|
||||||
(getiterfunc)0,
|
(getiterfunc)0,
|
||||||
(iternextfunc)0,
|
(iternextfunc)0,
|
||||||
|
@@ -196,8 +196,7 @@ PyObject* PyUNO_callable_call (PyObject* self, PyObject* args, PyObject*)
|
|||||||
|
|
||||||
static PyTypeObject PyUNO_callable_Type =
|
static PyTypeObject PyUNO_callable_Type =
|
||||||
{
|
{
|
||||||
PyObject_HEAD_INIT (&PyType_Type)
|
PyVarObject_HEAD_INIT( &PyType_Type, 0 )
|
||||||
0,
|
|
||||||
const_cast< char * >("PyUNO_callable"),
|
const_cast< char * >("PyUNO_callable"),
|
||||||
sizeof (PyUNO_callable),
|
sizeof (PyUNO_callable),
|
||||||
0,
|
0,
|
||||||
@@ -205,7 +204,7 @@ static PyTypeObject PyUNO_callable_Type =
|
|||||||
(printfunc) 0,
|
(printfunc) 0,
|
||||||
(getattrfunc) 0,
|
(getattrfunc) 0,
|
||||||
(setattrfunc) 0,
|
(setattrfunc) 0,
|
||||||
(cmpfunc) 0,
|
0,
|
||||||
(reprfunc) 0,
|
(reprfunc) 0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
|
@@ -167,7 +167,7 @@ static PyRef createClass( const OUString & name, const Runtime &runtime )
|
|||||||
PyTuple_SetItem( args.get(), 2, PyDict_New() );
|
PyTuple_SetItem( args.get(), 2, PyDict_New() );
|
||||||
|
|
||||||
PyRef ret(
|
PyRef ret(
|
||||||
PyObject_CallObject(reinterpret_cast<PyObject *>(&PyClass_Type) , args.get()),
|
PyObject_CallObject(reinterpret_cast<PyObject *>(&PyType_Type) , args.get()),
|
||||||
SAL_NO_ACQUIRE );
|
SAL_NO_ACQUIRE );
|
||||||
|
|
||||||
// now overwrite ctor and attrib functions
|
// now overwrite ctor and attrib functions
|
||||||
|
@@ -28,6 +28,8 @@
|
|||||||
#ifndef _PYUNO_IMPL_
|
#ifndef _PYUNO_IMPL_
|
||||||
#define _PYUNO_IMPL_
|
#define _PYUNO_IMPL_
|
||||||
|
|
||||||
|
#include <Python.h>
|
||||||
|
|
||||||
#include <pyuno/pyuno.hxx>
|
#include <pyuno/pyuno.hxx>
|
||||||
|
|
||||||
#include <boost/unordered_map.hpp>
|
#include <boost/unordered_map.hpp>
|
||||||
@@ -48,6 +50,49 @@
|
|||||||
#include <cppuhelper/implbase2.hxx>
|
#include <cppuhelper/implbase2.hxx>
|
||||||
#include <cppuhelper/weakref.hxx>
|
#include <cppuhelper/weakref.hxx>
|
||||||
|
|
||||||
|
// In Python 3, the PyString_* functions have been replaced by PyBytes_*
|
||||||
|
// and PyUnicode_* functions.
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
inline char* PyString_AsString(PyObject *object)
|
||||||
|
{
|
||||||
|
// check whether object is already of type "PyBytes"
|
||||||
|
if(PyBytes_Check(object))
|
||||||
|
{
|
||||||
|
return PyBytes_AsString(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
// object is not encoded yet, so encode it to utf-8
|
||||||
|
PyObject *pystring;
|
||||||
|
pystring = PyUnicode_AsUTF8String(object);
|
||||||
|
if(!pystring)
|
||||||
|
{
|
||||||
|
PyErr_SetString(PyExc_ValueError, "cannot utf-8 decode string");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return PyBytes_AsString(pystring);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline PyObject* PyString_FromString(const char *string)
|
||||||
|
{
|
||||||
|
return PyUnicode_FromString(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline int PyString_Check(PyObject *object)
|
||||||
|
{
|
||||||
|
return PyBytes_Check(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Py_ssize_t PyString_Size(PyObject *object)
|
||||||
|
{
|
||||||
|
return PyBytes_Size(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline PyObject* PyString_FromStringAndSize(const char *string, Py_ssize_t len)
|
||||||
|
{
|
||||||
|
return PyBytes_FromStringAndSize(string, len);
|
||||||
|
}
|
||||||
|
#endif /* PY_MAJOR_VERSION >= 3 */
|
||||||
|
|
||||||
namespace pyuno
|
namespace pyuno
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -142,9 +187,6 @@ com::sun::star::uno::Any PyObjectToAny (PyObject* o)
|
|||||||
void raiseInvocationTargetExceptionWhenNeeded( const Runtime &runtime )
|
void raiseInvocationTargetExceptionWhenNeeded( const Runtime &runtime )
|
||||||
throw ( com::sun::star::reflection::InvocationTargetException );
|
throw ( com::sun::star::reflection::InvocationTargetException );
|
||||||
|
|
||||||
// bool CheckPyObjectTypes (PyObject* o, Sequence<Type> types);
|
|
||||||
// bool CheckPyObjectType (PyObject* o, Type type); //Only check 1 object.
|
|
||||||
|
|
||||||
com::sun::star::uno::TypeClass StringToTypeClass (char* string);
|
com::sun::star::uno::TypeClass StringToTypeClass (char* string);
|
||||||
|
|
||||||
PyRef PyUNO_callable_new (
|
PyRef PyUNO_callable_new (
|
||||||
|
@@ -244,7 +244,6 @@ static PyObject *createUnoStructHelper(PyObject *, PyObject* args )
|
|||||||
{
|
{
|
||||||
Any IdlStruct;
|
Any IdlStruct;
|
||||||
PyRef ret;
|
PyRef ret;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Runtime runtime;
|
Runtime runtime;
|
||||||
@@ -253,7 +252,9 @@ static PyObject *createUnoStructHelper(PyObject *, PyObject* args )
|
|||||||
PyObject *structName = PyTuple_GetItem(args, 0);
|
PyObject *structName = PyTuple_GetItem(args, 0);
|
||||||
PyObject *initializer = PyTuple_GetItem(args, 1);
|
PyObject *initializer = PyTuple_GetItem(args, 1);
|
||||||
|
|
||||||
if( PyString_Check( structName ) )
|
// Perhaps in Python 3, only PyUnicode_Check returns true and
|
||||||
|
// in Python 2, only PyString_Check returns true.
|
||||||
|
if(PyString_Check(structName) || PyUnicode_Check(structName))
|
||||||
{
|
{
|
||||||
if( PyTuple_Check( initializer ) )
|
if( PyTuple_Check( initializer ) )
|
||||||
{
|
{
|
||||||
@@ -491,9 +492,9 @@ static PyObject *isInterface( PyObject *, PyObject *args )
|
|||||||
{
|
{
|
||||||
PyObject *obj = PyTuple_GetItem( args, 0 );
|
PyObject *obj = PyTuple_GetItem( args, 0 );
|
||||||
Runtime r;
|
Runtime r;
|
||||||
return PyInt_FromLong( isInterfaceClass( r, obj ) );
|
return PyLong_FromLong( isInterfaceClass( r, obj ) );
|
||||||
}
|
}
|
||||||
return PyInt_FromLong( 0 );
|
return PyLong_FromLong( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject * generateUuid( PyObject *, PyObject * )
|
static PyObject * generateUuid( PyObject *, PyObject * )
|
||||||
@@ -598,19 +599,20 @@ static PyObject * invoke ( PyObject *, PyObject * args )
|
|||||||
if(PyTuple_Check(args) && PyTuple_Size(args) == 3)
|
if(PyTuple_Check(args) && PyTuple_Size(args) == 3)
|
||||||
{
|
{
|
||||||
PyObject *object = PyTuple_GetItem(args, 0);
|
PyObject *object = PyTuple_GetItem(args, 0);
|
||||||
|
PyObject *item1 = PyTuple_GetItem(args, 1);
|
||||||
if( PyString_Check( PyTuple_GetItem( args, 1 ) ) )
|
if(PyString_Check(item1) || PyUnicode_Check(item1))
|
||||||
{
|
{
|
||||||
const char *name = PyString_AsString( PyTuple_GetItem( args, 1 ) );
|
const char *name = PyString_AsString(item1);
|
||||||
if( PyTuple_Check( PyTuple_GetItem( args , 2 )))
|
PyObject *item2 = PyTuple_GetItem(args, 2);
|
||||||
|
if(PyTuple_Check(item2))
|
||||||
{
|
{
|
||||||
ret = PyUNO_invoke( object, name , PyTuple_GetItem( args, 2 ) );
|
ret = PyUNO_invoke(object, name, item2);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
OStringBuffer buf;
|
OStringBuffer buf;
|
||||||
buf.append("uno.invoke expects a tuple as 3rd argument, got ");
|
buf.append("uno.invoke expects a tuple as 3rd argument, got ");
|
||||||
buf.append( PyString_AsString( PyObject_Str( PyTuple_GetItem( args, 2) ) ) );
|
buf.append(PyString_AsString(PyObject_Str(item2)));
|
||||||
PyErr_SetString(PyExc_RuntimeError, buf.makeStringAndClear());
|
PyErr_SetString(PyExc_RuntimeError, buf.makeStringAndClear());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -618,7 +620,7 @@ static PyObject * invoke ( PyObject *, PyObject * args )
|
|||||||
{
|
{
|
||||||
OStringBuffer buf;
|
OStringBuffer buf;
|
||||||
buf.append("uno.invoke expected a string as 2nd argument, got ");
|
buf.append("uno.invoke expected a string as 2nd argument, got ");
|
||||||
buf.append( PyString_AsString( PyObject_Str( PyTuple_GetItem( args, 1) ) ) );
|
buf.append(PyString_AsString(PyObject_Str(item1)));
|
||||||
PyErr_SetString(PyExc_RuntimeError, buf.makeStringAndClear());
|
PyErr_SetString(PyExc_RuntimeError, buf.makeStringAndClear());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -690,31 +692,52 @@ static PyObject *setCurrentContext( PyObject *, PyObject * args )
|
|||||||
|
|
||||||
struct PyMethodDef PyUNOModule_methods [] =
|
struct PyMethodDef PyUNOModule_methods [] =
|
||||||
{
|
{
|
||||||
{const_cast< char * >("getComponentContext"), getComponentContext, 1, NULL},
|
{const_cast< char * >("getComponentContext"), getComponentContext, METH_VARARGS, NULL},
|
||||||
{const_cast< char * >("_createUnoStructHelper"), createUnoStructHelper, 2, NULL},
|
{const_cast< char * >("_createUnoStructHelper"), createUnoStructHelper, METH_VARARGS | METH_KEYWORDS, NULL},
|
||||||
{const_cast< char * >("getTypeByName"), getTypeByName, 1, NULL},
|
{const_cast< char * >("getTypeByName"), getTypeByName, METH_VARARGS, NULL},
|
||||||
{const_cast< char * >("getConstantByName"), getConstantByName,1, NULL},
|
{const_cast< char * >("getConstantByName"), getConstantByName, METH_VARARGS, NULL},
|
||||||
{const_cast< char * >("getClass"), getClass,1, NULL},
|
{const_cast< char * >("getClass"), getClass, METH_VARARGS, NULL},
|
||||||
{const_cast< char * >("checkEnum"), checkEnum, 1, NULL},
|
{const_cast< char * >("checkEnum"), checkEnum, METH_VARARGS, NULL},
|
||||||
{const_cast< char * >("checkType"), checkType, 1, NULL},
|
{const_cast< char * >("checkType"), checkType, METH_VARARGS, NULL},
|
||||||
{const_cast< char * >("generateUuid"), generateUuid,0, NULL},
|
{const_cast< char * >("generateUuid"), generateUuid, METH_VARARGS, NULL},
|
||||||
{const_cast< char * >("systemPathToFileUrl"),systemPathToFileUrl,1, NULL},
|
{const_cast< char * >("systemPathToFileUrl"), systemPathToFileUrl, METH_VARARGS, NULL},
|
||||||
{const_cast< char * >("fileUrlToSystemPath"),fileUrlToSystemPath,1, NULL},
|
{const_cast< char * >("fileUrlToSystemPath"), fileUrlToSystemPath, METH_VARARGS, NULL},
|
||||||
{const_cast< char * >("absolutize"),absolutize,2, NULL},
|
{const_cast< char * >("absolutize"), absolutize, METH_VARARGS | METH_KEYWORDS, NULL},
|
||||||
{const_cast< char * >("isInterface"),isInterface,1, NULL},
|
{const_cast< char * >("isInterface"), isInterface, METH_VARARGS, NULL},
|
||||||
{const_cast< char * >("invoke"),invoke, 2, NULL},
|
{const_cast< char * >("invoke"), invoke, METH_VARARGS | METH_KEYWORDS, NULL},
|
||||||
{const_cast< char * >("setCurrentContext"),setCurrentContext,1, NULL},
|
{const_cast< char * >("setCurrentContext"), setCurrentContext, METH_VARARGS, NULL},
|
||||||
{const_cast< char * >("getCurrentContext"),getCurrentContext,1, NULL},
|
{const_cast< char * >("getCurrentContext"), getCurrentContext, METH_VARARGS, NULL},
|
||||||
{NULL, NULL, 0, NULL}
|
{NULL, NULL, 0, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" PY_DLLEXPORT void initpyuno()
|
extern "C" PY_DLLEXPORT
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
PyObject* PyInit_pyuno()
|
||||||
{
|
{
|
||||||
// noop when called already, otherwise needed to allow multiple threads
|
// noop when called already, otherwise needed to allow multiple threads
|
||||||
|
PyEval_InitThreads();
|
||||||
|
static struct PyModuleDef moduledef =
|
||||||
|
{
|
||||||
|
PyModuleDef_HEAD_INIT,
|
||||||
|
"pyuno", // module name
|
||||||
|
0, // module documentation
|
||||||
|
-1, // module keeps state in global variables,
|
||||||
|
PyUNOModule_methods, // modules methods
|
||||||
|
0, // m_reload (must be 0)
|
||||||
|
0, // m_traverse
|
||||||
|
0, // m_clear
|
||||||
|
0, // m_free
|
||||||
|
};
|
||||||
|
return PyModule_Create(&moduledef);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
void initpyuno()
|
||||||
|
{
|
||||||
PyEval_InitThreads();
|
PyEval_InitThreads();
|
||||||
Py_InitModule (const_cast< char * >("pyuno"), PyUNOModule_methods);
|
Py_InitModule (const_cast< char * >("pyuno"), PyUNOModule_methods);
|
||||||
}
|
}
|
||||||
|
#endif /* PY_MAJOR_VERSION >= 3 */
|
||||||
|
|
||||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||||
|
@@ -72,8 +72,7 @@ namespace pyuno
|
|||||||
|
|
||||||
static PyTypeObject RuntimeImpl_Type =
|
static PyTypeObject RuntimeImpl_Type =
|
||||||
{
|
{
|
||||||
PyObject_HEAD_INIT (&PyType_Type)
|
PyVarObject_HEAD_INIT (&PyType_Type, 0)
|
||||||
0,
|
|
||||||
const_cast< char * >("pyuno_runtime"),
|
const_cast< char * >("pyuno_runtime"),
|
||||||
sizeof (RuntimeImpl),
|
sizeof (RuntimeImpl),
|
||||||
0,
|
0,
|
||||||
@@ -81,7 +80,7 @@ static PyTypeObject RuntimeImpl_Type =
|
|||||||
(printfunc) 0,
|
(printfunc) 0,
|
||||||
(getattrfunc) 0,
|
(getattrfunc) 0,
|
||||||
(setattrfunc) 0,
|
(setattrfunc) 0,
|
||||||
(cmpfunc) 0,
|
0,
|
||||||
(reprfunc) 0,
|
(reprfunc) 0,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
@@ -445,7 +444,7 @@ PyRef Runtime::any2PyObject (const Any &a ) const
|
|||||||
{
|
{
|
||||||
sal_Int32 l = 0;
|
sal_Int32 l = 0;
|
||||||
a >>= l;
|
a >>= l;
|
||||||
return PyRef( PyInt_FromLong (l), SAL_NO_ACQUIRE );
|
return PyRef( PyLong_FromLong (l), SAL_NO_ACQUIRE );
|
||||||
}
|
}
|
||||||
case typelib_TypeClass_UNSIGNED_LONG:
|
case typelib_TypeClass_UNSIGNED_LONG:
|
||||||
{
|
{
|
||||||
@@ -666,6 +665,8 @@ Any Runtime::pyObject2Any ( const PyRef & source, enum ConversionMode mode ) con
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// In Python 3, there is no PyInt type.
|
||||||
|
#if PY_MAJOR_VERSION < 3
|
||||||
else if (PyInt_Check (o))
|
else if (PyInt_Check (o))
|
||||||
{
|
{
|
||||||
if( o == Py_True )
|
if( o == Py_True )
|
||||||
@@ -680,7 +681,7 @@ Any Runtime::pyObject2Any ( const PyRef & source, enum ConversionMode mode ) con
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sal_Int32 l = (sal_Int32) PyInt_AsLong( o );
|
sal_Int32 l = (sal_Int32) PyLong_AsLong( o );
|
||||||
if( l < 128 && l >= -128 )
|
if( l < 128 && l >= -128 )
|
||||||
{
|
{
|
||||||
sal_Int8 b = (sal_Int8 ) l;
|
sal_Int8 b = (sal_Int8 ) l;
|
||||||
@@ -697,8 +698,24 @@ Any Runtime::pyObject2Any ( const PyRef & source, enum ConversionMode mode ) con
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif /* PY_MAJOR_VERSION < 3 */
|
||||||
else if (PyLong_Check (o))
|
else if (PyLong_Check (o))
|
||||||
{
|
{
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
// Convert the Python 3 booleans that are actually of type PyLong.
|
||||||
|
if(o == Py_True)
|
||||||
|
{
|
||||||
|
sal_Bool b = sal_True;
|
||||||
|
a = Any(&b, getBooleanCppuType());
|
||||||
|
}
|
||||||
|
else if(o == Py_False)
|
||||||
|
{
|
||||||
|
sal_Bool b = sal_False;
|
||||||
|
a = Any(&b, getBooleanCppuType());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#endif /* PY_MAJOR_VERSION >= 3 */
|
||||||
sal_Int64 l = (sal_Int64)PyLong_AsLong (o);
|
sal_Int64 l = (sal_Int64)PyLong_AsLong (o);
|
||||||
if( l < 128 && l >= -128 )
|
if( l < 128 && l >= -128 )
|
||||||
{
|
{
|
||||||
@@ -720,16 +737,19 @@ Any Runtime::pyObject2Any ( const PyRef & source, enum ConversionMode mode ) con
|
|||||||
{
|
{
|
||||||
a <<= l;
|
a <<= l;
|
||||||
}
|
}
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else if (PyFloat_Check (o))
|
else if (PyFloat_Check (o))
|
||||||
{
|
{
|
||||||
double d = PyFloat_AsDouble (o);
|
double d = PyFloat_AsDouble (o);
|
||||||
a <<= d;
|
a <<= d;
|
||||||
}
|
}
|
||||||
else if (PyString_Check (o))
|
else if (PyString_Check(o) || PyUnicode_Check(o))
|
||||||
a <<= pyString2ustring(o);
|
{
|
||||||
else if( PyUnicode_Check( o ) )
|
|
||||||
a <<= pyString2ustring(o);
|
a <<= pyString2ustring(o);
|
||||||
|
}
|
||||||
else if (PyTuple_Check (o))
|
else if (PyTuple_Check (o))
|
||||||
{
|
{
|
||||||
Sequence<Any> s (PyTuple_Size (o));
|
Sequence<Any> s (PyTuple_Size (o));
|
||||||
|
@@ -27,7 +27,12 @@
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
import pyuno
|
import pyuno
|
||||||
|
|
||||||
|
try:
|
||||||
import __builtin__
|
import __builtin__
|
||||||
|
except ImportError:
|
||||||
|
import builtins as __builtin__
|
||||||
|
|
||||||
import socket # since on Windows sal3.dll no longer calls WSAStartup
|
import socket # since on Windows sal3.dll no longer calls WSAStartup
|
||||||
|
|
||||||
# all functions and variables starting with a underscore (_) must be considered private
|
# all functions and variables starting with a underscore (_) must be considered private
|
||||||
@@ -149,9 +154,9 @@ class Bool(object):
|
|||||||
Note: This class is deprecated. Use python's True and False directly instead
|
Note: This class is deprecated. Use python's True and False directly instead
|
||||||
"""
|
"""
|
||||||
def __new__(cls, value):
|
def __new__(cls, value):
|
||||||
if isinstance(value, (str, unicode)) and value == "true":
|
if isinstance(value, str) and value == "true":
|
||||||
return True
|
return True
|
||||||
if isinstance(value, (str, unicode)) and value == "false":
|
if isinstance(value, str) and value == "false":
|
||||||
return False
|
return False
|
||||||
if value:
|
if value:
|
||||||
return True
|
return True
|
||||||
@@ -161,7 +166,7 @@ class Char:
|
|||||||
"Represents a UNO char, use an instance of this class to explicitly pass a char to UNO"
|
"Represents a UNO char, use an instance of this class to explicitly pass a char to UNO"
|
||||||
# @param value pass a Unicode string with length 1
|
# @param value pass a Unicode string with length 1
|
||||||
def __init__(self,value):
|
def __init__(self,value):
|
||||||
assert isinstance(value, unicode)
|
assert isinstance(value, str)
|
||||||
assert len(value) == 1
|
assert len(value) == 1
|
||||||
self.value=value
|
self.value=value
|
||||||
|
|
||||||
@@ -169,7 +174,7 @@ class Char:
|
|||||||
return "<Char instance %s>" % (self.value, )
|
return "<Char instance %s>" % (self.value, )
|
||||||
|
|
||||||
def __eq__(self, that):
|
def __eq__(self, that):
|
||||||
if isinstance(that, (str, unicode)):
|
if isinstance(that, str):
|
||||||
if len(that) > 1:
|
if len(that) > 1:
|
||||||
return False
|
return False
|
||||||
return self.value == that[0]
|
return self.value == that[0]
|
||||||
@@ -260,7 +265,7 @@ def _uno_import( name, *optargs, **kwargs ):
|
|||||||
mod = None
|
mod = None
|
||||||
d = sys.modules
|
d = sys.modules
|
||||||
for x in modnames:
|
for x in modnames:
|
||||||
if d.has_key(x):
|
if x in d:
|
||||||
mod = d[x]
|
mod = d[x]
|
||||||
else:
|
else:
|
||||||
mod = pyuno.__class__(x) # How to create a module ??
|
mod = pyuno.__class__(x) # How to create a module ??
|
||||||
@@ -268,25 +273,25 @@ def _uno_import( name, *optargs, **kwargs ):
|
|||||||
|
|
||||||
RuntimeException = pyuno.getClass( "com.sun.star.uno.RuntimeException" )
|
RuntimeException = pyuno.getClass( "com.sun.star.uno.RuntimeException" )
|
||||||
for x in fromlist:
|
for x in fromlist:
|
||||||
if not d.has_key(x):
|
if x not in d:
|
||||||
if x.startswith( "typeOf" ):
|
if x.startswith( "typeOf" ):
|
||||||
try:
|
try:
|
||||||
d[x] = pyuno.getTypeByName( name + "." + x[6:len(x)] )
|
d[x] = pyuno.getTypeByName( name + "." + x[6:len(x)] )
|
||||||
except RuntimeException,e:
|
except RuntimeException as e:
|
||||||
raise ImportError( "type " + name + "." + x[6:len(x)] +" is unknown" )
|
raise ImportError( "type " + name + "." + x[6:len(x)] +" is unknown" )
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
# check for structs, exceptions or interfaces
|
# check for structs, exceptions or interfaces
|
||||||
d[x] = pyuno.getClass( name + "." + x )
|
d[x] = pyuno.getClass( name + "." + x )
|
||||||
except RuntimeException,e:
|
except RuntimeException as e:
|
||||||
# check for enums
|
# check for enums
|
||||||
try:
|
try:
|
||||||
d[x] = Enum( name , x )
|
d[x] = Enum( name , x )
|
||||||
except RuntimeException,e2:
|
except RuntimeException as e2:
|
||||||
# check for constants
|
# check for constants
|
||||||
try:
|
try:
|
||||||
d[x] = getConstantByName( name + "." + x )
|
d[x] = getConstantByName( name + "." + x )
|
||||||
except RuntimeException,e3:
|
except RuntimeException as e3:
|
||||||
# no known uno type !
|
# no known uno type !
|
||||||
raise ImportError( "type "+ name + "." +x + " is unknown" )
|
raise ImportError( "type "+ name + "." +x + " is unknown" )
|
||||||
return mod
|
return mod
|
||||||
@@ -296,7 +301,7 @@ __builtin__.__dict__["__import__"] = _uno_import
|
|||||||
|
|
||||||
# private function, don't use
|
# private function, don't use
|
||||||
def _impl_extractName(name):
|
def _impl_extractName(name):
|
||||||
r = range (len(name)-1,0,-1)
|
r = list(range(len(name)-1,0,-1))
|
||||||
for i in r:
|
for i in r:
|
||||||
if name[i] == ".":
|
if name[i] == ".":
|
||||||
name = name[i+1:len(name)]
|
name = name[i+1:len(name)]
|
||||||
@@ -336,7 +341,7 @@ def _uno_extract_printable_stacktrace( trace ):
|
|||||||
mod = None
|
mod = None
|
||||||
try:
|
try:
|
||||||
mod = __import__("traceback")
|
mod = __import__("traceback")
|
||||||
except ImportError,e:
|
except ImportError as e:
|
||||||
pass
|
pass
|
||||||
ret = ""
|
ret = ""
|
||||||
if mod:
|
if mod:
|
||||||
|
@@ -144,7 +144,7 @@ class ImplementationHelper:
|
|||||||
self.impls[implementationName] = _ImplementationHelperEntry(ctor,serviceNames)
|
self.impls[implementationName] = _ImplementationHelperEntry(ctor,serviceNames)
|
||||||
|
|
||||||
def writeRegistryInfo( self, regKey, smgr ):
|
def writeRegistryInfo( self, regKey, smgr ):
|
||||||
for i in self.impls.items():
|
for i in list(self.impls.items()):
|
||||||
keyName = "/"+ i[0] + "/UNO/SERVICES"
|
keyName = "/"+ i[0] + "/UNO/SERVICES"
|
||||||
key = regKey.createKey( keyName )
|
key = regKey.createKey( keyName )
|
||||||
for serviceName in i[1].serviceNames:
|
for serviceName in i[1].serviceNames:
|
||||||
@@ -231,7 +231,7 @@ def addComponentsToContext( toBeExtendedContext, contextRuntime, componentUrls,
|
|||||||
_g_typeTable = {}
|
_g_typeTable = {}
|
||||||
def _unohelper_getHandle( self):
|
def _unohelper_getHandle( self):
|
||||||
ret = None
|
ret = None
|
||||||
if _g_typeTable.has_key( self.__class__ ):
|
if self.__class__ in _g_typeTable:
|
||||||
ret = _g_typeTable[self.__class__]
|
ret = _g_typeTable[self.__class__]
|
||||||
else:
|
else:
|
||||||
names = {}
|
names = {}
|
||||||
@@ -245,7 +245,7 @@ def _unohelper_getHandle( self):
|
|||||||
# the "else if", because we only need the most derived interface
|
# the "else if", because we only need the most derived interface
|
||||||
traverse = traverse + list(bases)#
|
traverse = traverse + list(bases)#
|
||||||
|
|
||||||
lst = names.keys()
|
lst = list(names.keys())
|
||||||
types = []
|
types = []
|
||||||
for x in lst:
|
for x in lst:
|
||||||
t = uno.getTypeByName( x )
|
t = uno.getTypeByName( x )
|
||||||
|
Reference in New Issue
Block a user