當前位置: 首頁>>代碼示例>>Python>>正文


Python nt.stat方法代碼示例

本文整理匯總了Python中nt.stat方法的典型用法代碼示例。如果您正苦於以下問題:Python nt.stat方法的具體用法?Python nt.stat怎麽用?Python nt.stat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在nt的用法示例。


在下文中一共展示了nt.stat方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: is_package

# 需要導入模塊: import nt [as 別名]
# 或者: from nt import stat [as 別名]
def is_package(dir_name):
    '''
    Returns True if dir_name is actually a Python package in the current
    working directory.
    '''
    #*.py, *.pyd, etc
    if "." in dir_name:
        return False        
    
    #Make sure it exists
    try:
        if not nt.stat(dir_name): return False
    except:
        return False
    
    #Make sure it has an __init__.py
    try:
        if "__init__.py" not in nt.listdir(nt.getcwd() + "\\" + dir_name):
            return False
    except:
        return False
        
    return True 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:25,代碼來源:stdmodules.py

示例2: log_broken

# 需要導入模塊: import nt [as 別名]
# 或者: from nt import stat [as 別名]
def log_broken(name, e):
    global BROKEN_LIST
    
    if VERBOSE:
        print name, "FAILED"
    print >> LOG_FILE_BUSTED, "----------------------------------------------------------------"
    print >> LOG_FILE_BUSTED, "--", name
    if hasattr(e, "clsException"):
        print >> LOG_FILE_BUSTED, e.clsException
    else:
        print >> LOG_FILE_BUSTED, e
    
    temp_name = name.replace(".", "\\")
    try:
        if nt.stat(CPY_LIB_DIR + "\\" + temp_name + ".py"):
            BROKEN_LIST.append("/Lib/" + temp_name.replace("\\", "/") + ".py")
    except:
        pass
    try:
        if nt.stat(CPY_LIB_DIR + "\\" + temp_name):
            BROKEN_LIST.append("/Lib/" + temp_name.replace("\\", "/"))
            BROKEN_LIST.append("/Lib/" + temp_name.replace("\\", "/") + "/__init__.py")
    except:
        pass 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:26,代碼來源:stdmodules.py

示例3: test_fstat

# 需要導入模塊: import nt [as 別名]
# 或者: from nt import stat [as 別名]
def test_fstat(self):
        result = nt.fstat(1)
        self.assertTrue(result!=0,"0,The file stat object was not returned correctly")
        
        result = None
        tmpfile = "tmpfile1.tmp"
        f = open(tmpfile, "w")
        result = nt.fstat(f.fileno())
        self.assertTrue(result!=None,"0,The file stat object was not returned correctly")
        f.close()
        nt.unlink(tmpfile)
        
        # stdxx file descriptor
        self.assertEqual(10, len(nt.fstat(0)))
        self.assertEqual(10, len(nt.fstat(1)))
        self.assertEqual(10, len(nt.fstat(2)))
        
        # invalid file descriptor
        self.assertRaises(OSError,nt.fstat,3000)
        self.assertRaises(OSError,nt.fstat,-1) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:22,代碼來源:test_nt.py

示例4: test_remove_negative

# 需要導入模塊: import nt [as 別名]
# 或者: from nt import stat [as 別名]
def test_remove_negative(self):
        import stat
        self.assertRaisesNumber(WindowsError, errno.ENOENT, lambda : nt.remove('some_file_that_does_not_exist'))
        try:
            file('some_test_file.txt', 'w').close()
            nt.chmod('some_test_file.txt', stat.S_IREAD)
            self.assertRaisesNumber(WindowsError, errno.EACCES, lambda : nt.remove('some_test_file.txt'))
            nt.chmod('some_test_file.txt', stat.S_IWRITE)
            
            f = file('some_test_file.txt', 'w+')
            self.assertRaisesNumber(WindowsError, errno.EACCES, lambda : nt.remove('some_test_file.txt'))
            f.close()
        finally:
            nt.chmod('some_test_file.txt', stat.S_IWRITE)
            nt.unlink('some_test_file.txt')
            
            

    # rename tests 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:21,代碼來源:test_nt.py

示例5: log_broken

# 需要導入模塊: import nt [as 別名]
# 或者: from nt import stat [as 別名]
def log_broken(name, e):
    global BROKEN_LIST
    
    if VERBOSE:
        print(name, "FAILED")
    print("----------------------------------------------------------------", file=LOG_FILE_BUSTED)
    print("--", name, file=LOG_FILE_BUSTED)
    if hasattr(e, "clsException"):
        print(e.clsException, file=LOG_FILE_BUSTED)
    else:
        print(e, file=LOG_FILE_BUSTED)
    
    temp_name = name.replace(".", "\\")
    try:
        if nt.stat(CPY_LIB_DIR + "\\" + temp_name + ".py"):
            BROKEN_LIST.append("/Lib/" + temp_name.replace("\\", "/") + ".py")
    except:
        pass
    try:
        if nt.stat(CPY_LIB_DIR + "\\" + temp_name):
            BROKEN_LIST.append("/Lib/" + temp_name.replace("\\", "/"))
            BROKEN_LIST.append("/Lib/" + temp_name.replace("\\", "/") + "/__init__.py")
    except:
        pass 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:26,代碼來源:stdmodules.py

示例6: test_remove_negative

# 需要導入模塊: import nt [as 別名]
# 或者: from nt import stat [as 別名]
def test_remove_negative(self):
        import stat
        self.assertRaisesNumber(WindowsError, errno.ENOENT, lambda : nt.remove('some_file_that_does_not_exist'))
        try:
            open('some_test_file.txt', 'w').close()
            nt.chmod('some_test_file.txt', stat.S_IREAD)
            self.assertRaisesNumber(WindowsError, errno.EACCES, lambda : nt.remove('some_test_file.txt'))
            nt.chmod('some_test_file.txt', stat.S_IWRITE)

            with open('some_test_file.txt', 'w+'):
                self.assertRaisesNumber(WindowsError, errno.EACCES, lambda : nt.remove('some_test_file.txt'))
        finally:
            nt.chmod('some_test_file.txt', stat.S_IWRITE)
            nt.unlink('some_test_file.txt')

    # rename tests 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:18,代碼來源:test_nt.py

示例7: _os_bootstrap

# 需要導入模塊: import nt [as 別名]
# 或者: from nt import stat [as 別名]
def _os_bootstrap():
    "Set up 'os' module replacement functions for use during import bootstrap."

    names = sys.builtin_module_names

    join = None
    if 'posix' in names:
        sep = '/'
        from posix import stat
    elif 'nt' in names:
        sep = '\\'
        from nt import stat
    elif 'dos' in names:
        sep = '\\'
        from dos import stat
    elif 'os2' in names:
        sep = '\\'
        from os2 import stat
    else:
        raise ImportError, 'no os specific module found'

    if join is None:
        def join(a, b, sep=sep):
            if a == '':
                return b
            lastchar = a[-1:]
            if lastchar == '/' or lastchar == sep:
                return a + b
            return a + sep + b

    global _os_stat
    _os_stat = stat

    global _os_path_join
    _os_path_join = join 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:37,代碼來源:imputil.py

示例8: test_listdir

# 需要導入模塊: import nt [as 別名]
# 或者: from nt import stat [as 別名]
def test_listdir(self):
        self.assertRaises(TypeError, nt.listdir, None)
        self.assertEqual(nt.listdir(nt.getcwd()), nt.listdir('.'))

    # stat,lstat 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:7,代碼來源:test_nt.py

示例9: test_stat

# 需要導入模塊: import nt [as 別名]
# 或者: from nt import stat [as 別名]
def test_stat(self):
        # stat
        self.assertRaises(nt.error, nt.stat, 'doesnotexist.txt')
            
        #lstat
        self.assertRaises(nt.error, nt.lstat, 'doesnotexist.txt')

        self.assertRaisesNumber(WindowsError, 2, nt.stat, 'doesnotexist.txt')
        self.assertRaisesNumber(WindowsError, 22, nt.stat, 'bad?path.txt')

    # stat should accept bytes as argument 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:13,代碼來源:test_nt.py

示例10: test_chmod

# 需要導入模塊: import nt [as 別名]
# 或者: from nt import stat [as 別名]
def test_chmod(self):
        # chmod tests:
        # BUG 828,830
        nt.mkdir('tmp2')
        nt.chmod('tmp2', 256) # NOTE: change to flag when stat is implemented
        self.assertRaises(OSError, lambda:nt.rmdir('tmp2'))
        nt.chmod('tmp2', 128)
        nt.rmdir('tmp2')
        # /BUG

    ################################################################################################
    # popen/popen2/popen3/unlink tests 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:14,代碼來源:test_nt.py

示例11: test_utime

# 需要導入模塊: import nt [as 別名]
# 或者: from nt import stat [as 別名]
def test_utime(self):
        f = file('temp_file_does_not_exist.txt', 'w')
        f.close()
        import nt
        x = nt.stat('.')
        nt.utime('temp_file_does_not_exist.txt', (x[7], x[8]))
        y = nt.stat('temp_file_does_not_exist.txt')
        self.assertEqual(x[7], y[7])
        self.assertEqual(x[8], y[8])
        nt.unlink('temp_file_does_not_exist.txt') 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:12,代碼來源:test_nt.py

示例12: test_listdir

# 需要導入模塊: import nt [as 別名]
# 或者: from nt import stat [as 別名]
def test_listdir(self):
        self.assertEqual(nt.listdir(nt.getcwd()), nt.listdir())
        self.assertEqual(nt.listdir(nt.getcwd()), nt.listdir(None))
        self.assertEqual(nt.listdir(nt.getcwd()), nt.listdir('.'))

    # stat,lstat 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:8,代碼來源:test_nt.py

示例13: test_stat

# 需要導入模塊: import nt [as 別名]
# 或者: from nt import stat [as 別名]
def test_stat(self):
        # stat
        self.assertRaises(nt.error, nt.stat, 'doesnotexist.txt')

        #lstat
        self.assertRaises(nt.error, nt.lstat, 'doesnotexist.txt')

        self.assertRaisesNumber(WindowsError, 2, nt.stat, 'doesnotexist.txt')
        if is_netcoreapp:
            self.assertRaisesNumber(WindowsError, 2, nt.stat, 'bad?path.txt')
        else:
            self.assertRaisesNumber(WindowsError, 22, nt.stat, 'bad?path.txt')

    # stat should accept bytes as argument 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:16,代碼來源:test_nt.py

示例14: test_stat_cp34910

# 需要導入模塊: import nt [as 別名]
# 或者: from nt import stat [as 別名]
def test_stat_cp34910(self):
        self.assertEqual(nt.stat('/'), nt.stat(b'/'))
        self.assertEqual(nt.lstat('/'), nt.lstat(b'/'))

    # getcwdb test 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:7,代碼來源:test_nt.py

示例15: test_utime

# 需要導入模塊: import nt [as 別名]
# 或者: from nt import stat [as 別名]
def test_utime(self):
        open('temp_file_does_not_exist.txt', 'w').close()
        import nt
        x = nt.stat('.')
        nt.utime('temp_file_does_not_exist.txt', (x[7], x[8]))
        y = nt.stat('temp_file_does_not_exist.txt')
        self.assertEqual(x[7], y[7])
        self.assertEqual(x[8], y[8])
        nt.unlink('temp_file_does_not_exist.txt')

    # times test 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:13,代碼來源:test_nt.py


注:本文中的nt.stat方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。