Skip to content

Commit

Permalink
Change to instance #1654
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolay Kim committed Feb 17, 2017
1 parent d6bfe00 commit 3e2451d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 27 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ CHANGES
2.0.0 (2016-03-XX)
------------------

- Change `ClientResponse.url` to `yarl.URL` instance #1654

- `run_app` and the Command Line Interface now support serving over Unix domain sockets for
faster inter-process communication.

Expand Down
4 changes: 2 additions & 2 deletions aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def _request(self, method, url, *,
except OSError as exc:
raise aiohttp.ClientOSError(*exc.args) from exc

self._cookie_jar.update_cookies(resp.cookies, resp.url_obj)
self._cookie_jar.update_cookies(resp.cookies, resp.url)

# redirects
if resp.status in (301, 302, 303, 307) and allow_redirects:
Expand All @@ -258,7 +258,7 @@ def _request(self, method, url, *,
r_url = (resp.headers.get(hdrs.LOCATION) or
resp.headers.get(hdrs.URI))
if r_url is None:
raise RuntimeError("{0.method} {0.url_obj} returns "
raise RuntimeError("{0.method} {0.url} returns "
"a redirect [{0.status}] status "
"but response lacks a Location "
"or URI HTTP header".format(resp))
Expand Down
22 changes: 10 additions & 12 deletions aiohttp/client_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ def __init__(self, method, url, *,
assert isinstance(url, URL)

self.method = method
self._url_obj = url
self._url = url
self._content = None
self._writer = writer
self._continue = continue100
Expand All @@ -524,22 +524,20 @@ def __init__(self, method, url, *,
self.cookies = SimpleCookie()

@property
def url_obj(self):
return self._url_obj
def url(self):
return self._url

@property
def url(self):
warnings.warn("Deprecated, use .url_obj",
DeprecationWarning,
stacklevel=2)
return str(self._url_obj)
def url_obj(self):
warnings.warn(
"Deprecated, use .url #1654", DeprecationWarning, stacklevel=2)
return self._url

@property
def host(self):
warnings.warn("Deprecated, use .url_obj.host",
DeprecationWarning,
stacklevel=2)
return self._url_obj.host
warnings.warn(
"Deprecated, use .url.host", DeprecationWarning, stacklevel=2)
return self._url.host

@property
def _headers(self):
Expand Down
8 changes: 0 additions & 8 deletions docs/client_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -999,16 +999,8 @@ Response object

.. attribute:: url

URL of request (:class:`str`).

.. deprecated:: 1.1

.. attribute:: url_obj

URL of request (:class:`~yarl.URL`).

.. versionadded:: 1.1

.. attribute:: connection

:class:`Connection` used for handling response.
Expand Down
4 changes: 2 additions & 2 deletions tests/test_client_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def handler_ok(request):

resp = yield from client.get('/redirect')
assert resp.status == 200
assert resp.url_obj.path == '/ok'
assert resp.url.path == '/ok'


@asyncio.coroutine
Expand All @@ -407,7 +407,7 @@ def handler_ok(request):

resp = yield from client.get('/ok#fragment')
assert resp.status == 200
assert resp.url_obj.path == '/ok'
assert resp.url.path == '/ok'


@asyncio.coroutine
Expand Down
6 changes: 3 additions & 3 deletions tests/test_web_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ def handler2(request):
assert resp.status == 200
txt = yield from resp.text()
assert 'OK' == txt
assert resp.url_obj.path == '/path/final'
assert resp.url.path == '/path/final'


@asyncio.coroutine
Expand All @@ -927,7 +927,7 @@ def handler2(request):
assert resp.status == 200
txt = yield from resp.text()
assert 'OK' == txt
assert resp.url_obj.path == '/path/final'
assert resp.url.path == '/path/final'


@asyncio.coroutine
Expand All @@ -948,7 +948,7 @@ def handler(request):

client = yield from test_client(app)
resp = yield from client.get('/path/to')
assert resp.url_obj.path == '/path/static/' + fname
assert resp.url.path == '/path/static/' + fname
assert resp.status == 200
body = yield from resp.read()
with (here / fname).open('rb') as f:
Expand Down

0 comments on commit 3e2451d

Please sign in to comment.