当前位置: 首页>>代码示例>>Python>>正文


Python errno.EPERM属性代码示例

本文整理汇总了Python中errno.EPERM属性的典型用法代码示例。如果您正苦于以下问题:Python errno.EPERM属性的具体用法?Python errno.EPERM怎么用?Python errno.EPERM使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在errno的用法示例。


在下文中一共展示了errno.EPERM属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _copyxattr

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EPERM [as 别名]
def _copyxattr(src, dst, *, follow_symlinks=True):
        """Copy extended filesystem attributes from `src` to `dst`.

        Overwrite existing attributes.

        If `follow_symlinks` is false, symlinks won't be followed.

        """

        try:
            names = os.listxattr(src, follow_symlinks=follow_symlinks)
        except OSError as e:
            if e.errno not in (errno.ENOTSUP, errno.ENODATA):
                raise
            return
        for name in names:
            try:
                value = os.getxattr(src, name, follow_symlinks=follow_symlinks)
                os.setxattr(dst, name, value, follow_symlinks=follow_symlinks)
            except OSError as e:
                if e.errno not in (errno.EPERM, errno.ENOTSUP, errno.ENODATA):
                    raise 
开发者ID:war-and-code,项目名称:jawfish,代码行数:24,代码来源:shutil.py

示例2: test_no_permission_read

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EPERM [as 别名]
def test_no_permission_read(self):
    url_map = appinfo.URLMap(url='/',
                             static_files='index.html')

    h = static_files_handler.StaticContentHandler(
        root_path=None,
        url_map=url_map,
        url_pattern='/$')

    os.path.getmtime('/home/appdir/index.html').AndReturn(12345.6)
    error = IOError()
    error.errno = errno.EPERM
    static_files_handler.StaticContentHandler._read_file(
        '/home/appdir/index.html').AndRaise(error)

    self.mox.ReplayAll()
    self.assertResponse('403 Forbidden',
                        {},
                        '',
                        h._handle_path,
                        '/home/appdir/index.html',
                        {'REQUEST_METHOD': 'GET',
                         'PATH_INFO': '/'})
    self.mox.VerifyAll() 
开发者ID:elsigh,项目名称:browserscope,代码行数:26,代码来源:static_files_handler_test.py

示例3: custom_popen

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EPERM [as 别名]
def custom_popen(cmd):
    """Disconnect cmd from parent fds, read only from stdout.
    """
    # needed for py2exe
    creationflags = 0
    if sys.platform == 'win32':
        creationflags = 0x08000000   # CREATE_NO_WINDOW

    # run command
    try:
        p = Popen(cmd, bufsize=0, stdout=PIPE, stdin=PIPE, stderr=STDOUT,
                  creationflags=creationflags)
    except OSError as ex:
        if ex.errno == errno.ENOENT:
            raise RarCannotExec("Unrar not installed? (rarfile.UNRAR_TOOL=%r)" % UNRAR_TOOL)
        if ex.errno == errno.EACCES or ex.errno == errno.EPERM:
            raise RarCannotExec("Cannot execute unrar (rarfile.UNRAR_TOOL=%r)" % UNRAR_TOOL)
        raise
    return p 
开发者ID:BasioMeusPuga,项目名称:Lector,代码行数:21,代码来源:rarfile.py

示例4: _try_except_permissionerror_iter

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EPERM [as 别名]
def _try_except_permissionerror_iter(try_iter, except_iter):
    if sys.version_info >= (3, 3):
        try:
            for x in try_iter():
                yield x
        except PermissionError as exc:
            for x in except_iter(exc):
                yield x
    else:
        try:
            for x in try_iter():
                yield x
        except EnvironmentError as exc:
            if exc.errno not in (EPERM, EACCES):
                raise
            else:
                for x in except_iter(exc):
                    yield x 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:20,代码来源:__init__.py

示例5: _test_UNC_path

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EPERM [as 别名]
def _test_UNC_path(self):
        with open(os.path.join(self.path, 'test_trailing_slash.py'), 'w') as f:
            f.write("testdata = 'test_trailing_slash'")
        # Create the UNC path, like \\myhost\c$\foo\bar.
        path = os.path.abspath(self.path)
        import socket
        hn = socket.gethostname()
        drive = path[0]
        unc = "\\\\%s\\%s$"%(hn, drive)
        unc += path[2:]
        try:
            os.listdir(unc)
        except OSError as e:
            if e.errno in (errno.EPERM, errno.EACCES, errno.ENOENT):
                # See issue #15338
                self.skipTest("cannot access administrative share %r" % (unc,))
            raise
        sys.path.append(path)
        mod = __import__("test_trailing_slash")
        self.assertEqual(mod.testdata, 'test_trailing_slash')
        unload("test_trailing_slash") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:test_import.py

示例6: _test_chflags_regular_file

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EPERM [as 别名]
def _test_chflags_regular_file(self, chflags_func, target_file):
        st = os.stat(target_file)
        self.assertTrue(hasattr(st, 'st_flags'))

        # ZFS returns EOPNOTSUPP when attempting to set flag UF_IMMUTABLE.
        try:
            chflags_func(target_file, st.st_flags | stat.UF_IMMUTABLE)
        except OSError as err:
            if err.errno != errno.EOPNOTSUPP:
                raise
            msg = 'chflag UF_IMMUTABLE not supported by underlying fs'
            self.skipTest(msg)

        try:
            new_st = os.stat(target_file)
            self.assertEqual(st.st_flags | stat.UF_IMMUTABLE, new_st.st_flags)
            try:
                fd = open(target_file, 'w+')
            except IOError as e:
                self.assertEqual(e.errno, errno.EPERM)
        finally:
            posix.chflags(target_file, st.st_flags) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:24,代码来源:test_posix.py

示例7: setUpModule

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EPERM [as 别名]
def setUpModule():
    global OLD_SYS_PATH
    OLD_SYS_PATH = sys.path[:]

    if site.ENABLE_USER_SITE and not os.path.isdir(site.USER_SITE):
        # need to add user site directory for tests
        try:
            os.makedirs(site.USER_SITE)
            # modify sys.path: will be restored by tearDownModule()
            site.addsitedir(site.USER_SITE)
        except OSError as exc:
            if exc.errno in (errno.EACCES, errno.EPERM):
                raise unittest.SkipTest('unable to create user site directory (%r): %s'
                                        % (site.USER_SITE, exc))
            else:
                raise 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_site.py

示例8: scan

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EPERM [as 别名]
def scan(self, get_vendor, do_portscan, timeout=1):
        try:
            ans, unans = scapy.layers.l2.arping(self.cidr, iface=self.interface_name, timeout=timeout, verbose=False)
            for s, r in ans.res:
                self.neighbours.append(Host(r.psrc, r.src))
        except socket.error as e:
            if e.errno == errno.EPERM:  # Operation not permitted
                message = ("Error: {}\n"
                           "Run as root or - better - set the necessary capabilities for the python interpreter used and tcpdump.\n"
                           "Example: setcap cap_net_raw=eip /usr/bin/python3\n"
                           "Example: setcap cap_net_raw=eip $(which tcpdump)\n"
                           "You may need to install the libcap-progs package").format(e.strerror)
                exit_n(message, 2)
            else:
                raise

        self.neighbours.sort(key=lambda x: x.sort_value)
        if get_vendor:
            self.set_vendor_in_neighbours()
        if do_portscan:
            self.set_open_ports_in_neigbours()
        self.set_is_alive_in_neigbours() 
开发者ID:sumpfgottheit,项目名称:lanscan,代码行数:24,代码来源:lanscan.py

示例9: wrap_exceptions

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EPERM [as 别名]
def wrap_exceptions(fun):
    """Call callable into a try/except clause and translate ENOENT,
    EACCES and EPERM in NoSuchProcess or AccessDenied exceptions.
    """

    def wrapper(self, *args, **kwargs):
        try:
            return fun(self, *args, **kwargs)
        except EnvironmentError as err:
            # support for private module import
            if (NoSuchProcess is None or AccessDenied is None or
                    ZombieProcess is None):
                raise
            # ENOENT (no such file or directory) gets raised on open().
            # ESRCH (no such process) can get raised on read() if
            # process is gone in meantime.
            if err.errno in (errno.ENOENT, errno.ESRCH):
                if not pid_exists(self.pid):
                    raise NoSuchProcess(self.pid, self._name)
                else:
                    raise ZombieProcess(self.pid, self._name, self._ppid)
            if err.errno in (errno.EPERM, errno.EACCES):
                raise AccessDenied(self.pid, self._name)
            raise
    return wrapper 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:27,代码来源:_psaix.py

示例10: _send_signal

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EPERM [as 别名]
def _send_signal(self, sig):
            assert not self.pid < 0, self.pid
            if self.pid == 0:
                # see "man 2 kill"
                raise ValueError(
                    "preventing sending signal to process with PID 0 as it "
                    "would affect every process in the process group of the "
                    "calling process (os.getpid()) instead of PID 0")
            try:
                os.kill(self.pid, sig)
            except OSError as err:
                if err.errno == errno.ESRCH:
                    if OPENBSD and pid_exists(self.pid):
                        # We do this because os.kill() lies in case of
                        # zombie processes.
                        raise ZombieProcess(self.pid, self._name, self._ppid)
                    else:
                        self._gone = True
                        raise NoSuchProcess(self.pid, self._name)
                if err.errno in (errno.EPERM, errno.EACCES):
                    raise AccessDenied(self.pid, self._name)
                raise 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:24,代码来源:__init__.py

示例11: wrap_exceptions_procfs

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EPERM [as 别名]
def wrap_exceptions_procfs(inst):
    """Same as above, for routines relying on reading /proc fs."""
    try:
        yield
    except EnvironmentError as err:
        # ENOENT (no such file or directory) gets raised on open().
        # ESRCH (no such process) can get raised on read() if
        # process is gone in meantime.
        if err.errno in (errno.ENOENT, errno.ESRCH):
            if not pid_exists(inst.pid):
                raise NoSuchProcess(inst.pid, inst._name)
            else:
                raise ZombieProcess(inst.pid, inst._name, inst._ppid)
        if err.errno in (errno.EPERM, errno.EACCES):
            raise AccessDenied(inst.pid, inst._name)
        raise 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:18,代码来源:_psbsd.py

示例12: get_all_inodes

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EPERM [as 别名]
def get_all_inodes(self):
        inodes = {}
        for pid in pids():
            try:
                inodes.update(self.get_proc_inodes(pid))
            except OSError as err:
                # os.listdir() is gonna raise a lot of access denied
                # exceptions in case of unprivileged user; that's fine
                # as we'll just end up returning a connection with PID
                # and fd set to None anyway.
                # Both netstat -an and lsof does the same so it's
                # unlikely we can do any better.
                # ENOENT just means a PID disappeared on us.
                if err.errno not in (
                        errno.ENOENT, errno.ESRCH, errno.EPERM, errno.EACCES):
                    raise
        return inodes 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:19,代码来源:_pslinux.py

示例13: ppid_map

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EPERM [as 别名]
def ppid_map():
    """Obtain a {pid: ppid, ...} dict for all running processes in
    one shot. Used to speed up Process.children().
    """
    ret = {}
    procfs_path = get_procfs_path()
    for pid in pids():
        try:
            with open_binary("%s/%s/stat" % (procfs_path, pid)) as f:
                data = f.read()
        except EnvironmentError as err:
            # Note: we should be able to access /stat for all processes
            # aka it's unlikely we'll bump into EPERM, which is good.
            if err.errno not in (errno.ENOENT, errno.ESRCH):
                raise
        else:
            rpar = data.rfind(b')')
            dset = data[rpar + 2:].split()
            ppid = int(dset[1])
            ret[pid] = ppid
    return ret 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:23,代码来源:_pslinux.py

示例14: wrap_exceptions

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EPERM [as 别名]
def wrap_exceptions(fun):
    """Decorator which translates bare OSError and IOError exceptions
    into NoSuchProcess and AccessDenied.
    """
    @functools.wraps(fun)
    def wrapper(self, *args, **kwargs):
        try:
            return fun(self, *args, **kwargs)
        except EnvironmentError as err:
            if err.errno in (errno.EPERM, errno.EACCES):
                raise AccessDenied(self.pid, self._name)
            # ESRCH (no such process) can be raised on read() if
            # process is gone in the meantime.
            if err.errno == errno.ESRCH:
                raise NoSuchProcess(self.pid, self._name)
            # ENOENT (no such file or directory) can be raised on open().
            if err.errno == errno.ENOENT and not os.path.exists("%s/%s" % (
                    self._procfs_path, self.pid)):
                raise NoSuchProcess(self.pid, self._name)
            # Note: zombies will keep existing under /proc until they're
            # gone so there's no way to distinguish them in here.
            raise
    return wrapper 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:25,代码来源:_pslinux.py

示例15: exe

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EPERM [as 别名]
def exe(self):
        try:
            return readlink("%s/%s/exe" % (self._procfs_path, self.pid))
        except OSError as err:
            if err.errno in (errno.ENOENT, errno.ESRCH):
                # no such file error; might be raised also if the
                # path actually exists for system processes with
                # low pids (about 0-20)
                if os.path.lexists("%s/%s" % (self._procfs_path, self.pid)):
                    return ""
                else:
                    if not pid_exists(self.pid):
                        raise NoSuchProcess(self.pid, self._name)
                    else:
                        raise ZombieProcess(self.pid, self._name, self._ppid)
            if err.errno in (errno.EPERM, errno.EACCES):
                raise AccessDenied(self.pid, self._name)
            raise 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:20,代码来源:_pslinux.py


注:本文中的errno.EPERM属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。