Fix drag and drop to add files that contain the # character in the filename

This commit is contained in:
Kovid Goyal 2011-03-23 11:47:15 -06:00
parent a07fcf2fea
commit 1ccddbf41e

View File

@ -143,21 +143,27 @@ def dnd_has_extension(md, extensions):
urls = [unicode(u.toString()) for u in urls = [unicode(u.toString()) for u in
md.urls()] md.urls()]
purls = [urlparse(u) for u in urls] purls = [urlparse(u) for u in urls]
paths = [u2p(x) for x in purls]
if DEBUG: if DEBUG:
prints('URLS:', urls) prints('URLS:', urls)
prints('Paths:', [u2p(x) for x in purls]) prints('Paths:', paths)
exts = frozenset([posixpath.splitext(u.path)[1][1:].lower() for u in exts = frozenset([posixpath.splitext(u)[1][1:].lower() for u in
purls]) paths])
return bool(exts.intersection(frozenset(extensions))) return bool(exts.intersection(frozenset(extensions)))
return False return False
def _u2p(raw):
path = raw
if iswindows and path.startswith('/'):
path = path[1:]
return path.replace('/', os.sep)
def u2p(url): def u2p(url):
path = url.path path = url.path
if iswindows: ans = _u2p(path)
if path.startswith('/'): if not os.path.exists(ans):
path = path[1:] ans = _u2p(url.path + '#' + url.fragment)
ans = path.replace('/', os.sep)
if os.path.exists(ans): if os.path.exists(ans):
return ans return ans
# Try unquoting the URL # Try unquoting the URL