#44 PSP compilation produces syntax error

closed
PSP (7)
5
2003-06-10
2003-05-29
No

When the .psp file is compiled to a .py servlet, the
__orig_file__ value is inserted, but no quoting is done
on the file path. On Windows, this can mean that the \s
in the file path are interpreted as escape sequences,
which could potentially be invalid, leading to a
ValueError when the servlet is imported.

Example:

PSP file c:\xtian\webware\PSP\Examples\index.psp

results in a .py servlet with the line

__orig_file__ = 'c:\xtian\webware\PSP\Examples\index.psp'

Since \x expects a two-digit hex number, \xti triggers
a ValueError.

A related problem can occur if the file has
single-quotes in its path - the generated line would be

__orig_file__ = 'c:\xtian's\webware\PSP\Examples\index.psp'

which is a syntax error.

Fix:
In Webware/PSP/ParseEventHandler.py at line 277, change:

self._writer.println("__orig_file__ = '%s'" %
self._ctxt.getFullPspFileName())

to

self._writer.println("__orig_file__ = %r" %
self._ctxt.getFullPspFileName())

so that the %r format specifier correctly handles \ and
' quoting.

Cheers!

Discussion

    • assigned_to: nobody --> jdhildeb
     
  • Logged In: YES
    user_id=173690

    Thanks for the report. I've applied the fix to CVS.

     
    • status: open --> closed
     
  • John Bradbury
    John Bradbury
    2004-10-30

    Logged In: YES
    user_id=1149282

    When I make this change I then get an error when trying to
    run the examples under windows. Does anyone else use
    webware with windows?

    File
    "D:\xitami\Webware-0.8.1\WebKit\Cache\PSP\_xitami_Webware_0_8_1_PSP_Examples_index_psp.py",
    line 7
    __orig_file__ =
    ''D:\\xitami\\Webware-0.8.1\\PSP\\Examples\\index.psp''
    ^
    SyntaxError: invalid syntax

     
  • Logged In: YES
    user_id=173690

    I don't see what's causing the syntax error, unless there is
    a newline after __orig_file__ =

    Can you confirm that this is the problem? If you're not
    sure, maybe attach the generated PSP servlet
    (D:\xitami\Webware-0.8.1\WebKit\Cache\PSP\_xitami_Webware_0_8_1_P
    SP_Examples_index_psp.py) to this bug report and I'll take a
    look.

     
  • John Bradbury
    John Bradbury
    2004-10-31

    Logged In: YES
    user_id=1149282

    There was no newline, it was inserted in my error report. I am
    new to webware and since submitting my report I have found a
    new version of ParseEventHandler.py (Revision: 1.19, Tue Jun 10
    08:53:04 2003 UTC (16 months, 3 weeks ago) by jdhildeb ) in the
    CVS section. When I run the PSP demos with that version I do
    not get any problems.

    Thank you for responding so quickly and I am sorry to have
    troubled you