Path: blob/main/crypto/heimdal/lib/wind/stringprep.py
34889 views
#!/usr/local/bin/python1# -*- coding: iso-8859-1 -*-23# $Id$45# Copyright (c) 2008 Kungliga Tekniska Högskolan6# (Royal Institute of Technology, Stockholm, Sweden).7# All rights reserved.8#9# Redistribution and use in source and binary forms, with or without10# modification, are permitted provided that the following conditions11# are met:12#13# 1. Redistributions of source code must retain the above copyright14# notice, this list of conditions and the following disclaimer.15#16# 2. Redistributions in binary form must reproduce the above copyright17# notice, this list of conditions and the following disclaimer in the18# documentation and/or other materials provided with the distribution.19#20# 3. Neither the name of the Institute nor the names of its contributors21# may be used to endorse or promote products derived from this software22# without specific prior written permission.23#24# THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND25# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE26# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE27# ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE28# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL29# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS30# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)31# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT32# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY33# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF34# SUCH DAMAGE.3536import re37import string3839def _merge_table(res, source):40for table in source.keys():41res[table] = res.get(table, []) + source.get(table, [])4243name_error = ['C.1.2', 'C.2.2', 'C.3', 'C.4', 'C.5', 'C.6', 'C.7', 'C.8', 'C.9']44ldap_error = ['A.1', 'C.3', 'C.4', 'C.5', 'C.8', 'rfc4518-error' ]45sasl_error = ['C.1.2', 'C.2.1', 'C.2.2', 'C.3', 'C.4', 'C.5', 'C.6', 'C.7', 'C.8', 'C.9']4647name_map = ['B.1', 'B.2']48ldap_map = ['rfc4518-map']49ldap_case_map = ['rfc4518-map', 'B.2']50sasl_map = ['C.1.2', 'B.1']5152def symbols(tabledict, tables):53"""return CPP symbols to use for this symbols"""54list = []55for x in tables:56list = list + tabledict.get(x, [])57if len(list) == 0:58return ""59return "|".join(map(lambda x: "WIND_PROFILE_%s" % (string.upper(x)), list))6061def get_errorlist():62d = dict()63_merge_table(d, dict(map(lambda x: [x, ['name']], name_error)))64_merge_table(d, dict(map(lambda x: [x, ['ldap']], ldap_error)))65_merge_table(d, dict(map(lambda x: [x, ['sasl']], sasl_error)))66return d6768def get_maplist():69d = dict()70_merge_table(d, dict(map(lambda x: [x, ['name']], name_map)))71_merge_table(d, dict(map(lambda x: [x, ['ldap']], ldap_map)))72_merge_table(d, dict(map(lambda x: [x, ['ldap_case']], ldap_case_map)))73_merge_table(d, dict(map(lambda x: [x, ['sasl']], sasl_map)))74return d7576def sort_merge_trans(trans):77trans.sort()78ret = []79last = 080for x in trans:81if last:82if last[0] == x[0]:83last = (last[0], last[1], last[2], last[3] + x[3])84else:85ret.append(last)86last = x87else:88last = x89if last:90ret.append(last)91return ret929394