Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
_posixfile_ Class Reference

Public Member Functions

def __repr__
 
def open
 
def fileopen
 
def file
 
def dup
 
def dup2
 
def flags
 
def lock
 

Static Public Attributes

list states = ['open', 'closed']
 

Detailed Description

File wrapper class that provides extra POSIX file routines.

Definition at line 63 of file posixfile.py.

Member Function Documentation

def __repr__ (   self)

Definition at line 71 of file posixfile.py.

71 
72  def __repr__(self):
73  file = self._file_
74  return "<%s posixfile '%s', mode '%s' at %s>" % \
75  (self.states[file.closed], file.name, file.mode, \
76  hex(id(self))[2:])
def dup (   self)

Definition at line 103 of file posixfile.py.

104  def dup(self):
105  import posix
106 
107  if not hasattr(posix, 'fdopen'):
108  raise AttributeError, 'dup() method unavailable'
109 
110  return posix.fdopen(posix.dup(self._file_.fileno()), self._file_.mode)
def dup2 (   self,
  fd 
)

Definition at line 111 of file posixfile.py.

112  def dup2(self, fd):
113  import posix
114 
115  if not hasattr(posix, 'fdopen'):
116  raise AttributeError, 'dup() method unavailable'
117 
118  posix.dup2(self._file_.fileno(), fd)
119  return posix.fdopen(fd, self._file_.mode)
def file (   self)

Definition at line 100 of file posixfile.py.

References _posixfile_._file_.

101  def file(self):
102  return self._file_
def fileopen (   self,
  file 
)

Definition at line 84 of file posixfile.py.

References _posixfile_._file_, and sre_parse.dir.

84 
85  def fileopen(self, file):
86  import types
87  if `type(file)` != "<type 'file'>":
88  raise TypeError, 'posixfile.fileopen() arg must be file object'
89  self._file_ = file
90  # Copy basic file methods
91  for maybemethod in dir(file):
92  if not maybemethod.startswith('_'):
93  attr = getattr(file, maybemethod)
94  if isinstance(attr, types.BuiltinMethodType):
95  setattr(self, maybemethod, attr)
96  return self
def flags (   self,
  which 
)

Definition at line 120 of file posixfile.py.

References _posixfile_._file_.

121  def flags(self, *which):
122  import fcntl, os
123 
124  if which:
125  if len(which) > 1:
126  raise TypeError, 'Too many arguments'
127  which = which[0]
128  else: which = '?'
129 
130  l_flags = 0
131  if 'n' in which: l_flags = l_flags | os.O_NDELAY
132  if 'a' in which: l_flags = l_flags | os.O_APPEND
133  if 's' in which: l_flags = l_flags | os.O_SYNC
134 
135  file = self._file_
136 
137  if '=' not in which:
138  cur_fl = fcntl.fcntl(file.fileno(), fcntl.F_GETFL, 0)
139  if '!' in which: l_flags = cur_fl & ~ l_flags
140  else: l_flags = cur_fl | l_flags
141 
142  l_flags = fcntl.fcntl(file.fileno(), fcntl.F_SETFL, l_flags)
143 
144  if 'c' in which:
145  arg = ('!' not in which) # 0 is don't, 1 is do close on exec
146  l_flags = fcntl.fcntl(file.fileno(), fcntl.F_SETFD, arg)
147 
148  if '?' in which:
149  which = '' # Return current flags
150  l_flags = fcntl.fcntl(file.fileno(), fcntl.F_GETFL, 0)
151  if os.O_APPEND & l_flags: which = which + 'a'
152  if fcntl.fcntl(file.fileno(), fcntl.F_GETFD, 0) & 1:
153  which = which + 'c'
154  if os.O_NDELAY & l_flags: which = which + 'n'
155  if os.O_SYNC & l_flags: which = which + 's'
156  return which
def lock (   self,
  how,
  args 
)

Definition at line 157 of file posixfile.py.

158  def lock(self, how, *args):
159  import struct, fcntl
160 
161  if 'w' in how: l_type = fcntl.F_WRLCK
162  elif 'r' in how: l_type = fcntl.F_RDLCK
163  elif 'u' in how: l_type = fcntl.F_UNLCK
164  else: raise TypeError, 'no type of lock specified'
165 
166  if '|' in how: cmd = fcntl.F_SETLKW
167  elif '?' in how: cmd = fcntl.F_GETLK
168  else: cmd = fcntl.F_SETLK
169 
170  l_whence = 0
171  l_start = 0
172  l_len = 0
173 
174  if len(args) == 1:
175  l_len = args[0]
176  elif len(args) == 2:
177  l_len, l_start = args
178  elif len(args) == 3:
179  l_len, l_start, l_whence = args
180  elif len(args) > 3:
181  raise TypeError, 'too many arguments'
182 
183  # Hack by davem@magnet.com to get locking to go on freebsd;
184  # additions for AIX by Vladimir.Marangozov@imag.fr
185  import sys, os
186  if sys.platform in ('netbsd1',
187  'openbsd2',
188  'freebsd2', 'freebsd3', 'freebsd4', 'freebsd5',
189  'bsdos2', 'bsdos3', 'bsdos4'):
190  flock = struct.pack('lxxxxlxxxxlhh', \
191  l_start, l_len, os.getpid(), l_type, l_whence)
192  elif sys.platform in ['aix3', 'aix4']:
193  flock = struct.pack('hhlllii', \
194  l_type, l_whence, l_start, l_len, 0, 0, 0)
195  else:
196  flock = struct.pack('hhllhh', \
197  l_type, l_whence, l_start, l_len, 0, 0)
198 
199  flock = fcntl.fcntl(self._file_.fileno(), cmd, flock)
200 
201  if '?' in how:
202  if sys.platform in ('netbsd1',
203  'openbsd2',
204  'freebsd2', 'freebsd3', 'freebsd4', 'freebsd5',
205  'bsdos2', 'bsdos3', 'bsdos4'):
206  l_start, l_len, l_pid, l_type, l_whence = \
207  struct.unpack('lxxxxlxxxxlhh', flock)
208  elif sys.platform in ['aix3', 'aix4']:
209  l_type, l_whence, l_start, l_len, l_sysid, l_pid, l_vfs = \
210  struct.unpack('hhlllii', flock)
211  elif sys.platform == "linux2":
212  l_type, l_whence, l_start, l_len, l_pid, l_sysid = \
213  struct.unpack('hhllhh', flock)
214  else:
215  l_type, l_whence, l_start, l_len, l_sysid, l_pid = \
216  struct.unpack('hhllhh', flock)
217 
218  if l_type != fcntl.F_UNLCK:
219  if l_type == fcntl.F_RDLCK:
220  return 'r', l_len, l_start, l_whence, l_pid
221  else:
222  return 'w', l_len, l_start, l_whence, l_pid
def open (   self,
  name,
  mode = 'r',
  bufsize = -1 
)

Definition at line 80 of file posixfile.py.

References _posixfile_.fileopen().

80 
81  def open(self, name, mode='r', bufsize=-1):
82  import __builtin__
83  return self.fileopen(__builtin__.open(name, mode, bufsize))

Field Documentation

list states = ['open', 'closed']
static

Definition at line 66 of file posixfile.py.


The documentation for this class was generated from the following file: