/usr/lib/python2.7/dist-packages/betamax/matchers/uri.py is in python-betamax 0.5.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | # -*- coding: utf-8 -*-
from .base import BaseMatcher
from .query import QueryMatcher
from requests.compat import urlparse
class URIMatcher(BaseMatcher):
# Matches based on the uri of the request
name = 'uri'
def on_init(self):
# Get something we can use to match query strings with
self.query_matcher = QueryMatcher().match
def match(self, request, recorded_request):
queries_match = self.query_matcher(request, recorded_request)
request_url, recorded_url = request.url, recorded_request['uri']
return self.all_equal(request_url, recorded_url) and queries_match
def parse(self, uri):
parsed = urlparse(uri)
return {
'scheme': parsed.scheme,
'netloc': parsed.netloc,
'path': parsed.path,
'fragment': parsed.fragment
}
def all_equal(self, new_uri, recorded_uri):
new_parsed = self.parse(new_uri)
recorded_parsed = self.parse(recorded_uri)
return (new_parsed == recorded_parsed)
|