#i12673# some cosmetics and small bugfixes (provided by zagy)

This commit is contained in:
Jörg Budischewski 2003-03-30 12:32:01 +00:00
parent 4c937bbdbb
commit 8b829bbe3e
3 changed files with 85 additions and 40 deletions

View file

@ -1,4 +1,4 @@
# The bootstrap variable PYUNOLIBDIR will be set by the pyuno runtime library
PYUNO_BINPATH=$PYUNOLIBDIR/../bin$UPDMINOREXT
UNO_TYPES=$PYUNO_BINPATH/applicat.rdb
UNO_TYPES=$PYUNO_BINPATH/types.rdb
UNO_SERVICES=$PYUNO_BINPATH/pyuno_services.rdb

View file

@ -2,9 +2,9 @@
*
* $RCSfile: pyuno_runtime.cxx,v $
*
* $Revision: 1.1 $
* $Revision: 1.2 $
*
* last change: $Author: jbu $ $Date: 2003-03-23 12:12:58 $
* last change: $Author: jbu $ $Date: 2003-03-30 13:32:01 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@ -370,11 +370,11 @@ PyRef Runtime::any2PyObject (const Any &a ) const
{
long l;
a >>= l;
return PyRef( PyLong_FromLong (l), SAL_NO_ACQUIRE );
return PyRef( PyInt_FromLong (l), SAL_NO_ACQUIRE );
}
case typelib_TypeClass_UNSIGNED_LONG:
{
unsigned long l;
sal_uInt32 l;
a >>= l;
return PyRef( PyLong_FromUnsignedLong (l), SAL_NO_ACQUIRE );
}
@ -622,7 +622,25 @@ Any Runtime::pyObject2Any ( const PyRef & source ) const
else if (PyLong_Check (o))
{
sal_Int64 l = (sal_Int64)PyLong_AsLong (o);
a <<= l;
if( l < 128 && l >= -128 )
{
sal_Int8 b = (sal_Int8 ) l;
a <<= b;
}
else if( l <= 0x7fff && l >= -0x8000 )
{
sal_Int16 s = (sal_Int16) l;
a <<= s;
}
else if( l <= 0x7fffffff && l >= -0x80000000 )
{
sal_Int32 l32 = (sal_Int32) l;
a <<= l32;
}
else
{
a <<= l;
}
}
else if (PyFloat_Check (o))
{
@ -631,8 +649,20 @@ Any Runtime::pyObject2Any ( const PyRef & source ) const
}
else if (PyString_Check (o))
{
// needed, if ByteSequence becomes a string
// Runtime runtime;
// if( PyObject_IsInstance( o, getByteSequenceClass( runtime ).get() ) )
// {
// // is it the byte sequence ?
// Sequence< sal_Int8 > seq;
// seq = Sequence<sal_Int8 > ((sal_Int8*) PyString_AsString(o) , PyString_Size(o));
// a <<= seq;
// }
// else
// {
a <<= OUString(PyString_AsString (o), strlen( PyString_AsString(o)),
osl_getThreadTextEncoding());
// }
}
else if( PyUnicode_Check( o ) )
{
@ -668,6 +698,7 @@ Any Runtime::pyObject2Any ( const PyRef & source ) const
else
{
Runtime runtime;
// should be removed, in case ByteSequence gets derived from String
if( PyObject_IsInstance( o, getByteSequenceClass( runtime ).get() ) )
{
PyRef str(PyObject_GetAttrString( o , "value" ),SAL_NO_ACQUIRE);
@ -679,7 +710,8 @@ Any Runtime::pyObject2Any ( const PyRef & source ) const
}
a <<= seq;
}
else if( PyObject_IsInstance( o, getTypeClass( runtime ).get() ) )
else
if( PyObject_IsInstance( o, getTypeClass( runtime ).get() ) )
{
Type t = PyType2Type( o , runtime );
a <<= t;

View file

@ -2,9 +2,9 @@
#
# $RCSfile: uno.py,v $
#
# $Revision: 1.1 $
# $Revision: 1.2 $
#
# last change: $Author: jbu $ $Date: 2003-03-23 12:12:59 $
# last change: $Author: jbu $ $Date: 2003-03-30 13:32:01 $
#
# The Contents of this file are made available subject to the terms of
# either of the following licenses
@ -58,7 +58,6 @@
#
#*************************************************************************
import sys
from types import UnicodeType, StringTypes
import pyuno
import __builtin__
@ -137,8 +136,8 @@ class Enum:
def __eq__(self, that):
if not isinstance(that, Enum):
return 0
return (self.typeName == that.typeName ) and ( self.value == that.value)
return False
return (self.typeName == that.typeName) and (self.value == that.value)
class Type:
"Represents a UNO type, use an instance of this class to explicitly pass a boolean to UNO"
@ -153,7 +152,7 @@ class Type:
def __eq__(self, that):
if not isinstance(that, Type):
return 0
return False
return self.typeClass == that.typeClass and self.typeName == that.typeName
def __hash__(self):
@ -165,66 +164,80 @@ class Bool(object):
Note: This class is deprecated. Use python's True and False directly instead
"""
def __new__(cls, value):
if isinstance( value, type("") ) and value == "true":
if isinstance(value, (str, unicode)) and value == "true":
return True
elif isinstance( value, type("") ) and value == "false":
if isinstance(value, (str, unicode)) and value == "false":
return False
else:
if value:
return True
else:
return False
if value:
return True
return False
class Char:
"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
def __init__(self,value):
assert isinstance(value, UnicodeType)
assert isinstance(value, unicode)
assert len(value) == 1
self.value=value
def __repr__(self):
return "<Char instance %s>" & (self.value)
return "<Char instance %s>" % (self.value, )
def __eq__(self, that):
if isinstance(that, StringTypes):
if isinstance(that, (str, unicode)):
if len(that) > 1:
return 0
return False
return self.value == that[0]
elif isinstance(that, Char):
if isinstance(that, Char):
return self.value == that.value
return 0
return False
# Suggested by Christian, but still some open problems which need to be solved first
#
#class ByteSequence(str):
#
# def __repr__(self):
# return "<ByteSequence instance %s>" % str.__repr__(self)
# for a little bit compatitbility; setting value is not possible as
# strings are immutable
# def _get_value(self):
# return self
#
# value = property(_get_value)
class ByteSequence:
def __init__(self,value):
if isinstance( value, StringTypes ):
def __init__(self, value):
if isinstance(value, str):
self.value = value
elif isinstance( value, ByteSequence ):
elif isinstance(value, ByteSequence):
self.value = value.value
else:
raise TypeError( "expected string or bytesequence" )
raise TypeError("expected string or bytesequence")
def __repr__( self):
return "<ByteSequence instance %s>" % (self.value )
def __repr__(self):
return "<ByteSequence instance '%s'>" % (self.value, )
def __eq__( self,that):
def __eq__(self, that):
if isinstance( that, ByteSequence):
return self.value == that.value
elif isinstance( that, StringTypes ):
if isinstance(that, str):
return self.value == that
raise TypeError( "expected string or bytesequence for comparison" )
return False
def __len__( self ):
return len( self.value )
def __len__(self):
return len(self.value)
def __getitem__( self, index ):
def __getitem__(self, index):
return self.value[index]
def __iter__( self ):
return self.value.__iter__()
def __add__( self , b ):
if isinstance( b, StringTypes ):
if isinstance( b, str ):
return ByteSequence( self.value + b )
elif isinstance( b, ByteSequence ):
return ByteSequence( self.value + b.value )
@ -322,5 +335,5 @@ def _uno_struct__str__(self):
def _uno_struct__eq__(self,cmp):
if hasattr(cmp,"value"):
return self.__dict__["value"] == cmp.__dict__["value"]
return 0
return False