0001 #! /usr/bin/env python 0002 """Test program for the fcntl C module. 0003 OS/2+EMX doesn't support the file locking operations. 0004 Roger E. Masse 0005 """ 0006 import struct 0007 import fcntl 0008 import os, sys 0009 from test.test_support import verbose, TESTFN 0010 0011 filename = TESTFN 0012 0013 try: 0014 os.O_LARGEFILE 0015 except AttributeError: 0016 start_len = "ll" 0017 else: 0018 start_len = "qq" 0019 0020 if sys.platform.startswith('atheos'): 0021 start_len = "qq" 0022 0023 if sys.platform in ('netbsd1', 'Darwin1.2', 'darwin', 0024 'freebsd2', 'freebsd3', 'freebsd4', 'freebsd5', 'freebsd6', 0025 'bsdos2', 'bsdos3', 'bsdos4', 0026 'openbsd', 'openbsd2', 'openbsd3'): 0027 lockdata = struct.pack('lxxxxlxxxxlhh', 0, 0, 0, fcntl.F_WRLCK, 0) 0028 elif sys.platform in ['aix3', 'aix4', 'hp-uxB', 'unixware7']: 0029 lockdata = struct.pack('hhlllii', fcntl.F_WRLCK, 0, 0, 0, 0, 0, 0) 0030 elif sys.platform in ['os2emx']: 0031 lockdata = None 0032 else: 0033 lockdata = struct.pack('hh'+start_len+'hh', fcntl.F_WRLCK, 0, 0, 0, 0, 0) 0034 if lockdata: 0035 if verbose: 0036 print 'struct.pack: ', repr(lockdata) 0037 0038 # the example from the library docs 0039 f = open(filename, 'w') 0040 rv = fcntl.fcntl(f.fileno(), fcntl.F_SETFL, os.O_NONBLOCK) 0041 if verbose: 0042 print 'Status from fnctl with O_NONBLOCK: ', rv 0043 0044 if sys.platform not in ['os2emx']: 0045 rv = fcntl.fcntl(f.fileno(), fcntl.F_SETLKW, lockdata) 0046 if verbose: 0047 print 'String from fcntl with F_SETLKW: ', repr(rv) 0048 0049 f.close() 0050 os.unlink(filename) 0051 0052 0053 # Again, but pass the file rather than numeric descriptor: 0054 f = open(filename, 'w') 0055 rv = fcntl.fcntl(f, fcntl.F_SETFL, os.O_NONBLOCK) 0056 0057 if sys.platform not in ['os2emx']: 0058 rv = fcntl.fcntl(f, fcntl.F_SETLKW, lockdata) 0059 0060 f.close() 0061 os.unlink(filename) 0062
Generated by PyXR 0.9.4