1226031Sstas#!/usr/local/bin/python
2226031Sstas# -*- coding: iso-8859-1 -*-
3226031Sstas
4226031Sstas# $Id$
5226031Sstas
6226031Sstas# Copyright (c) 2004, 2008 Kungliga Tekniska H��gskolan
7226031Sstas# (Royal Institute of Technology, Stockholm, Sweden).
8226031Sstas# All rights reserved.
9226031Sstas#
10226031Sstas# Redistribution and use in source and binary forms, with or without
11226031Sstas# modification, are permitted provided that the following conditions
12226031Sstas# are met:
13226031Sstas#
14226031Sstas# 1. Redistributions of source code must retain the above copyright
15226031Sstas#    notice, this list of conditions and the following disclaimer.
16226031Sstas#
17226031Sstas# 2. Redistributions in binary form must reproduce the above copyright
18226031Sstas#    notice, this list of conditions and the following disclaimer in the
19226031Sstas#    documentation and/or other materials provided with the distribution.
20226031Sstas#
21226031Sstas# 3. Neither the name of the Institute nor the names of its contributors
22226031Sstas#    may be used to endorse or promote products derived from this software
23226031Sstas#    without specific prior written permission.
24226031Sstas#
25226031Sstas# THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
26226031Sstas# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27226031Sstas# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28226031Sstas# ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
29226031Sstas# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30226031Sstas# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31226031Sstas# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32226031Sstas# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33226031Sstas# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34226031Sstas# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35226031Sstas# SUCH DAMAGE.
36226031Sstas
37226031Sstasimport re
38226031Sstasimport string
39226031Sstas
40226031Sstasdef read():
41226031Sstas    """return a dict of tables from rfc4518"""
42226031Sstas
43226031Sstas    ret = {}
44226031Sstas
45226031Sstas#2.2.  Map
46226031Sstas#
47226031Sstas#   SOFT HYPHEN (U+00AD) and MONGOLIAN TODO SOFT HYPHEN (U+1806) code
48226031Sstas#   points are mapped to nothing.  COMBINING GRAPHEME JOINER (U+034F) and
49226031Sstas#   VARIATION SELECTORs (U+180B-180D, FF00-FE0F) code points are also
50226031Sstas#   mapped to nothing.  The OBJECT REPLACEMENT CHARACTER (U+FFFC) is
51226031Sstas#   mapped to nothing.
52226031Sstas
53226031Sstas    t = []
54226031Sstas    t.append(" 00AD; ; Map to nothing")
55226031Sstas    t.append(" 1806; ; Map to nothing")
56226031Sstas    t.append(" 034F; ; Map to nothing")
57226031Sstas
58226031Sstas    t.append(" 180B; ; Map to nothing")
59226031Sstas    t.append(" 180C; ; Map to nothing")
60226031Sstas    t.append(" 180D; ; Map to nothing")
61226031Sstas
62226031Sstas    t.append(" FE00; ; Map to nothing")
63226031Sstas    t.append(" FE01; ; Map to nothing")
64226031Sstas    t.append(" FE02; ; Map to nothing")
65226031Sstas    t.append(" FE03; ; Map to nothing")
66226031Sstas    t.append(" FE04; ; Map to nothing")
67226031Sstas    t.append(" FE05; ; Map to nothing")
68226031Sstas    t.append(" FE06; ; Map to nothing")
69226031Sstas    t.append(" FE07; ; Map to nothing")
70226031Sstas    t.append(" FE08; ; Map to nothing")
71226031Sstas    t.append(" FE09; ; Map to nothing")
72226031Sstas    t.append(" FE0A; ; Map to nothing")
73226031Sstas    t.append(" FE0B; ; Map to nothing")
74226031Sstas    t.append(" FE0C; ; Map to nothing")
75226031Sstas    t.append(" FE0D; ; Map to nothing")
76226031Sstas    t.append(" FE0E; ; Map to nothing")
77226031Sstas    t.append(" FE0F; ; Map to nothing")
78226031Sstas
79226031Sstas    t.append(" FFFC; ; Map to nothing")
80226031Sstas
81226031Sstas#   CHARACTER TABULATION (U+0009), LINE FEED (LF) (U+000A), LINE
82226031Sstas#   TABULATION (U+000B), FORM FEED (FF) (U+000C), CARRIAGE RETURN (CR)
83226031Sstas#  (U+000D), and NEXT LINE (NEL) (U+0085) are mapped to SPACE (U+0020).
84226031Sstas
85226031Sstas    t.append(" 0009; 0020 ; Map to SPACE")
86226031Sstas    t.append(" 000A; 0020 ; Map to SPACE")
87226031Sstas    t.append(" 000B; 0020 ; Map to SPACE")
88226031Sstas    t.append(" 000C; 0020 ; Map to SPACE")
89226031Sstas    t.append(" 000D; 0020 ; Map to SPACE")
90226031Sstas    t.append(" 0085; 0020 ; Map to SPACE")
91226031Sstas
92226031Sstas#   All other control code (e.g., Cc) points or code points with a
93226031Sstas#   control function (e.g., Cf) are mapped to nothing.  The following is
94226031Sstas#   a complete list of these code points: U+0000-0008, 000E-001F, 007F-
95226031Sstas#   0084, 0086-009F, 06DD, 070F, 180E, 200C-200F, 202A-202E, 2060-2063,
96226031Sstas#   206A-206F, FEFF, FFF9-FFFB, 1D173-1D17A, E0001, E0020-E007F.
97226031Sstas
98226031Sstas    t.append(" 0000-0008; ; Map to nothing")
99226031Sstas    t.append(" 000E-001F; ; Map to nothing")
100226031Sstas    t.append(" 007F-0084; ; Map to nothing")
101226031Sstas    t.append(" 0086-009F; ; Map to nothing")
102226031Sstas    t.append(" 06DD; ; Map to nothing")
103226031Sstas    t.append(" 070F; ; Map to nothing")
104226031Sstas    t.append(" 180E; ; Map to nothing")
105226031Sstas    t.append(" 200C-200F; ; Map to nothing")
106226031Sstas    t.append(" 202A-202E; ; Map to nothing")
107226031Sstas    t.append(" 2060-2063; ; Map to nothing")
108226031Sstas    t.append(" 206A-206F; ; Map to nothing")
109226031Sstas    t.append(" FEFF; ; Map to nothing")
110226031Sstas    t.append(" FFF9-FFFB; ; Map to nothing")
111226031Sstas    t.append(" 1D173-1D17A; ; Map to nothing")
112226031Sstas    t.append(" E0001; ; Map to nothing")
113226031Sstas    t.append(" E0020-E007F; ; Map to nothing")
114226031Sstas
115226031Sstas#   ZERO WIDTH SPACE (U+200B) is mapped to nothing.  All other code
116226031Sstas#   points with Separator (space, line, or paragraph) property (e.g., Zs,
117226031Sstas#   Zl, or Zp) are mapped to SPACE (U+0020).  The following is a complete
118226031Sstas#   list of these code points: U+0020, 00A0, 1680, 2000-200A, 2028-2029,
119226031Sstas#   202F, 205F, 3000.
120226031Sstas
121226031Sstas    t.append(" 200B; ; Map to nothing")
122226031Sstas    t.append(" 0020; 0020; Map to SPACE")
123226031Sstas    t.append(" 00A0; 0020; Map to SPACE")
124226031Sstas    t.append(" 1680; 0020; Map to SPACE")
125226031Sstas    t.append(" 2000-200A; 0020; Map to SPACE")
126226031Sstas    t.append(" 2028-2029; 0020; Map to SPACE")
127226031Sstas    t.append(" 202F; 0020; Map to SPACE")
128226031Sstas    t.append(" 205F; 0020; Map to SPACE")
129226031Sstas    t.append(" 3000; 0020; Map to SPACE")
130226031Sstas
131226031Sstas    ret["rfc4518-map"] = t
132226031Sstas
133226031Sstas#   For case ignore, numeric, and stored prefix string matching rules,
134226031Sstas#   characters are case folded per B.2 of [RFC3454].
135226031Sstas
136226031Sstas    t = []
137226031Sstas
138226031Sstas#2.4.  Prohibit
139226031Sstas
140226031Sstas#    The REPLACEMENT CHARACTER (U+FFFD) code point is prohibited.
141226031Sstas
142226031Sstas    t.append(" FFFD;")
143226031Sstas
144226031Sstas    ret["rfc4518-error"] = t
145226031Sstas
146226031Sstas    t = []
147226031Sstas
148226031Sstas
149226031Sstas
150226031Sstas    return ret
151