From e413ba6d8778592669dbaac1be57d29207e0a163 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Fri, 2 Jan 2015 22:21:42 +0200 Subject: [PATCH] cpython-uasyncio: Add StreamWriter with awrite() & aclose(). --- cpython-uasyncio/metadata.txt | 2 +- cpython-uasyncio/setup.py | 2 +- cpython-uasyncio/uasyncio.py | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/cpython-uasyncio/metadata.txt b/cpython-uasyncio/metadata.txt index 046c30f5..01093927 100644 --- a/cpython-uasyncio/metadata.txt +++ b/cpython-uasyncio/metadata.txt @@ -1,3 +1,3 @@ srctype = cpython-backport type = module -version = 0.1 +version = 0.2 diff --git a/cpython-uasyncio/setup.py b/cpython-uasyncio/setup.py index 2b21bddf..a70a3327 100644 --- a/cpython-uasyncio/setup.py +++ b/cpython-uasyncio/setup.py @@ -6,7 +6,7 @@ from setuptools import setup setup(name='micropython-cpython-uasyncio', - version='0.1', + version='0.2', description='MicroPython module uasyncio ported to CPython', long_description='This is MicroPython compatibility module, allowing applications using\nMicroPython-specific features to run on CPython.\n', url='https://github.com/micropython/micropython/issues/405', diff --git a/cpython-uasyncio/uasyncio.py b/cpython-uasyncio/uasyncio.py index 84e24409..fc83456f 100644 --- a/cpython-uasyncio/uasyncio.py +++ b/cpython-uasyncio/uasyncio.py @@ -78,3 +78,22 @@ class Task(OrgTask): asyncio.tasks.Task = Task + + +OrgStreamWriter = StreamWriter + +class StreamWriter(OrgStreamWriter): + + def awrite(self, data): + if isinstance(data, str): + data = data.encode("utf-8") + self.write(data) + yield from self.drain() + + def aclose(self): + self.close() + return + yield + + +asyncio.streams.StreamWriter = StreamWriter