1
# -*- test-case-name: twisted.test.test_paths -*-
2
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
3
# See LICENSE for details.
11
def __init__(self, scheme='', netloc='localhost', path='',
12
query='', fragment=''):
13
self.scheme = scheme or 'http'
15
self.path = path or '/'
17
self.fragment = fragment
22
def pathList(self, unquote=0, copy=1):
23
if self._qpathlist is None:
24
self._qpathlist = self.path.split('/')
25
self._uqpathlist = map(urllib.unquote, self._qpathlist)
27
result = self._uqpathlist
29
result = self._qpathlist
35
def fromString(klass, st):
36
t = urlparse.urlsplit(st)
40
fromString = classmethod(fromString)
42
def fromRequest(klass, request):
43
return klass.fromString(request.prePathURL())
45
fromRequest = classmethod(fromRequest)
47
def _pathMod(self, newpathsegs, keepQuery):
52
return URLPath(self.scheme,
54
'/'.join(newpathsegs),
57
def sibling(self, path, keepQuery=0):
60
return self._pathMod(l, keepQuery)
62
def child(self, path, keepQuery=0):
68
return self._pathMod(l, keepQuery)
70
def parent(self, keepQuery=0):
75
# We are a file, such as http://example.com/foo/bar
76
# our parent directory is http://example.com/
79
return self._pathMod(l, keepQuery)
81
def here(self, keepQuery=0):
85
return self._pathMod(l, keepQuery)
88
"""Return a path which is the URL where a browser would presumably take
89
you if you clicked on a link with an HREF as given.
91
scheme, netloc, path, query, fragment = urlparse.urlsplit(st)
105
return URLPath(scheme,
114
x = urlparse.urlunsplit((
115
self.scheme, self.netloc, self.path,
116
self.query, self.fragment))
120
return ('URLPath(scheme=%r, netloc=%r, path=%r, query=%r, fragment=%r)'
121
% (self.scheme, self.netloc, self.path, self.query, self.fragment))