[svn r37] Bugfix in httpc with setting content-type; move more greenlet accesses into api; add coros.execute which is like api.spawn but returns an event object for the return value of the function

This commit is contained in:
donovan.linden
2007-10-27 03:49:23 -04:00
parent 844d71caa8
commit 966ab3ff4a
5 changed files with 21 additions and 9 deletions

View File

@@ -231,6 +231,7 @@ def sleep(timeout=0):
switch = greenlib.switch
getcurrent = greenlet.getcurrent
GreenletExit = greenlet.GreenletExit
class Spew(object):

View File

@@ -24,7 +24,6 @@ THE SOFTWARE.
import time
import traceback
import greenlet
from eventlet import api
@@ -62,7 +61,7 @@ class event(object):
occured.
"""
if self._result is NOT_USED:
self._waiters[greenlet.getcurrent()] = True
self._waiters[api.getcurrent()] = True
return api.get_hub().switch()
if self._exc is not None:
raise self._exc
@@ -93,6 +92,15 @@ class event(object):
for waiter in self._waiters:
hub.schedule_call(0, greenlib.switch, waiter, self._result)
def execute(func, *args, **kw):
evt = event()
def _really_execute():
evt.send(func(*args, **kw))
api.spawn(_really_execute)
return evt
class CoroutinePool(pools.Pool):
""" Like a thread pool, but with coroutines. """
def _main_loop(self, sender):
@@ -104,7 +112,7 @@ class CoroutinePool(pools.Pool):
result = func(*args, **kw)
if evt is not None:
evt.send(result)
except greenlet.GreenletExit:
except api.GreenletExit:
pass
except Exception, e:
traceback.print_exc()

View File

@@ -485,6 +485,7 @@ class HttpSuite(object):
**kwargs):
if headers is None:
headers = {}
if 'content-type' not in headers:
if content_type is None:
headers['content-type'] = self.fallback_content_type
else:
@@ -508,7 +509,7 @@ class HttpSuite(object):
**kwargs):
if headers is None:
headers = {}
if 'content-type' in headers:
if 'content-type' not in headers:
if content_type is None:
headers['content-type'] = self.fallback_content_type
else:

View File

@@ -405,6 +405,7 @@ class HttpProtocol(BaseHTTPServer.BaseHTTPRequestHandler):
self.close_connection = True
continue
self._code = 200
request = Request(self, self.command, self.path, self.headers)
request.set_header('Server', self.version_string())
request.set_header('Date', self.date_time_string())

View File

@@ -29,4 +29,5 @@ import simplejson
suite = httpc.HttpSuite(simplejson.dumps, simplejson.loads, 'application/json')
head, get, put, delete, post = (
suite.head, suite.get, suite.put, suite.delete, suite.post)
head_, get_, put_, delete_, post_ = (
suite.head_, suite.get_, suite.put_, suite.delete_, suite.post_)