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

Public Member Functions

def __init__
 
def __repr__
 
def write
 
def read
 
def close
 
def __del__
 
def flush
 
def isatty
 
def tell
 
def rewind
 
def seek
 
def readline
 
def readlines
 
def writelines
 

Data Fields

 mode
 
 extrabuf
 
 extrasize
 
 filename
 
 compress
 
 fileobj
 
 offset
 
 crc
 
 size
 
 writebuf
 
 bufsize
 
 decompress
 

Static Public Attributes

 myfileobj = None
 

Detailed Description

Definition at line 32 of file gzip.py.

Constructor & Destructor Documentation

def __init__ (   self,
  filename = None,
  mode = None,
  compresslevel = 9,
  fileobj = None 
)

Definition at line 37 of file gzip.py.

References GzipFile.myfileobj.

37 
38  compresslevel=9, fileobj=None):
39  if fileobj is None:
40  fileobj = self.myfileobj = __builtin__.open(filename, mode or 'rb')
41  if filename is None:
42  if hasattr(fileobj, 'name'): filename = fileobj.name
43  else: filename = ''
44  if mode is None:
45  if hasattr(fileobj, 'mode'): mode = fileobj.mode
46  else: mode = 'rb'
47 
48  if mode[0:1] == 'r':
49  self.mode = READ
50  # Set flag indicating start of a new member
51  self._new_member = 1
52  self.extrabuf = ""
53  self.extrasize = 0
54  self.filename = filename
55 
56  elif mode[0:1] == 'w' or mode[0:1] == 'a':
57  self.mode = WRITE
58  self._init_write(filename)
59  self.compress = zlib.compressobj(compresslevel,
60  zlib.DEFLATED,
61  -zlib.MAX_WBITS,
62  zlib.DEF_MEM_LEVEL,
63  0)
64  else:
65  raise ValueError, "Mode " + mode + " not supported"
66 
67  self.fileobj = fileobj
68  self.offset = 0
69 
70  if self.mode == WRITE:
71  self._write_gzip_header()
def __del__ (   self)

Definition at line 257 of file gzip.py.

References Chunk.close(), openrsrc.close(), _Hqxcoderengine.close(), FileInput.close(), _Rlecoderengine.close(), BinHex.close(), GzipFile.close(), _Hqxdecoderengine.close(), Aifc_read.close(), _Rledecoderengine.close(), HexBin.close(), file_wrapper.close(), FTP.close(), GzipFile.fileobj, and GzipFile.myfileobj.

258  def __del__(self):
259  try:
260  if (self.myfileobj is None and
261  self.fileobj is None):
262  return
263  except AttributeError:
264  return
265  self.close()

Member Function Documentation

def __repr__ (   self)

Definition at line 72 of file gzip.py.

References GzipFile.filename, ParsingError.filename, MissingSectionHeaderError.filename, InteractiveConsole.filename, MiniFieldStorage.filename, FieldStorage.filename, and GzipFile.fileobj.

72 
73  def __repr__(self):
74  s = repr(self.fileobj)
75  return '<gzip ' + s[1:-1] + ' ' + hex(id(self)) + '>'
def close (   self)

Definition at line 245 of file gzip.py.

References GzipFile.crc, BinHex.crc, HexBin.crc, GzipFile.fileobj, GzipFile.mode, GzipFile.myfileobj, GzipFile.size, and gzip.write32().

246  def close(self):
247  if self.mode == WRITE:
248  self.fileobj.write(self.compress.flush())
249  write32(self.fileobj, self.crc)
250  write32(self.fileobj, self.size)
251  self.fileobj = None
252  elif self.mode == READ:
253  self.fileobj = None
254  if self.myfileobj:
255  self.myfileobj.close()
256  self.myfileobj = None
def flush (   self)

Definition at line 266 of file gzip.py.

267  def flush(self):
268  self.fileobj.flush()
def isatty (   self)

Definition at line 269 of file gzip.py.

270  def isatty(self):
271  return 0
def read (   self,
  size = -1 
)

Definition at line 144 of file gzip.py.

References GzipFile._init_read(), GzipFile._new_member, GzipFile._read(), HexBin._read(), GzipFile._read_gzip_header(), GzipFile.extrabuf, GzipFile.extrasize, GzipFile.fileobj, GzipFile.offset, and Chunk.offset.

145  def read(self, size=-1):
146  if self.extrasize <= 0 and self.fileobj is None:
147  return ''
148 
149  readsize = 1024
150  if size < 0: # get the whole thing
151  try:
152  while 1:
153  self._read(readsize)
154  readsize = readsize * 2
155  except EOFError:
156  size = self.extrasize
157  else: # just get some more of it
158  try:
159  while size > self.extrasize:
160  self._read(readsize)
161  readsize = readsize * 2
162  except EOFError:
163  if size > self.extrasize:
164  size = self.extrasize
165 
166  chunk = self.extrabuf[:size]
167  self.extrabuf = self.extrabuf[size:]
168  self.extrasize = self.extrasize - size
169 
170  self.offset += size
171  return chunk
def readline (   self,
  size = -1 
)

Definition at line 302 of file gzip.py.

References GzipFile._unread(), dospath.join(), sre_parse.min, openrsrc.read(), Chunk.read(), GzipFile.read(), StreamReader.read(), ConfigParser.read(), _Hqxdecoderengine.read(), StreamReaderWriter.read(), _Rledecoderengine.read(), StreamRecoder.read(), HexBin.read(), file_wrapper.read, Unpickler.read, and addbase.read.

303  def readline(self, size=-1):
304  if size < 0: size = sys.maxint
305  bufs = []
306  readsize = min(100, size) # Read from the file in small chunks
307  while 1:
308  if size == 0:
309  return "".join(bufs) # Return resulting line
310 
311  c = self.read(readsize)
312  i = c.find('\n')
313  if size is not None:
314  # We set i=size to break out of the loop under two
315  # conditions: 1) there's no newline, and the chunk is
316  # larger than size, or 2) there is a newline, but the
317  # resulting line would be longer than 'size'.
318  if i==-1 and len(c) > size: i=size-1
319  elif size <= i: i = size -1
320 
321  if i >= 0 or c == '':
322  bufs.append(c[:i+1]) # Add portion of last chunk
323  self._unread(c[i+1:]) # Push back rest of chunk
324  return ''.join(bufs) # Return resulting line
325 
326  # Append chunk to list, decrease 'size',
327  bufs.append(c)
328  size = size - len(c)
329  readsize = min(size, readsize * 2)
def readlines (   self,
  sizehint = 0 
)

Definition at line 330 of file gzip.py.

References FileInput.readline(), StreamReader.readline(), GzipFile.readline(), StreamReaderWriter.readline(), StreamRecoder.readline(), Unpickler.readline, and addbase.readline.

331  def readlines(self, sizehint=0):
332  # Negative numbers result in reading all the lines
333  if sizehint <= 0: sizehint = sys.maxint
334  L = []
335  while sizehint > 0:
336  line = self.readline()
337  if line == "": break
338  L.append( line )
339  sizehint = sizehint - len(line)
340 
341  return L
def rewind (   self)
Return the uncompressed stream file position indicator to the
beginning of the file

Definition at line 275 of file gzip.py.

References GzipFile._new_member, GzipFile.extrabuf, GzipFile.extrasize, GzipFile.mode, GzipFile.offset, and Chunk.offset.

276  def rewind(self):
277  '''Return the uncompressed stream file position indicator to the
278  beginning of the file'''
279  if self.mode != READ:
280  raise IOError("Can't rewind in write mode")
281  self.fileobj.seek(0)
282  self._new_member = 1
283  self.extrabuf = ""
284  self.extrasize = 0
285  self.offset = 0
def seek (   self,
  offset 
)

Definition at line 286 of file gzip.py.

References GzipFile.mode, GzipFile.offset, Chunk.offset, openrsrc.read(), Chunk.read(), GzipFile.read(), StreamReader.read(), ConfigParser.read(), _Hqxdecoderengine.read(), StreamReaderWriter.read(), _Rledecoderengine.read(), StreamRecoder.read(), HexBin.read(), file_wrapper.read, Unpickler.read, addbase.read, GzipFile.rewind(), Aifc_read.rewind(), Pickler.write, openrsrc.write(), _Hqxcoderengine.write(), StreamWriter.write(), GzipFile.write(), _Rlecoderengine.write(), InteractiveInterpreter.write(), BinHex.write(), StreamReaderWriter.write(), ConfigParser.write(), _SpoofOut.write(), StreamRecoder.write(), Marshaller.write, and file_wrapper.write.

287  def seek(self, offset):
288  if self.mode == WRITE:
289  if offset < self.offset:
290  raise IOError('Negative seek in write mode')
291  count = offset - self.offset
292  for i in range(count/1024):
293  self.write(1024*'\0')
294  self.write((count%1024)*'\0')
295  elif self.mode == READ:
296  if offset < self.offset:
297  # for negative seek, rewind and do positive seek
298  self.rewind()
299  count = offset - self.offset
300  for i in range(count/1024): self.read(1024)
301  self.read(count % 1024)
def tell (   self)

Definition at line 272 of file gzip.py.

References GzipFile.offset, and Chunk.offset.

273  def tell(self):
274  return self.offset
def write (   self,
  data 
)

Definition at line 135 of file gzip.py.

References GzipFile.crc, BinHex.crc, HexBin.crc, GzipFile.fileobj, GzipFile.offset, Chunk.offset, and GzipFile.size.

136  def write(self,data):
137  if self.fileobj is None:
138  raise ValueError, "write() on closed GzipFile object"
139  if len(data) > 0:
140  self.size = self.size + len(data)
141  self.crc = zlib.crc32(data, self.crc)
142  self.fileobj.write( self.compress.compress(data) )
143  self.offset += len(data)
def writelines (   self,
  L 
)

Definition at line 342 of file gzip.py.

References gzip.open(), Pickler.write, openrsrc.write(), _Hqxcoderengine.write(), StreamWriter.write(), GzipFile.write(), _Rlecoderengine.write(), InteractiveInterpreter.write(), BinHex.write(), StreamReaderWriter.write(), ConfigParser.write(), _SpoofOut.write(), StreamRecoder.write(), Marshaller.write, and file_wrapper.write.

343  def writelines(self, L):
344  for line in L:
345  self.write(line)
346 

Field Documentation

bufsize

Definition at line 83 of file gzip.py.

compress

Definition at line 58 of file gzip.py.

crc

Definition at line 80 of file gzip.py.

decompress

Definition at line 195 of file gzip.py.

extrabuf

Definition at line 51 of file gzip.py.

extrasize

Definition at line 52 of file gzip.py.

filename

Definition at line 53 of file gzip.py.

fileobj

Definition at line 66 of file gzip.py.

mode

Definition at line 48 of file gzip.py.

myfileobj = None
static

Definition at line 34 of file gzip.py.

offset

Definition at line 67 of file gzip.py.

size

Definition at line 81 of file gzip.py.

writebuf

Definition at line 82 of file gzip.py.


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