Re: [Zope] - Problem with ExternalMethod
A.M. Kuchling wrote:
I'm trying to figure out how to create a function that can be turned into an ExternalMethod. The module name is AMK.Tester, and the function name is test1.
The steps I followed were:
1) Create an AMK/Extensions directory in the Products/ directory. 2) Create Tester.py in the AMK/Extensions directory, and put a test() function in it. 3) Encrypt the .py file to produce a .pyp file with a little program. 4) Attempting to create the ExternalMethod object gets a traceback:
Traceback (innermost last): File /home/opt/zope/lib/python/ZPublisher/Publish.py, line 861, in publish_module File /home/opt/zope/lib/python/ZPublisher/Publish.py, line 583, in publish (Info: /manage_addExternalMethod) File /home/opt/zope/lib/python/Products/ExternalMethod/ExternalMethod.py, line 125, in manage_addExternalMethod (Object: ApplicationDefaultPermissions) File /home/opt/zope/lib/python/Products/ExternalMethod/ExternalMethod.py, line 167, in __init__ (Object: Item) File /home/opt/zope/lib/python/Products/ExternalMethod/ExternalMethod.py, line 186, in manage_edit (Object: Item) File /home/opt/zope/lib/python/Products/ExternalMethod/ExternalMethod.py, line 206, in getFunction (Object: Item) File /home/opt/zope/lib/python/App/Extensions.py, line 104, in __cmp__ AttributeError: 'None' object has no attribute 'co_argcount'
Looking at the code in ExternalMethod.py, the ExternalMethod class attribute func_code is set to None. When .getFunction() is called, self.func_code is None, so the comparison in the following line fails: if func_code != self.func_code: self.func_code=func_code
The FuncCode.__cmp__ method is: def __cmp__(self,other): return cmp((self.co_argcount, self.co_varnames), (other.co_argcount, other.co_varnames))
other is None, so the AttributeError results. I don't see what the problem is, unless some external thing is expected to set the .func_code attribute. Or are there more things that I need to define in my package directory?
The problem is that in Python 1.4, errors in cmp were ignored and caused an effective enequality. In Python 1.5 cmp is handled differently, which is a good thing, and I failed to test ExternalMethod with it, which is a bad thing. :| The next release will have following __cmp__ function, which seems to solve the problem: def __cmp__(self,other): if other is None: return 1 try: return cmp((self.co_argcount, self.co_varnames), (other.co_argcount, other.co_varnames)) except: return 1 -- Jim Fulton mailto:jim@digicool.com Technical Director (540) 371-6909 Python Powered! Digital Creations http://www.digicool.com http://www.python.org Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email address may not be added to any commercial mail list with out my permission. Violation of my privacy with advertising or SPAM will result in a suit for a MINIMUM of $500 damages/incident, $1500 for repeats.
On Tue, 8 Dec 1998, Jim Fulton wrote:
and caused an effective enequality. In Python 1.5 cmp is handled differently, which is a good thing, and I failed to test ExternalMethod with it, which is a bad thing. :|
The next release will have following __cmp__ function, which seems to solve the problem:
def __cmp__(self,other): if other is None: return 1 try: return cmp((self.co_argcount, self.co_varnames), (other.co_argcount, other.co_varnames)) except: return 1
Woo-hoo! Fixes my problems, too. -- Andy Dustman You should always say "spam" and "eggs" ComStar Communications Corp. instead of "foo" and "bar" (706) 549-7689 | PGP KeyID=0xC72F3F1D in Python examples. (Mark Lutz)
participants (2)
-
Andy Dustman -
Jim Fulton