[pitivi/ges: 204/287] Make quote_uri bulletproof and RFC 2396 compliant
- From: Jean-FranÃois Fortin Tam <jfft src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi/ges: 204/287] Make quote_uri bulletproof and RFC 2396 compliant
- Date: Thu, 15 Mar 2012 16:42:59 +0000 (UTC)
commit 298a23ae251d8a15053ba693c01e8924c7af3b4c
Author: Jean-FranÃois Fortin Tam <nekohayo gmail com>
Date: Wed Jan 11 11:56:42 2012 -0500
Make quote_uri bulletproof and RFC 2396 compliant
This prevents duplicating clips by dnd in the Media Library,
and also allows getting thumbnail hashes with perfect accuracy.
pitivi/medialibrary.py | 7 +++++--
pitivi/utils/misc.py | 13 ++++++++++++-
pitivi/utils/ui.py | 1 +
3 files changed, 18 insertions(+), 3 deletions(-)
---
diff --git a/pitivi/medialibrary.py b/pitivi/medialibrary.py
index 0fcb0f0..a8850c8 100644
--- a/pitivi/medialibrary.py
+++ b/pitivi/medialibrary.py
@@ -161,6 +161,10 @@ class MediaLibrary(Signallable, Loggable):
The uri will be analyzed before being added.
"""
+ # Ensure we really have a correctly encoded URI according to RFC 2396.
+ # Otherwise, in some cases we'd get rogue characters that break
+ # searching for duplicates
+ uri = quote_uri(uri)
if uri in self._sources:
# uri is already added. Nothing to do.
return
@@ -220,8 +224,7 @@ class MediaLibrary(Signallable, Loggable):
"""
uri = info.get_uri()
if self._sources.get(uri, None) is not None:
- raise MediaLibraryError("We already have a info for this URI",
- uri)
+ raise MediaLibraryError("We already have info for this URI", uri)
self._sources[uri] = info
self._ordered_sources.append(info)
self.nb_imported_files += 1
diff --git a/pitivi/utils/misc.py b/pitivi/utils/misc.py
index f367c12..dfb5c88 100644
--- a/pitivi/utils/misc.py
+++ b/pitivi/utils/misc.py
@@ -135,8 +135,19 @@ def get_filesystem_encoding():
def quote_uri(uri):
+ """
+ Encode a URI according to RFC 2396, without touching the file:/// part.
+ """
parts = list(urlsplit(uri, allow_fragments=False))
- parts[2] = quote(parts[2])
+ # Make absolutely sure the string is unquoted before quoting again!
+ raw = unquote(parts[2])
+ # For computing thumbnail md5 hashes in the source list, we must adhere to
+ # RFC 2396. However, urllib's quote method only uses alphanumeric and "/"
+ # as their safe chars. We need to add both the reserved and unreserved chars
+ RFC_2396_RESERVED = ";/?:@&=+$,"
+ RFC_2396_UNRESERVED = "-_.!~*'()"
+ URIC_SAFE_CHARS = "/" + "%" + RFC_2396_RESERVED + RFC_2396_UNRESERVED
+ parts[2] = quote(raw, URIC_SAFE_CHARS)
uri = urlunsplit(parts)
return uri
diff --git a/pitivi/utils/ui.py b/pitivi/utils/ui.py
index 0de63c9..1510843 100644
--- a/pitivi/utils/ui.py
+++ b/pitivi/utils/ui.py
@@ -179,6 +179,7 @@ def beautify_info(info):
def info_name(info):
+ """Return a human-readable filename (without the path and quoting)."""
return escape(unquote(os.path.basename(info.get_uri())))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]