def structured(inputSchema, outputSchema, schema_store=None, ignore_body=False):
 if (schema_store is None):
  schema_store = {}
 inputValidator = getValidator(inputSchema, schema_store)
 outputValidator = getValidator(outputSchema, schema_store)
 def deco(original):
  @wraps(original)
  @_remote_logging
  @_logging
  @_serialize(outputValidator)
  def loadAndDispatch(self, request, **routeArguments):
   if ((request.method in ('GET', 'DELETE')) or ignore_body):
    objects = {}
   else:
    body = request.content.read()
    try:
     objects = loads(body)
    except ValueError:
     raise DECODING_ERROR
    errors = []
    for error in inputValidator.iter_errors(objects):
     errors.append(error.message)
    if errors:
     raise InvalidRequestJSON(errors=errors, schema=inputSchema)
   objects.update(routeArguments)
   return maybeDeferred(original, self, **objects)
  loadAndDispatch.inputSchema = inputSchema
  loadAndDispatch.outputSchema = outputSchema
  return loadAndDispatch
 return deco

def structured ( inputSchema , outputSchema , schema_store = None , ignore_body = False ) : if ( schema_store is None ) : schema_store = { } inputValidator = getValidator ( inputSchema , schema_store ) outputValidator = getValidator ( outputSchema , schema_store ) def deco ( original ) : @ wraps ( original ) @ _remote_logging @ _logging @ _serialize ( outputValidator ) def loadAndDispatch ( self , request , ** routeArguments ) : if ( ( request . method in ( 'GET' , 'DELETE' ) ) or ignore_body ) : objects = { } else : body = request . content . read ( ) try : objects = loads ( body ) except ValueError : raise DECODING_ERROR errors = [ ] for error in inputValidator . iter_errors ( objects ) : errors . append ( error . message ) if errors : raise InvalidRequestJSON ( errors = errors , schema = inputSchema ) objects . update ( routeArguments ) return maybeDeferred ( original , self , ** objects ) loadAndDispatch . inputSchema = inputSchema loadAndDispatch . outputSchema = outputSchema return loadAndDispatch return deco
decorate a klein-style endpoint method so that the request body is automatically decoded and the response body is automatically encoded .