4Suite API Documentation

Module Ft.Rdf.ThirdParty.n3p.uripath

Uniform Resource Identifier (URI) path manipulation, above the access layer
The name of this module and the functions are somewhat
arbitrary; they hark to other parts of the python
library; e.g. uripath.join() is somewhat like os.path.join().

REFERENCES

  Uniform Resource Identifiers (URI): Generic Syntax
  http://www.ietf.org/rfc/rfc2396.txt

  The Web Model: Information hiding and URI syntax (Jan 98)
  http://www.w3.org/DesignIssues/Model.html

  URI API design [was: URI Test Suite] Dan Connolly (Sun, Aug 12 2001)
  http://lists.w3.org/Archives/Public/uri/2001Aug/0021.html
Classes:
Functions:
Globals:

Classes

class Tests(unittest.TestCase)

Methods

testPaths(self)
testRFCCases(self)
testSplit(self)

Methods inherited from class unittest.TestCase

__call__, __init__, __repr__, __str__, assertAlmostEqual, assertAlmostEquals, assertEqual, assertEquals, assertNotAlmostEqual, assertNotAlmostEquals, assertNotEqual, assertNotEquals, assertRaises, assert_, countTestCases, debug, defaultTestResult, fail, failIf, failIfAlmostEqual, failIfEqual, failUnless, failUnlessAlmostEqual, failUnlessEqual, failUnlessRaises, id, run, setUp, shortDescription, tearDown

Methods inherited from class object

__delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__

Members inherited from class unittest.TestCase

__dict__, __weakref__, failureException

Members inherited from class object

__class__

Functions

base()
The base URI for this process - the Web equiv of cwd
Relative or abolute unix-standard filenames parsed relative to
this yeild the URI of the file.
If we had a reliable way of getting a computer name,
we should put it in the hostname just to prevent ambiguity
join(here, there)
join an absolute URI and URI reference (non-ascii characters are supported/doctested; haven't checked the details of the IRI spec though)
here is assumed to be absolute.
there is URI reference.

>>> join('http://example/x/y/z', '../abc')
'http://example/x/abc'

Raise ValueError if there uses relative path
syntax but here has no hierarchical path.

>>> join('mid:foo@example', '../foo')
Traceback (most recent call last):
    raise ValueError, here
ValueError: Base <mid:foo@example> has no slash after colon - with relative '../foo'.


We grok IRIs

>>> len(u'Andr\xe9')
5

>>> join('http://example.org/', u'#Andr\xe9')
u'http://example.org/#Andr\xe9'
refTo(base, uri)
figure out a relative URI reference from base to uri
>>> refTo('http://example/x/y/z', 'http://example/x/abc')
'../abc'

>>> refTo('file:/ex/x/y', 'file:/ex/x/q/r#s')
'q/r#s'

>>> refTo(None, 'http://ex/x/y')
'http://ex/x/y'

>>> refTo('http://ex/x/y', 'http://ex/x/y')
''

Note the relationship between refTo and join:
join(x, refTo(x, y)) == y
which points out certain strings which cannot be URIs. e.g.
>>> x='http://ex/x/y';y='http://ex/x/q:r';join(x, refTo(x, y)) == y
0

So 'http://ex/x/q:r' is not a URI. Use 'http://ex/x/q%3ar' instead:
>>> x='http://ex/x/y';y='http://ex/x/q%3ar';join(x, refTo(x, y)) == y
1

This one checks that it uses a root-realtive one where that is
all they share.  Now uses root-relative where no path is shared.
This is a matter of taste but tends to give more resilience IMHO
-- and shorter paths

Note that base may be None, meaning no base.  In some situations, there
just ain't a base. Slife. In these cases, relTo returns the absolute value.
The axiom abs(,rel(b,x))=x still holds.
This saves people having to set the base to "bogus:".

>>> refTo('http://ex/x/y/z', 'http://ex/r')
'/r'
splitFrag(uriref)
split a URI reference between the fragment and the rest.
Punctuation is thrown away.

e.g.

>>> splitFrag("abc#def")
('abc', 'def')

>>> splitFrag("abcdef")
('abcdef', None)
splitFragP(uriref, punct=0)
split a URI reference before the fragment
Punctuation is kept.

e.g.

>>> splitFragP("abc#def")
('abc', '#def')

>>> splitFragP("abcdef")
('abcdef', '')

Globals

commonHost = <_sre.SRE_Pattern object>