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

Adapt istr #1015

Merged
merged 14 commits into from
Jul 29, 2016
Prev Previous commit
Next Next commit
Fix helpers tests
  • Loading branch information
asvetlov committed Jul 29, 2016
commit 468178c61b87ac95c370197be752e64048bfcd39
10 changes: 6 additions & 4 deletions aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from pathlib import Path
from urllib.parse import quote, urlencode, urlsplit

from multidict import istr, MultiDict, MultiDictProxy
from multidict import MultiDict, MultiDictProxy

from . import hdrs
from .abc import AbstractCookieJar
Expand Down Expand Up @@ -329,17 +329,19 @@ def compile_format(self, log_format):

@staticmethod
def _format_e(key, args):
return (args[1] or {}).get(istr(key), '-')
return (args[1] or {}).get(key, '-')

@staticmethod
def _format_i(key, args):
if not args[0]:
return '(no headers)'
return args[0].headers.get(istr(key), '-')
# suboptimal, make istr(key) once
return args[0].headers.get(key, '-')

@staticmethod
def _format_o(key, args):
return args[2].headers.get(istr(key), '-')
# suboptimal, make istr(key) once
return args[2].headers.get(key, '-')

@staticmethod
def _format_a(args):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ def test_access_logger_dicts():
log_format = '%{User-Agent}i %{Content-Length}o %{SPAM}e %{None}i'
mock_logger = mock.Mock()
access_logger = helpers.AccessLogger(mock_logger, log_format)
message = mock.Mock(headers={"USER-AGENT": "Mock/1.0"}, version=(1, 1))
message = mock.Mock(headers={"User-Agent": "Mock/1.0"}, version=(1, 1))
environ = {"SPAM": "EGGS"}
response = mock.Mock(headers={"CONTENT-LENGTH": 123})
response = mock.Mock(headers={"Content-Length": 123})
transport = mock.Mock()
transport.get_extra_info.return_value = ("127.0.0.2", 1234)
access_logger.log(message, environ, response, transport, 0.0)
Expand Down