Windows file paths, again

Dan Guido dguido at gmail.com
Wed Oct 21 22:58:22 CEST 2009


I'm writing a test case right now, will update in a few minutes :-).
I'm using Python 2.6.x

I need to read these values in from a configparser file or the windows
registry and get MD5 sums of the actual files on the filesystem and
copy the files to a new location. The open() method completely barfs
if I don't normalize the paths to the files first. I'll show the list,
just give me a little bit more time to separate the code from my
project that demonstrates this bug.
--
Dan Guido



On Wed, Oct 21, 2009 at 4:49 PM, Lie Ryan <lie.1296 at gmail.com> wrote:
> Dan Guido wrote:
>>
>> Hi Anthony,
>>
>> Thanks for your reply, but I don't think your tests have any control
>> characters in them. Try again with a \v, a \n, or a \x in your input
>> and I think you'll find it doesn't work as expected.
>
> A path read from a file, config file, or winreg would never contain control
> characters unless they contains that a control character.
>
> My crystal ball thinks that you used eval or exec somewhere in your script,
> which may cause a perfectly escaped path to get unescaped, like here:
>
> # python 3
> path = 'C:\\path\\to\\somewhere.txt'
> script = 'open("%s")' % path    # this calls str(path)
> exec(script)
>
> OR
>
> you stored the path incorrectly. Try seeing what exactly is stored in the
> registry using regedit.
>
>
>
> Remember that escape characters doesn't really exist in the in-memory
> representation of the string. The escape characters exist only in string
> literals (i.e. source code) and when you print the string using repr().
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list