Python nt.stat() Examples
The following are 27
code examples of nt.stat().
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
nt
, or try the search function
.
Example #1
Source File: stdmodules.py From ironpython2 with Apache License 2.0 | 6 votes |
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
Example #2
Source File: stdmodules.py From ironpython2 with Apache License 2.0 | 6 votes |
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
Example #3
Source File: test_nt.py From ironpython2 with Apache License 2.0 | 6 votes |
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)
Example #4
Source File: test_nt.py From ironpython3 with Apache License 2.0 | 6 votes |
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
Example #5
Source File: test_nt.py From ironpython2 with Apache License 2.0 | 6 votes |
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
Example #6
Source File: stdmodules.py From ironpython3 with Apache License 2.0 | 6 votes |
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
Example #7
Source File: stdmodules.py From ironpython3 with Apache License 2.0 | 6 votes |
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
Example #8
Source File: imputil.py From canape with GNU General Public License v3.0 | 5 votes |
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
Example #9
Source File: imputil.py From meddle with MIT License | 5 votes |
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
Example #10
Source File: imputil.py From unity-python with MIT License | 5 votes |
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
Example #11
Source File: imputil.py From PokemonGo-DesktopMap with MIT License | 5 votes |
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
Example #12
Source File: imputil.py From RevitBatchProcessor with GNU General Public License v3.0 | 5 votes |
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
Example #13
Source File: imputil.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
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
Example #14
Source File: test_nt.py From ironpython3 with Apache License 2.0 | 5 votes |
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
Example #15
Source File: test_nt.py From ironpython3 with Apache License 2.0 | 5 votes |
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
Example #16
Source File: test_nt.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_stat_cp34910(self): self.assertEqual(nt.stat('/'), nt.stat(b'/')) self.assertEqual(nt.lstat('/'), nt.lstat(b'/')) # getcwdb test
Example #17
Source File: test_nt.py From ironpython3 with Apache License 2.0 | 5 votes |
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
Example #18
Source File: test_nt.py From ironpython3 with Apache License 2.0 | 5 votes |
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
Example #19
Source File: imputil.py From oss-ftp with MIT License | 5 votes |
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
Example #20
Source File: imputil.py From BinderFilter with MIT License | 5 votes |
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
Example #21
Source File: test_nt.py From ironpython2 with Apache License 2.0 | 5 votes |
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')
Example #22
Source File: test_nt.py From ironpython2 with Apache License 2.0 | 5 votes |
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
Example #23
Source File: test_nt.py From ironpython2 with Apache License 2.0 | 5 votes |
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
Example #24
Source File: test_nt.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_listdir(self): self.assertRaises(TypeError, nt.listdir, None) self.assertEqual(nt.listdir(nt.getcwd()), nt.listdir('.')) # stat,lstat
Example #25
Source File: imputil.py From ironpython2 with Apache License 2.0 | 5 votes |
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
Example #26
Source File: test_nt.py From ironpython2 with Apache License 2.0 | 4 votes |
def test_tempnam(self): #sanity checks self.assertEqual(type(nt.tempnam()), str) self.assertEqual(type(nt.tempnam("garbage name should still work")), str) #Very basic case joe = nt.tempnam() last_dir = joe.rfind("\\") temp_dir = joe[:last_dir+1] self.assertTrue(os.path.exists(temp_dir)) self.assertTrue(not os.path.exists(joe)) #Basic case where we give it an existing directory and ensure #it uses that directory joe = nt.tempnam(self.temp_dir) last_dir = joe.rfind("\\") temp_dir = joe[:last_dir+1] self.assertTrue(os.path.exists(temp_dir)) self.assertTrue(not os.path.exists(joe)) # The next line is not guaranteed to be true in some scenarios. #self.assertEqual(nt.stat(temp_dir.strip("\\")), nt.stat(get_temp_dir())) #few random prefixes prefix_names = ["", "a", "1", "_", ".", "sillyprefix", " ", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", ] #test a few directory names that shouldn't really work dir_names = ["b", "2", "_", ".", "anotherprefix", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", None] for dir_name in dir_names: #just try the directory name on it's own joe = nt.tempnam(dir_name) last_dir = joe.rfind("\\") temp_dir = joe[:last_dir+1] self.assertTrue(os.path.exists(temp_dir)) self.assertTrue(not os.path.exists(joe)) self.assertTrue(temp_dir != dir_name) #now try every prefix for prefix_name in prefix_names: joe = nt.tempnam(dir_name, prefix_name) last_dir = joe.rfind("\\") temp_dir = joe[:last_dir+1] file_name = joe[last_dir+1:] self.assertTrue(os.path.exists(temp_dir)) self.assertTrue(not os.path.exists(joe)) self.assertTrue(temp_dir != dir_name) self.assertTrue(file_name.startswith(prefix_name))
Example #27
Source File: test_nt.py From ironpython3 with Apache License 2.0 | 4 votes |
def test_open(self): open('temp.txt', 'w+').close() try: fd = nt.open('temp.txt', nt.O_WRONLY | nt.O_CREAT) nt.close(fd) self.assertRaisesNumber(OSError, 17, nt.open, 'temp.txt', nt.O_CREAT | nt.O_EXCL) for flag in [nt.O_EXCL, nt.O_APPEND]: fd = nt.open('temp.txt', nt.O_RDONLY | flag) nt.close(fd) fd = nt.open('temp.txt', nt.O_WRONLY | flag) nt.close(fd) fd = nt.open('temp.txt', nt.O_RDWR | flag) nt.close(fd) # sanity test tempfilename = "temp.txt" fd = nt.open(tempfilename,256,1) nt.close(fd) nt.unlink('temp.txt') f = nt.open('temp.txt', nt.O_TEMPORARY | nt.O_CREAT) nt.close(f) self.assertRaises(OSError, nt.stat, 'temp.txt') # TODO: These tests should probably test more functionality regarding O_SEQUENTIAL/O_RANDOM f = nt.open('temp.txt', nt.O_TEMPORARY | nt.O_CREAT | nt.O_SEQUENTIAL | nt.O_RDWR) nt.close(f) self.assertRaises(OSError, nt.stat, 'temp.txt') f = nt.open('temp.txt', nt.O_TEMPORARY | nt.O_CREAT | nt.O_RANDOM | nt.O_RDWR) nt.close(f) self.assertRaises(OSError, nt.stat, 'temp.txt') finally: try: # should fail if the file doesn't exist nt.unlink('temp.txt') except: pass