Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes
MoinMoin.logfile.LineBuffer Class Reference

List of all members.

Public Member Functions

def __init__

Public Attributes

 loglevel
 offsets
 len
 lines

Detailed Description

Reads lines from a file
    self.len      number of lines in self.lines
    self.lines    list of lines (unicode)
    self.offsets  list of file offsets for each line. additionally the position
                  after the last read line is stored into self.offsets[-1]

Definition at line 24 of file __init__.py.


Constructor & Destructor Documentation

def MoinMoin.logfile.LineBuffer.__init__ (   self,
  file,
  offset,
  size,
  forward = True 
)
TODO: when this gets refactored, don't use "file" (is a builtin)

@param file: open file object
@param offset: position in file to start from
@param size: aproximate number of bytes to read
@param forward : read from offset on or from offset-size to offset
@type forward: boolean

Definition at line 32 of file __init__.py.

00032 
00033     def __init__(self, file, offset, size, forward=True):
00034         """
00035 
00036         TODO: when this gets refactored, don't use "file" (is a builtin)
00037 
00038         @param file: open file object
00039         @param offset: position in file to start from
00040         @param size: aproximate number of bytes to read
00041         @param forward : read from offset on or from offset-size to offset
00042         @type forward: boolean
00043         """
00044         self.loglevel = logging.NOTSET
00045         if forward:
00046             begin = offset
00047             logging.log(self.loglevel, "LineBuffer.init: forward seek %d read %d" % (begin, size))
00048             file.seek(begin)
00049             lines = file.readlines(size)
00050         else:
00051             if offset < 2 * size:
00052                 begin = 0
00053                 size = offset
00054             else:
00055                 begin = offset - size
00056             logging.log(self.loglevel, "LineBuffer.init: backward seek %d read %d" % (begin, size))
00057             file.seek(begin)
00058             lines = file.read(size).splitlines(True)
00059             if begin != 0:
00060                 # remove potentially incomplete first line
00061                 begin += len(lines[0])
00062                 lines = lines[1:]
00063                 # XXX check for min one line read
00064 
00065         linecount = len(lines)
00066 
00067         # now calculate the file offsets of all read lines
00068         offsets = [len(line) for line in lines]
00069         offsets.append(0) # later this element will have the file offset after the last read line
00070 
00071         lengthpreviousline = 0
00072         offset = begin
00073         for i in xrange(linecount+1):
00074             offset += lengthpreviousline
00075             lengthpreviousline = offsets[i]
00076             offsets[i] = offset
00077 
00078         self.offsets = offsets
00079         self.len = linecount
00080         # Decode lines after offset in file is calculated
00081         self.lines = [unicode(line, config.charset) for line in lines]
00082 


Member Data Documentation

Definition at line 78 of file __init__.py.

Definition at line 80 of file __init__.py.

Definition at line 43 of file __init__.py.

Definition at line 77 of file __init__.py.


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