rfc3454.py revision 233294
1278332Semaste#!/usr/local/bin/python 2278332Semaste# -*- coding: iso-8859-1 -*- 3278332Semaste 4278332Semaste# $Id$ 5278332Semaste 6278332Semaste# Copyright (c) 2004 Kungliga Tekniska H��gskolan 7278332Semaste# (Royal Institute of Technology, Stockholm, Sweden). 8278332Semaste# All rights reserved. 9278332Semaste# 10278332Semaste# Redistribution and use in source and binary forms, with or without 11278332Semaste# modification, are permitted provided that the following conditions 12278332Semaste# are met: 13309124Sdim# 14278332Semaste# 1. Redistributions of source code must retain the above copyright 15278332Semaste# notice, this list of conditions and the following disclaimer. 16278332Semaste# 17278332Semaste# 2. Redistributions in binary form must reproduce the above copyright 18278332Semaste# notice, this list of conditions and the following disclaimer in the 19321369Sdim# documentation and/or other materials provided with the distribution. 20278332Semaste# 21278332Semaste# 3. Neither the name of the Institute nor the names of its contributors 22278332Semaste# may be used to endorse or promote products derived from this software 23278332Semaste# without specific prior written permission. 24314564Sdim# 25314564Sdim# THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 26314564Sdim# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27314564Sdim# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28314564Sdim# ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 29314564Sdim# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30278332Semaste# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31278332Semaste# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32314564Sdim# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33314564Sdim# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34278332Semaste# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35278332Semaste# SUCH DAMAGE. 36314564Sdim 37314564Sdimimport re 38314564Sdimimport string 39314564Sdim 40314564Sdimdef read(filename): 41278332Semaste """return a dict of tables from rfc3454""" 42278332Semaste f = open(filename, 'r') 43314564Sdim inTable = False 44278332Semaste ret = {} 45314564Sdim while True: 46278332Semaste l = f.readline() 47314564Sdim if not l: 48278332Semaste break 49314564Sdim if inTable: 50278332Semaste m = re.search('^ *----- End Table ([A-Z0-9\.]+) ----- *$', l) 51314564Sdim if m: 52278332Semaste ret[m.group(1)] = t 53278332Semaste inTable = False 54314564Sdim else: 55314564Sdim t.append(l) 56314564Sdim if re.search('^ *----- Start Table ([A-Z0-9\.]+) ----- *$', l): 57314564Sdim inTable = True 58314564Sdim t = [] 59314564Sdim f.close() 60314564Sdim return ret 61314564Sdim