From 6ebd0b0a7777392962f00a1cdeeec5e1e83a0cb7 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Wed, 6 May 2009 13:11:31 +0000 Subject: [PATCH] Added two methods: parse_path and get_full_path, but the Url class will need to be enhanced and refined to be more useful for web development svn: r12506 --- src/gen/lib/url.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/gen/lib/url.py b/src/gen/lib/url.py index 1050d57d1..df5896e87 100644 --- a/src/gen/lib/url.py +++ b/src/gen/lib/url.py @@ -2,6 +2,7 @@ # Gramps - a GTK+/GNOME based genealogy program # # Copyright (C) 2000-2006 Donald N. Allingham +# Copyright (C) 2009 Douglas S. Blank # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -30,6 +31,7 @@ Url class for GRAMPS. # #------------------------------------------------------------------------- from warnings import warn +from urlparse import urlparse #------------------------------------------------------------------------- # @@ -115,3 +117,29 @@ class Url(SecondaryObject, PrivacyBase): warn( "Use is_equal instead of are_equal", DeprecationWarning, 2) return self.is_equal(other) + + def parse_path(self): + """ + Returns a 6 tuple-based object with the following items: + + Property Pos Meaning + -------- --- --------------------------------- + scheme 0 URL scheme specifier + netloc 1 Network location part + path 2 Hierarchical path + params 3 Parameters for last path element + query 4 Query component + fragment 5 Fragment identifier + """ + return urlparse(self.path) + + def get_full_path(self): + """ + Returns a full url, complete with scheme, even if missing from path. + """ + if self.type == UrlType.EMAIL and not self.path.startswith("mailto:"): + return "mailto:" + self.path + elif url.get_type() == UrlType.WEB_FTP and not self.path.startswith("ftp://"): + return "ftp://" + self.path + else: + return self.path