Python os.supports_effective_ids() Examples

The following are 6 code examples of os.supports_effective_ids(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module os , or try the search function .
Example #1
Source File: _utils.py    From torf with GNU General Public License v3.0 5 votes vote down vote up
def list_files(path):
    """
    Return list of sorted file paths in `path`

    Raise ReadError if `path` or any file or directory underneath it is not
    readable.
    """
    def assert_readable(path):
        os_supports_effective_ids = os.access in os.supports_effective_ids
        if not os.access(path, os.R_OK, effective_ids=os_supports_effective_ids):
            raise error.ReadError(errno.EACCES, path)

    if os.path.isfile(path):
        assert_readable(path)
        return [path]
    else:
        def onerror(exc):
            raise error.ReadError(getattr(exc, 'errno', None),
                                  getattr(exc, 'filename', None))
        filepaths = []
        for dirpath, dirnames, filenames in os.walk(path, onerror=onerror):
            for filename in filenames:
                filepath = os.path.join(dirpath, filename)
                assert_readable(filepath)
                filepaths.append(filepath)
        return list(sorted(filepaths, key=lambda fp: str(fp).casefold())) 
Example #2
Source File: test_zipfile.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def requiresWriteAccess(self, path):
        # effective_ids unavailable on windows
        if not os.access(path, os.W_OK,
                         effective_ids=os.access in os.supports_effective_ids):
            self.skipTest('requires write access to the installed location')
        filename = os.path.join(path, 'test_zipfile.try')
        try:
            fd = os.open(filename, os.O_WRONLY | os.O_CREAT)
            os.close(fd)
        except Exception:
            self.skipTest('requires write access to the installed location')
        unlink(filename) 
Example #3
Source File: test_zipfile.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def requiresWriteAccess(self, path):
        # effective_ids unavailable on windows
        if not os.access(path, os.W_OK,
                         effective_ids=os.access in os.supports_effective_ids):
            self.skipTest('requires write access to the installed location')
        filename = os.path.join(path, 'test_zipfile.try')
        try:
            fd = os.open(filename, os.O_WRONLY | os.O_CREAT)
            os.close(fd)
        except Exception:
            self.skipTest('requires write access to the installed location')
        unlink(filename) 
Example #4
Source File: utils.py    From pid with Apache License 2.0 5 votes vote down vote up
def effective_access(*args, **kwargs):
    if 'effective_ids' not in kwargs:
        try:
            kwargs['effective_ids'] = os.access in os.supports_effective_ids
        except AttributeError:
            pass

    return os.access(*args, **kwargs) 
Example #5
Source File: test_zipfile.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def requiresWriteAccess(self, path):
        # effective_ids unavailable on windows
        if not os.access(path, os.W_OK,
                         effective_ids=os.access in os.supports_effective_ids):
            self.skipTest('requires write access to the installed location')
        filename = os.path.join(path, 'test_zipfile.try')
        try:
            fd = os.open(filename, os.O_WRONLY | os.O_CREAT)
            os.close(fd)
        except Exception:
            self.skipTest('requires write access to the installed location')
        unlink(filename) 
Example #6
Source File: test_zipfile.py    From android_universal with MIT License 5 votes vote down vote up
def requiresWriteAccess(self, path):
        # effective_ids unavailable on windows
        if not os.access(path, os.W_OK,
                         effective_ids=os.access in os.supports_effective_ids):
            self.skipTest('requires write access to the installed location')
        filename = os.path.join(path, 'test_zipfile.try')
        try:
            fd = os.open(filename, os.O_WRONLY | os.O_CREAT)
            os.close(fd)
        except Exception:
            self.skipTest('requires write access to the installed location')
        unlink(filename)