Here's how DanC's code does them: >>> import uripath >>> print uripath.join.__doc__ join an absolute URI and URI reference here must be an absolute URI. there must be a URI reference Raise ValueError if there uses relative path syntax but here has no hierarchical path. >>> #EASY: ... uripath.join("http://example.org/dir/file", "../relfile") 'http://example.org/relfile' >>> uripath.join("http://example.org/dir/file", "/absfile") 'http://example.org/absfile' >>> uripath.join("http://example.org/dir/file", "//another.example.org/absfile") 'http://another.example.org/absfile' >>> >>> #GETTING HARDER: ... uripath.join("http://example.org/dir/file", "../../../relfile") 'http://example.org/relfile' >>> uripath.join("http://example.org/dir/file", "") 'http://example.org/dir/file' >>> uripath.join("http://example.org/dir/file", "#frag") 'http://example.org/dir/file#frag' >>> >>> #MASTER CLASS: ... uripath.join("http://example.org", "relfile") 'http://example.org/relfile' >>> >>> uripath.join("http://example.org/dir/file#frag", "relfile") Traceback (most recent call last): File "<stdin>", line 1, in ? File "uripath.py", line 61, in join assert(find(here, "#") < 0) # caller must splitFrag AssertionError >>> uripath.join("http://example.org/dir/file#frag", "#foo") Traceback (most recent call last): File "<stdin>", line 1, in ? File "uripath.py", line 61, in join assert(find(here, "#") < 0) # caller must splitFrag AssertionError >>> uripath.join("http://example.org/dir/file#frag", "") Traceback (most recent call last): File "<stdin>", line 1, in ? File "uripath.py", line 61, in join assert(find(here, "#") < 0) # caller must splitFrag AssertionError >>> >>> uripath.join("mailto:Jeremy_Carroll@hp.com", "#foo") Traceback (most recent call last): File "<stdin>", line 1, in ? File "uripath.py", line 75, in join raise ValueError, here ValueError: mailto:Jeremy_Carroll@hp.com >>> uripath.join("mailto:Jeremy_Carroll@hp.com", "") Traceback (most recent call last): File "<stdin>", line 1, in ? File "uripath.py", line 75, in join raise ValueError, here ValueError: mailto:Jeremy_Carroll@hp.com >>> uripath.join("mailto:Jeremy_Carroll@hp.com", "relfile") Traceback (most recent call last): File "<stdin>", line 1, in ? File "uripath.py", line 75, in join raise ValueError, here ValueError: mailto:Jeremy_Carroll@hp.com Here's the code I used: import uripath #EASY: uripath.join("http://example.org/dir/file", "../relfile") uripath.join("http://example.org/dir/file", "/absfile") uripath.join("http://example.org/dir/file", "//another.example.org/absfile") #GETTING HARDER: uripath.join("http://example.org/dir/file", "../../../relfile") uripath.join("http://example.org/dir/file", "") uripath.join("http://example.org/dir/file", "#frag") #MASTER CLASS: uripath.join("http://example.org", "relfile") uripath.join("http://example.org/dir/file#frag", "relfile") uripath.join("http://example.org/dir/file#frag", "#foo") uripath.join("http://example.org/dir/file#frag", "") uripath.join("mailto:Jeremy_Carroll@hp.com", "#foo") uripath.join("mailto:Jeremy_Carroll@hp.com", "") uripath.join("mailto:Jeremy_Carroll@hp.com", "relfile") All the best, -- [ "Aaron Swartz" ; <mailto:me@aaronsw.com> ; <http://www.aaronsw.com/> ]Received on Friday, 22 March 2002 15:11:20 EST
This archive was generated by hypermail pre-2.1.9 : Wednesday, 3 September 2003 09:46:21 EDT