Hello, I am trying to add an external metod (used in a CMF Calendar example) but it fails. Now I'm not into these external methods (and I am not sure it's the best solution) but I just want to see how this example works. The method file is named monthRange.py and I have placed it in /usr/local/Zope/Extensions it contains this code: from DateTime import DateTime def monthRange( dt ): """ Return a pair of DateTime values representing the earliest and latest times in the month in which 'dt' falls. """ y, m, d = dt.year(), dt.month(), dt.day() first = DateTime( y, m, 1 ) last = first - 1 + DateTime._month_len[dt.isLeapYear() ][ m ] return first.earliestTime(), last.latestTime() I have filled in these values in the add form in ZMI: Id: monthRange Module Name: monthRange Function Name: monthRange I get this error when I try to add it: Error Type: SyntaxError Error Value: invalid syntax And this traceback: Traceback (innermost last): File /usr/local/Zope-2.3.2-linux2-x86/lib/python/ZPublisher/Publish.py, line 223, in publish_module File /usr/local/Zope-2.3.2-linux2-x86/lib/python/ZPublisher/Publish.py, line 187, in publish File /usr/local/Zope-2.3.2-linux2-x86/lib/python/Zope/__init__.py, line 221, in zpublisher_exception_hook File /usr/local/Zope-2.3.2-linux2-x86/lib/python/ZPublisher/Publish.py, line 171, in publish File /usr/local/Zope-2.3.2-linux2-x86/lib/python/ZPublisher/mapply.py, line 160, in mapply (Object: manage_addExternalMethod) File /usr/local/Zope-2.3.2-linux2-x86/lib/python/ZPublisher/Publish.py, line 112, in call_object (Object: manage_addExternalMethod) File /usr/local/Zope-2.3.2-linux2-x86/lib/python/Products/ExternalMethod/ExternalMethod.py, line 131, in manage_addExternalMethod File /usr/local/Zope-2.3.2-linux2-x86/lib/python/Products/ExternalMethod/ExternalMethod.py, line 179, in __init__ (Object: monthRange) File /usr/local/Zope-2.3.2-linux2-x86/lib/python/Products/ExternalMethod/ExternalMethod.py, line 202, in manage_edit (Object: monthRange) File /usr/local/Zope-2.3.2-linux2-x86/lib/python/Products/ExternalMethod/ExternalMethod.py, line 209, in getFunction (Object: monthRange) File /usr/local/Zope-2.3.2-linux2-x86/lib/python/App/Extensions.py, line 217, in getObject (Info: ('/usr/local/Zope-2.3.2-linux2-x86/Extensions/monthRange.py', 'monthRange')) SyntaxError: (see above) Well it looks like it finds the file. To me it looks like there is a syntax error in the add of the external method. or is the syntax error in the python code ? I haven't debugged this kind of scripts before so I hope there is someone who can help me :-) Regards, -- Gitte Wange Jensen Sys Admin, Developer and a lot more MMmanager.org Aps, Denmark Phone: +45 29 72 79 72 Email: gitte@mmmanager.org Web: www.mmmanager.org Quote of the day: Unix is user friendly; it's just a little paticular about which users it is friendly to.
Hi, the definition of your method is wrong. Because the external method is a method of the object which contain it. The correct definition is: def monthRange (self, dt) --On Freitag, Juli 06, 2001 14:57:41 +0200 Gitte Wange <gitte@mmmanager.org> wrote:
Hello,
I am trying to add an external metod (used in a CMF Calendar example) but it fails.
Now I'm not into these external methods (and I am not sure it's the best solution) but I just want to see how this example works.
The method file is named monthRange.py and I have placed it in /usr/local/Zope/Extensions it contains this code: from DateTime import DateTime
def monthRange( dt ): """ Return a pair of DateTime values representing the earliest and latest times in the month in which 'dt' falls. """ y, m, d = dt.year(), dt.month(), dt.day() first = DateTime( y, m, 1 ) last = first - 1 + DateTime._month_len[dt.isLeapYear() ][ m ] return first.earliestTime(), last.latestTime()
I have filled in these values in the add form in ZMI: Id: monthRange Module Name: monthRange Function Name: monthRange
I get this error when I try to add it: Error Type: SyntaxError Error Value: invalid syntax
And this traceback: Traceback (innermost last): File /usr/local/Zope-2.3.2-linux2-x86/lib/python/ZPublisher/Publish.py, line 223, in publish_module File /usr/local/Zope-2.3.2-linux2-x86/lib/python/ZPublisher/Publish.py, line 187, in publish File /usr/local/Zope-2.3.2-linux2-x86/lib/python/Zope/__init__.py, line 221, in zpublisher_exception_hook File /usr/local/Zope-2.3.2-linux2-x86/lib/python/ZPublisher/Publish.py, line 171, in publish File /usr/local/Zope-2.3.2-linux2-x86/lib/python/ZPublisher/mapply.py, line 160, in mapply (Object: manage_addExternalMethod) File /usr/local/Zope-2.3.2-linux2-x86/lib/python/ZPublisher/Publish.py, line 112, in call_object (Object: manage_addExternalMethod) File /usr/local/Zope-2.3.2-linux2-x86/lib/python/Products/ExternalMethod/Exter nalMethod.py, line 131, in manage_addExternalMethod File /usr/local/Zope-2.3.2-linux2-x86/lib/python/Products/ExternalMethod/Exter nalMethod.py, line 179, in __init__ (Object: monthRange) File /usr/local/Zope-2.3.2-linux2-x86/lib/python/Products/ExternalMethod/Exter nalMethod.py, line 202, in manage_edit (Object: monthRange) File /usr/local/Zope-2.3.2-linux2-x86/lib/python/Products/ExternalMethod/Exter nalMethod.py, line 209, in getFunction (Object: monthRange) File /usr/local/Zope-2.3.2-linux2-x86/lib/python/App/Extensions.py, line 217, in getObject (Info: ('/usr/local/Zope-2.3.2-linux2-x86/Extensions/monthRange.py', 'monthRange')) SyntaxError: (see above)
Well it looks like it finds the file. To me it looks like there is a syntax error in the add of the external method. or is the syntax error in the python code ?
I haven't debugged this kind of scripts before so I hope there is someone who can help me :-)
Regards,
-- Gitte Wange Jensen
Sys Admin, Developer and a lot more MMmanager.org Aps, Denmark
Phone: +45 29 72 79 72 Email: gitte@mmmanager.org Web: www.mmmanager.org
Quote of the day: Unix is user friendly; it's just a little paticular about which users it is friendly to.
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
On Friday 06 July 2001 15:11, Özgür Caner wrote:
Hi,
the definition of your method is wrong. Because the external method is a method of the object which contain it. The correct definition is:
def monthRange (self, dt)
<Snipped out my code> Well I just added it but the error is still there :-( I tried to import it into python from the FS but got an error. Here's the traceback: Traceback (most recent call last): File "<stdin>", line 1, in ? File "monthRange.py", line 3 def monthRange(self,dt): ^ SyntaxError: invalid syntax Well .. maybe I have missed something but is def an invalid syntax ?? What is the script missing ? Regards, -- Gitte Wange Jensen Sys Admin, Developer and a lot more MMmanager.org Aps, Denmark Phone: +45 29 72 79 72 Email: gitte@mmmanager.org Web: www.mmmanager.org Quote of the day: Now, the above won't work for drivers/net, but I think it will work for just about anything else. So let's just leave drivers/net alone for now. Simplicity is good. - Linus Torvalds
On Fri, 6 Jul 2001, Gitte Wange wrote:
File "monthRange.py", line 3 def monthRange(self,dt): ^ SyntaxError: invalid syntax
Something wrong before the "def". For example, CRLF line endings on UNIX. Oleg. ---- Oleg Broytmann http://www.zope.org/Members/phd/ phd@phd.pp.ru Programmers don't die, they just GOSUB without RETURN.
On Friday 06 July 2001 15:19, Oleg Broytmann wrote:
On Fri, 6 Jul 2001, Gitte Wange wrote:
File "monthRange.py", line 3 def monthRange(self,dt): ^ SyntaxError: invalid syntax
Something wrong before the "def". For example, CRLF line endings on UNIX.
Oleg. ---- Oleg Broytmann http://www.zope.org/Members/phd/ phd@phd.pp.ru Programmers don't die, they just GOSUB without RETURN.
You were right ... I typed in the few lines of code again (instead of copy/paste) and it added the external method without errors. Thinking of it I should have thought of that - copy/paste from browsers always fails for me :-) Thank you for the help ... Regards,
You should always test an external method to make sure it works before trying to use it in Zope. One easy way is to make the file self-testing: if __name__=='__main__': #place test code here # Run this file from the command line to perform the test. If you don't do this, you can't tell if you have a Zope problem or a Python problem. Cheers, Tom P [Gitte Wange] On Friday 06 July 2001 15:19, Oleg Broytmann wrote:
On Fri, 6 Jul 2001, Gitte Wange wrote:
File "monthRange.py", line 3 def monthRange(self,dt): ^ SyntaxError: invalid syntax
Something wrong before the "def". For example, CRLF line endings on UNIX.
Oleg. ---- Oleg Broytmann http://www.zope.org/Members/phd/ phd@phd.pp.ru Programmers don't die, they just GOSUB without RETURN.
You were right ... I typed in the few lines of code again (instead of copy/paste) and it added the external method without errors. Thinking of it I should have thought of that - copy/paste from browsers always fails for me :-)
Which version of python are you using? If you are using python 2.1 then from the command prompt if you debug line-by-line you get an error from DateTime/DateTime.py:90: DeprecationWarning: the regex module is deprecated; please use the re module import sys, os, math, regex, ts_regex, DateTimeZone /usr/local/lib/python2.1/regsub.py:15: DeprecationWarning: the regsub module is deprecated; please use re.sub() DeprecationWarning) perhaps this may be the problem Norman -----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Gitte Wange Sent: Friday, July 06, 2001 1:58 PM To: zope@zope.org Subject: [Zope] Adding an external method Hello, I am trying to add an external metod (used in a CMF Calendar example) but it fails. Now I'm not into these external methods (and I am not sure it's the best solution) but I just want to see how this example works. The method file is named monthRange.py and I have placed it in /usr/local/Zope/Extensions it contains this code: from DateTime import DateTime def monthRange( dt ): """ Return a pair of DateTime values representing the earliest and latest times in the month in which 'dt' falls. """ y, m, d = dt.year(), dt.month(), dt.day() first = DateTime( y, m, 1 ) last = first - 1 + DateTime._month_len[dt.isLeapYear() ][ m ] return first.earliestTime(), last.latestTime() I have filled in these values in the add form in ZMI: Id: monthRange Module Name: monthRange Function Name: monthRange I get this error when I try to add it: Error Type: SyntaxError Error Value: invalid syntax And this traceback: Traceback (innermost last): File /usr/local/Zope-2.3.2-linux2-x86/lib/python/ZPublisher/Publish.py, line 223, in publish_module File /usr/local/Zope-2.3.2-linux2-x86/lib/python/ZPublisher/Publish.py, line 187, in publish File /usr/local/Zope-2.3.2-linux2-x86/lib/python/Zope/__init__.py, line 221, in zpublisher_exception_hook File /usr/local/Zope-2.3.2-linux2-x86/lib/python/ZPublisher/Publish.py, line 171, in publish File /usr/local/Zope-2.3.2-linux2-x86/lib/python/ZPublisher/mapply.py, line 160, in mapply (Object: manage_addExternalMethod) File /usr/local/Zope-2.3.2-linux2-x86/lib/python/ZPublisher/Publish.py, line 112, in call_object (Object: manage_addExternalMethod) File /usr/local/Zope-2.3.2-linux2-x86/lib/python/Products/ExternalMethod/External Method.py, line 131, in manage_addExternalMethod File /usr/local/Zope-2.3.2-linux2-x86/lib/python/Products/ExternalMethod/External Method.py, line 179, in __init__ (Object: monthRange) File /usr/local/Zope-2.3.2-linux2-x86/lib/python/Products/ExternalMethod/External Method.py, line 202, in manage_edit (Object: monthRange) File /usr/local/Zope-2.3.2-linux2-x86/lib/python/Products/ExternalMethod/External Method.py, line 209, in getFunction (Object: monthRange) File /usr/local/Zope-2.3.2-linux2-x86/lib/python/App/Extensions.py, line 217, in getObject (Info: ('/usr/local/Zope-2.3.2-linux2-x86/Extensions/monthRange.py', 'monthRange')) SyntaxError: (see above) Well it looks like it finds the file. To me it looks like there is a syntax error in the add of the external method. or is the syntax error in the python code ? I haven't debugged this kind of scripts before so I hope there is someone who can help me :-) Regards, -- Gitte Wange Jensen Sys Admin, Developer and a lot more MMmanager.org Aps, Denmark Phone: +45 29 72 79 72 Email: gitte@mmmanager.org Web: www.mmmanager.org Quote of the day: Unix is user friendly; it's just a little paticular about which users it is friendly to. _______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
participants (5)
-
Gitte Wange -
Norman Khine -
Oleg Broytmann -
Thomas B. Passin -
Özgür Caner