/usr/lib/python2.7/dist-packages/dhm/textfile.py is in python-dhm 0.6-4.
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 79 80 81 82 83 84 | # textfile.py
#
# Copyright 2002 Wichert Akkerman <wichert@deephackmode.org>
#
# This file is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
"""Simple file abstraction.
The TextFile class which this class implements is a small subset
of the standard python file object which only supports reading
complete lines of text. It keeps track of the filename and linenumber
currently being read, which can be useful to produce more informative
error messages.
"""
__docformat__ = "epytext en"
class TextFile:
"""Text file
This class works mostly similar to a standard file object,
featuring the methods as open(), close() and readline().
@ivar filename: name of file being read
@type filename: string
@ivar lineno: linenumber last read
@type lineno: integer
@ivar file: file being read
@type file: file object
"""
def __init__(self, file=None):
"""Constructor.
@param file: name of file to read
@type file: string
"""
self.filename=None
self.lineno=0
self.file=None
if file:
self.open(file)
def open(self, file):
"""Open a file for reading.
@param file: name of file to read
@type file: string
"""
self.filename=file
self.lineno=0
self.file=open(file, "rt")
def close(self):
"""Close the file and reset context.
"""
self.filename=None
self.lineno=0
if self.file:
self.file.close()
self.file=None
def readline(self):
"""Read a line.
@return: line of text
@rtype: string
"""
line=self.file.readline()
self.lineno+=1
return line
|