(self, os_path='')
context manager for turning permission errors into 403.
context manager for turning permission errors into 403.
context manager for turning permission errors into 403 .
def perm_to_403(self, os_path=''):
        """context manager for turning permission errors into 403."""
        try:
            yield
        except (OSError, IOError) as e:
            if e.errno in {errno.EPERM, errno.EACCES}:
                # make 403 error message without root prefix
                # this may not work perfectly on unicode paths on Python 2,
                # but nobody should be doing that anyway.
                if not os_path:
                    os_path = str_to_unicode(e.filename or 'unknown file')
                path = to_api_path(os_path, root=self.root_dir)
                raise HTTPError(403, u'Permission denied: %s' % path) from e
            else:
                raise
def perm_to_403 ( self , os_path = '' ) : try : yield except ( OSError , IOError ) as e : if e . errno in { errno . EPERM , errno . EACCES } : # make 403 error message without root prefix # this may not work perfectly on unicode paths on Python 2, # but nobody should be doing that anyway. if not os_path : os_path = str_to_unicode ( e . filename or 'unknown file' ) path = to_api_path ( os_path , root = self . root_dir ) raise HTTPError ( 403 , u'Permission denied: %s' % path ) from e else : raise