Skip to content

Commit

Permalink
get os.path.relpath working for py25
Browse files Browse the repository at this point in the history
  • Loading branch information
Dane committed Nov 2, 2010
1 parent 1325e5e commit ce74a64
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions cascadenik/compile.py
Expand Up @@ -18,11 +18,26 @@
from urlparse import urlparse, urljoin
from operator import lt, le, eq, ge, gt

# os.path.relpath was added in Python 2.6
def _relpath(path, start=posixpath.curdir):
"""Return a relative version of a path"""
if not path:
raise ValueError("no path specified")
start_list = posixpath.abspath(start).split(posixpath.sep)
path_list = posixpath.abspath(path).split(posixpath.sep)
i = len(posixpath.commonprefix([start_list, path_list]))
rel_list = [posixpath.pardir] * (len(start_list)-i) + path_list[i:]
if not rel_list:
return posixpath.curdir
return posixpath.join(*rel_list)

# timeout parameter to HTTPConnection was added in Python 2.6
if sys.hexversion >= 0x020600F0:
from httplib import HTTPConnection

else:
posixpath.relpath = _relpath

from httplib import HTTPConnection as _HTTPConnection
import socket

Expand All @@ -31,6 +46,8 @@ def HTTPConnection(host, port=None, strict=None, timeout=None):
socket.setdefaulttimeout(timeout)
return _HTTPConnection(host, port=port, strict=strict)



# cascadenik
import safe64
import style
Expand Down Expand Up @@ -153,9 +170,8 @@ def output_path(self, path_name):
assert (path == path_name), "path_name passed to output_path must be in posix format"

if posixpath.isabs(path):
if self.output == self.cache and sys.hexversion >= 0x020600F0:
if self.output == self.cache:
# worth seeing if an absolute path can be avoided
# only python 2.6 has relpath function
path = posixpath.relpath(path, self.output)

else:
Expand Down

0 comments on commit ce74a64

Please sign in to comment.