def virtual_root(resource, request):
 try:
  reg = request.registry
 except AttributeError:
  reg = get_current_registry()
 url_adapter = reg.queryMultiAdapter((resource, request), IResourceURL)
 if (url_adapter is None):
  url_adapter = ResourceURL(resource, request)
 (vpath, rpath) = (url_adapter.virtual_path, url_adapter.physical_path)
 if ((rpath != vpath) and rpath.endswith(vpath)):
  vroot_path = rpath[:(- len(vpath))]
  return find_resource(resource, vroot_path)
 try:
  return request.root
 except AttributeError:
  return find_root(resource)

def virtual_root ( resource , request ) : try : reg = request . registry except AttributeError : reg = get_current_registry ( ) url_adapter = reg . queryMultiAdapter ( ( resource , request ) , IResourceURL ) if ( url_adapter is None ) : url_adapter = ResourceURL ( resource , request ) ( vpath , rpath ) = ( url_adapter . virtual_path , url_adapter . physical_path ) if ( ( rpath != vpath ) and rpath . endswith ( vpath ) ) : vroot_path = rpath [ : ( - len ( vpath ) ) ] return find_resource ( resource , vroot_path ) try : return request . root except AttributeError : return find_root ( resource )
provided any :term:resource and a :term:request object .