durusmail: quixote-users: Syntax error if .ptl ends with whitespaces
Syntax error if .ptl ends with whitespaces
2004-07-06
2004-07-06
Re: Syntax error if .ptl ends with whitespaces
2004-07-06
Re: R: [Quixote-users] Syntax error if .ptl ends with whitespaces
Syntax error if .ptl ends with whitespaces
Daniele Varrazzo
2004-07-06
> On Tue, Jul 06, 2004 at 12:57:42PM +0200, Daniele Varrazzo wrote:
> > As i reported some days ago, any ptl file that ends up with any
> whitespace
> > after the last cr/lf doesn't compile and issue a SyntaxError.
>
>    I didn't get such an error. Are tou sure the problem is really in the
> whitespaces? May be you have forgotten to close a triple-quote, or
> paren, or such?

I'm sure i didn't. I never met such error in 0.7a3: it shows with 1.0c1,
also with previously well-compiled files. Removing the extra whitespaces is
enough to have them back to work.

To reproduce the error is enough to add any whitespace after the last CR/LF
in demo/pages.ptl in the Quixote distribution: it fails compiling. A copy of
the full traceback is at the end of this message.

Notice that adding 4 or more whitespaces i obtain:

  File "C:\PROGRA~1\Python23\lib\site-packages\quixote\demo\pages.ptl", line
88



    ^

SyntaxError: invalid syntax (line 88)

....but adding 3 or less the traceback ends with:

  File "C:\PROGRA~1\Python23\lib\site-packages\quixote\demo\pages.ptl", line
88



    ^

SyntaxError: unindent does not match any outer indentation level (line 88)


....whick makes me think the last row is interpreted as an instruction also
if it's not blank but made up with whitespaces, just like a:
def x():
    pass
   pass

I have no experience in ptl compiler internals, so i'm likely to be wrong
about that.

There is no problem with the presence of any whitespace in the blank lines
before the last non-blank.

> > Am i wrong? I tried with Python 2.3.4 and quixote 1.0c1 over win32. I
> > currently read the mailing list: did i miss the point?
>
>    Python 2.3.4, quixote 0.7a3, Debian GNU/Linux.
>
As i said, what used to work in 0.7a3 doesn't work anymore in 1.0c1: just a
matter of whitespaces on the last (blank) line. I doesn't look like a win32
issue anyway. I never tried any intermediate versions since Python 2.2 +
Quixote 0.7a3.

Regards

Daniele

P.S. The full traceback of a compile error due to 4 whitespaces in the last
line:

Mod_python error: "PythonHandler quixote.mod_python_handler"

Traceback (most recent call last):

  File "C:\PROGRA~1\Python23\Lib\site-packages\mod_python\apache.py", line
299, in HandlerDispatch
    result = object(req)

  File
"C:\Programmi\Python23\Lib\site-packages\quixote\mod_python_handler.py",
line 79, in handler
    pub = ModPythonPublisher(package, config)

  File
"C:\Programmi\Python23\Lib\site-packages\quixote\mod_python_handler.py",
line 26, in __init__
    Publisher.__init__(self, package, config)

  File "C:\Programmi\Python23\Lib\site-packages\quixote\publish.py", line
107, in __init__
    self.root_namespace = _get_module(root_namespace)

  File "C:\Programmi\Python23\Lib\site-packages\quixote\publish.py", line
32, in _get_module
    __import__(name)

  File "C:\PROGRA~1\Python23\Lib\ihooks.py", line 399, in import_module
    m = self.load_tail(q, tail)

  File "C:\PROGRA~1\Python23\Lib\ihooks.py", line 450, in load_tail
    m = self.import_it(head, mname, m)

  File "C:\PROGRA~1\Python23\Lib\ihooks.py", line 489, in import_it
    m = self.loader.load_module(fqname, stuff)

  File "C:\Programmi\Python23\Lib\site-packages\quixote\ptl_import.py", line
111, in load_module
    return ihooks.ModuleLoader.load_module( self, name, stuff)

  File "C:\PROGRA~1\Python23\Lib\ihooks.py", line 274, in load_module
    m = self.hooks.load_package(name, filename, file)

  File "C:\PROGRA~1\Python23\Lib\ihooks.py", line 174, in load_package
    return imp.load_module(name, file, filename, ("", "", PKG_DIRECTORY))

  File "C:\Programmi\Python23\Lib\site-packages\quixote\demo\__init__.py",
line 7, in ?
    from quixote.demo.pages import _q_index, _q_exception_handler, dumpreq

  File "C:\PROGRA~1\Python23\Lib\ihooks.py", line 399, in import_module
    m = self.load_tail(q, tail)

  File "C:\PROGRA~1\Python23\Lib\ihooks.py", line 450, in load_tail
    m = self.import_it(head, mname, m)

  File "C:\PROGRA~1\Python23\Lib\ihooks.py", line 489, in import_it
    m = self.loader.load_module(fqname, stuff)

  File "C:\Programmi\Python23\Lib\site-packages\quixote\ptl_import.py", line
107, in load_module
    return _load_ptl(name, filename, file)

  File "C:\Programmi\Python23\Lib\site-packages\quixote\ptl_import.py", line
72, in _load_ptl
    code = compile_template(file, filename, output)

  File "C:\Programmi\Python23\Lib\site-packages\quixote\ptl_compile.py",
line 286, in compile_template
    template.compile()

  File "C:\PROGRA~1\Python23\Lib\compiler\pycodegen.py", line 111, in
compile
    tree = self._get_tree()

  File "C:\Programmi\Python23\Lib\site-packages\quixote\ptl_compile.py",
line 257, in _get_tree
    tree = parse(self.source, self.filename)

  File "C:\Programmi\Python23\Lib\site-packages\quixote\ptl_compile.py",
line 215, in parse
    raise SyntaxError(str(e), (filename, e.lineno, e.offset, e.text))

  File "C:\PROGRA~1\Python23\lib\site-packages\quixote\demo\pages.ptl", line
88



    ^

SyntaxError: invalid syntax (line 88)


reply