Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/imh-pyth.../lib/python2....
File: posixfile.py
"""Extended file operations available in POSIX.
[0] Fix | Delete
[1] Fix | Delete
f = posixfile.open(filename, [mode, [bufsize]])
[2] Fix | Delete
will create a new posixfile object
[3] Fix | Delete
[4] Fix | Delete
f = posixfile.fileopen(fileobject)
[5] Fix | Delete
will create a posixfile object from a builtin file object
[6] Fix | Delete
[7] Fix | Delete
f.file()
[8] Fix | Delete
will return the original builtin file object
[9] Fix | Delete
[10] Fix | Delete
f.dup()
[11] Fix | Delete
will return a new file object based on a new filedescriptor
[12] Fix | Delete
[13] Fix | Delete
f.dup2(fd)
[14] Fix | Delete
will return a new file object based on the given filedescriptor
[15] Fix | Delete
[16] Fix | Delete
f.flags(mode)
[17] Fix | Delete
will turn on the associated flag (merge)
[18] Fix | Delete
mode can contain the following characters:
[19] Fix | Delete
[20] Fix | Delete
(character representing a flag)
[21] Fix | Delete
a append only flag
[22] Fix | Delete
c close on exec flag
[23] Fix | Delete
n no delay flag
[24] Fix | Delete
s synchronization flag
[25] Fix | Delete
(modifiers)
[26] Fix | Delete
! turn flags 'off' instead of default 'on'
[27] Fix | Delete
= copy flags 'as is' instead of default 'merge'
[28] Fix | Delete
? return a string in which the characters represent the flags
[29] Fix | Delete
that are set
[30] Fix | Delete
[31] Fix | Delete
note: - the '!' and '=' modifiers are mutually exclusive.
[32] Fix | Delete
- the '?' modifier will return the status of the flags after they
[33] Fix | Delete
have been changed by other characters in the mode string
[34] Fix | Delete
[35] Fix | Delete
f.lock(mode [, len [, start [, whence]]])
[36] Fix | Delete
will (un)lock a region
[37] Fix | Delete
mode can contain the following characters:
[38] Fix | Delete
[39] Fix | Delete
(character representing type of lock)
[40] Fix | Delete
u unlock
[41] Fix | Delete
r read lock
[42] Fix | Delete
w write lock
[43] Fix | Delete
(modifiers)
[44] Fix | Delete
| wait until the lock can be granted
[45] Fix | Delete
? return the first lock conflicting with the requested lock
[46] Fix | Delete
or 'None' if there is no conflict. The lock returned is in the
[47] Fix | Delete
format (mode, len, start, whence, pid) where mode is a
[48] Fix | Delete
character representing the type of lock ('r' or 'w')
[49] Fix | Delete
[50] Fix | Delete
note: - the '?' modifier prevents a region from being locked; it is
[51] Fix | Delete
query only
[52] Fix | Delete
"""
[53] Fix | Delete
import warnings
[54] Fix | Delete
warnings.warn("The posixfile module is deprecated; "
[55] Fix | Delete
"fcntl.lockf() provides better locking", DeprecationWarning, 2)
[56] Fix | Delete
[57] Fix | Delete
class _posixfile_:
[58] Fix | Delete
"""File wrapper class that provides extra POSIX file routines."""
[59] Fix | Delete
[60] Fix | Delete
states = ['open', 'closed']
[61] Fix | Delete
[62] Fix | Delete
#
[63] Fix | Delete
# Internal routines
[64] Fix | Delete
#
[65] Fix | Delete
def __repr__(self):
[66] Fix | Delete
file = self._file_
[67] Fix | Delete
return "<%s posixfile '%s', mode '%s' at %s>" % \
[68] Fix | Delete
(self.states[file.closed], file.name, file.mode, \
[69] Fix | Delete
hex(id(self))[2:])
[70] Fix | Delete
[71] Fix | Delete
#
[72] Fix | Delete
# Initialization routines
[73] Fix | Delete
#
[74] Fix | Delete
def open(self, name, mode='r', bufsize=-1):
[75] Fix | Delete
import __builtin__
[76] Fix | Delete
return self.fileopen(__builtin__.open(name, mode, bufsize))
[77] Fix | Delete
[78] Fix | Delete
def fileopen(self, file):
[79] Fix | Delete
import types
[80] Fix | Delete
if repr(type(file)) != "<type 'file'>":
[81] Fix | Delete
raise TypeError, 'posixfile.fileopen() arg must be file object'
[82] Fix | Delete
self._file_ = file
[83] Fix | Delete
# Copy basic file methods
[84] Fix | Delete
for maybemethod in dir(file):
[85] Fix | Delete
if not maybemethod.startswith('_'):
[86] Fix | Delete
attr = getattr(file, maybemethod)
[87] Fix | Delete
if isinstance(attr, types.BuiltinMethodType):
[88] Fix | Delete
setattr(self, maybemethod, attr)
[89] Fix | Delete
return self
[90] Fix | Delete
[91] Fix | Delete
#
[92] Fix | Delete
# New methods
[93] Fix | Delete
#
[94] Fix | Delete
def file(self):
[95] Fix | Delete
return self._file_
[96] Fix | Delete
[97] Fix | Delete
def dup(self):
[98] Fix | Delete
import posix
[99] Fix | Delete
[100] Fix | Delete
if not hasattr(posix, 'fdopen'):
[101] Fix | Delete
raise AttributeError, 'dup() method unavailable'
[102] Fix | Delete
[103] Fix | Delete
return posix.fdopen(posix.dup(self._file_.fileno()), self._file_.mode)
[104] Fix | Delete
[105] Fix | Delete
def dup2(self, fd):
[106] Fix | Delete
import posix
[107] Fix | Delete
[108] Fix | Delete
if not hasattr(posix, 'fdopen'):
[109] Fix | Delete
raise AttributeError, 'dup() method unavailable'
[110] Fix | Delete
[111] Fix | Delete
posix.dup2(self._file_.fileno(), fd)
[112] Fix | Delete
return posix.fdopen(fd, self._file_.mode)
[113] Fix | Delete
[114] Fix | Delete
def flags(self, *which):
[115] Fix | Delete
import fcntl, os
[116] Fix | Delete
[117] Fix | Delete
if which:
[118] Fix | Delete
if len(which) > 1:
[119] Fix | Delete
raise TypeError, 'Too many arguments'
[120] Fix | Delete
which = which[0]
[121] Fix | Delete
else: which = '?'
[122] Fix | Delete
[123] Fix | Delete
l_flags = 0
[124] Fix | Delete
if 'n' in which: l_flags = l_flags | os.O_NDELAY
[125] Fix | Delete
if 'a' in which: l_flags = l_flags | os.O_APPEND
[126] Fix | Delete
if 's' in which: l_flags = l_flags | os.O_SYNC
[127] Fix | Delete
[128] Fix | Delete
file = self._file_
[129] Fix | Delete
[130] Fix | Delete
if '=' not in which:
[131] Fix | Delete
cur_fl = fcntl.fcntl(file.fileno(), fcntl.F_GETFL, 0)
[132] Fix | Delete
if '!' in which: l_flags = cur_fl & ~ l_flags
[133] Fix | Delete
else: l_flags = cur_fl | l_flags
[134] Fix | Delete
[135] Fix | Delete
l_flags = fcntl.fcntl(file.fileno(), fcntl.F_SETFL, l_flags)
[136] Fix | Delete
[137] Fix | Delete
if 'c' in which:
[138] Fix | Delete
arg = ('!' not in which) # 0 is don't, 1 is do close on exec
[139] Fix | Delete
l_flags = fcntl.fcntl(file.fileno(), fcntl.F_SETFD, arg)
[140] Fix | Delete
[141] Fix | Delete
if '?' in which:
[142] Fix | Delete
which = '' # Return current flags
[143] Fix | Delete
l_flags = fcntl.fcntl(file.fileno(), fcntl.F_GETFL, 0)
[144] Fix | Delete
if os.O_APPEND & l_flags: which = which + 'a'
[145] Fix | Delete
if fcntl.fcntl(file.fileno(), fcntl.F_GETFD, 0) & 1:
[146] Fix | Delete
which = which + 'c'
[147] Fix | Delete
if os.O_NDELAY & l_flags: which = which + 'n'
[148] Fix | Delete
if os.O_SYNC & l_flags: which = which + 's'
[149] Fix | Delete
return which
[150] Fix | Delete
[151] Fix | Delete
def lock(self, how, *args):
[152] Fix | Delete
import struct, fcntl
[153] Fix | Delete
[154] Fix | Delete
if 'w' in how: l_type = fcntl.F_WRLCK
[155] Fix | Delete
elif 'r' in how: l_type = fcntl.F_RDLCK
[156] Fix | Delete
elif 'u' in how: l_type = fcntl.F_UNLCK
[157] Fix | Delete
else: raise TypeError, 'no type of lock specified'
[158] Fix | Delete
[159] Fix | Delete
if '|' in how: cmd = fcntl.F_SETLKW
[160] Fix | Delete
elif '?' in how: cmd = fcntl.F_GETLK
[161] Fix | Delete
else: cmd = fcntl.F_SETLK
[162] Fix | Delete
[163] Fix | Delete
l_whence = 0
[164] Fix | Delete
l_start = 0
[165] Fix | Delete
l_len = 0
[166] Fix | Delete
[167] Fix | Delete
if len(args) == 1:
[168] Fix | Delete
l_len = args[0]
[169] Fix | Delete
elif len(args) == 2:
[170] Fix | Delete
l_len, l_start = args
[171] Fix | Delete
elif len(args) == 3:
[172] Fix | Delete
l_len, l_start, l_whence = args
[173] Fix | Delete
elif len(args) > 3:
[174] Fix | Delete
raise TypeError, 'too many arguments'
[175] Fix | Delete
[176] Fix | Delete
# Hack by davem@magnet.com to get locking to go on freebsd;
[177] Fix | Delete
# additions for AIX by Vladimir.Marangozov@imag.fr
[178] Fix | Delete
import sys, os
[179] Fix | Delete
if sys.platform in ('netbsd1',
[180] Fix | Delete
'openbsd2',
[181] Fix | Delete
'freebsd2', 'freebsd3', 'freebsd4', 'freebsd5',
[182] Fix | Delete
'freebsd6', 'freebsd7', 'freebsd8',
[183] Fix | Delete
'bsdos2', 'bsdos3', 'bsdos4'):
[184] Fix | Delete
flock = struct.pack('lxxxxlxxxxlhh', \
[185] Fix | Delete
l_start, l_len, os.getpid(), l_type, l_whence)
[186] Fix | Delete
elif sys.platform in ('aix3', 'aix4'):
[187] Fix | Delete
flock = struct.pack('hhlllii', \
[188] Fix | Delete
l_type, l_whence, l_start, l_len, 0, 0, 0)
[189] Fix | Delete
else:
[190] Fix | Delete
flock = struct.pack('hhllhh', \
[191] Fix | Delete
l_type, l_whence, l_start, l_len, 0, 0)
[192] Fix | Delete
[193] Fix | Delete
flock = fcntl.fcntl(self._file_.fileno(), cmd, flock)
[194] Fix | Delete
[195] Fix | Delete
if '?' in how:
[196] Fix | Delete
if sys.platform in ('netbsd1',
[197] Fix | Delete
'openbsd2',
[198] Fix | Delete
'freebsd2', 'freebsd3', 'freebsd4', 'freebsd5',
[199] Fix | Delete
'bsdos2', 'bsdos3', 'bsdos4'):
[200] Fix | Delete
l_start, l_len, l_pid, l_type, l_whence = \
[201] Fix | Delete
struct.unpack('lxxxxlxxxxlhh', flock)
[202] Fix | Delete
elif sys.platform in ('aix3', 'aix4'):
[203] Fix | Delete
l_type, l_whence, l_start, l_len, l_sysid, l_pid, l_vfs = \
[204] Fix | Delete
struct.unpack('hhlllii', flock)
[205] Fix | Delete
elif sys.platform == "linux2":
[206] Fix | Delete
l_type, l_whence, l_start, l_len, l_pid, l_sysid = \
[207] Fix | Delete
struct.unpack('hhllhh', flock)
[208] Fix | Delete
else:
[209] Fix | Delete
l_type, l_whence, l_start, l_len, l_sysid, l_pid = \
[210] Fix | Delete
struct.unpack('hhllhh', flock)
[211] Fix | Delete
[212] Fix | Delete
if l_type != fcntl.F_UNLCK:
[213] Fix | Delete
if l_type == fcntl.F_RDLCK:
[214] Fix | Delete
return 'r', l_len, l_start, l_whence, l_pid
[215] Fix | Delete
else:
[216] Fix | Delete
return 'w', l_len, l_start, l_whence, l_pid
[217] Fix | Delete
[218] Fix | Delete
def open(name, mode='r', bufsize=-1):
[219] Fix | Delete
"""Public routine to open a file as a posixfile object."""
[220] Fix | Delete
return _posixfile_().open(name, mode, bufsize)
[221] Fix | Delete
[222] Fix | Delete
def fileopen(file):
[223] Fix | Delete
"""Public routine to get a posixfile object from a Python file object."""
[224] Fix | Delete
return _posixfile_().fileopen(file)
[225] Fix | Delete
[226] Fix | Delete
#
[227] Fix | Delete
# Constants
[228] Fix | Delete
#
[229] Fix | Delete
SEEK_SET = 0
[230] Fix | Delete
SEEK_CUR = 1
[231] Fix | Delete
SEEK_END = 2
[232] Fix | Delete
[233] Fix | Delete
#
[234] Fix | Delete
# End of posixfile.py
[235] Fix | Delete
#
[236] Fix | Delete
[237] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function