Package pythonutils :: Module urlpath
[hide private]
[frames] | no frames]

Module urlpath
source code

Functions [hide private]
  pathjoin(base, *paths)
Join paths to a base, observing pardir.
  nativejoin(base, path)
Joins two paths - returning a native file path.
  relpathto(thisdir, origin, dest)
Given two paths relative to a directory, work out a path from origin to destination.
  relpath(origin, dest)
Given two absolute paths, work out a path from origin to destination.
  tslash(apath)
Add a trailing slash to a path if it needs one.
  testJoin()
  testRelpathto()
  testRelpathto2()
  testRelpath()

Imports: posixpath, os, urllib.url2pathname, urllib.pathname2url

Function Details [hide private]

pathjoin(base, *paths)

source code 

Join paths to a base, observing pardir.

If base doesn't end with '/' we assume it's a file rather than a directory.
(so we get rid of it)

nativejoin(base, path)

source code 

Joins two paths - returning a native file path.

Given a base path and a relative location, (in posix format) return a file path in a (relatively) OS native way.

relpathto(thisdir, origin, dest)

source code 

Given two paths relative to a directory, work out a path from origin to destination.

Assumes UNIX/URL type relative paths. If origin doesn't end with '/' we assume it's a file rather than a directory.

If the same paths are passed in :
if the path ends with ('/') then we return '' else we return the last part of the path (presumably a filename)
If thisdir doesn't start with '/' then we add one
(this makes the top level of thisdir our root directory)

relpath(origin, dest)

source code 

Given two absolute paths, work out a path from origin to destination.

Assumes UNIX/URL type relative paths. If origin doesn't end with '/' we assume it's a file rather than a directory.

If the same paths are passed in :
if the path ends with ('/') then we return '' else we return the last part of the path (presumably a filename)

If origin or dest don't start with '/' then we add it.

We are assuming relative paths on the same device
(i.e. same top level directory)

tslash(apath)

source code 

Add a trailing slash to a path if it needs one.

Doesn't use os.sep because you end up jiggered on windoze - when you want separators for URLs.

testJoin()

source code 

testRelpathto()

source code 

testRelpathto2()

source code 

testRelpath()

source code