本文整理匯總了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
示例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
示例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)
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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')
示例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
示例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
示例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
示例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