path_qs for swob.Request

Add path_qs property to swob.Request. First of all this property
has webob.Request, also this property can be used in swift3 middleware
for generate canonical string, if webob will be replaced in swift3 with
swob (2b36fbd477).

Change-Id: Idf58096baaf7830dd0d624ea6c72eda1eb91ff0d
This commit is contained in:
Victor Rodionov 2012-10-15 19:00:36 +04:00
parent bdafc29fd9
commit 22a8adfcb9
2 changed files with 16 additions and 0 deletions

View File

@ -688,6 +688,14 @@ class Request(object):
return self._params_cache
str_params = params
@property
def path_qs(self):
"""The path of the request, without host but with query string."""
path = self.path
if self.query_string:
path += '?' + self.query_string
return path
@property
def path(self):
"Provides the full path of the request, excluding the QUERY_STRING"

View File

@ -309,6 +309,14 @@ class TestRequest(unittest.TestCase):
req.accept.best_match(['text/plain', 'application/json']),
'application/json')
def test_path_qs(self):
req = swift.common.swob.Request.blank('/hi/there?hello=equal&acl')
self.assertEqual(req.path_qs, '/hi/there?hello=equal&acl')
req = swift.common.swob.Request({'PATH_INFO': '/hi/there',
'QUERY_STRING': 'hello=equal&acl'})
self.assertEqual(req.path_qs, '/hi/there?hello=equal&acl')
class TestStatusMap(unittest.TestCase):
def test_status_map(self):