Re: Spyce compiler newline sensitivity?
"Jonathan Ellis" <[email protected]>
| Newsgroups | gmane.comp.python.spyce.general |
|---|---|
| Message-ID | <[email protected]> |
Hi Philip,
the culprit was a long-standing bug in the handling of multiline string
constants. Change the findMultiLineQuote function in spyceCompile.py to
the following:
def findMultiLineQuote(s):
quotelist = []
def eatToken(type, string, begin, end, _, quotelist=quotelist):
if type == token.STRING:
if string.startswith('r"""') or string.startswith("r'''"):
quotelist.append((string, begin, end))
tokenize.tokenize(StringIO(s).readline, eatToken)
return quotelist
(I'll commit this to subversion as soon as sourceforge gets their server
back up. Grr.)
-J
On Wed, 31 May 2006 23:30:12 -0400, "Philip Semanchuk"
<[email protected]> said:
> Hi all,
> It's Philip with another weird problem. I use Spyce to generate Spyce
> code which has worked well up until this point. Today I found some code
> that causes the compilation step to exit ungracefully
> ("spyceSyntaxError: <unprintable instance object>"). What's really odd
> is that the code compiles OK if I save it in TextEdit (I'm on a Mac)
> and only fails to compile if I save it in BBEdit, which I use to save
> *all* of my Spyce, Python and HTML files and have not had a problem
> with up until this point. The files only differ in their newlines.
>
> Here's the code which has been stripped down to a minimal test case:
> [[\
> OpenBrackets = "[" * 2
> CloseBrackets = "]" * 2
>
> s = r"""
>
> %(OpenBrackets)s\
>
> if True == False:
> pass
>
> %(CloseBrackets)s
>
> """ % vars()
>
> ]]
>
>
> A hex dump of the files (compiling and non-compiling versions) shows
> that they're the same size, but the TextEdit version uses 0x0D as
> newlines and ends the file with 0x0D 0x0A, while the BBEdit version
> uses 0x0A as newlines and ends the file with 0x0A 0x0A.
>
> I created a tarball and a zip file (same contents in each) that contain
> the two versions of the code as well as a hex dump of each. Those files
> are here:
> http://semanchuk.com/philip/temp/SpyceNewlineCode.tar.gz
> http://semanchuk.com/philip/temp/SpyceNewlineCode.zip
>
> I'd appreciate it if anyone else would be willing to try to compile
> these files and report the results.
>
> Thanks
> Philip
>
>
> PS - here's the error I get with the version that fails to compile:
> $ /usr/local/spyce-2.0.3/spyceCmd.py -c CompileFails.spy
> cache miss for ('/usr/local/spyce-2.0.3/modules/error.py',
> 'defaultErrorTemplate')
> cache miss for ('/usr/local/spyce-2.0.3/tags/core.py', 'core')
> cache miss for ('/usr/local/spyce-2.0.3/tags/form.py', 'form')
> generating new spyceCode for test4.spy
> cache hit (1116524720) for core in /usr/local/spyce-2.0.3/tags/core.py
> cache hit (1115998066) for form in /usr/local/spyce-2.0.3/tags/form.py
> Traceback (most recent call last):
> File "/usr/local/spyce-2.0.3/spyceCmd.py", line 297, in spyceMain
> s = server.spyce_cache['file', script]
> File "/usr/local/spyce-2.0.3/spyceCache.py", line 145, in __getitem__
> return self.get(key)
> File "/usr/local/spyce-2.0.3/spyceCache.py", line 133, in get
> self.cache[key] = self.generate(key)
> File "/usr/local/spyce-2.0.3/spyce.py", line 819, in
> spyceCacheGenerate
> return {
> File "/usr/local/spyce-2.0.3/spyce.py", line 798, in
> spyceFileCacheGenerate
> s = spyceCode(code, filename=filename, sig=sig)
> File "/usr/local/spyce-2.0.3/spyce.py", line 492, in __init__
> self._code, self._coderefs, self._modrefs = \
> File "/usr/local/spyce-2.0.3/spyceCompile.py", line 1437, in
> spyceCompile
> refs = emitPython(out, bracedPythonCode, refs)
> File "/usr/local/spyce-2.0.3/spyceCompile.py", line 1384, in
> emitPython
> tokenize.tokenize(StringIO(bracedPythonCode).readline, eatToken)
> File
> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
> python2.3/tokenize.py", line 153, in tokenize
> tokenize_loop(readline, tokeneater)
> File
> "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
> python2.3/tokenize.py", line 160, in tokenize_loop
> tokeneater(*token_info)
> File "/usr/local/spyce-2.0.3/spyceCompile.py", line 1382, in eatToken
> raise spyceException.spyceSyntaxError(sys.exc_info()[0])
> spyceSyntaxError: <unprintable instance object>
>
>
>
>
> -------------------------------------------------------
> All the advantages of Linux Managed Hosting--Without the Cost and Risk!
> Fully trained technicians. The highest number of Red Hat certifications
> in
> the hosting industry. Fanatical Support. Click to learn more
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
> _______________________________________________
> Spyce-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/spyce-users
--
C++ is history repeated as tragedy. Java is history repeated as farce. --Scott McKay
-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642