Skip to content

Commit

Permalink
Trim up initial state dict
Browse files Browse the repository at this point in the history
Push the setting of `exc_info` and `state` down into flow, and require
the rest to get populated from the return value of flow functions.
  • Loading branch information
chadwhitacre committed Nov 1, 2013
1 parent 33b0b50 commit 2ff265c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
8 changes: 6 additions & 2 deletions aspen/flow.py
Expand Up @@ -69,11 +69,15 @@ def run(self, state, through=None):
if through not in self.get_names():
raise FunctionNotFound(through)
print()

if 'exc_info' not in state:
state['exc_info'] = None
if 'state' not in state:
state['state'] = state

for function in self.functions:
function_name = function.func_name
try:
if 'exc_info' not in state:
state['exc_info'] = None
deps = self._resolve_dependencies(function, state)
if 'exc_info' in deps.required and state['exc_info'] is None:
pass # Hook needs an exc_info but we don't have it.
Expand Down
5 changes: 2 additions & 3 deletions aspen/flows/request.py
Expand Up @@ -55,9 +55,8 @@ def get_response_for_socket(request):
socket = sockets.get(request)
if socket is None:
# This is not a socket request.
return

if isinstance(socket, Response):
response = None
elif isinstance(socket, Response):
# Actually, this is a handshake request.
response = socket
else:
Expand Down
3 changes: 2 additions & 1 deletion aspen/testing/harness.py
Expand Up @@ -263,7 +263,8 @@ def _build_wsgi_environ(self, path, method="GET", body=None, **kw):
def _perform_request(self, environ, cookie_info, run_through, want):
self.add_cookie_info(environ, **(cookie_info or {}))
state = self.website.respond(environ, _run_through=run_through)
response = state['response']

response = state.get('response')
if response is not None:
if response.headers.cookie:
self.cookies.update(response.headers.cookie)
Expand Down
6 changes: 0 additions & 6 deletions aspen/website.py
Expand Up @@ -60,12 +60,6 @@ def respond(self, environ, _run_through=None):
state = {}
state['website'] = self
state['environ'] = environ
state['request'] = None
state['resource'] = None
state['socket'] = None
state['response'] = None
state['exc_info'] = None
state['state'] = state

state = self.flow.run(state, through=_run_through)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_flow.py
Expand Up @@ -125,7 +125,7 @@ def buz(): return {'val': 3}
'''))
bar_flow = Flow('foo')
state = bar_flow.run({'val': None})
assert state == {'val': 3, 'exc_info': None}
assert state == {'val': 3, 'exc_info': None, 'state': state}

def test_can_run_through_flow_to_a_certain_point(sys_path):
sys_path.mk(('foo.py', '''
Expand All @@ -135,7 +135,7 @@ def buz(): return {'val': 3}
'''))
bar_flow = Flow('foo')
state = bar_flow.run({'val': None}, through='baz')
assert state == {'val': 2, 'exc_info': None}
assert state == {'val': 2, 'exc_info': None, 'state': state}

def test_error_raised_if_we_try_to_run_through_an_unknown_function(sys_path):
sys_path.mk(('foo.py', '''
Expand Down

0 comments on commit 2ff265c

Please sign in to comment.