Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a94414a

Browse files
committed
Remove all remaining uses of the FCNTL module from the standard library.
1 parent 7c116d7 commit a94414a

3 files changed

Lines changed: 29 additions & 30 deletions

File tree

Lib/asyncore.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,6 @@ def close_all (map=None):
510510
import os
511511
if os.name == 'posix':
512512
import fcntl
513-
import FCNTL
514513

515514
class file_wrapper:
516515
# here we override just enough to make a file
@@ -538,9 +537,9 @@ def __init__ (self, fd):
538537
dispatcher.__init__ (self)
539538
self.connected = 1
540539
# set it to non-blocking mode
541-
flags = fcntl.fcntl (fd, FCNTL.F_GETFL, 0)
542-
flags = flags | FCNTL.O_NONBLOCK
543-
fcntl.fcntl (fd, FCNTL.F_SETFL, flags)
540+
flags = fcntl.fcntl (fd, fcntl.F_GETFL, 0)
541+
flags = flags | os.O_NONBLOCK
542+
fcntl.fcntl (fd, fcntl.F_SETFL, flags)
544543
self.set_file (fd)
545544

546545
def set_file (self, fd):

Lib/lib-old/lockfile.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import struct, fcntl, FCNTL
1+
import struct, fcntl
22

33
def writelock(f):
4-
_lock(f, FCNTL.F_WRLCK)
4+
_lock(f, fcntl.F_WRLCK)
55

66
def readlock(f):
7-
_lock(f, FCNTL.F_RDLCK)
7+
_lock(f, fcntl.F_RDLCK)
88

99
def unlock(f):
10-
_lock(f, FCNTL.F_UNLCK)
10+
_lock(f, fcntl.F_UNLCK)
1111

1212
def _lock(f, op):
13-
dummy = fcntl.fcntl(f.fileno(), FCNTL.F_SETLKW,
13+
dummy = fcntl.fcntl(f.fileno(), fcntl.F_SETLKW,
1414
struct.pack('2h8l', op,
1515
0, 0, 0, 0, 0, 0, 0, 0, 0))

Lib/posixfile.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def dup2(self, fd):
107107
return posix.fdopen(fd, self._file_.mode)
108108

109109
def flags(self, *which):
110-
import fcntl, FCNTL
110+
import fcntl
111111

112112
if which:
113113
if len(which) > 1:
@@ -116,44 +116,44 @@ def flags(self, *which):
116116
else: which = '?'
117117

118118
l_flags = 0
119-
if 'n' in which: l_flags = l_flags | FCNTL.O_NDELAY
120-
if 'a' in which: l_flags = l_flags | FCNTL.O_APPEND
121-
if 's' in which: l_flags = l_flags | FCNTL.O_SYNC
119+
if 'n' in which: l_flags = l_flags | os.O_NDELAY
120+
if 'a' in which: l_flags = l_flags | os.O_APPEND
121+
if 's' in which: l_flags = l_flags | os.O_SYNC
122122

123123
file = self._file_
124124

125125
if '=' not in which:
126-
cur_fl = fcntl.fcntl(file.fileno(), FCNTL.F_GETFL, 0)
126+
cur_fl = fcntl.fcntl(file.fileno(), fcntl.F_GETFL, 0)
127127
if '!' in which: l_flags = cur_fl & ~ l_flags
128128
else: l_flags = cur_fl | l_flags
129129

130-
l_flags = fcntl.fcntl(file.fileno(), FCNTL.F_SETFL, l_flags)
130+
l_flags = fcntl.fcntl(file.fileno(), fcntl.F_SETFL, l_flags)
131131

132132
if 'c' in which:
133133
arg = ('!' not in which) # 0 is don't, 1 is do close on exec
134-
l_flags = fcntl.fcntl(file.fileno(), FCNTL.F_SETFD, arg)
134+
l_flags = fcntl.fcntl(file.fileno(), fcntl.F_SETFD, arg)
135135

136136
if '?' in which:
137137
which = '' # Return current flags
138-
l_flags = fcntl.fcntl(file.fileno(), FCNTL.F_GETFL, 0)
139-
if FCNTL.O_APPEND & l_flags: which = which + 'a'
140-
if fcntl.fcntl(file.fileno(), FCNTL.F_GETFD, 0) & 1:
138+
l_flags = fcntl.fcntl(file.fileno(), fcntl.F_GETFL, 0)
139+
if os.O_APPEND & l_flags: which = which + 'a'
140+
if fcntl.fcntl(file.fileno(), fcntl.F_GETFD, 0) & 1:
141141
which = which + 'c'
142-
if FCNTL.O_NDELAY & l_flags: which = which + 'n'
143-
if FCNTL.O_SYNC & l_flags: which = which + 's'
142+
if os.O_NDELAY & l_flags: which = which + 'n'
143+
if os.O_SYNC & l_flags: which = which + 's'
144144
return which
145145

146146
def lock(self, how, *args):
147-
import struct, fcntl, FCNTL
147+
import struct, fcntl
148148

149-
if 'w' in how: l_type = FCNTL.F_WRLCK
150-
elif 'r' in how: l_type = FCNTL.F_RDLCK
151-
elif 'u' in how: l_type = FCNTL.F_UNLCK
149+
if 'w' in how: l_type = fcntl.F_WRLCK
150+
elif 'r' in how: l_type = fcntl.F_RDLCK
151+
elif 'u' in how: l_type = fcntl.F_UNLCK
152152
else: raise TypeError, 'no type of lock specified'
153153

154-
if '|' in how: cmd = FCNTL.F_SETLKW
155-
elif '?' in how: cmd = FCNTL.F_GETLK
156-
else: cmd = FCNTL.F_SETLK
154+
if '|' in how: cmd = fcntl.F_SETLKW
155+
elif '?' in how: cmd = fcntl.F_GETLK
156+
else: cmd = fcntl.F_SETLK
157157

158158
l_whence = 0
159159
l_start = 0
@@ -203,8 +203,8 @@ def lock(self, how, *args):
203203
l_type, l_whence, l_start, l_len, l_sysid, l_pid = \
204204
struct.unpack('hhllhh', flock)
205205

206-
if l_type != FCNTL.F_UNLCK:
207-
if l_type == FCNTL.F_RDLCK:
206+
if l_type != fcntl.F_UNLCK:
207+
if l_type == fcntl.F_RDLCK:
208208
return 'r', l_len, l_start, l_whence, l_pid
209209
else:
210210
return 'w', l_len, l_start, l_whence, l_pid

0 commit comments

Comments
 (0)