1616
1717
1818
19- def get_lockdata ():
20- try :
21- os .O_LARGEFILE
22- except AttributeError :
23- start_len = "ll"
24- else :
25- start_len = "qq"
26-
27- if (sys .platform .startswith (('netbsd' , 'freebsd' , 'openbsd' ))
28- or sys .platform == 'darwin' ):
29- if struct .calcsize ('l' ) == 8 :
30- off_t = 'l'
31- pid_t = 'i'
32- else :
33- off_t = 'lxxxx'
34- pid_t = 'l'
35- lockdata = struct .pack (off_t + off_t + pid_t + 'hh' , 0 , 0 , 0 ,
36- fcntl .F_WRLCK , 0 )
37- elif sys .platform .startswith ('gnukfreebsd' ):
38- lockdata = struct .pack ('qqihhi' , 0 , 0 , 0 , fcntl .F_WRLCK , 0 , 0 )
39- elif sys .platform in ['hp-uxB' , 'unixware7' ]:
40- lockdata = struct .pack ('hhlllii' , fcntl .F_WRLCK , 0 , 0 , 0 , 0 , 0 , 0 )
41- else :
42- lockdata = struct .pack ('hh' + start_len + 'hh' , fcntl .F_WRLCK , 0 , 0 , 0 , 0 , 0 )
43- if lockdata :
44- if verbose :
45- print ('struct.pack: ' , repr (lockdata ))
46- return lockdata
47-
48- lockdata = get_lockdata ()
49-
5019class BadFile :
5120 def __init__ (self , fn ):
5221 self .fn = fn
@@ -78,12 +47,43 @@ def tearDown(self):
7847 self .f .close ()
7948 unlink (TESTFN )
8049
50+ @staticmethod
51+ def get_lockdata ():
52+ try :
53+ os .O_LARGEFILE
54+ except AttributeError :
55+ start_len = "ll"
56+ else :
57+ start_len = "qq"
58+
59+ if (sys .platform .startswith (('netbsd' , 'freebsd' , 'openbsd' ))
60+ or sys .platform == 'darwin' ):
61+ if struct .calcsize ('l' ) == 8 :
62+ off_t = 'l'
63+ pid_t = 'i'
64+ else :
65+ off_t = 'lxxxx'
66+ pid_t = 'l'
67+ lockdata = struct .pack (off_t + off_t + pid_t + 'hh' , 0 , 0 , 0 ,
68+ fcntl .F_WRLCK , 0 )
69+ elif sys .platform .startswith ('gnukfreebsd' ):
70+ lockdata = struct .pack ('qqihhi' , 0 , 0 , 0 , fcntl .F_WRLCK , 0 , 0 )
71+ elif sys .platform in ['hp-uxB' , 'unixware7' ]:
72+ lockdata = struct .pack ('hhlllii' , fcntl .F_WRLCK , 0 , 0 , 0 , 0 , 0 , 0 )
73+ else :
74+ lockdata = struct .pack ('hh' + start_len + 'hh' , fcntl .F_WRLCK , 0 , 0 , 0 , 0 , 0 )
75+ if lockdata :
76+ if verbose :
77+ print ('struct.pack: ' , repr (lockdata ))
78+ return lockdata
79+
8180 def test_fcntl_fileno (self ):
8281 # the example from the library docs
8382 self .f = open (TESTFN , 'wb' )
8483 rv = fcntl .fcntl (self .f .fileno (), fcntl .F_SETFL , os .O_NONBLOCK )
8584 if verbose :
8685 print ('Status from fcntl with O_NONBLOCK: ' , rv )
86+ lockdata = self .get_lockdata ()
8787 rv = fcntl .fcntl (self .f .fileno (), fcntl .F_SETLKW , lockdata )
8888 if verbose :
8989 print ('String from fcntl with F_SETLKW: ' , repr (rv ))
@@ -95,6 +95,7 @@ def test_fcntl_file_descriptor(self):
9595 rv = fcntl .fcntl (self .f , fcntl .F_SETFL , os .O_NONBLOCK )
9696 if verbose :
9797 print ('Status from fcntl with O_NONBLOCK: ' , rv )
98+ lockdata = self .get_lockdata ()
9899 rv = fcntl .fcntl (self .f , fcntl .F_SETLKW , lockdata )
99100 if verbose :
100101 print ('String from fcntl with F_SETLKW: ' , repr (rv ))
0 commit comments