Skip to content

Commit

Permalink
Merge pull request #527 from kgriffs/optimize-datetime
Browse files Browse the repository at this point in the history
perf(Request): Remove extra datetime namespace lookup
  • Loading branch information
kgriffs committed Apr 22, 2015
2 parents c542ef6 + a0a639d commit 2e84286
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions falcon/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
_maybe_wrap_wsgi_stream = True


# PERF(kgriffs): Avoid an extra namespace lookup when using these functions
strptime = datetime.strptime
now = datetime.now


class Request(object):
"""Represents a client's HTTP request.
Expand Down Expand Up @@ -928,7 +933,7 @@ def get_param_as_date(self, name, format_string='%Y-%m-%d',
return None

try:
date = datetime.strptime(param_value, format_string).date()
date = strptime(param_value, format_string).date()
except ValueError:
msg = "The date value does not match the required format"
raise HTTPInvalidParam(msg, name)
Expand Down Expand Up @@ -958,8 +963,7 @@ def log_error(self, message): # pragma: no cover

log_line = (
DEFAULT_ERROR_LOG_FORMAT.
format(datetime.now(), self.method, self.path,
query_string_formatted)
format(now(), self.method, self.path, query_string_formatted)
)

if six.PY3:
Expand Down

0 comments on commit 2e84286

Please sign in to comment.