Commit f31b3dd7 authored by Lars Kruse's avatar Lars Kruse

improve handling of filename URI

* Windows: use "urllib.url2pathname" instead of manual decoding
* non-Windows: use "urllib.url2pathname" instead of doing nothing

Filenames including whitespace or special characters can now be used
with the RecentChooserMenu ("recently used model files").
parent af1fe18e
...@@ -143,12 +143,12 @@ class URIHandler(object): ...@@ -143,12 +143,12 @@ class URIHandler(object):
return None return None
def get_path(self): def get_path(self):
encoded_path = self._uri.path
if get_platform() == PLATFORM_WINDOWS: if get_platform() == PLATFORM_WINDOWS:
text = self._uri.netloc + self._uri.path # prepend "netloc" (the drive letter - e.g. "c:")
text = text.lstrip("/").replace("/", "\\") encoded_path = self._uri.netloc + encoded_path
return re.sub("%([0-9a-fA-F]{2})", lambda token: chr(int(token.groups()[0], 16)), text) # decode all special characters like "%20" and replace "/" with "\\" (Windows)
else: return urllib.url2pathname(encoded_path)
return self._uri.path
def get_url(self): def get_url(self):
return self._uri.geturl() return self._uri.geturl()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment