diff options
author | Jörg Budischewski <jbu@openoffice.org> | 2003-03-30 12:32:01 +0000 |
---|---|---|
committer | Jörg Budischewski <jbu@openoffice.org> | 2003-03-30 12:32:01 +0000 |
commit | 8b829bbe3e25bc5562100b5de3b0e5a0aff30d3f (patch) | |
tree | 538baa3b4ed27efccd735c6562a08386d0d9bcb4 /pyuno | |
parent | 4c937bbdbbfd954936fdc92c4b35d90c2233719e (diff) |
#i12673# some cosmetics and small bugfixes (provided by zagy)
Diffstat (limited to 'pyuno')
-rw-r--r-- | pyuno/source/module/pyuno | 2 | ||||
-rw-r--r-- | pyuno/source/module/pyuno_runtime.cxx | 44 | ||||
-rw-r--r-- | pyuno/source/module/uno.py | 79 |
3 files changed, 85 insertions, 40 deletions
diff --git a/pyuno/source/module/pyuno b/pyuno/source/module/pyuno index 1cd17390d57b..5d13997bfde6 100644 --- a/pyuno/source/module/pyuno +++ b/pyuno/source/module/pyuno @@ -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 diff --git a/pyuno/source/module/pyuno_runtime.cxx b/pyuno/source/module/pyuno_runtime.cxx index 48994e56eef7..c9697137a3ad 100644 --- a/pyuno/source/module/pyuno_runtime.cxx +++ b/pyuno/source/module/pyuno_runtime.cxx @@ -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; diff --git a/pyuno/source/module/uno.py b/pyuno/source/module/uno.py index 592f04395f86..003b028868f3 100644 --- a/pyuno/source/module/uno.py +++ b/pyuno/source/module/uno.py @@ -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 |