Kaydet (Commit) 8b829bbe authored tarafından Jörg Budischewski's avatar Jörg Budischewski

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

üst 4c937bbd
# The bootstrap variable PYUNOLIBDIR will be set by the pyuno runtime library # The bootstrap variable PYUNOLIBDIR will be set by the pyuno runtime library
PYUNO_BINPATH=$PYUNOLIBDIR/../bin$UPDMINOREXT PYUNO_BINPATH=$PYUNOLIBDIR/../bin$UPDMINOREXT
UNO_TYPES=$PYUNO_BINPATH/applicat.rdb UNO_TYPES=$PYUNO_BINPATH/types.rdb
UNO_SERVICES=$PYUNO_BINPATH/pyuno_services.rdb UNO_SERVICES=$PYUNO_BINPATH/pyuno_services.rdb
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* *
* $RCSfile: pyuno_runtime.cxx,v $ * $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 * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
...@@ -370,11 +370,11 @@ PyRef Runtime::any2PyObject (const Any &a ) const ...@@ -370,11 +370,11 @@ PyRef Runtime::any2PyObject (const Any &a ) const
{ {
long l; long l;
a >>= l; a >>= l;
return PyRef( PyLong_FromLong (l), SAL_NO_ACQUIRE ); return PyRef( PyInt_FromLong (l), SAL_NO_ACQUIRE );
} }
case typelib_TypeClass_UNSIGNED_LONG: case typelib_TypeClass_UNSIGNED_LONG:
{ {
unsigned long l; sal_uInt32 l;
a >>= l; a >>= l;
return PyRef( PyLong_FromUnsignedLong (l), SAL_NO_ACQUIRE ); return PyRef( PyLong_FromUnsignedLong (l), SAL_NO_ACQUIRE );
} }
...@@ -622,7 +622,25 @@ Any Runtime::pyObject2Any ( const PyRef & source ) const ...@@ -622,7 +622,25 @@ Any Runtime::pyObject2Any ( const PyRef & source ) const
else if (PyLong_Check (o)) else if (PyLong_Check (o))
{ {
sal_Int64 l = (sal_Int64)PyLong_AsLong (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)) else if (PyFloat_Check (o))
{ {
...@@ -631,8 +649,20 @@ Any Runtime::pyObject2Any ( const PyRef & source ) const ...@@ -631,8 +649,20 @@ Any Runtime::pyObject2Any ( const PyRef & source ) const
} }
else if (PyString_Check (o)) 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)), a <<= OUString(PyString_AsString (o), strlen( PyString_AsString(o)),
osl_getThreadTextEncoding()); osl_getThreadTextEncoding());
// }
} }
else if( PyUnicode_Check( o ) ) else if( PyUnicode_Check( o ) )
{ {
...@@ -668,6 +698,7 @@ Any Runtime::pyObject2Any ( const PyRef & source ) const ...@@ -668,6 +698,7 @@ Any Runtime::pyObject2Any ( const PyRef & source ) const
else else
{ {
Runtime runtime; Runtime runtime;
// should be removed, in case ByteSequence gets derived from String
if( PyObject_IsInstance( o, getByteSequenceClass( runtime ).get() ) ) if( PyObject_IsInstance( o, getByteSequenceClass( runtime ).get() ) )
{ {
PyRef str(PyObject_GetAttrString( o , "value" ),SAL_NO_ACQUIRE); PyRef str(PyObject_GetAttrString( o , "value" ),SAL_NO_ACQUIRE);
...@@ -679,7 +710,8 @@ Any Runtime::pyObject2Any ( const PyRef & source ) const ...@@ -679,7 +710,8 @@ Any Runtime::pyObject2Any ( const PyRef & source ) const
} }
a <<= seq; a <<= seq;
} }
else if( PyObject_IsInstance( o, getTypeClass( runtime ).get() ) ) else
if( PyObject_IsInstance( o, getTypeClass( runtime ).get() ) )
{ {
Type t = PyType2Type( o , runtime ); Type t = PyType2Type( o , runtime );
a <<= t; a <<= t;
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
# #
# $RCSfile: uno.py,v $ # $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 # The Contents of this file are made available subject to the terms of
# either of the following licenses # either of the following licenses
...@@ -58,7 +58,6 @@ ...@@ -58,7 +58,6 @@
# #
#************************************************************************* #*************************************************************************
import sys import sys
from types import UnicodeType, StringTypes
import pyuno import pyuno
import __builtin__ import __builtin__
...@@ -137,8 +136,8 @@ class Enum: ...@@ -137,8 +136,8 @@ class Enum:
def __eq__(self, that): def __eq__(self, that):
if not isinstance(that, Enum): if not isinstance(that, Enum):
return 0 return False
return (self.typeName == that.typeName ) and ( self.value == that.value) return (self.typeName == that.typeName) and (self.value == that.value)
class Type: class Type:
"Represents a UNO type, use an instance of this class to explicitly pass a boolean to UNO" "Represents a UNO type, use an instance of this class to explicitly pass a boolean to UNO"
...@@ -153,7 +152,7 @@ class Type: ...@@ -153,7 +152,7 @@ class Type:
def __eq__(self, that): def __eq__(self, that):
if not isinstance(that, Type): if not isinstance(that, Type):
return 0 return False
return self.typeClass == that.typeClass and self.typeName == that.typeName return self.typeClass == that.typeClass and self.typeName == that.typeName
def __hash__(self): def __hash__(self):
...@@ -165,66 +164,80 @@ class Bool(object): ...@@ -165,66 +164,80 @@ 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, type("") ) and value == "true": if isinstance(value, (str, unicode)) and value == "true":
return True return True
elif isinstance( value, type("") ) and value == "false": if isinstance(value, (str, unicode)) and value == "false":
return False return False
else: if value:
if value: return True
return True return False
else:
return False
class Char: 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, UnicodeType) assert isinstance(value, unicode)
assert len(value) == 1 assert len(value) == 1
self.value=value self.value=value
def __repr__(self): def __repr__(self):
return "<Char instance %s>" & (self.value) return "<Char instance %s>" % (self.value, )
def __eq__(self, that): def __eq__(self, that):
if isinstance(that, StringTypes): if isinstance(that, (str, unicode)):
if len(that) > 1: if len(that) > 1:
return 0 return False
return self.value == that[0] return self.value == that[0]
elif isinstance(that, Char): if isinstance(that, Char):
return self.value == that.value 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: class ByteSequence:
def __init__(self,value): def __init__(self, value):
if isinstance( value, StringTypes ): if isinstance(value, str):
self.value = value self.value = value
elif isinstance( value, ByteSequence ): elif isinstance(value, ByteSequence):
self.value = value.value self.value = value.value
else: else:
raise TypeError( "expected string or bytesequence" ) raise TypeError("expected string or bytesequence")
def __repr__( self): def __repr__(self):
return "<ByteSequence instance %s>" % (self.value ) return "<ByteSequence instance '%s'>" % (self.value, )
def __eq__( self,that): def __eq__(self, that):
if isinstance( that, ByteSequence): if isinstance( that, ByteSequence):
return self.value == that.value return self.value == that.value
elif isinstance( that, StringTypes ): if isinstance(that, str):
return self.value == that return self.value == that
raise TypeError( "expected string or bytesequence for comparison" ) return False
def __len__( self ): def __len__(self):
return len( self.value ) return len(self.value)
def __getitem__( self, index ): def __getitem__(self, index):
return self.value[index] return self.value[index]
def __iter__( self ): def __iter__( self ):
return self.value.__iter__() return self.value.__iter__()
def __add__( self , b ): def __add__( self , b ):
if isinstance( b, StringTypes ): if isinstance( b, str ):
return ByteSequence( self.value + b ) return ByteSequence( self.value + b )
elif isinstance( b, ByteSequence ): elif isinstance( b, ByteSequence ):
return ByteSequence( self.value + b.value ) return ByteSequence( self.value + b.value )
...@@ -322,5 +335,5 @@ def _uno_struct__str__(self): ...@@ -322,5 +335,5 @@ def _uno_struct__str__(self):
def _uno_struct__eq__(self,cmp): def _uno_struct__eq__(self,cmp):
if hasattr(cmp,"value"): if hasattr(cmp,"value"):
return self.__dict__["value"] == cmp.__dict__["value"] return self.__dict__["value"] == cmp.__dict__["value"]
return 0 return False
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment