From bacfdfd11bb29a640c6244e8c3f75b61f6a36088 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Tue, 5 Dec 2017 10:36:33 +0200 Subject: [PATCH 1/2] Make multipart.boundary a str property --- aiohttp/multipart.py | 4 ++-- docs/multipart_reference.rst | 6 +++++- tests/test_multipart.py | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/aiohttp/multipart.py b/aiohttp/multipart.py index fc38725a9a3..f41ae726dbf 100644 --- a/aiohttp/multipart.py +++ b/aiohttp/multipart.py @@ -686,7 +686,7 @@ def _boundary_value(self): # / DIGIT / ALPHA # ; any VCHAR, except delimiters # VCHAR = %x21-7E - value = self.boundary + value = self._boundary if re.match(self._valid_tchar_regex, value): return value.decode('ascii') # cannot fail @@ -701,7 +701,7 @@ def _boundary_value(self): @property def boundary(self): - return self._boundary + return self._boundary.decode('ascii') def append(self, obj, headers=None): if headers is None: diff --git a/docs/multipart_reference.rst b/docs/multipart_reference.rst index f7c67fb9e3a..1d43e6d4822 100644 --- a/docs/multipart_reference.rst +++ b/docs/multipart_reference.rst @@ -165,7 +165,11 @@ Multipart reference .. attribute:: boundary - The byte-string representation of the boundary. + The string (:class:`str`) representation of the boundary. + + .. versionchanged:: 3.0 + + Property type was changed from :class:`bytes` to :class:`str`. .. method:: append(obj, headers=None) diff --git a/tests/test_multipart.py b/tests/test_multipart.py index 5f4fae14da8..131d6739883 100644 --- a/tests/test_multipart.py +++ b/tests/test_multipart.py @@ -762,7 +762,7 @@ async def test_reading_skips_prelude(self): async def test_writer(writer): assert writer.size == 0 - assert writer.boundary == b':' + assert writer.boundary == ':' async def test_writer_serialize_io_chunk(buf, stream, writer): From 655f388c1f0f3b52bec5a1fac7a79aaa46423be6 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Tue, 5 Dec 2017 11:44:44 +0200 Subject: [PATCH 2/2] Add changenote --- CHANGES/2589.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 CHANGES/2589.feature diff --git a/CHANGES/2589.feature b/CHANGES/2589.feature new file mode 100644 index 00000000000..0e835afba33 --- /dev/null +++ b/CHANGES/2589.feature @@ -0,0 +1 @@ +`MultipartWriter.boundary` is `str` now.