parameters: (self, os_path='')
docstring: context manager for turning permission errors into 403.
docstring_summary: context manager for turning permission errors into 403.
docstring_tokens: context manager for turning permission errors into 403 .
function: 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
function_tokens: 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