/usr/lib/cgi-bin/doc-central/sectionedfile.py is in doc-central 1.8.3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | # sectionedfily.py
#
# A sectionedfile is a file that contains multiple sections, which are seperator
# by a specific seperator.
# Import all system packages we need
import sys, string
class SectionedFile:
def __init__(self, fp):
'''Simple constructor to initialize our data'''
self.fp=fp
self.blocked=0
self.eof=0
self.divider=''
self.mustunget=0
self.unget=''
def readline(self):
'''Read the next line from our input. If we hit a divider we return
an empty line and block ourselves. Dividers found at the beginning
are skipped.'''
if self.blocked:
return ''
eating=0
while 1:
line=''
if self.mustunget:
line=self.unget
self.mustunget=0
else:
line=self.fp.readline()
if not line:
self.eof=1
self.blocked=1
return ''
if string.strip(line)==self.divider:
eating=1
continue;
else:
if eating:
self.mustunget=1
self.unget=line
self.blocked=1
return ''
else:
return line
self.newblock=0
return line
def readlines(self):
'''Read as much lines from our input as possible until we hit a
divider.'''
lines=[]
while 1:
line=self.readline()
if not line:
break
lines.append(line)
return lines
def read(self):
'''Read all lines up to a divider and return them.'''
return string.joinfields(self.readlines(), '')
def unblock(self):
'''Unblock ourselves so we can proceed to the next section.'''
if self.eof:
return 0
self.blocked=0
self.newblock=1
return 1
|