/usr/share/pyshared/dhm/simplerfc822.py is in python-dhm 0.6-3build1.
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 85 86 87 88 89 90 91 92 93 94 95 96 97 | # simplerfc822.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.
"""Trivial RFC822-like parser.
Much like the rfc822 module from the standard python library, but
much simpler and faster. This module only supports simple "field: value"
style fields with the normal rfc822 line continuation. Repeated fields
are also not supported.
Assumes it reads from a TextFile so it can produce more informative error
message.
"""
__docformat__ = "epytext en"
import UserDict
class FileException(Exception):
"""Parse error.
@ivar file: name of file being parsed
@type file: string
@ivar line: linenumber on which error occured
@type line: integer
"""
def __init__(self, file, line, reason):
"""Constructur
@param file: name of file being parsed
@type file: string
@param line: linenumber on which error occured
@type line: integer
@param reason: description of the error
@type reason: string
"""
Exception.__init__(reason)
self.file=file
self.line=line
def __str__(self):
return "%s(%d): %s" % (self.file, self.line, self.value)
class Message(UserDict.UserDict):
"""Simple-RFC822 message object.
This class works just like the standard python rfc822 module.
"""
def __init__(self, fp=None):
UserDict.UserDict.__init__(self)
if fp:
self.Parse(fp)
def Parse(self, fp):
"""Parse a textfile
@param fp: file to parse
@type fp: dpkg.textfile.TextFile instance
"""
self.data.clear()
lasthdr=None
while 1:
line=fp.readline()
if not line or line in [ "\r\n", "\n" ]:
break
line=line.rstrip()
if line[0] in " \t":
self.data[lasthdr]+="\n"+line[1:]
else:
i=line.find(":")
if i==-1:
raise FileException(fp.filename, fp.lineno, "Syntax error")
lasthdr=line[:i]
self.data[lasthdr]=line[(i+1):].lstrip()
|