Skip to content

Commit

Permalink
Bump to 0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Nov 7, 2016
1 parent e3bb749 commit 88a9bfc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGES
=======

0.7.0 (2016-11-07)
------------------

* Accept `int` as value for `.with_query()`

0.6.0 (2016-11-07)
------------------

Expand Down
18 changes: 9 additions & 9 deletions tests/test_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,16 +691,11 @@ def test_with_query_kwargs_and_args_are_mutually_exclusive():
{'a': '2', 'b': '4'}, a='1')


def test_with_query_kwargs_should_be_str():
url = URL('http://example.com')
with pytest.raises(TypeError):
url.with_query(b=3)


def test_with_query_only_single_arg_is_supported():
url = URL('http://example.com')
with pytest.raises(TypeError):
url.with_query(b=3)
u1 = url.with_query(b=3)
u2 = URL('http://example.com/?b=3')
assert u1 == u2
with pytest.raises(ValueError):
url.with_query('a=1', 'a=b')

Expand All @@ -727,10 +722,15 @@ def test_with_query_str_non_ascii_and_spaces():
assert url2.query_string == 'a=1+2&b=знач'


def test_with_query_int():
url = URL('http://example.com')
assert url.with_query({'a': 1}) == URL('http://example.com/?a=1')


def test_with_query_non_str():
url = URL('http://example.com')
with pytest.raises(TypeError):
url.with_query({'a': 1})
url.with_query({'a': 1.1})


def test_with_query_multidict():
Expand Down
22 changes: 15 additions & 7 deletions yarl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from .quoting import quote, unquote

__version__ = '0.6.0'
__version__ = '0.7.0'

__all__ = ['URL', 'quote', 'unquote']

Expand Down Expand Up @@ -653,9 +653,6 @@ def with_query(self, *args, **kwargs):
raise ValueError("Either kwargs or single query parameter "
"must be present")
query = kwargs
for _, value in kwargs.items():
if not isinstance(value, str):
raise TypeError("Invalid variable type")
elif len(args) == 1:
query = args[0]
else:
Expand All @@ -666,8 +663,16 @@ def with_query(self, *args, **kwargs):
query = ''
elif isinstance(query, Mapping):
quoter = partial(quote, safe='', plus=True)
query = '&'.join(quoter(k)+'='+quoter(v)
for k, v in query.items())
lst = []
for k, v in query.items():
if isinstance(v, str):
pass
elif type(v) == int: # no subclasses like bool
v = str(v)
else:
raise TypeError("Invalid variable type")
lst.append(quoter(k)+'='+quoter(v))
query = '&'.join(lst)
elif isinstance(query, str):
query = quote(query, safe='=+&', plus=True)
elif isinstance(query, (bytes, bytearray, memoryview)):
Expand All @@ -678,7 +683,10 @@ def with_query(self, *args, **kwargs):
for k, v in query)
else:
raise TypeError("Invalid query type")
return URL(self._val._replace(query=query),
path = self._val.path
if path == '':
path = '/'
return URL(self._val._replace(path=path, query=query),
encoded=True)

def with_fragment(self, fragment):
Expand Down

0 comments on commit 88a9bfc

Please sign in to comment.