Mercurial > cosocket
changeset 10:f51acb369f03
Renamed to_receive() to until_received().
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Fri, 17 Apr 2009 17:31:07 -0700 |
parents | 9053424eb47d |
children | 8574ff006a28 |
files | cosocket.py example.py |
diffstat | 2 files changed, 11 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/cosocket.py Fri Apr 17 17:09:26 2009 -0700 +++ b/cosocket.py Fri Apr 17 17:31:07 2009 -0700 @@ -76,11 +76,11 @@ # Instructions that coroutines yield. -def to_receive(terminator = None, bytes = None): +def until_received(terminator = None, bytes = None): return {'op': 'receive', 'terminator': terminator, 'bytes': bytes} -def to_send(content): +def until_sent(content): return {'op': 'send', 'content': content}
--- a/example.py Fri Apr 17 17:09:26 2009 -0700 +++ b/example.py Fri Apr 17 17:31:07 2009 -0700 @@ -1,19 +1,19 @@ from cosocket import * def lame_http_server_coroutine(addr): - request = yield to_receive(terminator = '\r\n\r\n') + request = yield until_received(terminator = '\r\n\r\n') msg = 'hello %s.' % addr[0] - yield to_send('HTTP/1.1 200 OK\r\n' + - 'Content-Length: %d\r\n' % len(msg) + - 'Content-Type: text/plain\r\n\r\n' + - msg) + yield until_sent('HTTP/1.1 200 OK\r\n' + + 'Content-Length: %d\r\n' % len(msg) + + 'Content-Type: text/plain\r\n\r\n' + + msg) def lame_http_client_coroutine(addr): - yield to_send('GET / HTTP/1.1\r\n\r\n') - response_headers = yield to_receive(terminator = '\r\n\r\n') - response = yield to_receive(bytes = 20) + yield until_sent('GET / HTTP/1.1\r\n\r\n') + response_headers = yield until_received(terminator = '\r\n\r\n') + response = yield until_received(bytes = 20) print 'first response: %s' % repr(response) - response = yield to_receive(bytes = 20) + response = yield until_received(bytes = 20) print 'second response: %s' % repr(response) if __name__ == '__main__':