def setup_version_redirection(config):
 settings = config.get_settings()
 redirect_enabled = settings['version_prefix_redirect_enabled']
 version_prefix_redirection_enabled = asbool(redirect_enabled)
 route_prefix = config.route_prefix
 config.registry.route_prefix = route_prefix
 if (not version_prefix_redirection_enabled):
  return
 def _redirect_to_version_view(request):
  if (request.method.lower() == 'options'):
   return utils.reapply_cors(request, Response())
  querystring = request.url[(request.url.rindex(request.path) + len(request.path)):]
  redirect = ('/%s%s%s' % (route_prefix, request.path, querystring))
  raise HTTPTemporaryRedirect(redirect)
 config.route_prefix = None
 config.add_route(name='redirect_to_version', pattern='/{path:(?!v[0-9]+)[^\\r\\n]*}')
 config.add_view(view=_redirect_to_version_view, route_name='redirect_to_version', permission=NO_PERMISSION_REQUIRED)
 config.route_prefix = route_prefix

def setup_version_redirection ( config ) : settings = config . get_settings ( ) redirect_enabled = settings [ 'version_prefix_redirect_enabled' ] version_prefix_redirection_enabled = asbool ( redirect_enabled ) route_prefix = config . route_prefix config . registry . route_prefix = route_prefix if ( not version_prefix_redirection_enabled ) : return def _redirect_to_version_view ( request ) : if ( request . method . lower ( ) == 'options' ) : return utils . reapply_cors ( request , Response ( ) ) querystring = request . url [ ( request . url . rindex ( request . path ) + len ( request . path ) ) : ] redirect = ( '/%s%s%s' % ( route_prefix , request . path , querystring ) ) raise HTTPTemporaryRedirect ( redirect ) config . route_prefix = None config . add_route ( name = 'redirect_to_version' , pattern = '/{path:(?!v[0-9]+)[^\\r\\n]*}' ) config . add_view ( view = _redirect_to_version_view , route_name = 'redirect_to_version' , permission = NO_PERMISSION_REQUIRED ) config . route_prefix = route_prefix
add a view which redirects to the current version of the api .