Remove all remaining uses of the FCNTL module from the standard library.
This commit is contained in:
parent
7c116d7acb
commit
a94414a287
|
@ -510,7 +510,6 @@ def close_all (map=None):
|
|||
import os
|
||||
if os.name == 'posix':
|
||||
import fcntl
|
||||
import FCNTL
|
||||
|
||||
class file_wrapper:
|
||||
# here we override just enough to make a file
|
||||
|
@ -538,9 +537,9 @@ if os.name == 'posix':
|
|||
dispatcher.__init__ (self)
|
||||
self.connected = 1
|
||||
# set it to non-blocking mode
|
||||
flags = fcntl.fcntl (fd, FCNTL.F_GETFL, 0)
|
||||
flags = flags | FCNTL.O_NONBLOCK
|
||||
fcntl.fcntl (fd, FCNTL.F_SETFL, flags)
|
||||
flags = fcntl.fcntl (fd, fcntl.F_GETFL, 0)
|
||||
flags = flags | os.O_NONBLOCK
|
||||
fcntl.fcntl (fd, fcntl.F_SETFL, flags)
|
||||
self.set_file (fd)
|
||||
|
||||
def set_file (self, fd):
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
import struct, fcntl, FCNTL
|
||||
import struct, fcntl
|
||||
|
||||
def writelock(f):
|
||||
_lock(f, FCNTL.F_WRLCK)
|
||||
_lock(f, fcntl.F_WRLCK)
|
||||
|
||||
def readlock(f):
|
||||
_lock(f, FCNTL.F_RDLCK)
|
||||
_lock(f, fcntl.F_RDLCK)
|
||||
|
||||
def unlock(f):
|
||||
_lock(f, FCNTL.F_UNLCK)
|
||||
_lock(f, fcntl.F_UNLCK)
|
||||
|
||||
def _lock(f, op):
|
||||
dummy = fcntl.fcntl(f.fileno(), FCNTL.F_SETLKW,
|
||||
dummy = fcntl.fcntl(f.fileno(), fcntl.F_SETLKW,
|
||||
struct.pack('2h8l', op,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0))
|
||||
|
|
|
@ -107,7 +107,7 @@ class _posixfile_:
|
|||
return posix.fdopen(fd, self._file_.mode)
|
||||
|
||||
def flags(self, *which):
|
||||
import fcntl, FCNTL
|
||||
import fcntl
|
||||
|
||||
if which:
|
||||
if len(which) > 1:
|
||||
|
@ -116,44 +116,44 @@ class _posixfile_:
|
|||
else: which = '?'
|
||||
|
||||
l_flags = 0
|
||||
if 'n' in which: l_flags = l_flags | FCNTL.O_NDELAY
|
||||
if 'a' in which: l_flags = l_flags | FCNTL.O_APPEND
|
||||
if 's' in which: l_flags = l_flags | FCNTL.O_SYNC
|
||||
if 'n' in which: l_flags = l_flags | os.O_NDELAY
|
||||
if 'a' in which: l_flags = l_flags | os.O_APPEND
|
||||
if 's' in which: l_flags = l_flags | os.O_SYNC
|
||||
|
||||
file = self._file_
|
||||
|
||||
if '=' not in which:
|
||||
cur_fl = fcntl.fcntl(file.fileno(), FCNTL.F_GETFL, 0)
|
||||
cur_fl = fcntl.fcntl(file.fileno(), fcntl.F_GETFL, 0)
|
||||
if '!' in which: l_flags = cur_fl & ~ l_flags
|
||||
else: l_flags = cur_fl | l_flags
|
||||
|
||||
l_flags = fcntl.fcntl(file.fileno(), FCNTL.F_SETFL, l_flags)
|
||||
l_flags = fcntl.fcntl(file.fileno(), fcntl.F_SETFL, l_flags)
|
||||
|
||||
if 'c' in which:
|
||||
arg = ('!' not in which) # 0 is don't, 1 is do close on exec
|
||||
l_flags = fcntl.fcntl(file.fileno(), FCNTL.F_SETFD, arg)
|
||||
l_flags = fcntl.fcntl(file.fileno(), fcntl.F_SETFD, arg)
|
||||
|
||||
if '?' in which:
|
||||
which = '' # Return current flags
|
||||
l_flags = fcntl.fcntl(file.fileno(), FCNTL.F_GETFL, 0)
|
||||
if FCNTL.O_APPEND & l_flags: which = which + 'a'
|
||||
if fcntl.fcntl(file.fileno(), FCNTL.F_GETFD, 0) & 1:
|
||||
l_flags = fcntl.fcntl(file.fileno(), fcntl.F_GETFL, 0)
|
||||
if os.O_APPEND & l_flags: which = which + 'a'
|
||||
if fcntl.fcntl(file.fileno(), fcntl.F_GETFD, 0) & 1:
|
||||
which = which + 'c'
|
||||
if FCNTL.O_NDELAY & l_flags: which = which + 'n'
|
||||
if FCNTL.O_SYNC & l_flags: which = which + 's'
|
||||
if os.O_NDELAY & l_flags: which = which + 'n'
|
||||
if os.O_SYNC & l_flags: which = which + 's'
|
||||
return which
|
||||
|
||||
def lock(self, how, *args):
|
||||
import struct, fcntl, FCNTL
|
||||
import struct, fcntl
|
||||
|
||||
if 'w' in how: l_type = FCNTL.F_WRLCK
|
||||
elif 'r' in how: l_type = FCNTL.F_RDLCK
|
||||
elif 'u' in how: l_type = FCNTL.F_UNLCK
|
||||
if 'w' in how: l_type = fcntl.F_WRLCK
|
||||
elif 'r' in how: l_type = fcntl.F_RDLCK
|
||||
elif 'u' in how: l_type = fcntl.F_UNLCK
|
||||
else: raise TypeError, 'no type of lock specified'
|
||||
|
||||
if '|' in how: cmd = FCNTL.F_SETLKW
|
||||
elif '?' in how: cmd = FCNTL.F_GETLK
|
||||
else: cmd = FCNTL.F_SETLK
|
||||
if '|' in how: cmd = fcntl.F_SETLKW
|
||||
elif '?' in how: cmd = fcntl.F_GETLK
|
||||
else: cmd = fcntl.F_SETLK
|
||||
|
||||
l_whence = 0
|
||||
l_start = 0
|
||||
|
@ -203,8 +203,8 @@ class _posixfile_:
|
|||
l_type, l_whence, l_start, l_len, l_sysid, l_pid = \
|
||||
struct.unpack('hhllhh', flock)
|
||||
|
||||
if l_type != FCNTL.F_UNLCK:
|
||||
if l_type == FCNTL.F_RDLCK:
|
||||
if l_type != fcntl.F_UNLCK:
|
||||
if l_type == fcntl.F_RDLCK:
|
||||
return 'r', l_len, l_start, l_whence, l_pid
|
||||
else:
|
||||
return 'w', l_len, l_start, l_whence, l_pid
|
||||
|
|
Loading…
Reference in New Issue