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


Python stat.S_IFMT属性代码示例

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


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

示例1: assertS_IS

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IFMT [as 别名]
def assertS_IS(self, name, mode):
        # test format, lstrip is for S_IFIFO
        fmt = getattr(stat, "S_IF" + name.lstrip("F"))
        self.assertEqual(stat.S_IFMT(mode), fmt)
        # test that just one function returns true
        testname = "S_IS" + name
        for funcname in self.format_funcs:
            func = getattr(stat, funcname, None)
            if func is None:
                if funcname == testname:
                    raise ValueError(funcname)
                continue
            if funcname == testname:
                self.assertTrue(func(mode))
            else:
                self.assertFalse(func(mode)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_stat.py

示例2: mode_filetype

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IFMT [as 别名]
def mode_filetype(mode):
    mode = stat.S_IFMT(mode)
    dic = {
            stat.S_ISFIFO: "fifo file",
            stat.S_ISCHR: "character device",
            stat.S_ISDIR: "directory",
            stat.S_ISBLK: "block device",
            stat.S_ISREG: "regular file",
            stat.S_ISLNK: "symbolic link",
            stat.S_ISSOCK: "socket",
            stat.S_ISDOOR: "door",
            }
    for test_func, name in dic.items():
        if test_func(mode):
            return name
    return "???" 
开发者ID:nil0x42,项目名称:phpsploit,代码行数:18,代码来源:plugin.py

示例3: __new

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IFMT [as 别名]
def __new(cls, name, path, st):

        dirname, filename = os.path.split(name)
        mode = st.st_mode
        ifmt = S_IFMT(mode)
        inode = st.st_ino
        dev = st.st_dev
        try:
            mtime = st.st_mtime_ns
        except AttributeError:
            mtime = st.st_mtime
        size = st.st_size
        fileid = (ifmt, size)

        global _counter
        _counter += 1

        new = super(FileInfo, cls).__new__
        return new(cls, _counter, fileid, path, filename, dirname, mode, inode,
                   dev, mtime, size) 
开发者ID:deplicate,项目名称:deplicate,代码行数:22,代码来源:structs.py

示例4: test_unix_nomode_dir

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IFMT [as 别名]
def test_unix_nomode_dir(self):

        perms = stat.S_IRUSR | stat.S_IWUSR | stat.S_IROTH | stat.S_IRGRP
        stamp = time_ns()
        inode = self.db.rowid("INSERT INTO inodes (mode,uid,gid,mtime_ns,atime_ns,ctime_ns,refcount) "
                              "VALUES (?,?,?,?,?,?,?)",
                              (perms, os.getuid(), os.getgid(), stamp, stamp, stamp, 1))
        inode2 = self.db.rowid("INSERT INTO inodes (mode,uid,gid,mtime_ns,atime_ns,ctime_ns,refcount) "
                              "VALUES (?,?,?,?,?,?,?)",
                              (perms | stat.S_IFREG, os.getuid(), os.getgid(), stamp,
                               stamp, stamp, 1))

        self._link(b'test-entry', inode)
        self._link(b'subentry', inode2, inode)

        self.assert_fsck(self.fsck.check_unix)

        newmode = self.db.get_val('SELECT mode FROM inodes WHERE id=?', (inode,))
        self.assertEqual(stat.S_IMODE(newmode), perms)
        self.assertEqual(stat.S_IFMT(newmode), stat.S_IFDIR) 
开发者ID:s3ql,项目名称:s3ql,代码行数:22,代码来源:t3_fsck.py

示例5: _sig

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IFMT [as 别名]
def _sig(st):
    return (stat.S_IFMT(st.st_mode),
            st.st_size,
            st.st_mtime) 
开发者ID:glmcdona,项目名称:meddle,代码行数:6,代码来源:filecmp.py

示例6: test_mode

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IFMT [as 别名]
def test_mode(self):
        with open(TESTFN, 'w'):
            pass
        if os.name == 'posix':
            os.chmod(TESTFN, 0o700)
            st_mode = self.get_mode()
            self.assertS_IS("REG", st_mode)
            self.assertEqual(stat.S_IMODE(st_mode),
                             stat.S_IRWXU)

            os.chmod(TESTFN, 0o070)
            st_mode = self.get_mode()
            self.assertS_IS("REG", st_mode)
            self.assertEqual(stat.S_IMODE(st_mode),
                             stat.S_IRWXG)

            os.chmod(TESTFN, 0o007)
            st_mode = self.get_mode()
            self.assertS_IS("REG", st_mode)
            self.assertEqual(stat.S_IMODE(st_mode),
                             stat.S_IRWXO)

            os.chmod(TESTFN, 0o444)
            st_mode = self.get_mode()
            self.assertS_IS("REG", st_mode)
            self.assertEqual(stat.S_IMODE(st_mode), 0o444)
        else:
            os.chmod(TESTFN, 0o700)
            st_mode = self.get_mode()
            self.assertS_IS("REG", st_mode)
            self.assertEqual(stat.S_IFMT(st_mode),
                             stat.S_IFREG) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:34,代码来源:test_stat.py

示例7: is_device

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IFMT [as 别名]
def is_device(mode):
    mode = stat.S_IFMT(mode)
    return stat.S_ISCHR(mode) or stat.S_ISBLK(mode) 
开发者ID:nil0x42,项目名称:phpsploit,代码行数:5,代码来源:plugin.py

示例8: _filecheck

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IFMT [as 别名]
def _filecheck(fileinfo, minsize, maxsize, included_match, excluded_match,
               scanempties, scansystem, scanarchived, scanhidden):

    _sizecheck(fileinfo.size, minsize, maxsize, scanempties)
    _rulecheck(fileinfo.path, included_match, excluded_match)
    _attrcheck(fileinfo.path, scansystem, scanarchived, scanhidden)

    return S_IFMT(fileinfo.mode), fileinfo.size 
开发者ID:deplicate,项目名称:deplicate,代码行数:10,代码来源:core.py

示例9: write

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IFMT [as 别名]
def write(self, filename, arcname=None, compress_type=None):
        with open(filename, 'rb') as f:
            st = os.fstat(f.fileno())
            data = f.read()

        zinfo = ZipInfo(arcname or filename, date_time=get_zipinfo_datetime(st.st_mtime))
        zinfo.external_attr = (stat.S_IMODE(st.st_mode) | stat.S_IFMT(st.st_mode)) << 16
        zinfo.compress_type = ZIP_DEFLATED
        self.writestr(zinfo, data, compress_type) 
开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:11,代码来源:wheelfile.py

示例10: _sig

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IFMT [as 别名]
def _sig(st):
        return (stat.S_IFMT(st.st_mode), st.st_size, st.st_mtime) 
开发者ID:RhetTbull,项目名称:osxphotos,代码行数:4,代码来源:fileutil.py

示例11: cal_mode

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IFMT [as 别名]
def cal_mode(mode):
    if stat.S_ISLNK(mode):
        return stat.S_IFLNK
    elif stat.S_ISDIR(mode):
        return stat.S_IFDIR
    elif stat.S_IFMT(mode) == S_IFGITLINK:
        return S_IFGITLINK
    ret = stat.S_IFREG | 0o644
    ret |= (mode & 0o111)
    return ret 
开发者ID:lizherui,项目名称:git-in-python,代码行数:12,代码来源:utils.py

示例12: phase2

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IFMT [as 别名]
def phase2(self): # Distinguish files, directories, funnies
        self.common_dirs = []
        self.common_files = []
        self.common_funny = []

        for x in self.common:
            a_path = os.path.join(self.left, x)
            b_path = os.path.join(self.right, x)

            ok = 1
            try:
                a_stat = os.stat(a_path)
            except OSError as why:
                # print('Can\'t stat', a_path, ':', why.args[1])
                ok = 0
            try:
                b_stat = os.stat(b_path)
            except OSError as why:
                # print('Can\'t stat', b_path, ':', why.args[1])
                ok = 0

            if ok:
                a_type = stat.S_IFMT(a_stat.st_mode)
                b_type = stat.S_IFMT(b_stat.st_mode)
                if a_type != b_type:
                    self.common_funny.append(x)
                elif stat.S_ISDIR(a_type):
                    self.common_dirs.append(x)
                elif stat.S_ISREG(a_type):
                    self.common_files.append(x)
                else:
                    self.common_funny.append(x)
            else:
                self.common_funny.append(x) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:36,代码来源:filecmp.py

示例13: get_file_info

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IFMT [as 别名]
def get_file_info(system, path, verbose=False):
    fullpath = get_fullpath(system, path)
    if fullpath == IO_ERROR:
        return IO_ERROR
    
    result = {}    
    if system.startswith('/'): # local or sub
        if can_read(system, path):
            # TODO platform-specific
            stats = os.stat(fullpath)
            stm = stats.st_mode
            result['type'] = get_file_type_char(stat.S_IFMT(stm))
            result['permissions'] = '%o' % (stat.S_IMODE(stm))
            result['UID'] = stats[stat.ST_UID]
            result['GID'] = stats[stat.ST_GID]
            result['ATIME'] = stats[stat.ST_ATIME]
            result['MTIME'] = stats[stat.ST_MTIME]
            result['CTIME'] = stats[stat.ST_CTIME] # actually mtime on UNIX, TODO
        else:
            if verbose:
                log.info('File \'%s\' is not accessible.' % (fullpath))
            result['type'] = None
            result['permissions'] =  None
            result['UID'] = None
            result['GID'] = None
            result['ATIME'] = None
            result['MTIME'] = None
            result['CTIME'] = None
        return result

    else: # SSH/FTP/TFTP/HTTP
        # TODO NOT IMPLEMENTED
        return IO_ERROR 
开发者ID:lightfaith,项目名称:locasploit,代码行数:35,代码来源:io.py

示例14: path_mode

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IFMT [as 别名]
def path_mode(self, path):
		if not self.path_mod.exists(path):
			return 0
		return stat.S_IFMT(self.stat(path).st_mode) 
开发者ID:rsmusllp,项目名称:king-phisher-plugins,代码行数:6,代码来源:directory.py

示例15: write

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IFMT [as 别名]
def write(self, filename, arcname=None, compress_type=None):
        with open(filename, 'rb') as f:
            st = os.fstat(f.fileno())
            data = f.read()

        zinfo = ZipInfo(arcname or filename, date_time=get_zipinfo_datetime(st.st_mtime))
        zinfo.external_attr = (stat.S_IMODE(st.st_mode) | stat.S_IFMT(st.st_mode)) << 16
        zinfo.compress_type = compress_type or self.compression
        self.writestr(zinfo, data, compress_type) 
开发者ID:ali5h,项目名称:rules_pip,代码行数:11,代码来源:wheelfile.py


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