Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance by caching urlparse #655

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions vcr/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Request:
def __init__(self, method, uri, body, headers):
self.method = method
self.uri = uri
self.parsed_uri = urlparse(self.uri)
self._was_file = hasattr(body, "read")
if self._was_file:
self.body = body.read()
Expand Down Expand Up @@ -52,30 +53,29 @@ def add_header(self, key, value):

@property
def scheme(self):
return urlparse(self.uri).scheme
return self.parsed_uri.scheme

@property
def host(self):
return urlparse(self.uri).hostname
return self.parsed_uri.hostname

@property
def port(self):
parse_uri = urlparse(self.uri)
port = parse_uri.port
port = self.parsed_uri.port
if port is None:
try:
port = {"https": 443, "http": 80}[parse_uri.scheme]
port = {"https": 443, "http": 80}[self.parsed_uri.scheme]
except KeyError:
pass
return port

@property
def path(self):
return urlparse(self.uri).path
return self.parsed_uri.path

@property
def query(self):
q = urlparse(self.uri).query
q = self.parsed_uri.query
return sorted(parse_qsl(q))

# alias for backwards compatibility
Expand Down