equal
deleted
inserted
replaced
73 return StaticLabel(match.group('name')) |
73 return StaticLabel(match.group('name')) |
74 |
74 |
75 # invalid |
75 # invalid |
76 raise URLError("Invalid label: %r" % (mask, )) |
76 raise URLError("Invalid label: %r" % (mask, )) |
77 |
77 |
78 def match (self, value) : |
78 def match (self, value=None) : |
79 """ |
79 """ |
80 Match this label against the given value, returning either True to match without a value, a LabelValue |
80 Match this label against the given value, returning either True to match without a value, a LabelValue |
81 object, or boolean false to not match |
81 object, or boolean false to not match. |
|
82 |
|
83 If value is None, this means that only a default value should be accepted. XXX: currently returned default |
|
84 is not used. |
82 """ |
85 """ |
83 |
86 |
84 abstract |
87 abstract |
85 |
88 |
86 class EmptyLabel (Label) : |
89 class EmptyLabel (Label) : |
93 Just compares type |
96 Just compares type |
94 """ |
97 """ |
95 |
98 |
96 return isinstance(other, EmptyLabel) |
99 return isinstance(other, EmptyLabel) |
97 |
100 |
98 def match (self, value) : |
101 def match (self, value=None) : |
99 """ |
102 """ |
100 Match empty string -> True |
103 Match empty string -> True |
101 """ |
104 """ |
102 |
105 |
|
106 # no default |
|
107 if value is None : |
|
108 return False |
|
109 |
|
110 # only empty segments |
103 if value == '' : |
111 if value == '' : |
104 return True |
112 return True |
105 |
113 |
106 def __str__ (self) : |
114 def __str__ (self) : |
107 return '' |
115 return '' |
125 Compares names |
133 Compares names |
126 """ |
134 """ |
127 |
135 |
128 return isinstance(other, StaticLabel) and self.name == other.name |
136 return isinstance(other, StaticLabel) and self.name == other.name |
129 |
137 |
130 def match (self, value) : |
138 def match (self, value=None) : |
131 """ |
139 """ |
132 Match exactly -> True |
140 Match exactly -> True |
133 """ |
141 """ |
134 |
142 |
|
143 # no defaults |
|
144 if value is None : |
|
145 return False |
|
146 |
|
147 # match name |
135 if value == self.name : |
148 if value == self.name : |
136 return True |
149 return True |
137 |
150 |
138 def __str__ (self) : |
151 def __str__ (self) : |
139 return self.name |
152 return self.name |
172 The given key is the name of this label's value |
185 The given key is the name of this label's value |
173 """ |
186 """ |
174 |
187 |
175 super(SimpleValueLabel, self).__init__(key, default) |
188 super(SimpleValueLabel, self).__init__(key, default) |
176 |
189 |
177 def match (self, value) : |
190 def match (self, value=None) : |
178 """ |
191 """ |
179 Match -> LabelValue |
192 Match -> LabelValue |
180 |
193 """ |
181 XXX: empty string? |
194 |
182 """ |
195 # default? |
183 |
196 if value is None and self.default : |
184 return LabelValue(self, value) |
197 return LabelValue(self, self.default) |
|
198 |
|
199 # only non-empty values! |
|
200 elif value : |
|
201 return LabelValue(self, value) |
185 |
202 |
186 def __str__ (self) : |
203 def __str__ (self) : |
187 if self.default : |
204 if self.default : |
188 return '{%s=%s}' % (self.key, self.default) |
205 return '{%s=%s}' % (self.key, self.default) |
189 |
206 |
324 # the search ends at this node |
341 # the search ends at this node |
325 if self.url : |
342 if self.url : |
326 # this URL is the best match |
343 # this URL is the best match |
327 return (self.url, []) |
344 return (self.url, []) |
328 |
345 |
|
346 # look for default-only values, DFS |
|
347 for child in self.children : |
|
348 # does the child's label accept a default match? |
|
349 if child.label.match() : |
|
350 return child.match(label_path) |
|
351 |
329 else : |
352 else : |
330 # incomplete URL |
353 # incomplete URL |
331 raise URLError("no URL handler defined for this Node") |
354 raise URLError("no URL handler defined for this Node") |
332 |
355 |
333 else : |
356 else : |