16
16
17
17
18
18
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
-
50
19
class BadFile :
51
20
def __init__ (self , fn ):
52
21
self .fn = fn
@@ -78,12 +47,43 @@ def tearDown(self):
78
47
self .f .close ()
79
48
unlink (TESTFN )
80
49
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
+
81
80
def test_fcntl_fileno (self ):
82
81
# the example from the library docs
83
82
self .f = open (TESTFN , 'wb' )
84
83
rv = fcntl .fcntl (self .f .fileno (), fcntl .F_SETFL , os .O_NONBLOCK )
85
84
if verbose :
86
85
print ('Status from fcntl with O_NONBLOCK: ' , rv )
86
+ lockdata = self .get_lockdata ()
87
87
rv = fcntl .fcntl (self .f .fileno (), fcntl .F_SETLKW , lockdata )
88
88
if verbose :
89
89
print ('String from fcntl with F_SETLKW: ' , repr (rv ))
@@ -95,6 +95,7 @@ def test_fcntl_file_descriptor(self):
95
95
rv = fcntl .fcntl (self .f , fcntl .F_SETFL , os .O_NONBLOCK )
96
96
if verbose :
97
97
print ('Status from fcntl with O_NONBLOCK: ' , rv )
98
+ lockdata = self .get_lockdata ()
98
99
rv = fcntl .fcntl (self .f , fcntl .F_SETLKW , lockdata )
99
100
if verbose :
100
101
print ('String from fcntl with F_SETLKW: ' , repr (rv ))
0 commit comments