Windows file paths, again

Dan Guido dguido at gmail.com
Wed Oct 21 16:21:04 EDT 2009


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.

--
Dan Guido



On Wed, Oct 21, 2009 at 3:50 PM, Anthony Tolle <anthony.tolle at gmail.com> wrote:
> On Oct 21, 3:20 pm, Dan Guido <dgu... at gmail.com> wrote:
>> Hi Diez,
>>
>> The source of the string literals is ConfigParser, so I can't just
>> mark them with an 'r'.
>>
>> config = ConfigParser.RawConfigParser()
>> config.read(filename)
>> crazyfilepath = config.get(name, "ImagePath")
>> normalfilepath = normalize_path(crazyfilepath)
>>
>> The ultimate origin of the strings is the _winreg function. Here I
>> also can't mark them with an 'r'.
>>
>> regkey = OpenKey(HKEY_LOCAL_MACHINE,
>> "SYSTEM\\CurrentControlSet\\Services\\" + name)
>> crazyimagepath = QueryValueEx(regkey, "ImagePath")[0]
>> CloseKey(key)
>>
>> --
>> Dan Guido
>>
>
> I just did a quick test using Python 2.5.1 with the following script
> on Windows:
>
> # start of test.py
> import ConfigParser
> config = ConfigParser.RawConfigParser()
> config.read("cfg.ini")
> x = config.get("foo", "bar")
> print x
> print repr(x)
> from _winreg import *
> regkey = OpenKey(HKEY_LOCAL_MACHINE,
> r"SYSTEM\CurrentControlSet\Services\IPSec")
> x = QueryValueEx(regkey, "ImagePath")[0]
> CloseKey(regkey)
> print x
> print repr(x)
> # end of test.py
>
>
> Here is the contesnts of cfg.ini:
>
> [foo]
> bar=c:\dir\file.txt
>
>
> Here is the output of the script:
>
> c:\dir\file.txt
> 'c:\\dir\\file.txt'
> system32\DRIVERS\ipsec.sys
> u'system32\\DRIVERS\\ipsec.sys'
>
>
> In either case, I don't see the functions returning strings that
> requires special handling.  The backslashes are properly escaped in
> the repr of both strings.
>
> Something else must be going on if the strings are getting messed up
> along the way.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list