SyntaxErrors all over the place

Bug #175898 reported by Peter Bengtsson
2
Affects Status Importance Assigned to Milestone
RefreshNG
New
Undecided
Unassigned

Bug Description

Really uncertain how to report this bug but I'll try.
I'm trying to refresh a otherwise working fine product of mine which refreshes fine in zope 2.8.5. This time I'm trying the same product in zope 2.10.5.

The error I get looks something like this:

2007-12-12 16:31:04 INFO Refresh Refreshing product MExpenses
2007-12-12 16:31:04 ERROR Refresh Exception while refreshing MExpenses
Traceback (most recent call last):
  File "/home/peterbe/zope/zope2105/Products/RefreshNG/refresh.py", line 213, in performSafeRefresh
    if not performRefresh(jar, productid):
  File "/home/peterbe/zope/zope2105/Products/RefreshNG/refresh.py", line 175, in performRefresh
    r.reload()
  File "/home/peterbe/zope/zope2105/Products/RefreshNG/xreload.py", line 71, in reload
    code = compile(source, filename, "exec")
  File "/home/peterbe/zope/zope2105/Products/MExpenses/Configs.py", line 336

     ^
 SyntaxError: invalid syntax

There is no syntax error in that file. Line 336 is the very last line and it's blank.
Line 71 in xreload.py does this::

 code = compile(source, filename, "exec")

I injected this line just before to get a copy of the read source code:

 open('/tmp/%s' % os.path.basename(filename), 'w').write(source)
 code = compile(source, filename, "exec")

Running them from the /tmp directory with the same Python doesn't work because of the lack of other stuff but at least it doesn't raise a SyntaxError.

Any idea?

Revision history for this message
Peter Bengtsson (mail-peterbe) wrote : Solution!

The patch is dumb-easy but made all the difference. This is simply a standard Python "limitation":

peterbe@trillian:/tmp $ python2.4
Python 2.4.4 (#2, Apr 12 2007, 21:03:11)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> filename = 'UserCookies.py'
>>> source = open(filename).read()
>>> print str(repr(source))[-50:]
n self._del_usercookie(uid, key)\n '
>>> compile(source, filename, 'exec')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "UserCookies.py", line 29

SyntaxError: invalid syntax
>>> compile(source.strip()+'\n', filename, 'exec')
<code object ? at 0xb79ee120, file "UserCookies.py", line 1>

Revision history for this message
Christian Theune (ctheune) wrote : Re: [Bug 175898] Solution!

Interesting. Looks weird as a solution anyway. :/ I'll try to digg up
where this comes from really.

Am Freitag, den 14.12.2007, 16:05 +0000 schrieb peterbe:
> The patch is dumb-easy but made all the difference. This is simply a
> standard Python "limitation":
>
> peterbe@trillian:/tmp $ python2.4
> Python 2.4.4 (#2, Apr 12 2007, 21:03:11)
> [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> filename = 'UserCookies.py'
> >>> source = open(filename).read()
> >>> print str(repr(source))[-50:]
> n self._del_usercookie(uid, key)\n '
> >>> compile(source, filename, 'exec')
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "UserCookies.py", line 29
>
> SyntaxError: invalid syntax
> >>> compile(source.strip()+'\n', filename, 'exec')
> <code object ? at 0xb79ee120, file "UserCookies.py", line 1>
>
>
> ** Attachment added: "xreload.py.patch"
> http://launchpadlibrarian.net/10904139/xreload.py.patch
>
--
gocept gmbh & co. kg - forsterstrasse 29 - 06112 halle (saale) - germany
www.gocept.com - <email address hidden> - phone +49 345 122 9889 7 -
fax +49 345 122 9889 1 - zope and plone consulting and development

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.