[Python-modules-commits] [yarl] 01/08: Import yarl_0.12.0.orig.tar.gz

Piotr Ożarowski piotr at moszumanska.debian.org
Sun Jul 16 12:14:17 UTC 2017


This is an automated email from the git hooks/post-receive script.

piotr pushed a commit to branch master
in repository yarl.

commit 39878b79830132ac7dc6d4b5ad138c3d6b3543e1
Author: Piotr Ożarowski <piotr at debian.org>
Date:   Sun Jul 16 14:10:51 2017 +0200

    Import yarl_0.12.0.orig.tar.gz
---
 CHANGES.rst                |   7 +++
 PKG-INFO                   |  12 +++-
 README.rst                 |   3 +
 docs/api.rst               |   6 +-
 tests/test_update_query.py | 154 +++++++++++++++++++++++++++++++++++++++++++++
 tests/test_url.py          | 149 ++-----------------------------------------
 yarl.egg-info/PKG-INFO     |  12 +++-
 yarl.egg-info/SOURCES.txt  |   2 +
 yarl/__init__.py           |   4 +-
 yarl/__init__.pyi          |  32 +++++++---
 yarl/_quoting.c            |  10 +--
 yarl/_quoting.pyi          |   5 ++
 yarl/_quoting.pyx          |   4 +-
 13 files changed, 236 insertions(+), 164 deletions(-)

diff --git a/CHANGES.rst b/CHANGES.rst
index a97882f..139777a 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,6 +1,13 @@
 CHANGES
 =======
 
+0.12.0 (2017-06-26)
+-------------------
+
+* Properly support paths without leading slash in `URL.with_path()` #90
+
+* Enable type annotation checks
+
 0.11.0 (2017-06-26)
 -------------------
 
diff --git a/PKG-INFO b/PKG-INFO
index a467e00..8fc2ed9 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: yarl
-Version: 0.11.0
+Version: 0.12.0
 Summary: Yet another URL library
 Home-page: https://github.com/aio-libs/yarl/
 Author: Andrew Svetlov
@@ -27,6 +27,9 @@ Description: yarl
         .. image:: https://img.shields.io/pypi/pyversions/yarl.svg
             :target: https://pypi.python.org/pypi/yarl
         
+        .. image:: https://badges.gitter.im/Join%20Chat.svg
+            :target: https://gitter.im/aio-libs/Lobby
+            :alt: Chat on Gitter
         
         Introduction
         ------------
@@ -164,6 +167,13 @@ Description: yarl
         CHANGES
         =======
         
+        0.12.0 (2017-06-26)
+        -------------------
+        
+        * Properly support paths without leading slash in `URL.with_path()` #90
+        
+        * Enable type annotation checks
+        
         0.11.0 (2017-06-26)
         -------------------
         
diff --git a/README.rst b/README.rst
index 2839099..811d3b3 100644
--- a/README.rst
+++ b/README.rst
@@ -19,6 +19,9 @@ yarl
 .. image:: https://img.shields.io/pypi/pyversions/yarl.svg
     :target: https://pypi.python.org/pypi/yarl
 
+.. image:: https://badges.gitter.im/Join%20Chat.svg
+    :target: https://gitter.im/aio-libs/Lobby
+    :alt: Chat on Gitter
 
 Introduction
 ------------
diff --git a/docs/api.rst b/docs/api.rst
index 6f9b057..232e54d 100644
--- a/docs/api.rst
+++ b/docs/api.rst
@@ -370,7 +370,8 @@ New URL generation
 URL is an immutable object, every operation described in the
 section generates a new *URL* instance.
 
-.. method:: URL.build(scheme, user, password, host, port, path, query, query_string, fragment, strict=False)
+.. method:: URL.build(*, scheme, user, password, host, port, path, query, \
+                      query_string, fragment, strict=False)
 
    Creates and returns a new URL:
 
@@ -388,7 +389,8 @@ section generates a new *URL* instance.
       >>> URL.build()
       URL('')
 
-   Calling ``build`` method without arguments is equal to calling ``__init__`` without arguments.
+   Calling ``build`` method without arguments is equal to calling
+   ``__init__`` without arguments.
 
    .. note::
       When ``scheme`` and ``host`` are passed new URL will be “absolute”. If only one of ``scheme`` or ``host`` is
diff --git a/tests/test_update_query.py b/tests/test_update_query.py
new file mode 100644
index 0000000..6c4bdce
--- /dev/null
+++ b/tests/test_update_query.py
@@ -0,0 +1,154 @@
+import pytest
+
+from multidict import MultiDict
+
+
+from yarl import URL
+
+
+# with_query
+
+def test_with_query():
+    url = URL('http://example.com')
+    assert str(url.with_query({'a': '1'})) == 'http://example.com/?a=1'
+
+
+def test_update_query():
+    url = URL('http://example.com/')
+    assert str(url.update_query({'a': '1'})) == 'http://example.com/?a=1'
+
+    url = URL('http://example.com/?foo=bar')
+    expected_url = URL('http://example.com/?foo=bar&baz=foo')
+
+    assert url.update_query({'baz': 'foo'}) == expected_url
+    assert url.update_query(baz='foo') == expected_url
+    assert url.update_query("?baz=foo") == expected_url
+
+
+def test_update_query_with_args_and_kwargs():
+    url = URL('http://example.com/')
+
+    with pytest.raises(ValueError):
+        url.update_query('a', foo='bar')
+
+
+def test_update_query_with_multiple_args():
+    url = URL('http://example.com/')
+
+    with pytest.raises(ValueError):
+        url.update_query('a', 'b')
+
+
+def test_with_query_list_of_pairs():
+    url = URL('http://example.com')
+    assert str(url.with_query([('a', '1')])) == 'http://example.com/?a=1'
+
+
+def test_with_query_kwargs():
+    url = URL('http://example.com')
+    q = url.with_query(query='1', query2='1').query
+    assert q == dict(query='1', query2='1')
+
+
+def test_with_query_kwargs_and_args_are_mutually_exclusive():
+    url = URL('http://example.com')
+    with pytest.raises(ValueError):
+        url.with_query(
+            {'a': '2', 'b': '4'}, a='1')
+
+
+def test_with_query_only_single_arg_is_supported():
+    url = URL('http://example.com')
+    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')
+
+
+def test_with_query_empty_dict():
+    url = URL('http://example.com/?a=b')
+    assert str(url.with_query({})) == 'http://example.com/'
+
+
+def test_with_query_empty_str():
+    url = URL('http://example.com/?a=b')
+    assert str(url.with_query('')) == 'http://example.com/'
+
+
+def test_with_query_str():
+    url = URL('http://example.com')
+    assert str(url.with_query('a=1&b=2')) == 'http://example.com/?a=1&b=2'
+
+
+def test_with_query_str_non_ascii_and_spaces():
+    url = URL('http://example.com')
+    url2 = url.with_query('a=1 2&b=знач')
+    assert url2.raw_query_string == 'a=1+2&b=%D0%B7%D0%BD%D0%B0%D1%87'
+    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.1})
+
+
+def test_with_query_multidict():
+    url = URL('http://example.com/path')
+    q = MultiDict([('a', 'b'), ('c', 'd')])
+    assert str(url.with_query(q)) == 'http://example.com/path?a=b&c=d'
+
+
+def test_with_multidict_with_spaces_and_non_ascii():
+    url = URL('http://example.com')
+    url2 = url.with_query({'a b': 'ю б'})
+    assert url2.raw_query_string == 'a+b=%D1%8E+%D0%B1'
+
+
+def test_with_query_multidict_with_unsafe():
+    url = URL('http://example.com/path')
+    url2 = url.with_query({'a+b': '?=+&'})
+    assert url2.raw_query_string == 'a%2Bb=?%3D%2B%26'
+    assert url2.query_string == 'a%2Bb=?%3D%2B%26'
+    assert url2.query == {'a+b': '?=+&'}
+
+
+def test_with_query_None():
+    url = URL('http://example.com/path?a=b')
+    assert url.with_query(None).query_string == ''
+
+
+def test_with_query_bad_type():
+    url = URL('http://example.com')
+    with pytest.raises(TypeError):
+        url.with_query(123)
+
+
+def test_with_query_bytes():
+    url = URL('http://example.com')
+    with pytest.raises(TypeError):
+        url.with_query(b'123')
+
+
+def test_with_query_bytearray():
+    url = URL('http://example.com')
+    with pytest.raises(TypeError):
+        url.with_query(bytearray(b'123'))
+
+
+def test_with_query_memoryview():
+    url = URL('http://example.com')
+    with pytest.raises(TypeError):
+        url.with_query(memoryview(b'123'))
+
+
+def test_with_query_params():
+    url = URL('http://example.com/get')
+    url2 = url.with_query([('key', '1;2;3')])
+    assert str(url2) == 'http://example.com/get?key=1;2;3'
diff --git a/tests/test_url.py b/tests/test_url.py
index b04d6f4..b5d365e 100644
--- a/tests/test_url.py
+++ b/tests/test_url.py
@@ -1,7 +1,6 @@
 import sys
 import pytest
 from urllib.parse import SplitResult
-from multidict import MultiDict
 
 from yarl import URL
 
@@ -501,152 +500,14 @@ def test_with_path_fragment():
     assert str(url.with_path('/test')) == 'http://example.com/test'
 
 
-# with_query
-
-def test_with_query():
-    url = URL('http://example.com')
-    assert str(url.with_query({'a': '1'})) == 'http://example.com/?a=1'
-
-
-def test_update_query():
-    url = URL('http://example.com/')
-    assert str(url.update_query({'a': '1'})) == 'http://example.com/?a=1'
-
-    url = URL('http://example.com/?foo=bar')
-    expected_url = URL('http://example.com/?foo=bar&baz=foo')
-
-    assert url.update_query({'baz': 'foo'}) == expected_url
-    assert url.update_query(baz='foo') == expected_url
-    assert url.update_query("?baz=foo") == expected_url
-
-
-def test_update_query_with_args_and_kwargs():
-    url = URL('http://example.com/')
-
-    with pytest.raises(ValueError):
-        url.update_query('a', foo='bar')
-
-
-def test_update_query_with_multiple_args():
-    url = URL('http://example.com/')
-
-    with pytest.raises(ValueError):
-        url.update_query('a', 'b')
-
-
-def test_with_query_list_of_pairs():
-    url = URL('http://example.com')
-    assert str(url.with_query([('a', '1')])) == 'http://example.com/?a=1'
-
-
-def test_with_query_kwargs():
-    url = URL('http://example.com')
-    q = url.with_query(query='1', query2='1').query
-    assert q == dict(query='1', query2='1')
-
-
-def test_with_query_kwargs_and_args_are_mutually_exclusive():
-    url = URL('http://example.com')
-    with pytest.raises(ValueError):
-        url.with_query(
-            {'a': '2', 'b': '4'}, a='1')
-
-
-def test_with_query_only_single_arg_is_supported():
-    url = URL('http://example.com')
-    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')
-
-
-def test_with_query_empty_dict():
-    url = URL('http://example.com/?a=b')
-    assert str(url.with_query({})) == 'http://example.com/'
-
-
-def test_with_query_empty_str():
-    url = URL('http://example.com/?a=b')
-    assert str(url.with_query('')) == 'http://example.com/'
-
-
-def test_with_query_str():
-    url = URL('http://example.com')
-    assert str(url.with_query('a=1&b=2')) == 'http://example.com/?a=1&b=2'
-
-
-def test_with_query_str_non_ascii_and_spaces():
-    url = URL('http://example.com')
-    url2 = url.with_query('a=1 2&b=знач')
-    assert url2.raw_query_string == 'a=1+2&b=%D0%B7%D0%BD%D0%B0%D1%87'
-    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.1})
-
-
-def test_with_query_multidict():
-    url = URL('http://example.com/path')
-    q = MultiDict([('a', 'b'), ('c', 'd')])
-    assert str(url.with_query(q)) == 'http://example.com/path?a=b&c=d'
-
-
-def test_with_multidict_with_spaces_and_non_ascii():
-    url = URL('http://example.com')
-    url2 = url.with_query({'a b': 'ю б'})
-    assert url2.raw_query_string == 'a+b=%D1%8E+%D0%B1'
-
-
-def test_with_query_multidict_with_unsafe():
-    url = URL('http://example.com/path')
-    url2 = url.with_query({'a+b': '?=+&'})
-    assert url2.raw_query_string == 'a%2Bb=?%3D%2B%26'
-    assert url2.query_string == 'a%2Bb=?%3D%2B%26'
-    assert url2.query == {'a+b': '?=+&'}
-
-
-def test_with_query_None():
-    url = URL('http://example.com/path?a=b')
-    assert url.with_query(None).query_string == ''
-
-
-def test_with_query_bad_type():
-    url = URL('http://example.com')
-    with pytest.raises(TypeError):
-        url.with_query(123)
+def test_with_path_empty():
+    url = URL('http://example.com/test')
+    assert str(url.with_path('')) == 'http://example.com'
 
 
-def test_with_query_bytes():
+def test_with_path_leading_slash():
     url = URL('http://example.com')
-    with pytest.raises(TypeError):
-        url.with_query(b'123')
-
-
-def test_with_query_bytearray():
-    url = URL('http://example.com')
-    with pytest.raises(TypeError):
-        url.with_query(bytearray(b'123'))
-
-
-def test_with_query_memoryview():
-    url = URL('http://example.com')
-    with pytest.raises(TypeError):
-        url.with_query(memoryview(b'123'))
-
-
-def test_with_query_params():
-    url = URL('http://example.com/get')
-    url2 = url.with_query([('key', '1;2;3')])
-    assert str(url2) == 'http://example.com/get?key=1;2;3'
+    assert url.with_path('test').path == '/test'
 
 
 # with_fragment
diff --git a/yarl.egg-info/PKG-INFO b/yarl.egg-info/PKG-INFO
index a467e00..8fc2ed9 100644
--- a/yarl.egg-info/PKG-INFO
+++ b/yarl.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: yarl
-Version: 0.11.0
+Version: 0.12.0
 Summary: Yet another URL library
 Home-page: https://github.com/aio-libs/yarl/
 Author: Andrew Svetlov
@@ -27,6 +27,9 @@ Description: yarl
         .. image:: https://img.shields.io/pypi/pyversions/yarl.svg
             :target: https://pypi.python.org/pypi/yarl
         
+        .. image:: https://badges.gitter.im/Join%20Chat.svg
+            :target: https://gitter.im/aio-libs/Lobby
+            :alt: Chat on Gitter
         
         Introduction
         ------------
@@ -164,6 +167,13 @@ Description: yarl
         CHANGES
         =======
         
+        0.12.0 (2017-06-26)
+        -------------------
+        
+        * Properly support paths without leading slash in `URL.with_path()` #90
+        
+        * Enable type annotation checks
+        
         0.11.0 (2017-06-26)
         -------------------
         
diff --git a/yarl.egg-info/SOURCES.txt b/yarl.egg-info/SOURCES.txt
index 2cb3e3d..196b437 100644
--- a/yarl.egg-info/SOURCES.txt
+++ b/yarl.egg-info/SOURCES.txt
@@ -15,6 +15,7 @@ tests/test_cached_property.py
 tests/test_normalize_path.py
 tests/test_pickle.py
 tests/test_quoting.py
+tests/test_update_query.py
 tests/test_url.py
 tests/test_url_build.py
 tests/test_url_cmp_and_hash.py
@@ -23,6 +24,7 @@ tests/test_url_update_netloc.py
 yarl/__init__.py
 yarl/__init__.pyi
 yarl/_quoting.c
+yarl/_quoting.pyi
 yarl/_quoting.pyx
 yarl/quoting.py
 yarl.egg-info/PKG-INFO
diff --git a/yarl/__init__.py b/yarl/__init__.py
index 639cd5c..9c0ca4e 100644
--- a/yarl/__init__.py
+++ b/yarl/__init__.py
@@ -10,7 +10,7 @@ from multidict import MultiDict, MultiDictProxy
 
 from .quoting import quote, unquote
 
-__version__ = '0.11.0'
+__version__ = '0.12.0'
 
 __all__ = ['URL']
 
@@ -718,6 +718,8 @@ class URL:
             path = _quote(path, safe='@:', protected='/', strict=self._strict)
             if self.is_absolute():
                 path = _normalize_path(path)
+        if len(path) > 0 and path[0] != '/':
+            path = '/' + path
         return URL(self._val._replace(path=path, query='', fragment=''),
                    encoded=True)
 
diff --git a/yarl/__init__.pyi b/yarl/__init__.pyi
index cf977bd..f691428 100644
--- a/yarl/__init__.pyi
+++ b/yarl/__init__.pyi
@@ -1,4 +1,4 @@
-from typing import overload, Tuple, Optional, Mapping, Union
+from typing import overload, Tuple, Optional, Mapping, Union, Sequence
 import multidict
 
 
@@ -17,7 +17,7 @@ class URL:
     query_string = ...  # type: str
     raw_fragment = ...  # type: str
     fragment = ...  # type: str
-    query = ...  # type: multidict.Multidict
+    query = ...  # type: multidict.MultiDict
     raw_name = ...  # type: str
     name = ...  # type: str
     raw_parts = ...  # type: Tuple[str, ...]
@@ -25,14 +25,15 @@ class URL:
     parent = ...  # type: URL
 
     @overload
-    def __new__(cls, val: str='', *, encoded: bool=False) -> URL: ...
+    def __new__(cls, val: str='', *, strict: bool=...) -> URL: ...
     @overload
     def __new__(cls, val: URL) -> URL: ...
 
     @classmethod
-    def build(cls, *, scheme: str='', user: str='', password: str='', host: str='',
-              port: int=None, path: str='', query: Mapping=None, query_string: str='',
-              fragment: str='', strict: bool=False) -> URL: ...
+    def build(cls, *, scheme: str=..., user: str=..., password: str=...,
+              host: str=..., port: int=..., path: str=...,
+              query: Mapping=..., query_string: str=...,
+              fragment: str=..., strict: bool=...) -> URL: ...
 
     def __str__(self) -> str: ...
     def __repr__(self) -> str: ...
@@ -58,10 +59,25 @@ class URL:
     def with_host(self, host: str) -> URL: ...
     def with_port(self, port: Optional[int]) -> URL: ...
     def with_path(self, path: str) -> URL: ...
+
+    @overload
+    def with_query(self, query: str) -> URL: ...
+    @overload
+    def with_query(self, query: Mapping[str, str]) -> URL: ...
     @overload
-    def with_query(self, query: Optional[Union[Mapping[str, str], str]]) -> URL: ...
+    def with_query(self, query: Sequence[Tuple[str, str]]) -> URL: ...
+    @overload
+    def with_query(self, **kwargs) -> URL: ...
+
     @overload
-    def with_query(self, **kwargs: Mapping[str, str]) -> URL: ...
+    def update_query(self, query: str) -> URL: ...
+    @overload
+    def update_query(self, query: Mapping[str, str]) -> URL: ...
+    @overload
+    def update_query(self, query: Sequence[Tuple[str, str]]) -> URL: ...
+    @overload
+    def update_query(self, **kwargs) -> URL: ...
+
     def with_fragment(self, fragment: Optional[str]) -> URL: ...
     def with_name(self, name: str) -> URL: ...
 
diff --git a/yarl/_quoting.c b/yarl/_quoting.c
index 1895a39..307cd09 100644
--- a/yarl/_quoting.c
+++ b/yarl/_quoting.c
@@ -1594,9 +1594,9 @@ static PyObject *__pyx_f_4yarl_8_quoting__do_quote(PyObject *__pyx_v_val, PyObje
   __Pyx_INCREF(__pyx_v_safe);
 
   /* "yarl/_quoting.pyx":55
- *     # UTF8 may take up to 5 bytes per symbol
+ *     # UTF8 may take up to 4 bytes per symbol
  *     # every byte is encoded as %XX -- 3 bytes
- *     cdef Py_ssize_t ret_size = len(val)*3*5 + 1             # <<<<<<<<<<<<<<
+ *     cdef Py_ssize_t ret_size = len(val)*3*4 + 1             # <<<<<<<<<<<<<<
  *     cdef object ret = PyUnicode_New(ret_size, 1114111)
  *     cdef Py_ssize_t ret_idx = 0
  */
@@ -1605,11 +1605,11 @@ static PyObject *__pyx_f_4yarl_8_quoting__do_quote(PyObject *__pyx_v_val, PyObje
     __PYX_ERR(0, 55, __pyx_L1_error)
   }
   __pyx_t_1 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_val); if (unlikely(__pyx_t_1 == -1)) __PYX_ERR(0, 55, __pyx_L1_error)
-  __pyx_v_ret_size = (((__pyx_t_1 * 3) * 5) + 1);
+  __pyx_v_ret_size = (((__pyx_t_1 * 3) * 4) + 1);
 
   /* "yarl/_quoting.pyx":56
  *     # every byte is encoded as %XX -- 3 bytes
- *     cdef Py_ssize_t ret_size = len(val)*3*5 + 1
+ *     cdef Py_ssize_t ret_size = len(val)*3*4 + 1
  *     cdef object ret = PyUnicode_New(ret_size, 1114111)             # <<<<<<<<<<<<<<
  *     cdef Py_ssize_t ret_idx = 0
  *     cdef int has_pct = 0
@@ -1620,7 +1620,7 @@ static PyObject *__pyx_f_4yarl_8_quoting__do_quote(PyObject *__pyx_v_val, PyObje
   __pyx_t_2 = 0;
 
   /* "yarl/_quoting.pyx":57
- *     cdef Py_ssize_t ret_size = len(val)*3*5 + 1
+ *     cdef Py_ssize_t ret_size = len(val)*3*4 + 1
  *     cdef object ret = PyUnicode_New(ret_size, 1114111)
  *     cdef Py_ssize_t ret_idx = 0             # <<<<<<<<<<<<<<
  *     cdef int has_pct = 0
diff --git a/yarl/_quoting.pyi b/yarl/_quoting.pyi
new file mode 100644
index 0000000..363a544
--- /dev/null
+++ b/yarl/_quoting.pyi
@@ -0,0 +1,5 @@
+
+def _quote(val: str, *, safe: str=..., protected: str=..., qs: bool=...,
+           strict: bool=...): ...
+
+def _unquote(val:str, *, unsafe:str=..., qs:bool=...): ...
diff --git a/yarl/_quoting.pyx b/yarl/_quoting.pyx
index 8236ec4..0369f73 100644
--- a/yarl/_quoting.pyx
+++ b/yarl/_quoting.pyx
@@ -50,9 +50,9 @@ cdef str _do_quote(str val, str safe, str protected, bint qs, bint strict):
     cdef Py_UCS4 ch, unquoted
     cdef str tmp
     cdef Py_ssize_t i
-    # UTF8 may take up to 5 bytes per symbol
+    # UTF8 may take up to 4 bytes per symbol
     # every byte is encoded as %XX -- 3 bytes
-    cdef Py_ssize_t ret_size = len(val)*3*5 + 1
+    cdef Py_ssize_t ret_size = len(val)*3*4 + 1
     cdef object ret = PyUnicode_New(ret_size, 1114111)
     cdef Py_ssize_t ret_idx = 0
     cdef int has_pct = 0

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/yarl.git



More information about the Python-modules-commits mailing list