From: Noel O'B. <no...@ca...> - 2005-11-07 09:12:01
Attachments:
mishandledfilenames.txt
|
Dear all, Please find attached a patch for the following problem: Problem: On Windows, if your user name contains an apostrophe, the use of temporary files causes an error, as gnuplot uses apropostrophes (i.e. single quotes) to delimit the filename. gnuplot> plot 'c:\docume~1\noelo'~1\locals~1\temp\tmpcxnwsm' notitle ^ invalid character Solution: If you replace the single quotes with double quotes, gnuplot is happy with the apostrophe but misinterprets the backslashes as escape character sequences. gnuplot> plot "c:\docume~1\noelo'~1\locals~1\temp\tmpcxnwsm" notitle ^ can't read data file "c:docume~1 oelo'~1locals~1 emp mpcxnwsm" ....so you need to also replace all of the backslashes with forward slashes. gnuplot> plot "c:/docume~1/noelo'~1/locals~1/temp/tmpcxnwsm" notitle **Success!!** Patch Attached: mishandledfilenames.txt |
From: Michael H. <mh...@al...> - 2005-11-07 11:14:48
|
Noel O'Boyle wrote: > Problem: > > On Windows, if your user name contains an apostrophe, the use of > temporary files causes an error, as gnuplot uses apropostrophes (i.e. > single quotes) to delimit the filename. > > gnuplot> plot 'c:\docume~1\noelo'~1\locals~1\temp\tmpcxnwsm' notitle > ^ > invalid character > > > Solution: > > If you replace the single quotes with double quotes, gnuplot is happy > with the apostrophe but misinterprets the backslashes as escape > character sequences. > > gnuplot> plot "c:\docume~1\noelo'~1\locals~1\temp\tmpcxnwsm" notitle > ^ > can't read data file "c:docume~1 > oelo'~1locals~1 emp mpcxnwsm" > > ....so you need to also replace all of the backslashes with forward > slashes. > > gnuplot> plot "c:/docume~1/noelo'~1/locals~1/temp/tmpcxnwsm" > notitle > > **Success!!** Hello, Thanks for the information and the patch. Won't your patch create new problems for filenames that contain double-quotes? Or is that somehow forbidden? What if a filename contains single-quotes *and* double-quotes? In other words, is there a way to solve this problem in such a way that it works for *all* legitimate Windows filenames? Regarding your specific proposed patch: 1. I think the conversion of filenames should happen via a call to the os-specific code. 2. string.replace() would be easier than an explicit loop. Michael |
From: Juho S. <juh...@as...> - 2005-11-07 12:14:47
|
On Mon, 7 Nov 2005, Noel O'Boyle wrote: >Problem: > >On Windows, if your user name contains an apostrophe, the use of >temporary files causes an error, as gnuplot uses apropostrophes (i.e. >single quotes) to delimit the filename. > >gnuplot> plot 'c:\docume~1\noelo'~1\locals~1\temp\tmpcxnwsm' notitle > ^ > invalid character > > >Solution: > >If you replace the single quotes with double quotes, gnuplot is happy >with the apostrophe but misinterprets the backslashes as escape >character sequences. > >gnuplot> plot "c:\docume~1\noelo'~1\locals~1\temp\tmpcxnwsm" notitle > ^ > can't read data file "c:docume~1 >oelo'~1locals~1 emp mpcxnwsm" > >....so you need to also replace all of the backslashes with forward >slashes. Or you could use raw strings: r"c:\docume~1\noelo'~1\locals~1\temp\tmpcxnwsm" So python treats \ in the string just like any other character. -- Juho Schultz e-mail: juh...@as... www.astro.helsinki.fi/~jschultz Observatory P.O. Box 14 FIN-00014 University of Helsinki FINLAND |
From: Michael H. <mh...@al...> - 2005-11-07 13:24:28
|
Juho Schultz wrote: > Or you could use raw strings: > > r"c:\docume~1\noelo'~1\locals~1\temp\tmpcxnwsm" > > So python treats \ in the string just like any other character. The problem isn't Python's string translation, it is gnuplot's. The situation is that there is a valid python string containing a filename, and that filename has to be passed to gnuplot quoted in such a way that gnuplot interprets it as the original string. For all characters except "'" (single-quote), simply single-quoting the string to gnuplot works. But there doesn't seem to be any way to pass a single quote to gnuplot within a single-quoted string (e.g., '\'' results in a two-character string containing "\" and "'"). So if we need to support filenames with single-quotes, we have to use gnuplot's double-quoted format. I think double-quoted strings should work OK, but we have to quote both '"' (double-quote) and "\" (backslash). It might not be necessary to handle double-quote for windows filenames, but we should handle it anyway for generality. Then, I believe, we could use the same quoting code for all operating systems. Michael |
From: Michael H. <mh...@al...> - 2005-11-07 21:17:23
|
Noel, Thanks again for the patch, and the additional information about allowed characters. It seems to me that *all* characters can get through if we use double-quoted strings and simply backslash-quote '"' and '\'. So I just added a function in the gp.py module called double_quote_string() that does just this, and use this method in the definitions of the two get_base_command_string() methods that return filenames. These changes are committed into the main branch of CVS. This seems to work under Linux. Would you please check whether they work under Windows, and whether you can see any other problems with this solution? Thanks, Michael Noel O'Boyle wrote: > On Windows, if your user name contains an apostrophe, the use of > temporary files causes an error, as gnuplot uses apropostrophes (i.e. > single quotes) to delimit the filename. |
From: Noel O'B. <no...@ca...> - 2005-11-09 14:01:54
|
On Mon, 2005-11-07 at 22:17 +0100, Michael Haggerty wrote: > Noel, > > Thanks again for the patch, and the additional information about allowed > characters. > > It seems to me that *all* characters can get through if we use > double-quoted strings and simply backslash-quote '"' and '\'. So I just > added a function in the gp.py module called double_quote_string() that > does just this, and use this method in the definitions of the two > get_base_command_string() methods that return filenames. These changes > are committed into the main branch of CVS. > > This seems to work under Linux. Would you please check whether they > work under Windows, and whether you can see any other problems with this > solution? I cannot see any problems with the fix and it works for me under windows. A big thanks on behalf of all people with funny characters in their name. Regards, Noel > Noel O'Boyle wrote: > > On Windows, if your user name contains an apostrophe, the use of > > temporary files causes an error, as gnuplot uses apropostrophes (i.e. > > single quotes) to delimit the filename. |