Ronald Oussoren avatar Ronald Oussoren committed 810c779

- Some cleanup (less print statements)
- Added type objc.informal_protocol, this should take a way the need to
manually specify signatures in 90% of the code.
- Use objc.informal_protocol to defien a number of the standard AppKit protocols- Use these to eliminate selector calls in the iClass and TableModel examples

Comments (0)

Files changed (28)

+2002-10-18 Ronald Oussoren <oussoren@cistron.nl>
+	* Better fix for crash while converting exception from Python to
+	  Objective-C
+	* Code cleanup in OC_*.[hm], ObjCPointer.m
+	* Cleaner code to check if the Objective-C class has a changed 
+	  method table.
+	* Native selectors now have a 'defining_class' attribute, which 
+	  contains a reference to the class that defined this method.
+	* Added type objc.informal_protocol, which can be used to eliminate
+	  most existing cases of explicit calls to 'objc.selector'
+
 2002-10-17  Bill Bumgarner  <bbum@codefab.com>
 	* Fixed a situation where ObjCErr_ToObjC() would crash if the
 	exception lacked a value or traceback.

pyobjc/Examples/TableModel/TableModel.py

 from Foundation import NSObject
-from AppKit import NSApplicationMain
+from AppKit import NSApplicationMain, NSTableDataSource
 from objc import selector
 import sys
 
-class PyModel (NSObject):
+class PyModel (NSObject, NSTableDataSource):
 	__slots__  = ('rowcount')
 
 	def awakeFromNib(self):
 		print "numerOfRowsInTableView: called"
 		return self.rowcount
 
-	numberOfRowsInTableView_ = selector(numberOfRowsInTableView_,
-		signature="i@:@")
-
 
 	def tableView_objectValueForTableColumn_row_(self, 
 			aTableView, aTableColumn, rowIndex):
 		print "tableView:objectValueForTableColumn:row: called"
 		return "{%s, %d}"%(aTableColumn.identifier(), rowIndex)
 
-	tableView_objectValueForTableColumn_row_ = selector(
-		tableView_objectValueForTableColumn_row_,
-		signature='@@:@@i')
 
 
 sys.exit(NSApplicationMain(sys.argv))

pyobjc/Examples/TableModel/setup-app.py

 objc.builder.build_applet(
 	app_name= 'TableModelPY',
 	main_py = 'TableModel.py',
+	raw = 1,
 	extra_files = ['English.lproj'])

pyobjc/Examples/iClass/datasource.py

 from Foundation import NSObject, NSBundle
+from AppKit import NSOutlineViewDataSource, NSTableDataSource
 from objc import selector, class_list, objc_object, IBOutlet
 
 WRAPPED={}
 			framework = framework[:-len('.framework')]
 	return framework
 
-class ClassesDataSource (NSObject):
+class ClassesDataSource (NSObject, NSOutlineViewDataSource, NSTableDataSource):
 	__slots__ = ('_classList', '_classTree', '_methodInfo')
 
 	_window = IBOutlet('window')
 			WRAPPED[v] = Wrapper.alloc().init_(v)
 		return WRAPPED[v]
 
-	outlineView_child_ofItem_ = selector(outlineView_child_ofItem_,
-		signature='@@:@i@')
-
 	def outlineView_isItemExpandable_(self, outlineview, item):
 		print "isItemExpandable:", item
 		if not (item is None):
 			item = item.value
 		return len(self._classTree[item]) != 0
 
-	outlineView_isItemExpandable_ = selector(outlineView_isItemExpandable_,
-		signature='c@:@@')
-	
 
 	def outlineView_numberOfChildrenOfItem_(self, outlineview, item):
 		print "numChildren:", item
 			item = item.value
 		return len(self._classTree[item])
 
-	outlineView_numberOfChildrenOfItem_ = selector(
-		outlineView_numberOfChildrenOfItem_,
-		signature='i@:@@')
-
 	def outlineView_objectValueForTableColumn_byItem_(self, outlineview, column, item):
 		print "objectValue:", item
 		if item is None:
 		print "numberOfRows", aTableView
 		return len(self._methodInfo)
 
-	numberOfRowsInTableView_ = selector(numberOfRowsInTableView_, 
-		signature="i@:@")
-
-
 	def tableView_objectValueForTableColumn_row_(self,    
 	                         aTableView, aTableColumn, rowIndex):  
 		print "objectValue", aTableView, aTableColumn, rowIndex
 		return self._methodInfo[rowIndex][methodIdentifier[aTableColumn.identifier()]]
-
-	tableView_objectValueForTableColumn_row_ = selector(  
-		tableView_objectValueForTableColumn_row_,     
-		signature='@@:@@i')                           

pyobjc/Lib/AppKit/__init__.py

 This module does not contain docstrings for the wrapped code, check Apple's
 documentation for details on how to use these functions and classes.
 """
+import objc as _objc
 
 # We first register special methods signatures with the runtime. The module
 # is not used for anything else.
-try:
-	import _AppKitSignatures as dummy
-	del dummy
-except ImportError:
-	pass
+import _AppKitSignatures as dummy
+del dummy
 
-try:
-	from _AppKit 		import *
-except ImportError:
-	pass
+from _AppKit 		import *
 
 
-try:
-	# We try to import a module containing support code, the code
-	# is only ever used from the C side.
-	import _AppKitMapping 
-except ImportError:
-	pass
+# We try to import a module containing support code, the code
+# is only ever used from the C side.
+#import _AppKitMapping 
 
 # Load the Cocoa bundle, and gather all classes defined there
 import Foundation
 for cls in class_list:
 	gl[cls.__name__] = cls
 
+Foundation._objc.recycle_autorelease_pool()
+
 # clean-up after ourselves.
 del class_list
 del cls
 del gl
 del Foundation
 
+
+
 # Define usefull utility methods here
+NSClassForName = _objc.lookup_class
+
+
+#
+# (Informal) protocols
+#
+# These can be used as (secondary) base-classes when subclassing an 
+# Objective-C class, but won't show up in the inheritance tree.
+#
+# NOTE: This currently lists all protocols in the AppKit, should remove
+# all protocols that are not actually used by user code.
+
+NSAccessibility = _objc.informal_protocol(
+	'NSAccessibility',
+	[
+		_objc.selector(
+			None, 
+			selector='accessibilityActionDescription:',
+			signature='@@:@',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='accessibilityActionNames',
+			signature='@@:',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='accessibilityAtributeNames',
+			signature='@@:',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='accessibilityAttributeValue:',
+			signature='@@:@',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='accessibilityFocusedUIElement',
+			signature='@@:',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='accessibilityHitTest:',
+			signature='@@:{_NSPoint=ff}',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='accessibilityIsAttributeSettable',
+			signature='c@:@',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='accessibilityIsIgnored',
+			signature='c@:',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='accessibilityPerformAction:',
+			signature='v@:@',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='accessibilitySetValue:ForAttribute:',
+			signature='@@:@@',
+			required=True
+		),
+	]
+)
+
+NSChangeSpelling = _objc.informal_protocol(
+	'NSChangeSpelling', [
+		_objc.selector(
+			None, 
+			selector='changeSpelling:',
+			signature='v@:@',
+			required=True
+		),
+	]
+)
+
+NSColorPickingCustom = _objc.informal_protocol(
+	'NSColorPickingCustom',
+	[
+		_objc.selector(
+			None, 
+			selector='currentMode',
+			signature='i@:',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='provideNewView:',
+			signature='@@:c',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='setColor:',
+			signature='v@:@',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='supportsMode:',
+			signature='c@:i',
+			required=True
+		),
+	]
+)
+
+NSColorPickingDefault = _objc.informal_protocol(
+	'NSColorPickingDefault',
+	[
+		_objc.selector(
+			None, 
+			selector='alphaControlAddedOrRemoved:',
+			signature='v@:@',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='attachColorList:',
+			signature='v@:@',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='detachColorList:',
+			signature='v@:@',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='initWithPickerMask:colorPanel:',
+			signature='@@:i@',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='insertNewButtonImage:in:',
+			signature='@@:@@',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='provideNewButtonImage',
+			signature='@@:',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='setMode:',
+			signature='v@:i',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='viewSizeChanged:',
+			signature='v@:@',
+			required=True
+		),
+	]
+)
+
+NSComboBoxCellDataSource = _objc.informal_protocol(
+	'NSComboBoxCellDataSource',
+	[
+		_objc.selector(
+			None, 
+			selector='comboBoxCell:completedString:',
+			signature='@@:@',
+			required=False
+		),
+		_objc.selector(
+			None, 
+			selector='comboBoxCell:indexOfItemWithStringValue:',
+			signature='I@:@@',
+			required=False
+		),
+		_objc.selector(
+			None, 
+			selector='comboBoxCell:objectValueForItemAtIndex:',
+			signature='@@:@i',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='numberOfItemsInComboBoxCell:',
+			signature='i@:@',
+			required=True
+		),
+	]
+)
+
+NSComboBoxDataSource = _objc.informal_protocol(
+	'NSComboBoxDataSource',
+	[
+		_objc.selector(
+			None, 
+			selector='comboBox:completedString:',
+			signature='@@:@@',
+			required=False
+		),
+		_objc.selector(
+			None, 
+			selector='comboBox:indexOfItemWithStringValue:',
+			signature='I@:@@',
+			required=False
+		),
+		_objc.selector(
+			None, 
+			selector='comboxBox:objectValueForItemAtIndex:',
+			signature='@@:@i',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='numberOfItemsInComboBox:',
+			signature='i@:@',
+			required=True
+		),
+	]
+)
+
+NSDraggingDestination = _objc.informal_protocol(
+	'NSDraggingDestination',
+	[
+		_objc.selector(
+			None, 
+			selector='concludeDragOperation:',
+			signature='v@:@',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='draggingEnded:',
+			signature='v@:@',
+			required=False # Not implemented yet (10.2)
+		),
+		_objc.selector(
+			None, 
+			selector='draggingEntered',
+			signature='i@:@',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='draggingExited:',
+			signature='v@:@',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='draggingUpdated:',
+			signature='i@:@',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='performDragOperation:',
+			signature='c@:@',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='prepareForDragOperation:',
+			signature='c@:@',
+			required=True
+		),
+	]
+)
+
+NSDraggingInfo = _objc.informal_protocol(
+	'NSDraggingInfo',
+	[
+		_objc.selector(
+			None, 
+			selector='draggedImage',
+			signature='@@:',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='draggedImageLocation',
+			signature='{_NSPoint=ff}@:',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='draggingDestinationWindow',
+			signature='@@:',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='draggingLocation',
+			signature='{_NSPoint=ff}@:',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='draggingPasteboard',
+			signature='@@:',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='draggingSequenceNumber',
+			signature='i@:',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='draggingSource',
+			signature='@@:',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='draggingSourceOperationMask',
+			signature='i@:',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='namesOfPromisedFilesDroppedAtDestination:',
+			signature='@@:@',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='slideDraggedImageTo:',
+			signature='v@:{_NSPoint=ff}',
+			required=True
+		),
+	]
+)
+
+NSDraggingSource = _objc.informal_protocol(
+	'NSDraggingSource',
+	[
+		_objc.selector(
+			None, 
+			selector='draggedImage:beganAt:',
+			signature='v@:@{_NSPoint=ff}',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='draggedImage:endedAt:deposited:',
+			signature='v@:@{_NSPoint=ff}c',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='draggedImage:endedAt:operation:',
+			signature='v@:@{_NSPoint=ff}i',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='draggedImage:movedTo:',
+			signature='v@:@{_NSPoint=ff}',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='draggingSourceOperationMaskForLocal:',
+			signature='I@:c',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='ignoreModifierKeysWhileDragging',
+			signature='c@:',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='namesOfPromisedFilesDroppedAtDestination:',
+			signature='@@:@',
+			required=True
+		),
+	]
+)
+
+NSIgnoreMisspelledWords = _objc.informal_protocol(
+	'NSIgnoreMisspelledWords',
+	[
+		_objc.selector(
+			None, 
+			selector='ignoreSpelling:',
+			signature='v@:@',
+			required=True
+		),
+	]
+)
+
+NSInputServerMouseTracker = _objc.informal_protocol(
+	'NSInputServerMouseTracker',
+	[
+		_objc.selector(
+			None, 
+			selector='mouseDownOnCharacterIndex:atCoordinate:withModifier:client:',
+			signature='c@:I{_NSPoint=ff}I@',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='mouseDraggedOnCharacterIndex:atCoordinate:withModifier:client:',
+			signature='c@:I{_NSPoint=ff}I@',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='mouseUpOnCharacterIndex:atCoordinate:withModifier:client:',
+			signature='c@:I{_NSPoint=ff}I@',
+			required=True
+		),
+	]
+)
+
+
+# TODO: NSInputServiceProvider
+
+NSMenuValidation = _objc.informal_protocol(
+	'NSMenuValidation',
+	[
+		_objc.selector(
+			None, 
+			selector='validateMenuItem:',
+			signature='c@:@',
+			required=True
+		),
+	]
+)
+
+NSNibAwakening = _objc.informal_protocol(
+	'NSNibAwakening',
+	[
+		_objc.selector(
+			None, 
+			selector='awakeFromNib',
+			signature='v@:',
+			required=True
+		),
+	]
+)
+
+NSOutlineViewDataSource = _objc.informal_protocol(
+	'NSOutlineViewDataSource',
+	[
+		_objc.selector(
+			None, 
+			selector='outlineView:accepDrop:item:childIndex:',
+			signature='c@@@i',
+			required=False
+		),
+		_objc.selector(
+			None, 
+			selector='outlineView:child:ofItem:',
+			signature='@@:@i@',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='outlineView:isItemExpandable:',
+			signature='c@:@@',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='outlineView:itemForPersistentObject:',
+			signature='@@:@@',
+			required=False
+		),
+		_objc.selector(
+			None, 
+			selector='outlineView:numberOfChildrenOfItem:',
+			signature='i@:@@',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='outlineView:objectValueForTableColumn:byItem:',
+			signature='@@:@@@',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='outlineView:persistentObjectForItem:',
+			signature='@@:@@',
+			required=False
+		),
+		_objc.selector(
+			None, 
+			selector='outlineView:setObjectValue:forTableColumn:byItem:',
+			signature='v@:@@@@',
+			required=False
+		),
+		_objc.selector(
+			None, 
+			selector='outlineView:validateDrop:proposedItem:proposedChildIndex:',
+			signature='i@:@@@i',
+			required=False
+		),
+		_objc.selector(
+			None, 
+			selector='outlineView:writeItems:toPasteBoard:',
+			signature='c@:@@@',
+			required=False
+		),
+	]
+)
+
+NSServicesRequests = _objc.informal_protocol(
+	'NSServicesRequests',
+	[
+		_objc.selector(
+			None, 
+			selector='readSelectionFromPasteboard:',
+			signature='c@:@',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='writeSelectionToPasteboard:types:',
+			signature='c@:@@',
+			required=True
+		),
+	]
+)
+
+NSTableDataSource = _objc.informal_protocol(
+	'NSTableDataSource',
+	[
+		_objc.selector(
+			None, 
+			selector='numberOfRowsInTableView:',
+			signature='i@:@',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='tableView:acceptDrop:row:dropOperation:',
+			signature='c@:@@ii',
+			required=False
+		),
+		_objc.selector(
+			None, 
+			selector='tableView:objectValueForTableColumn:row:',
+			signature='@@:@@i',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='tableView:setObjectValue:forTableColumn:row:',
+			signature='@@:@@@i',
+			required=False
+		),
+		_objc.selector(
+			None, 
+			selector='tableView:validateDrop:proposedRow:proposedOperation:',
+			signature='i@:@@ii',
+			required=False
+		),
+		_objc.selector(
+			None, 
+			selector='tableView:writeRows:toPasteboard:',
+			signature='c@:@@@',
+			required=False
+		),
+	]
+)		
+
+NSTextAttachmentCell = _objc.informal_protocol(
+	'NSTextAttachmentCell',
+	[
+		_objc.selector(
+			None, 
+			selector='attachment',
+			signature='@@:',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='cellBaselineOffset',
+			signature='{_NSPoint=ff}@:',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='cellFrameforTextContainer:proposedLineFragment:glyphPosition:characterIndex:',
+			signature='{_NSRect={_NSPoint=ff}{_NSSize=ff}}@:@{_NSRect={_NSPoint=ff}{_NSSize=ff}}{_NSPoint=ff}I',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='cellSize',
+			signature='{_NSSize=ff}@:',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='drawWithFrame:inView:',
+			signature='v@:{_NSRect={_NSPoint=ff}{_NSSize=ff}}@',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='drawWithFrame:inView:characterIndex:',
+			signature='v@:{_NSRect={_NSPoint=ff}{_NSSize=ff}}@I',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='drawWithFrame:inView:characterIndex:layoutManager:',
+			signature='v@:{_NSRect={_NSPoint=ff}{_NSSize=ff}}@I@',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='highlight:withFrame:inView:',
+			signature='v@:c{_NSRect={_NSPoint=ff}{_NSSize=ff}}@',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='setAttachment:',
+			signature='v@:@',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='trackMouse:inRect:ofView:untilMouseUp:',
+			signature='c@:@{_NSRect={_NSPoint=ff}{_NSSize=ff}}@c',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='trackMouse:inRect:ofView:atCharacterIndex:untilMouseUp:',
+			signature='c@:@{_NSRect={_NSPoint=ff}{_NSSize=ff}}@Ic',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='wantsToTrackMouse',
+			signature='c@:',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='wantsToTrackMouseForEvent:inRect:ofView:atCharacterIndex:',
+			signature='c@:@{_NSRect={_NSPoint=ff}{_NSSize=ff}}@I',
+			required=True
+		),
+	]
+)
+
+# TODO: NSTextInput
+
+# TODO: NSTextStorageScripting
+
+NSToolTipOwner = _objc.informal_protocol(
+	'NSToolTipOwner',
+	[
+		_objc.selector(
+			None, 
+			selector='view:stringForToolTip:point:userData:',
+			signature='@@:@i{_NSPoint=ff}i^v',
+			required=True
+		),
+	]
+)
+
+NSToolbarItemValidation = _objc.informal_protocol(
+	'NSToolbarItemValidation',
+	[
+		_objc.selector(
+			None, 
+			selector='validateToolbarItem:',
+			signature='c@:@',
+			required=True
+		),
+	]
+)
+
+
+NSUserInterfaceValidations = _objc.informal_protocol(
+	'NSUserInterfaceValidations',
+	[
+		_objc.selector(
+			None, 
+			selector='validateUserInterfaceItem:',
+			signature='c@:@',
+			required=True
+		),
+	]
+)
+
+
+NSValidatedUserInterfaceItem = _objc.informal_protocol(
+	'NSValidatedUserInterfaceItem',
+	[
+		_objc.selector(
+			None, 
+			selector='action',
+			signature=':@:',
+			required=True
+		),
+		_objc.selector(
+			None, 
+			selector='tag',
+			signature='i@:',
+			required=True
+		),
+	]
+)
+
+# TODO: NSWindowScripting

pyobjc/Lib/objc/__init__.py

 from _objc import *
 from _objc import __version__
 
-# Backward compat stuff
-try:
-	getattr(__builtins__, 'True')
-except AttributeError:
-	# Python 2.2.0 doesn't have 'True' and 'False'
-	True=1
-	False=0
+
+
+# Import values used to define signatures
+import _objc
+gl = globals()
+for nm in [ x for x in dir(_objc) if x.startswith('_C_') ]:
+	gl[nm] = getattr(_objc, nm)
+del gl, nm, _objc
+
 
 # This is a hack, should probably patch python:
 # - We want the resources directory to be on the python search-path
 #
 # These 5 are documented in Apple's Objective-C book, in theory these
 # are the only methods that transfer ownership.
-ALLOCATOR_METHODS['alloc'] = True
-ALLOCATOR_METHODS['allocWithZone:'] = True
-ALLOCATOR_METHODS['copy'] = True
-ALLOCATOR_METHODS['copyWithZone:'] = True
-ALLOCATOR_METHODS['mutableCopyWithZone:'] = True
+ALLOCATOR_METHODS['alloc'] = 1
+ALLOCATOR_METHODS['allocWithZone:'] = 1
+ALLOCATOR_METHODS['copy'] = 1
+ALLOCATOR_METHODS['copyWithZone:'] = 1
+ALLOCATOR_METHODS['mutableCopyWithZone:'] = 1
 
 # Some special modules needed to correctly wrap all
 # methods in the Foundation framework. Doing it here
 
 	def __eq__(self, other):
 		if self is other:
-			return True
-		return False
+			return 1
+		return 0
 
 	def __repr__(self):
 		return "objc.runtime"
 IBOutlet = ivar
 
 # Signature for an action in Interface Builder
-#IBAction = "v@:"
 def IBAction(func):
 	return selector(func, signature="v@:@")
 
 # Aliases for Objective-C lovers...
-YES=True
-NO=False
+YES=1
+NO=0
 nil=None
 
 
 		value = enum.nextObject()
 	return result
 
-#CONVENIENCE_METHODS['description'] = ('__repr__', lambda self: self.description())
+CONVENIENCE_METHODS['description'] = ('__repr__', lambda self: self.description())
 # Mappings (e.g. like dict)
 # TODO (not all are needed or even possible): 
 #   iter*, update, pop, popitem, setdefault
 CONVENIENCE_METHODS['doesContain:'] = ('__contains__', lambda self, elem: self.doesContain_(elem))
 def eq_func(self, other):
 	print "eq_func(%s, %s)"%(self, other)
-	if self is other: return True
+	if self is other: return 1
 	return self.isEqualTo_(other)
 
 CONVENIENCE_METHODS['isEqualTo:'] = ('__eq__', eq_func) # lambda self, other: self.isEqualTo_(other))

pyobjc/Modules/objc/OC_PythonInt.h

 {
 }
 
-//#M Initialize the version number of this class.
-+ (void) initialize;
-
 //#M Returns a new autoreleased PyInt object with @var{i} as contents.
 + (id <PythonObject>) fromLong:(long) i;
 

pyobjc/Modules/objc/OC_PythonInt.m

 
 #include "OC_PythonInt.h"
 
-#define CLASS_VERSION 0
-
 @implementation OC_PythonInt
-+ (void) initialize
-{
-/*
-  // NSProxy does not implement +setVersion:
-  if (self == [OC_PythonInt class])
-    {
-      [OC_PythonInt setVersion:CLASS_VERSION];
-    }
-*/
-}
 
 + (id <PythonObject>) fromLong:(long) i
 {
-  PyObject *pyint = PyInt_FromLong (i);
-  id <PythonObject> result = [self newWithObject:pyint];
+	PyObject *pyint = PyInt_FromLong(i);
+	id <PythonObject> result = [self newWithObject:pyint];
 
-  Py_DECREF(pyint);
-  return result;
+	Py_DECREF(pyint);
+	return result;
 }
 
 - (long) asLong
 {
-  return PyInt_AsLong ([self pyObject]);
+	return PyInt_AsLong([self pyObject]);
 }
 
 

pyobjc/Modules/objc/OC_PythonObject.h

 #ifndef _OC_PythonObject_H
 #define _OC_PythonObject_H
 
-//#include "pyobjc.h"
 #include <Python.h>
 #import <Foundation/NSProxy.h>
 #import <Foundation/NSMethodSignature.h>
   PyObject *pyObject;
 }
 
-//#M Initialize the version number of this class.
-//+ (void) initialize;
-
 //#M Returns a new autoreleased instance of this class.
 + (id <PythonObject>) newWithObject:(PyObject *) obj;
 

pyobjc/Modules/objc/OC_PythonObject.m

  */
 
 #include "objc_support.h"
-#include "abstract.h"
+#include "compile.h"
 
 #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION == 2 && PY_MICRO_VERSION == 0
- /* Python 2.2.0 forgets to define PyMapping_DelItem */
-#undef PyMapping_DelItem
-#define PyMapping_DelItem(O,K) PyDict_DelItem((O),(K))
-#undef PyMapping_DelItemString
-#define PyMapping_DelItemString(O,K) PyDict_DelItemString((O),(K))
-#endif
 
-#include "compile.h"
+    /* Python 2.2.0 contains incorrect definitions for PyMapping_DelItem
+     * and PyMapping_DelItemString
+     */
+#   undef PyMapping_DelItem
+#   undef PyMapping_DelItemString
+
+#   define PyMapping_DelItem(O,K) PyDict_DelItem((O),(K))
+#   define PyMapping_DelItemString(O,K) PyDict_DelItemString((O),(K))
+
+#endif /* Python 2.2.0 */
+
 
 #include <stdarg.h>
 
 #import  <Foundation/NSObject.h>  
-#import  <Foundation/NSMethodSignature.h>  /* sdm7g- chg #include to #import */
-#import  <Foundation/NSInvocation.h>       /* sdm7g */
-
-#define CLASS_VERSION 0
-
-#ifndef MAX
-#define MAX(x,y) ({ unsigned int __x=(x), __y=(y); (__x > __y ? __x : __y); })
-#define MIN(x,y) ({ unsigned int __x=(x), __y=(y); (__x < __y ? __x : __y); })
-#endif
+#import  <Foundation/NSMethodSignature.h>
+#import  <Foundation/NSInvocation.h>
 
 @implementation OC_PythonObject
 
-#if 0 /* NSProxy doesn't seem to define +setVersion, making this useless */
-+ (void) initialize
-{
-  if (self == [OC_PythonObject class])
-    {
-      [OC_PythonObject setVersion:CLASS_VERSION];
-    }
-}
-#endif
-
 + newWithObject:(PyObject *) obj
 {
-  if (ObjCObject_Check (obj)) 
-    {
-    // YYYY Ronald: If Jack is right (see below), we should 'retain' the 
-    // wrapped object to maintain the correct refcount
-    id objc_obj = ObjCObject_GetObject(obj);
-    
-    //[objc_obj retain];
-    return objc_obj;
-    }
-  else
-    {
-      id instance = [[self alloc] initWithObject:obj];
-      
-      // XXXX Jack thinks this shouldn't be done. And because these wrapper
-      // objects used to be released as soon as we get back into the mainloop
-      // he's strengthened in that belief:-)
-      [instance autorelease];
-
-      return instance;
-    }
+	if (ObjCObject_Check (obj)) {
+		id objc_obj = ObjCObject_GetObject(obj);
+		return objc_obj;
+	} else {
+		id instance = [[self alloc] initWithObject:obj];
+		[instance autorelease];
+		return instance;
+	}
 }
 
 - initWithObject:(PyObject *) obj
 {
-  //Py_XDECREF(pyObject);
-  pyObject = obj;
-  Py_XINCREF(obj);
+	Py_XDECREF(pyObject);
+	pyObject = obj;
+	Py_XINCREF(obj);
 
-  return self;
+	return self;
 }
 
-#if 1
 - (void)dealloc
 {
-  Py_XDECREF(pyObject);
-  [super dealloc];
+	Py_XDECREF(pyObject);
+	[super dealloc];
 }
-#else
-// XXX Jack thinks this is a bad idea: this ObjC object is exactly one reference
-// to the Python object (to be decreffed in dealloc)
-- retain
-{
-  Py_XINCREF (pyObject);
-  return [super retain];
-}
-
-- (oneway void) release
-{
-  [super release];
-  Py_XDECREF (pyObject);
-}
-#endif
 
 - (NSString *) description
 {
-  PyStringObject *repr = (PyStringObject *) PyObject_Repr (pyObject);
-  if (repr)
-    {
-      NSString *result = [NSString stringWithCString:PyString_AS_STRING (repr)
-				   length:PyString_GET_SIZE (repr)];
+	PyObject *repr = PyObject_Repr (pyObject);
+	if (repr) {
+		const char* error;
+		NSString* result;
 
-      Py_DECREF (repr);
-      return result;
-    }
-  else
-    {
-      PyErr_Clear();
-      return [super description];
-    }
+		error = depythonify_c_value ("@", repr, &result);
+		Py_DECREF (repr);
+		if (error) {
+			NSLog(@"PyObjC: `repr` failed to depythonify: %s",
+				error);
+			return @"a python object";
+		}
+		return result;
+	} else {
+		PyErr_Clear();
+		return [super description];
+	}
 }
   
-#define RETURN_RESULT(result) do {                                      \
-  if (result)                                                           \
-    {                                                                   \
-      OC_PythonObject *ret = [[self class] newWithObject:result];       \
-                                                                        \
-      Py_DECREF (result);                                               \
-      return ret;                                                       \
-    }                                                                   \
-  else {                                                                \
-    PySys_WriteStderr("Error in Python call from ObjC:\n");             \
-    PyErr_Print();                                                      \
-    return nil;                                                         \
-    }                                                                   \
-} while(0)
+#define RETURN_RESULT(result) 						\
+	do {								\
+		if (result)                                             \
+		{                                                       \
+			OC_PythonObject *ret = [[self class] 		\
+					newWithObject:result];		\
+			Py_DECREF (result);				\
+			return ret;					\
+		} else {						\
+			PySys_WriteStderr("Error in Python call from ObjC:\n");\
+			PyErr_Print();                                  \
+			return nil;					\
+		}							\
+	} while (0)
 
 - (void) doesNotRecognizeSelector:(SEL) aSelector
 {
-#define ERRORMSG " does not recognize -"
-  const char *whoiam = [[super description] cString];
-  const char *selname = [NSStringFromSelector (aSelector) cString];
-  char buffer[strlen (whoiam) + sizeof ERRORMSG + strlen (selname) + 1];
-
-  strcpy (buffer, whoiam);
-  strcat (buffer, ERRORMSG);
-  strcat (buffer, selname);
-  PyErr_SetString (objc_error, buffer);
+	ObjCErr_Set(objc_error, "%s does not recognize -%s",
+		[[super description] cString], SELNAME(aSelector));
+	ObjCErr_ToObjC();
 }
 
 
 static inline PyObject *
 check_argcount (PyObject *pymethod, unsigned int argcount)
 {
-  if (pymethod && (PyFunction_Check (pymethod) || PyMethod_Check (pymethod)))
-    {
-      PyCodeObject *func_code;
-      
-      if (PyMethod_Check (pymethod))
-        {
-          func_code = (PyCodeObject *) PyFunction_GetCode (PyMethod_Function (pymethod));
-          argcount++;           // for `self'
-        }
-      else
-        func_code = (PyCodeObject *) PyFunction_GetCode (pymethod);
-      
-      if (func_code->co_argcount == argcount)
-        return pymethod;
-    }
+	PyCodeObject *func_code;
 
-  return NULL;
+	if (!pymethod) {
+		return NULL;
+	}
+	if (PyFunction_Check(pymethod)) {
+		func_code = (PyCodeObject *)PyFunction_GetCode(
+			PyMethod_Function (pymethod));
+		if (argcount == func_code->co_argcount - 1) {
+			return pymethod;
+		}
+	} else if (PyMethod_Check(pymethod)) {
+        	func_code = (PyCodeObject *)PyFunction_GetCode(pymethod);
+		if (argcount == func_code->co_argcount) {
+			return pymethod;
+		}
+	} 
+	return NULL;
 }
 
 
 /*#F If the Python object @var{obj} implements a method whose name matches
   the Objective-C selector @var{aSelector} and accepts the correct number
   of arguments, return that method, otherwise NULL. */
-static PyObject *
-get_method_for_selector (PyObject *obj, SEL aSelector)
+static PyObject*
+get_method_for_selector(PyObject *obj, SEL aSelector)
 {
-  if (aSelector)
-    {
-      const char *meth_name = [NSStringFromSelector (aSelector) cString];
-      int len = strlen (meth_name);
-      char *pymeth_name;
-      unsigned int argcount;
-      PyObject *pymethod;
-      register const char *p;
+	const char*  meth_name;
+	int          len;
+	char*        pymeth_name;
+	unsigned int argcount;
+	PyObject*    pymethod;
+	const char*  p;
+
+	if (!aSelector) {
+		[NSException raise:NSInvalidArgumentException
+			     format:@"nil selector"];
+	}
+
+	meth_name = SELNAME(aSelector);
+	len = strlen(meth_name);
       
-      for (argcount=0, p=meth_name; *p; p++)
-        if (*p == ':')
-          argcount++;
+	for (argcount=0, p=meth_name; *p; p++) {
+		if (*p == ':') {
+			argcount++;
+		}
+	}
   
-      pymeth_name = alloca (PYTHONIFIED_LENGTH(meth_name, len, argcount));
-#if PYTHONIFICATION_METHOD != WITH_BOTH
-      pythonify_objc_message (meth_name, pymeth_name);
+	pymeth_name = alloca(PYTHONIFIED_LENGTH(meth_name, len, argcount));
+	pythonify_objc_message(meth_name, pymeth_name);
 
-      pymethod = PyObject_GetAttrString (obj, pymeth_name);
-      return check_argcount (pymethod, argcount);
-#else
-      {
-        PyObject *meth;
-
-        pythonify_objc_message (meth_name, pymeth_name, PYTHONIFICATION_FIRST_TRY);
-        pymethod = PyObject_GetAttrString (obj, pymeth_name);
-        meth = check_argcount (pymethod, argcount);
-        if (meth)
-          return meth;
-
-#if PYTHONIFICATION_FIRST_TRY == WITH_DOUBLE_UNDERSCORE
-        pythonify_objc_message (meth_name, pymeth_name, WITH_SINGLE_UNDERSCORE);
-#else
-        pythonify_objc_message (meth_name, pymeth_name, WITH_DOUBLE_UNDERSCORE);
-#endif
-        pymethod = PyObject_GetAttrString (obj, pymeth_name);
-        meth = check_argcount (pymethod, argcount);
-        if (meth)
-          {
-            if (Py_VerboseFlag)
-              {
-                char faster_name[200];
-                
-                fprintf (stderr, "PyObjC Warning: method `%s' matches `%s',\n\t", pymeth_name, meth_name);
-                
-                pythonify_objc_message (meth_name, faster_name, PYTHONIFICATION_FIRST_TRY);
-                
-                fprintf (stderr, "but `%s' would be faster.\n", faster_name);
-              }
-
-            return meth;
-          }
-      }
-#endif /* PYTHONIFICATION_METHOD != WITH_BOTH */
-    }
-  return NULL;    
+	pymethod = PyObject_GetAttrString(obj, pymeth_name);
+	return check_argcount(pymethod, argcount);
 }
 
 
 - (BOOL) respondsToSelector:(SEL) aSelector
 {
-  
-  if ([super respondsToSelector:aSelector])
-    {
-    return YES;
-    }
-  else
-    {
-      PyObject *m;
+	PyObject *m;
+
+	if ([super respondsToSelector:aSelector]) {
+		return YES;
+	} 
     
-      m = get_method_for_selector ([self pyObject], aSelector);
+	m = get_method_for_selector([self pyObject], aSelector);
 
-      if (m) {
-        return YES;
-      } else
-        {
-          PyErr_Clear();
-          return NO;
-        }
-    }
+	if (m) {
+        	return YES;
+	} else {
+		PyErr_Clear();
+		return NO;
+	}
 }
 
+
 - (NSMethodSignature *) methodSignatureForSelector:(SEL) sel
 {
+	/* We can't call our superclass implementation, NSProxy just raises
+	 * and exception.
+	 */
 
-  NSMethodSignature *result = nil;
+	char*        	   encoding;
+	PyObject*          pymethod;
+	PyCodeObject*      func_code;
+	int                argcount;
 
-  fflush(stdout);
+	encoding = (char*)get_selector_encoding (self, sel);
+	if (encoding) {
+		/* A real Objective-C method */
+		return [NSMethodSignature signatureWithObjCTypes:encoding];
+	}
 
-  NS_DURING
-    result = [super methodSignatureForSelector:sel];
-  NS_HANDLER
-    result = nil;
-    NSLog( [localException name]);
-    NSLog( [localException reason] );
-  NS_ENDHANDLER
-  
-  if (!result)
-    {
-      const char *encoding = get_selector_encoding (self, sel);
+	pymethod = get_method_for_selector([self pyObject], sel);
+	if (!pymethod) {
+		PyErr_Clear();
+		[NSException raise:NSInvalidArgumentException 
+			format:@"No such selector: %s", SELNAME(sel)];
+	}
 
-      if (!encoding) {
-	  PyObject *pymethod;
 
-	  pymethod = get_method_for_selector ([self pyObject], sel);
-	  if (pymethod) {
-	      PyCodeObject *func_code;
-	      int argcount;
-		  
-	      if (PyMethod_Check (pymethod))
-		{
-		  func_code = (PyCodeObject *) PyFunction_GetCode (PyMethod_Function (pymethod));
-		  argcount = func_code->co_argcount-1; // adjust for `self'
-		}
-	      else
-		{
-		  func_code = (PyCodeObject *) PyFunction_GetCode (pymethod);
+	if (PyMethod_Check (pymethod)) {
+		func_code = (PyCodeObject *) PyFunction_GetCode(
+			PyMethod_Function (pymethod));
+		argcount = func_code->co_argcount-1;
+	} else {
+		func_code = (PyCodeObject *) PyFunction_GetCode(
+			pymethod);
 		  argcount = func_code->co_argcount;
-		}
+	}
 
-		/* XXXX Jack thinks we may be able to handle getting the signatures
-		** if we make our Python classes subclass the corresponding ObjC
-		** classes: we should be able to use instanceMethodSignatureForSelector
-		*/
-		/*
-		** Hack by Jack: if our underlying Python object has a getObjCSignatureString
-		** method we call that.
-		*/
-		if (PyObject_HasAttrString([self pyObject], "getObjCSignatureString")) {
-			PyObject *sigstr;
-			
-			sigstr = PyObject_CallMethod([self pyObject], "getObjCSignatureString",
-					"s", [NSStringFromSelector (sel) cString]);
-			if (sigstr == NULL) {
-				fprintf(stderr, "Exception in getObjCSignatureString()\n");
-				PyErr_Clear();
-			} else if (PyString_Check(sigstr)) {
-				char *sigcstr = PyString_AsString(sigstr);
-				
-				id rv = [NSMethodSignature signatureWithObjCTypes:sigcstr];
-				
-				Py_DECREF(sigstr);
-				return rv;
-			} else {
-				fprintf(stderr, "getObjCSignatureString() did not return a string\n");
-				PyErr_Clear();
-			}
-		}
-	  }
-	/* Returning nil is not allowed here, crashes later in 
-	** [NSInvocation newInvocationWithMethodSignature:]
-	** XXXX For now we abort().
-	*/
-	abort();
-	return nil;
-      } else {
+	encoding = alloca(argcount+3);
+	memset(encoding, '@', argcount+2);
+	encoding[argcount+2] = '\0';
+	encoding[2] = ':';
 	return [NSMethodSignature signatureWithObjCTypes:encoding];
-    }
-    }
-  return result;
 }
 
 - (void) forwardInvocation:(NSInvocation *) invocation
 {
-  NSMethodSignature *msign = [invocation methodSignature];
-  SEL aSelector = [invocation selector];
-  PyObject *pymethod;
+	NSMethodSignature* msign = [invocation methodSignature];
+	SEL                aSelector = [invocation selector];
+	PyObject*          pymethod;
+	PyObject*          result;
+	const char*        rettype = [msign methodReturnType];
+	char*              retbuffer = alloca(objc_sizeof_type (rettype));
+	const char*        error;
+	PyObject*          args = NULL;
+	unsigned int       i;
+	unsigned int       argcount;      
+	PyCodeObject*      func_code;
   
-  pymethod = get_method_for_selector ([self pyObject], aSelector);
+	pymethod = get_method_for_selector([self pyObject], aSelector);
 
-  if (pymethod)
-    {
-      PyObject *args = NULL;
-      unsigned int i, argcount;      
-      PyCodeObject *func_code;
-          
-      if (PyMethod_Check (pymethod))
-        {
-          func_code = (PyCodeObject *) PyFunction_GetCode (PyMethod_Function (pymethod));
-          argcount = func_code->co_argcount-1; // adjust for `self'
-        }
-      else
-        {
-          func_code = (PyCodeObject *) PyFunction_GetCode (pymethod);
-          argcount = func_code->co_argcount;
-        }
-      
-      args = PyTuple_New (argcount);
-      if (args)
-        {
-          PyObject *result;
+	if (!pymethod) {
+		/* The method does not exist. We cannot forward this to our 
+		 * super because NSProxy doesn't implement forwardInvocation. 
+		 */
+		PyErr_Clear();
+		[self doesNotRecognizeSelector:aSelector];
+		return;
+	}
+  
+	if (PyMethod_Check(pymethod)) {
+		func_code = (PyCodeObject *)PyFunction_GetCode(
+			PyMethod_Function(pymethod));
+		argcount = func_code->co_argcount-1;
+	} else {
+		func_code = (PyCodeObject *)PyFunction_GetCode (
+			pymethod);
+		argcount = func_code->co_argcount;
+	}
 
-	  /*for (i=argcount+2; i>=2; i--) */
-	  for (i=argcount+1; i>1; i--) 
-	    {
-	      const char *argtype;
-	      char *argbuffer;
-	      PyObject *pyarg;
+	args = PyTuple_New(argcount);
+	if (args == NULL) {
+		ObjCErr_ToObjC();
+	}
+	for (i=argcount+1; i>1; i--) {
+		const char *argtype;
+		char *argbuffer;
+		PyObject *pyarg;
 
-	      NS_DURING
-#ifdef NOTOSX
+#ifdef NOTOSX /* XXX: This should be abstracted into a macro/function */
 		argtype = [msign argumentInfoAtIndex:i].type;
 #else
-	      argtype = [msign getArgumentTypeAtIndex:i];
+		argtype = [msign getArgumentTypeAtIndex:i];
 #endif
-	      NS_HANDLER
-		Py_DECREF(args);
-	        fprintf (stderr, "error getting type of arg %d\n", i);
-	        /* XXX Jack thinks this shouldn't happen */abort();
-		[super forwardInvocation:invocation];
-		return;
-	      NS_ENDHANDLER
-		
-	      argbuffer = alloca (objc_sizeof_type (argtype));
-	      [invocation getArgument:argbuffer atIndex:i];
-	      pyarg = pythonify_c_value (argtype, argbuffer);
+		argbuffer = alloca (objc_sizeof_type (argtype));
+		[invocation getArgument:argbuffer atIndex:i];
+		pyarg = pythonify_c_value (argtype, argbuffer);
 
-	      PyTuple_SET_ITEM (args, i-2, pyarg);
-	    }
-          result = PyObject_CallObject (pymethod, args);
-  
-          Py_DECREF(args);
+		PyTuple_SET_ITEM (args, i-2, pyarg);
+	}
+	result = PyObject_CallObject(pymethod, args);
+	Py_DECREF(args);
 
-	  if (result)
-	    {
-	      const char *rettype = [msign methodReturnType];
-	      char *retbuffer = alloca (objc_sizeof_type (rettype));
-	      const char *error;
-	      
-	      error = depythonify_c_value (rettype, result, retbuffer);
-	      if (error)
-		{
-		  fprintf (stderr, "error depythonifying: %s\n", error);
-		  /* XXX Jack thinks this shouldn't happen */abort();
-		}
-	      else
+	if (result == NULL) {
+		ObjCErr_ToObjC();
+	}
+
+	error = depythonify_c_value (rettype, result, retbuffer);
+	if (error) {
+		NSLog(@"PyObjC: error depythonifying return value of %s: %s\n", SELNAME(aSelector), error);
+		/* XXX: Throw ObjC exception */
+		abort();
+	} else {
 		[invocation setReturnValue:retbuffer];
-	    }
-	  else
-	    {
-                PySys_WriteStderr("Error in Python call from ObjC:\n");
-                PyErr_Print();  /* this also clears the error */
-            }
-	      
-        }
-// XXXX Jack thinks that commenting out the super call is not the right thing to do.
-// But if we enable it we get an exception.
-//    } else {
-//    	printf("WARNING: forwardInvocation: no Python method for %s\n", SELNAME(aSelector));
-//    	fflush(stdout);
-//    	[super forwardInvocation:invocation];
 	}
-	/*
-  [super forwardInvocation:invocation];
-  */
-}    
+}
 
 
-// NUMBER PROTOCOL
+/************************ NUMBER PROTOCOL ***********************************/
 
 - (int) numberCheck
 {
-  return PyNumber_Check ([self pyObject]);
+	return PyNumber_Check([self pyObject]);
 }
 
 - (id <PythonObject>) numberAdd:(id <PythonObject>) o2
 {
-  PyObject *pyo1 = [self pyObject];
-  PyObject *pyo2 = [o2 pyObject];
-  PyObject *result = PyNumber_Add (pyo1, pyo2);
+	PyObject *pyo1 = [self pyObject];
+	PyObject *pyo2 = [o2 pyObject];
+	PyObject *result = PyNumber_Add(pyo1, pyo2);
 
-  RETURN_RESULT(result);
+	RETURN_RESULT(result);
 }
 
 - (id <PythonObject>) numberSubtract:(id <PythonObject>) o2
 {
-  PyObject *pyo1 = [self pyObject];
-  PyObject *pyo2 = [o2 pyObject];
-  PyObject *result = PyNumber_Subtract (pyo1, pyo2);
+	PyObject *pyo1 = [self pyObject];
+	PyObject *pyo2 = [o2 pyObject];
+	PyObject *result = PyNumber_Subtract(pyo1, pyo2);
 
-  RETURN_RESULT(result);
+	RETURN_RESULT(result);
 }
 
 - (id <PythonObject>) numberMultiply:(id <PythonObject>) o2
 {
-  PyObject *pyo1 = [self pyObject];
-  PyObject *pyo2 = [o2 pyObject];
-  PyObject *result = PyNumber_Multiply (pyo1, pyo2);
+	PyObject *pyo1 = [self pyObject];
+	PyObject *pyo2 = [o2 pyObject];
+	PyObject *result = PyNumber_Multiply(pyo1, pyo2);
 
-  RETURN_RESULT(result);
+	RETURN_RESULT(result);
 }
 
 - (id <PythonObject>) numberDivide:(id <PythonObject>) o2
 {
-  PyObject *pyo1 = [self pyObject];
-  PyObject *pyo2 = [o2 pyObject];
-  PyObject *result = PyNumber_Divide (pyo1, pyo2);
+	PyObject *pyo1 = [self pyObject];
+	PyObject *pyo2 = [o2 pyObject];
+	PyObject *result = PyNumber_Divide(pyo1, pyo2);
 
-  RETURN_RESULT(result);
+	RETURN_RESULT(result);
 }
 
 - (id <PythonObject>) numberRemainder:(id <PythonObject>) o2
 {
-  PyObject *pyo1 = [self pyObject];
-  PyObject *pyo2 = [o2 pyObject];
-  PyObject *result = PyNumber_Remainder (pyo1, pyo2);
+	PyObject *pyo1 = [self pyObject];
+	PyObject *pyo2 = [o2 pyObject];
+	PyObject *result = PyNumber_Remainder(pyo1, pyo2);
 
-  RETURN_RESULT(result);
+	RETURN_RESULT(result);
 }
 
 - (id <PythonObject>) numberDivmod:(id <PythonObject>) o2
 {
-  PyObject *pyo1 = [self pyObject];
-  PyObject *pyo2 = [o2 pyObject];
-  PyObject *result = PyNumber_Divmod (pyo1, pyo2);
+	PyObject *pyo1 = [self pyObject];
+	PyObject *pyo2 = [o2 pyObject];
+	PyObject *result = PyNumber_Divmod(pyo1, pyo2);
 
-  RETURN_RESULT(result);
+	RETURN_RESULT(result);
 }
 
 - (id <PythonObject>) numberPower:(id <PythonObject>) o2
                                  :(id <PythonObject>) o3
 {
-  PyObject *pyo1 = [self pyObject];
-  PyObject *pyo2 = [o2 pyObject];
-  PyObject *pyo3 = [o3 pyObject];
-  PyObject *result = PyNumber_Power (pyo1, pyo2, pyo3);
+	PyObject *pyo1 = [self pyObject];
+	PyObject *pyo2 = [o2 pyObject];
+	PyObject *pyo3 = [o3 pyObject];
+	PyObject *result = PyNumber_Power(pyo1, pyo2, pyo3);
 
-  RETURN_RESULT(result);
+	RETURN_RESULT(result);
 }
 
 - (id <PythonObject>) numberNegative
 {
-  PyObject *pyo = [self pyObject];
-  PyObject *result = PyNumber_Negative (pyo);
+	PyObject *pyo = [self pyObject];
+	PyObject *result = PyNumber_Negative(pyo);
 
-  RETURN_RESULT(result);
+	RETURN_RESULT(result);
 }
 
 - (id <PythonObject>) numberPositive
 {
-  PyObject *pyo = [self pyObject];
-  PyObject *result = PyNumber_Positive (pyo);
+	PyObject *pyo = [self pyObject];
+	PyObject *result = PyNumber_Positive(pyo);
 
-  RETURN_RESULT(result);
+	RETURN_RESULT(result);
 }
 
 - (id <PythonObject>) numberAbsolute
 {
-  PyObject *pyo = [self pyObject];
-  PyObject *result = PyNumber_Absolute (pyo);
+	PyObject *pyo = [self pyObject];
+	PyObject *result = PyNumber_Absolute(pyo);
 
-  RETURN_RESULT(result);
+	RETURN_RESULT(result);
 }
 
 - (id <PythonObject>) numberInvert
 {
-  PyObject *pyo = [self pyObject];
-  PyObject *result = PyNumber_Invert (pyo);
+	PyObject *pyo = [self pyObject];
+	PyObject *result = PyNumber_Invert(pyo);
 
-  RETURN_RESULT(result);
+	RETURN_RESULT(result);
 }
 
 - (id <PythonObject>) numberLshift:(id <PythonObject>) o2
 {
-  PyObject *pyo1 = [self pyObject];
-  PyObject *pyo2 = [o2 pyObject];
-  PyObject *result = PyNumber_Lshift (pyo1, pyo2);
+	PyObject *pyo1 = [self pyObject];
+	PyObject *pyo2 = [o2 pyObject];
+	PyObject *result = PyNumber_Lshift(pyo1, pyo2);
 
-  RETURN_RESULT(result);
+	RETURN_RESULT(result);
 }
 
 - (id <PythonObject>) numberRshift:(id <PythonObject>) o2
 {
-  PyObject *pyo1 = [self pyObject];
-  PyObject *pyo2 = [o2 pyObject];
-  PyObject *result = PyNumber_Rshift (pyo1, pyo2);
+	PyObject *pyo1 = [self pyObject];
+	PyObject *pyo2 = [o2 pyObject];
+	PyObject *result = PyNumber_Rshift(pyo1, pyo2);
 
-  RETURN_RESULT(result);
+	RETURN_RESULT(result);
 }
 
 - (id <PythonObject>) numberAnd:(id <PythonObject>) o2
 {
-  PyObject *pyo1 = [self pyObject];
-  PyObject *pyo2 = [o2 pyObject];
-  PyObject *result = PyNumber_And (pyo1, pyo2);
+	PyObject *pyo1 = [self pyObject];
+	PyObject *pyo2 = [o2 pyObject];
+	PyObject *result = PyNumber_And(pyo1, pyo2);
 
-  RETURN_RESULT(result);
+	RETURN_RESULT(result);
 }
 
 - (id <PythonObject>) numberXor:(id <PythonObject>) o2
 {
-  PyObject *pyo1 = [self pyObject];
-  PyObject *pyo2 = [o2 pyObject];
-  PyObject *result = PyNumber_Xor (pyo1, pyo2);
+	PyObject *pyo1 = [self pyObject];
+	PyObject *pyo2 = [o2 pyObject];
+	PyObject *result = PyNumber_Xor(pyo1, pyo2);
 
-  RETURN_RESULT(result);
+	RETURN_RESULT(result);
 }
 
 - (id <PythonObject>) numberOr:(id <PythonObject>) o2
 {
-  PyObject *pyo1 = [self pyObject];
-  PyObject *pyo2 = [o2 pyObject];
-  PyObject *result = PyNumber_Or (pyo1, pyo2);
+	PyObject *pyo1 = [self pyObject];
+	PyObject *pyo2 = [o2 pyObject];
+	PyObject *result = PyNumber_Or(pyo1, pyo2);
 
-  RETURN_RESULT(result);
+	RETURN_RESULT(result);
 }
 
 - (id <PythonObject>) numberInt
 {
-  PyObject *pyo = [self pyObject];
-  PyObject *result = PyNumber_Int (pyo);
+	PyObject *pyo = [self pyObject];
+	PyObject *result = PyNumber_Int(pyo);
 
-  RETURN_RESULT(result);
+	RETURN_RESULT(result);
 }
 
 - (id <PythonObject>) numberLong
 {
-  PyObject *pyo = [self pyObject];
-  PyObject *result = PyNumber_Long (pyo);
+	PyObject *pyo = [self pyObject];
+	PyObject *result = PyNumber_Long(pyo);
 
-  RETURN_RESULT(result);
+	RETURN_RESULT(result);
 }
 
 - (id <PythonObject>) numberFloat
 {
-  PyObject *pyo = [self pyObject];
-  PyObject *result = PyNumber_Float (pyo);
+	PyObject *pyo = [self pyObject];
+	PyObject *result = PyNumber_Float(pyo);
 
-  RETURN_RESULT(result);
+	RETURN_RESULT(result);
 }
 
-// SEQUENCE PROTOCOL
+/************************ SEQUENCE PROTOCOL ********************************/
 
 - (int) sequenceCheck
 {
-  return PySequence_Check ([self pyObject]);
+	return PySequence_Check([self pyObject]);
 }
 
 - (int) sequenceLength
 {
-  return PySequence_Length ([self pyObject]);
+	return PySequence_Length([self pyObject]);
 }
 
 - (id <PythonObject>) sequenceConcat:(id <PythonObject>) o2
 {
-  PyObject *pyo1 = [self pyObject];
-  PyObject *pyo2 = [o2 pyObject];
-  PyObject *result = PySequence_Concat (pyo1, pyo2);
+	PyObject *pyo1 = [self pyObject];
+	PyObject *pyo2 = [o2 pyObject];
+	PyObject *result = PySequence_Concat(pyo1, pyo2);
 
-  RETURN_RESULT(result);
+	RETURN_RESULT(result);
 }
 
 - (id <PythonObject>) sequenceRepeat:(int) count
 {
-  PyObject *pyo = [self pyObject];
-  PyObject *result = PySequence_Repeat (pyo, count);
+	PyObject *pyo = [self pyObject];
+	PyObject *result = PySequence_Repeat(pyo, count);
 
-  RETURN_RESULT(result);
+	RETURN_RESULT(result);
 }
 
 - (id <PythonObject>) sequenceGetItem:(int) count
 {
-  PyObject *pyo = [self pyObject];
-  PyObject *result = PySequence_GetItem (pyo, count);
+	PyObject *pyo = [self pyObject];
+	PyObject *result = PySequence_GetItem(pyo, count);
 
-  RETURN_RESULT(result);
+	RETURN_RESULT(result);
 }
   
 - (id <PythonObject>) sequenceGetSliceFrom:(int) i1 to:(int) i2
 {
-  PyObject *pyo = [self pyObject];
-  PyObject *result = PySequence_GetSlice (pyo, i1, i2);
+	PyObject *pyo = [self pyObject];
+	PyObject *result = PySequence_GetSlice(pyo, i1, i2);
 
-  RETURN_RESULT(result);
+	RETURN_RESULT(result);
 }
 
 - (int) sequenceSetItem:(int) i value:(id <PythonObject>) v
 {
-  
-  PyObject *pyo = [self pyObject];
-  PyObject *pyv = [v pyObject];
+	PyObject *pyo = [self pyObject];
+	PyObject *pyv = [v pyObject];
 
-  return PySequence_SetItem (pyo, i, pyv);
+	return PySequence_SetItem(pyo, i, pyv);
 }
 
 - (int) sequenceDelItem:(int) i
 {
-  
-  PyObject *pyo = [self pyObject];
+	PyObject *pyo = [self pyObject];
 
-  return PySequence_DelItem (pyo, i);
+	return PySequence_DelItem(pyo, i);
 }
 
 - (int) sequenceSetSliceFrom:(int) i1
                           to:(int) i2
                        value:(id <PythonObject>) v
 {
-  PyObject *pyo = [self pyObject];
-  PyObject *pyv = [v pyObject];
+	PyObject *pyo = [self pyObject];
+	PyObject *pyv = [v pyObject];
 
-  return PySequence_SetSlice (pyo, i1, i2, pyv);
+	return PySequence_SetSlice(pyo, i1, i2, pyv);
 }
 
 - (int) sequenceDelSliceFrom:(int) i1
                           to:(int) i2
 {
-  PyObject *pyo = [self pyObject];
+	PyObject *pyo = [self pyObject];
 
-  return PySequence_DelSlice (pyo, i1, i2);
+	return PySequence_DelSlice(pyo, i1, i2);
 }
 
 - (id <PythonObject>) sequenceTuple
 {
-  PyObject *pyo = [self pyObject];
-  PyObject *result = PySequence_Tuple (pyo);
+	PyObject *pyo = [self pyObject];
+	PyObject *result = PySequence_Tuple(pyo);
 
-  RETURN_RESULT(result);
+	RETURN_RESULT(result);
 }
 
 - (id <PythonObject>) sequenceList
 {
-  PyObject *pyo = [self pyObject];
-  PyObject *result = PySequence_List (pyo);
+	PyObject *pyo = [self pyObject];
+	PyObject *result = PySequence_List(pyo);
 
-  RETURN_RESULT(result);
+	RETURN_RESULT(result);
 }
 
 - (int) sequenceCount:(id <PythonObject>) value
 {
-  PyObject *pyo = [self pyObject];
-  PyObject *pyv = [value pyObject];
+	PyObject *pyo = [self pyObject];
+	PyObject *pyv = [value pyObject];
 
-  return PySequence_Count (pyo, pyv);
+	return PySequence_Count(pyo, pyv);
 }
 
 - (int) sequenceIn:(id <PythonObject>) value
 {
-  PyObject *pyo = [self pyObject];
-  PyObject *pyv = [value pyObject];
+	PyObject *pyo = [self pyObject];
+	PyObject *pyv = [value pyObject];
 
-  return PySequence_In (pyo, pyv);
+	return PySequence_In(pyo, pyv);
 }
 
 - (int) sequenceIndex:(id <PythonObject>) value
 {
-  PyObject *pyo = [self pyObject];
-  PyObject *pyv = [value pyObject];
+	PyObject *pyo = [self pyObject];
+	PyObject *pyv = [value pyObject];
 
-  return PySequence_Index (pyo, pyv);
+	return PySequence_Index(pyo, pyv);
 }
 
-// CALLING PROTOCOL
+/************************* CALLING PROTOCOL ********************************/
 
 - (int) callableCheck
 {
-  return PyCallable_Check ([self pyObject]);
+	return PyCallable_Check([self pyObject]);
 }
 
 - (id <PythonObject>) callableCall:(id <PythonObject>) args
 {
-  PyObject *pyo = [self pyObject];
-  PyObject *pyargs = [args pyObject];
-  PyObject *result = PyObject_CallObject (pyo, pyargs);
+	PyObject *pyo = [self pyObject];
+	PyObject *pyargs = [args pyObject];
+	PyObject *result = PyObject_CallObject(pyo, pyargs);
 
-  RETURN_RESULT(result);
+	RETURN_RESULT(result);
 }
 
 - (id <PythonObject>) callableCallFunction:(char *) format, ...
 {
-  va_list va;
-  PyObject *args;
-  PyObject *result;
+	va_list va;
+	PyObject *args;
+	PyObject *result;
 
-  va_start (va, format);
+	va_start(va, format);
 
-  if (format)
-    args = Py_VaBuildValue (format, va);
-  else
-    args = PyTuple_New (0);
-  
-  va_end(va);
-  
-  if (! args)