37 @param key key for the item |
37 @param key key for the item |
38 @param value value of the item |
38 @param value value of the item |
39 """ |
39 """ |
40 if key in self: |
40 if key in self: |
41 raise DuplicateParamError(key) |
41 raise DuplicateParamError(key) |
42 super().__setitem__(key, value) |
42 super(UniqueNamespace, self).__setitem__(key, value) |
43 |
43 |
44 # RFC 2616 |
44 # RFC 2616 |
45 separator_chars = "()<>@,;:\\\"/[]?={} \t" # __IGNORE_WARNING__ |
45 separator_chars = "()<>@,;:\\\"/[]?={} \t" # __IGNORE_WARNING__ |
46 ctl_chars = ''.join(chr(i) for i in range(32)) + chr(127) |
46 ctl_chars = ''.join(chr(i) for i in range(32)) + chr(127) |
47 nontoken_chars = separator_chars + ctl_chars |
47 nontoken_chars = separator_chars + ctl_chars |
86 A quoted string (RFC 2616, Section 2.2). |
86 A quoted string (RFC 2616, Section 2.2). |
87 """ |
87 """ |
88 grammar = re.compile(r'"({0}|{1})+"'.format(quoted_pair_re, qdtext_re)) |
88 grammar = re.compile(r'"({0}|{1})+"'.format(quoted_pair_re, qdtext_re)) |
89 |
89 |
90 def __str__(self): |
90 def __str__(self): |
91 s = super().__str__() |
91 s = super(QuotedString, self).__str__() |
92 s = s[1:-1] # remove quotes |
92 s = s[1:-1] # remove quotes |
93 s = re.sub(r'\\(.)', r'\1', s) # drop backslashes |
93 s = re.sub(r'\\(.)', r'\1', s) # drop backslashes |
94 return s |
94 return s |
95 |
95 |
96 class Value(str): |
96 class Value(str): |
140 A token introducing an extended value (RFC 6266, Section 4.1). |
140 A token introducing an extended value (RFC 6266, Section 4.1). |
141 """ |
141 """ |
142 regex = re.compile(token_re + r'\*') |
142 regex = re.compile(token_re + r'\*') |
143 |
143 |
144 def __str__(self): |
144 def __str__(self): |
145 return super().__str__().lower() |
145 return super(ExtToken, self).__str__().lower() |
146 |
146 |
147 class NoExtToken(peg.Symbol): |
147 class NoExtToken(peg.Symbol): |
148 """ |
148 """ |
149 A token introducing a normal value (RFC 6266, Section 4.1). |
149 A token introducing a normal value (RFC 6266, Section 4.1). |
150 """ |
150 """ |
151 regex = re.compile(token_re + r'(?<!\*)') |
151 regex = re.compile(token_re + r'(?<!\*)') |
152 |
152 |
153 def __str__(self): |
153 def __str__(self): |
154 return super().__str__().lower() |
154 return super(NoExtToken, self).__str__().lower() |
155 |
155 |
156 class DispositionParm(str): |
156 class DispositionParm(str): |
157 """ |
157 """ |
158 A parameter for the Disposition-Type header (RFC6266, Section 4.1). |
158 A parameter for the Disposition-Type header (RFC6266, Section 4.1). |
159 """ |
159 """ |