Commits

Bob Ippolito committed c7167ef

Bump version to 1.3a1
Bridge NSDecimalNumber -> NSDecimal
Remove NSNumber convenience crap!

Comments (0)

Files changed (7)

Lib/objc/_convenience.py

 # NSNumber seems to be and abstract base-class that is implemented using
 # NSCFNumber, a CoreFoundation 'proxy'.
 #
-NSDecimalNumber = lookUpClass('NSDecimalNumber')
 NSNull = lookUpClass('NSNull')
 NSArray = lookUpClass('NSArray')
 null = NSNull.null()
         raise exc_type(*exc_args)
     return v
 
-def _numberForDecimal(v):
-    # make sure we have a NSDecimal type around
-    import Foundation
-    return v.decimalValue()
-
-def _num_to_python(v):
-    """
-    Magic method that converts NSNumber values to Python, see
-    <CoreFoundation/CFNumber.h> for the magic numbers
-    """
-    if isinstance(v, NSDecimalNumber):
-        return _numberForDecimal(v)
-    if hasattr(v, 'objCType'):
-        tp = v.objCType()
-        if tp in 'sil':
-            v = v.longValue()
-        elif tp in 'SIL':
-            v = v.unsignedlongValue()
-
-        elif tp == 'q':
-            v = v.longLongValue()
-
-        elif tp == 'Q':
-            v = v.unsignedLonglongValue()
-
-        elif tp in 'fd':
-            v = v.doubleValue()
-
-        else:
-            import warnings
-            warnings.warn(RuntimeWarning, "Unhandled numeric type: %r" % (tp,))
-
-    return v
-
-def __abs__CFNumber(numA):
-    return number_wrap(abs(_num_to_python(numA)))
-
-def __add__CFNumber(numA, numB):
-    return number_wrap(_num_to_python(numA) + _num_to_python(numB))
-
-def __and__CFNumber(numA, numB):
-    return number_wrap(_num_to_python(numA) & _num_to_python(numB))
-
-def __div__CFNumber(numA, numB):
-    return number_wrap(_num_to_python(numA) / _num_to_python(numB))
-
-def __divmod__CFNumber(numA, numB):
-    return number_wrap(divmod(_num_to_python(numA), _num_to_python(numB)))
-
-def __float__CFNumber(numA):
-    return numA.doubleValue()
-
-def __floordiv__CFNumber(numA, numB):
-    return number_wrap(_num_to_python(numA) // _num_to_python(numB))
-
-def __hex__CFNumber(numA):
-    return hex(_num_to_python(numA))
-
-def __int__CFNumber(numA):
-    return numA.longValue()
-
-def __invert__CFNumber(numA):
-    return number_wrap(~_num_to_python(numA))
-
-def __long__CFNumber(numA):
-    return numA.longLongValue()
-
-def __lshift__CFNumber(numA, numB):
-    return number_wrap(_num_to_python(numA) << _num_to_python(numB))
-
-def __rshift__CFNumber(numA, numB):
-    return number_wrap(_num_to_python(numA) >> _num_to_python(numB))
-
-def __mod__CFNumber(numA, numB):
-    return number_wrap(_num_to_python(numA) % _num_to_python(numB))
-
-def __mul__CFNumber(numA, numB):
-    return number_wrap(_num_to_python(numA) * _num_to_python(numB))
-
-def __neg__CFNumber(numA):
-    return number_wrap(-_num_to_python(numA))
-
-def __oct__CFNumber(numA):
-    return oct(_num_to_python(numA))
-
-def __or__CFNumber(numA, numB):
-    return number_wrap(_num_to_python(numA)  | _num_to_python(numB))
-
-def __pos__CFNumber(numA):
-    return number_wrap(+_num_to_python(numA))
-
-def __pow__CFNumber(numA, numB, modulo=None):
-    if modulo is None:
-        return number_wrap(_num_to_python(numA)  ** _num_to_python(numB))
-    else:
-        return number_wrap(pow(_num_to_python(numA), _num_to_python(numB), modulo))
-
-def __sub__CFNumber(numA, numB):
-    return number_wrap(_num_to_python(numA)  - _num_to_python(numB))
-
-def __truediv__CFNumber(numA, numB):
-    return number_wrap(_num_to_python(numA) / _num_to_python(numB))
-
-def __xor__CFNumber(numA, numB):
-    return number_wrap(_num_to_python(numA)  ^ _num_to_python(numB))
-
-def __nonzero__CFNumber(numA):
-    return bool(numA.boolValue())
-
-CONVENIENCE_METHODS['_cfNumberType'] = (
-    ('__abs__', __abs__CFNumber),
-    ('__add__', __add__CFNumber),
-    ('__and__', __and__CFNumber),
-    ('__div__', __div__CFNumber),
-    ('__divmod__', __divmod__CFNumber),
-    ('__float__', __float__CFNumber),
-    ('__floordiv__', __floordiv__CFNumber),
-    ('__hex__', __hex__CFNumber),
-    ('__int__', __int__CFNumber),
-    ('__invert__', __invert__CFNumber),
-    ('__long__', __long__CFNumber),
-    ('__lshift__', __lshift__CFNumber),
-    ('__mod__', __mod__CFNumber),
-    ('__mul__', __mul__CFNumber),
-    ('__neg__', __neg__CFNumber),
-    ('__oct__', __oct__CFNumber),
-    ('__or__', __or__CFNumber),
-    ('__pos__', __pos__CFNumber),
-    ('__pow__', __pow__CFNumber),
-    ('__radd__', lambda x, y: __add__CFNumber(y, x)),
-    ('__rand__', lambda x, y: __and__CFNumber(y, x)),
-    ('__rdiv__', lambda x, y: __div__CFNumber(y, x)),
-    ('__rdivmod__', lambda x, y: __divmod__CFNumber(y, x)),
-    ('__rfloordiv__', lambda x, y: _rfloordiv__CFNumber(y, x)),
-    ('__rlshift__', lambda x, y: __lshift__CFNumber(y, x)),
-    ('__rmod__', lambda x, y: __mod__CFNumber(y, x)),
-    ('__rmul__', lambda x, y: __mul__CFNumber(y, x)),
-    ('__ror__', lambda x, y: __or__CFNumber(y, x)),
-    ('__rpow__', lambda x, y, z=None: __pow__CFNumber(y, x, z)),
-    ('__rrshift__', lambda x, y: __rshift__CFNumber(y, x)),
-    ('__rshift__', lambda x, y: __shift__CFNumber(y, x)),
-    ('__rsub__', lambda x, y: __sub__CFNumber(y, x)),
-    ('__rtruediv__', lambda x, y: __truediv__CFNumber(y, x)),
-    ('__rxor__', lambda x, y: __xor__CFNumber(y, x)),
-    ('__sub__', __sub__CFNumber),
-    ('__truediv__', __truediv__CFNumber),
-    ('__xor__', __xor__CFNumber),
-    ('__nonzero__', __nonzero__CFNumber),
-)
-CONVENIENCE_METHODS['decimalNumberByAdding:'] = CONVENIENCE_METHODS['_cfNumberType']
-
-#CONVENIENCE_METHODS['boolValue'] = (
-#    ('__nonzero__', lambda (self): self.boolValue() != 0),
-#)
-
-
 #
 # Special wrappers for a number of varargs functions (constructors)
 #

Lib/objc/_pythonify.py

 
 NSNumber = _objc.lookUpClass('NSNumber')
 NSDecimalNumber = _objc.lookUpClass('NSDecimalNumber')
+Foundation = None
+
 def numberWrapper(obj):
-    if isinstance(obj, NSDecimalNumber) or not hasattr(obj, 'objCType'):
+    if isinstance(obj, NSDecimalNumber):
+        # ensure that NSDecimal is around
+        global Foundation
+        if Foundation is None:
+            import Foundation
+        # return NSDecimal
+        return obj.decimalValue()
+    try:
+        tp = obj.objCType()
+    except AttributeError:
+        import warnings
+        warnings.warn(RuntimeWarning, "NSNumber instance doesn't implement objCType? %r" % (obj,))
         return obj
-    tp = obj.objCType()
     if tp in 'qQLfd':
         if tp == 'q':
             return OC_PythonLong(obj, obj.longLongValue())

Modules/Foundation/decimals.m

 }
 
 static PyObject *decimal_get__pyobjc_object__(PyObject *self, void *closure __attribute__((__unused__))) {
-	PyObject *rval = PyObjC_IdToPython(Decimal_ObjCValue(self));
+	PyObject *rval = PyObjCObject_New(Decimal_ObjCValue(self));
 	return rval;
 }
 
 	if (res == NULL) {
 		PyObject *tmp;
 		PyErr_Clear();
-		tmp = PyObjC_IdToPython(Decimal_ObjCValue(o));
+		tmp = decimal_get__pyobjc_object__(o, NULL);
 		res = PyObject_GenericGetAttr(tmp, attr_name);
 		Py_XDECREF(tmp);
 	}

Modules/objc/pyobjc-api.h

  * - Version 10 changes the signature of PyObjCRT_SimplifySignature
  * - Version 11 adds PyObjCObject_Convert, PyObjCSelector_Convert,
      PyObjCClass_Convert, PyObjC_ConvertBOOL, and PyObjC_ConvertChar
+ * - Version 12 adds PyObjCObject_New
  */
-#define PYOBJC_API_VERSION 11
+#define PYOBJC_API_VERSION 12
 
 #define PYOBJC_API_NAME "__C_API__"
 
 
 	/* PyObjC_ConvertChar */
 	int (*pyobjc_convertchar)(PyObject*,void*);
+
+	/* PyObjCObject_New */
+	PyObject* (*pyobjc_object_new)(id);
 };
 
 #ifndef PYOBJC_BUILD
 #define PyObjCClass_Convert (PyObjC_API->pyobjcselector_convert)
 #define PyObjC_ConvertBOOL (PyObjC_API->pyobjc_convertbool)
 #define PyObjC_ConvertChar (PyObjC_API->pyobjc_convertchar)
+#define PyObjCObject_New (PyObjC_API->pyobjc_object_new)
 
 #ifndef PYOBJC_METHOD_STUB_IMPL
 

Modules/objc/pyobjc-api.m

     PyObjCSelector_Convert, /* pyobjcselector_convert */
     PyObjCClass_Convert,    /* pyobjcclass_convert */
     PyObjC_ConvertBOOL,     /* pyobjc_convertbool */
-    PyObjC_ConvertChar      /* pyobjc_convertchar */
+    PyObjC_ConvertChar,     /* pyobjc_convertchar */
+	PyObjCObject_New		/* pyobjc_object_new */
 };
 
 int PyObjCAPI_Register(PyObject* module)

Modules/objc/pyobjc.h

  * Central include file for PyObjC. 
  */
 
-#define OBJC_VERSION "1.3a0"
+#define OBJC_VERSION "1.3a1"
 
 // Loading in AppKit on Mac OS X 10.3 results in
 // a bit less than 1500 classes.

Modules/objc/unicode-object.m

 	class_new,				/* tp_new */
 	0,		        		/* tp_free */
 	0,					/* tp_is_gc */
-        0,                                      /* tp_bases */
-        0,                                      /* tp_mro */
-        0,                                      /* tp_cache */
-        0,                                      /* tp_subclasses */
-        0,                                      /* tp_weaklist */
-        0                                       /* tp_del */
+	0,                                      /* tp_bases */
+	0,                                      /* tp_mro */
+	0,                                      /* tp_cache */
+	0,                                      /* tp_subclasses */
+	0,                                      /* tp_weaklist */
+	0                                       /* tp_del */
 };
 
 PyObject* 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.