def wsgifunc(func, *middleware):
 middleware = list(middleware)
 if (reloader in middleware):
  relr = reloader(None)
  relrcheck = relr.check
  middleware.remove(reloader)
 else:
  relr = None
  relrcheck = (lambda : None)
 def wsgifunc(env, start_resp):
  _load(env)
  relrcheck()
  try:
   result = func()
  except StopIteration:
   result = None
  is_generator = (result and hasattr(result, 'next'))
  if is_generator:
   try:
    firstchunk = result.next()
   except StopIteration:
    firstchunk = ''
  (status, headers, output) = (ctx.status, ctx.headers, ctx.output)
  _unload()
  start_resp(status, headers)
  if is_generator:
   return itertools.chain([firstchunk], result)
  elif isinstance(output, str):
   return [output]
  elif hasattr(output, 'next'):
   return output
  else:
   raise Exception, 'Invalid web.context.output'
 for mw_func in middleware:
  wsgifunc = mw_func(wsgifunc)
 if relr:
  relr.func = wsgifunc
  return wsgifunc
 return wsgifunc

def wsgifunc ( func , * middleware ) : middleware = list ( middleware ) if ( reloader in middleware ) : relr = reloader ( None ) relrcheck = relr . check middleware . remove ( reloader ) else : relr = None relrcheck = ( lambda : None ) def wsgifunc ( env , start_resp ) : _load ( env ) relrcheck ( ) try : result = func ( ) except StopIteration : result = None is_generator = ( result and hasattr ( result , 'next' ) ) if is_generator : try : firstchunk = result . next ( ) except StopIteration : firstchunk = '' ( status , headers , output ) = ( ctx . status , ctx . headers , ctx . output ) _unload ( ) start_resp ( status , headers ) if is_generator : return itertools . chain ( [ firstchunk ] , result ) elif isinstance ( output , str ) : return [ output ] elif hasattr ( output , 'next' ) : return output else : raise Exception , 'Invalid web.context.output' for mw_func in middleware : wsgifunc = mw_func ( wsgifunc ) if relr : relr . func = wsgifunc return wsgifunc return wsgifunc
returns a wsgi-compatible function from a webpy-function .