Changeset 698
- Timestamp:
- 08/05/07 19:33:20 (2 years ago)
- Location:
- trunk/genshi/filters
- Files:
-
- 2 modified
-
html.py (modified) (7 diffs)
-
tests/html.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/genshi/filters/html.py
r690 r698 70 70 in_form = in_select = in_option = in_textarea = False 71 71 select_value = option_value = textarea_value = None 72 option_start = option_text = None 72 option_start = None 73 option_text = [] 74 no_option_value = False 73 75 74 76 for kind, data, pos in stream: … … 95 97 if isinstance(value, (list, tuple)): 96 98 if declval: 97 checked = declval in [ str(v) for v99 checked = declval in [unicode(v) for v 98 100 in value] 99 101 else: … … 101 103 else: 102 104 if declval: 103 checked = declval == str(value)105 checked = declval == unicode(value) 104 106 elif type == 'checkbox': 105 107 checked = bool(value) … … 131 133 option_start = kind, data, pos 132 134 option_value = attrs.get('value') 135 if option_value is None: 136 no_option_value = True 137 option_value = '' 133 138 in_option = True 134 139 continue … … 137 142 elif in_form and kind is TEXT: 138 143 if in_select and in_option: 139 if option_value is None:140 option_value = data141 option_text = kind, data, pos144 if no_option_value: 145 option_value += data 146 option_text.append((kind, data, pos)) 142 147 continue 143 148 elif in_textarea: … … 154 159 elif in_select and tagname == 'option': 155 160 if isinstance(select_value, (tuple, list)): 156 selected = option_value in [ str(v) for v161 selected = option_value in [unicode(v) for v 157 162 in select_value] 158 163 else: 159 selected = option_value == str(select_value)164 selected = option_value == unicode(select_value) 160 165 okind, (tag, attrs), opos = option_start 161 166 if selected: … … 165 170 yield okind, (tag, attrs), opos 166 171 if option_text: 167 yield option_text 172 for event in option_text: 173 yield event 168 174 in_option = False 169 option_start = option_text = option_value = None 175 no_option_value = False 176 option_start = option_value = None 177 option_text = [] 170 178 elif tagname == 'textarea': 171 179 if textarea_value: -
trunk/genshi/filters/tests/html.py
r682 r698 17 17 from genshi.input import HTML, ParseError 18 18 from genshi.filters.html import HTMLFormFiller, HTMLSanitizer 19 19 from genshi.template import MarkupTemplate 20 20 21 21 class HTMLFormFillerTestCase(unittest.TestCase): … … 270 270 </select> 271 271 </p></form>""", unicode(html)) 272 273 def test_fill_option_segmented_text(self): 274 html = MarkupTemplate("""<form> 275 <select name="foo"> 276 <option value="1">foo $x</option> 277 </select> 278 </form>""").generate(x=1) | HTMLFormFiller(data={'foo': '1'}) 279 self.assertEquals("""<form> 280 <select name="foo"> 281 <option value="1" selected="selected">foo 1</option> 282 </select> 283 </form>""", unicode(html)) 284 285 def test_fill_option_segmented_text_no_value(self): 286 html = MarkupTemplate("""<form> 287 <select name="foo"> 288 <option>foo $x bar</option> 289 </select> 290 </form>""").generate(x=1) | HTMLFormFiller(data={'foo': 'foo 1 bar'}) 291 self.assertEquals("""<form> 292 <select name="foo"> 293 <option selected="selected">foo 1 bar</option> 294 </select> 295 </form>""", unicode(html)) 296 297 def test_fill_option_unicode_value(self): 298 html = HTML(u"""<form> 299 <select name="foo"> 300 <option value="ö">foo</option> 301 </select> 302 </form>""") | HTMLFormFiller(data={'foo': u'ö'}) 303 self.assertEquals(u"""<form> 304 <select name="foo"> 305 <option value="ö" selected="selected">foo</option> 306 </select> 307 </form>""", unicode(html)) 272 308 273 309
