Back to index

apport  2.3
Public Member Functions | Public Attributes
problem_report.CompressedValue Class Reference

List of all members.

Public Member Functions

def __init__
def set_value
def get_value
def write
def __len__
def splitlines

Public Attributes

 gzipvalue
 name
 legacy_zlib

Detailed Description

Represent a ProblemReport value which is gzip compressed.

Definition at line 30 of file problem_report.py.


Constructor & Destructor Documentation

def problem_report.CompressedValue.__init__ (   self,
  value = None,
  name = None 
)
Initialize an empty CompressedValue object with an optional name.

Definition at line 33 of file problem_report.py.

00033 
00034     def __init__(self, value=None, name=None):
00035         '''Initialize an empty CompressedValue object with an optional name.'''
00036 
00037         self.gzipvalue = None
00038         self.name = name
00039         # By default, compressed values are in gzip format. Earlier versions of
00040         # problem_report used zlib format (without gzip header). If you have
00041         # such a case, set legacy_zlib to True.
00042         self.legacy_zlib = False
00043 
00044         if value:
00045             self.set_value(value)


Member Function Documentation

Return length of uncompressed value.

Definition at line 80 of file problem_report.py.

00080 
00081     def __len__(self):
00082         '''Return length of uncompressed value.'''
00083 
00084         assert self.gzipvalue
00085         if self.legacy_zlib:
00086             return len(self.get_value())
00087         return int(struct.unpack('<L', self.gzipvalue[-4:])[0])

Here is the call graph for this function:

Return uncompressed value.

Definition at line 54 of file problem_report.py.

00054 
00055     def get_value(self):
00056         '''Return uncompressed value.'''
00057 
00058         if not self.gzipvalue:
00059             return None
00060 
00061         if self.legacy_zlib:
00062             return zlib.decompress(self.gzipvalue)
00063         return gzip.GzipFile(fileobj=BytesIO(self.gzipvalue)).read()

Here is the caller graph for this function:

def problem_report.CompressedValue.set_value (   self,
  value 
)
Set uncompressed value.

Definition at line 46 of file problem_report.py.

00046 
00047     def set_value(self, value):
00048         '''Set uncompressed value.'''
00049 
00050         out = BytesIO()
00051         gzip.GzipFile(self.name, mode='wb', fileobj=out).write(value)
00052         self.gzipvalue = out.getvalue()
00053         self.legacy_zlib = False

Here is the call graph for this function:

Behaves like splitlines() for a normal string.

Definition at line 88 of file problem_report.py.

00088 
00089     def splitlines(self):
00090         '''Behaves like splitlines() for a normal string.'''
00091 
00092         return self.get_value().splitlines()
00093 

Here is the call graph for this function:

def problem_report.CompressedValue.write (   self,
  file 
)
Write uncompressed value into given file-like object.

Definition at line 64 of file problem_report.py.

00064 
00065     def write(self, file):
00066         '''Write uncompressed value into given file-like object.'''
00067 
00068         assert self.gzipvalue
00069 
00070         if self.legacy_zlib:
00071             file.write(zlib.decompress(self.gzipvalue))
00072             return
00073 
00074         gz = gzip.GzipFile(fileobj=BytesIO(self.gzipvalue))
00075         while True:
00076             block = gz.read(1048576)
00077             if not block:
00078                 break
00079             file.write(block)

Here is the caller graph for this function:


Member Data Documentation

Definition at line 36 of file problem_report.py.

Definition at line 41 of file problem_report.py.

Definition at line 37 of file problem_report.py.


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