home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_673 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  5.3 KB  |  177 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import warnings
  5. warnings.warn('The posixfile module is deprecated; fcntl.lockf() provides better locking', DeprecationWarning, 2)
  6.  
  7. class _posixfile_:
  8.     states = [
  9.         'open',
  10.         'closed']
  11.     
  12.     def __repr__(self):
  13.         file = self._file_
  14.         return "<%s posixfile '%s', mode '%s' at %s>" % (self.states[file.closed], file.name, file.mode, hex(id(self))[2:])
  15.  
  16.     
  17.     def open(self, name, mode = 'r', bufsize = -1):
  18.         import __builtin__
  19.         return self.fileopen(__builtin__.open(name, mode, bufsize))
  20.  
  21.     
  22.     def fileopen(self, file):
  23.         import types
  24.         if repr(type(file)) != "<type 'file'>":
  25.             raise TypeError, 'posixfile.fileopen() arg must be file object'
  26.         repr(type(file)) != "<type 'file'>"
  27.         self._file_ = file
  28.         for maybemethod in dir(file):
  29.             if not maybemethod.startswith('_'):
  30.                 attr = getattr(file, maybemethod)
  31.                 if isinstance(attr, types.BuiltinMethodType):
  32.                     setattr(self, maybemethod, attr)
  33.                 
  34.             isinstance(attr, types.BuiltinMethodType)
  35.         
  36.         return self
  37.  
  38.     
  39.     def file(self):
  40.         return self._file_
  41.  
  42.     
  43.     def dup(self):
  44.         import posix
  45.         if not hasattr(posix, 'fdopen'):
  46.             raise AttributeError, 'dup() method unavailable'
  47.         hasattr(posix, 'fdopen')
  48.         return posix.fdopen(posix.dup(self._file_.fileno()), self._file_.mode)
  49.  
  50.     
  51.     def dup2(self, fd):
  52.         import posix
  53.         if not hasattr(posix, 'fdopen'):
  54.             raise AttributeError, 'dup() method unavailable'
  55.         hasattr(posix, 'fdopen')
  56.         posix.dup2(self._file_.fileno(), fd)
  57.         return posix.fdopen(fd, self._file_.mode)
  58.  
  59.     
  60.     def flags(self, *which):
  61.         import fcntl
  62.         import os
  63.         if which:
  64.             if len(which) > 1:
  65.                 raise TypeError, 'Too many arguments'
  66.             len(which) > 1
  67.             which = which[0]
  68.         else:
  69.             which = '?'
  70.         l_flags = 0
  71.         if 'n' in which:
  72.             l_flags = l_flags | os.O_NDELAY
  73.         
  74.         if 'a' in which:
  75.             l_flags = l_flags | os.O_APPEND
  76.         
  77.         if 's' in which:
  78.             l_flags = l_flags | os.O_SYNC
  79.         
  80.         file = self._file_
  81.         if '=' not in which:
  82.             cur_fl = fcntl.fcntl(file.fileno(), fcntl.F_GETFL, 0)
  83.             if '!' in which:
  84.                 l_flags = cur_fl & ~l_flags
  85.             else:
  86.                 l_flags = cur_fl | l_flags
  87.         
  88.         l_flags = fcntl.fcntl(file.fileno(), fcntl.F_SETFL, l_flags)
  89.         if 'c' in which:
  90.             arg = '!' not in which
  91.             l_flags = fcntl.fcntl(file.fileno(), fcntl.F_SETFD, arg)
  92.         
  93.         if '?' in which:
  94.             which = ''
  95.             l_flags = fcntl.fcntl(file.fileno(), fcntl.F_GETFL, 0)
  96.             if os.O_APPEND & l_flags:
  97.                 which = which + 'a'
  98.             
  99.             if fcntl.fcntl(file.fileno(), fcntl.F_GETFD, 0) & 1:
  100.                 which = which + 'c'
  101.             
  102.             if os.O_NDELAY & l_flags:
  103.                 which = which + 'n'
  104.             
  105.             if os.O_SYNC & l_flags:
  106.                 which = which + 's'
  107.             
  108.             return which
  109.  
  110.     
  111.     def lock(self, how, *args):
  112.         import struct
  113.         import fcntl
  114.         if 'w' in how:
  115.             l_type = fcntl.F_WRLCK
  116.         elif 'r' in how:
  117.             l_type = fcntl.F_RDLCK
  118.         elif 'u' in how:
  119.             l_type = fcntl.F_UNLCK
  120.         else:
  121.             raise TypeError, 'no type of lock specified'
  122.         if 'w' in how in how:
  123.             cmd = fcntl.F_SETLKW
  124.         elif '?' in how:
  125.             cmd = fcntl.F_GETLK
  126.         else:
  127.             cmd = fcntl.F_SETLK
  128.         l_whence = 0
  129.         l_start = 0
  130.         l_len = 0
  131.         if len(args) == 1:
  132.             l_len = args[0]
  133.         elif len(args) == 2:
  134.             (l_len, l_start) = args
  135.         elif len(args) == 3:
  136.             (l_len, l_start, l_whence) = args
  137.         elif len(args) > 3:
  138.             raise TypeError, 'too many arguments'
  139.         
  140.         import sys
  141.         import os
  142.         if sys.platform in ('netbsd1', 'openbsd2', 'freebsd2', 'freebsd3', 'freebsd4', 'freebsd5', 'freebsd6', 'freebsd7', 'freebsd8', 'bsdos2', 'bsdos3', 'bsdos4'):
  143.             flock = struct.pack('lxxxxlxxxxlhh', l_start, l_len, os.getpid(), l_type, l_whence)
  144.         elif sys.platform in ('aix3', 'aix4'):
  145.             flock = struct.pack('hhlllii', l_type, l_whence, l_start, l_len, 0, 0, 0)
  146.         else:
  147.             flock = struct.pack('hhllhh', l_type, l_whence, l_start, l_len, 0, 0)
  148.         flock = fcntl.fcntl(self._file_.fileno(), cmd, flock)
  149.         if '?' in how:
  150.             if sys.platform in ('netbsd1', 'openbsd2', 'freebsd2', 'freebsd3', 'freebsd4', 'freebsd5', 'bsdos2', 'bsdos3', 'bsdos4'):
  151.                 (l_start, l_len, l_pid, l_type, l_whence) = struct.unpack('lxxxxlxxxxlhh', flock)
  152.             elif sys.platform in ('aix3', 'aix4'):
  153.                 (l_type, l_whence, l_start, l_len, l_sysid, l_pid, l_vfs) = struct.unpack('hhlllii', flock)
  154.             elif sys.platform == 'linux2':
  155.                 (l_type, l_whence, l_start, l_len, l_pid, l_sysid) = struct.unpack('hhllhh', flock)
  156.             else:
  157.                 (l_type, l_whence, l_start, l_len, l_sysid, l_pid) = struct.unpack('hhllhh', flock)
  158.             if l_type != fcntl.F_UNLCK:
  159.                 if l_type == fcntl.F_RDLCK:
  160.                     return ('r', l_len, l_start, l_whence, l_pid)
  161.                 return ('w', l_len, l_start, l_whence, l_pid)
  162.             l_type != fcntl.F_UNLCK
  163.         
  164.  
  165.  
  166.  
  167. def open(name, mode = 'r', bufsize = -1):
  168.     return _posixfile_().open(name, mode, bufsize)
  169.  
  170.  
  171. def fileopen(file):
  172.     return _posixfile_().fileopen(file)
  173.  
  174. SEEK_SET = 0
  175. SEEK_CUR = 1
  176. SEEK_END = 2
  177.