From 742a65ce66a9739a01307a79e452850f26979d52 Mon Sep 17 00:00:00 2001 From: Marcelo Matus Date: Sat, 18 Feb 2006 09:23:55 +0000 Subject: [PATCH] add swigregister proxy method and move __repr__ to a single global module git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@8840 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/python.cxx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 0a14b657f..0fb5d70f7 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -676,6 +676,13 @@ public: tab4, "raise AttributeError,name\n\n", NIL); + Printv(f_shadow, + "def _swig_repr(self):\n", + tab4, "try: strthis = \"at 0x%x\" %( self.this, )\n", + tab4, "except: strthis = \"\"\n", + tab4, "return \"<%s.%s; proxy of C++ swig::PySwigIterator instance %s>\" % (self.__class__.__module__, self.__class__.__name__, strthis,)\n\n", + NIL); + if (!classic) { Printv(f_shadow, "import types\n", @@ -2678,10 +2685,7 @@ public: String *rname = SwigType_namestr(real_classname); if (new_repr) { Printv(f_shadow_file, - tab4, "def __repr__(self):\n", - tab8, "try: strthis = \"at 0x%x\" %( self.this, ) \n", - tab8, "except: strthis = \"\" \n", - tab8, "return \"<%s.%s; proxy of ", CPlusPlus ? "C++ " : "C ", rname," instance %s>\" % (self.__class__.__module__, self.__class__.__name__, strthis,)\n", + tab4, "__repr__ = lambda self: _swig_repr(self)\n", NIL); } else { @@ -2730,10 +2734,11 @@ public: for (int i = 0; i < Len(shadow_list); ++i) { String *symname = Getitem(shadow_list,i); Printf(f_shadow_file,"%s.%s = new_instancemethod(%s.%s,None,%s)\n", - class_name, symname, module, Swig_name_member(class_name,symname), class_name,0); + class_name, symname, module, Swig_name_member(class_name,symname), class_name); } } Printf(f_shadow_file,"%s.%s_swigregister(%s)\n", module, class_name, class_name,0); + Printf(f_shadow_file,"%s_swigregister = %s.%s_swigregister\n", class_name, module, class_name); shadow_indent = 0; Printf(f_shadow_file,"%s\n", f_shadow_stubs);