Commits

Mikhail Korobov committed 7e42d2f

Don't cast str on unicode strings

Comments (0)

Files changed (3)

tests/test_input.py

-#coding: utf-8
+# -*- coding: utf-8 -*-
 from webob import Request
 import webtest
 

tests/test_select.py

+# -*- coding: utf-8 -*-
 from webob import Request
 import webtest
 
 
     single_form = res.forms["single_select_form"]
     assert single_form["single"].value == "4"
-    single_form.set("single", "6")
+    single_form.set("single", 6)
     assert single_form["single"].value == "6"
     display = single_form.submit("button")
     assert "<p>You selected 6</p>" in display, display

webtest/__init__.py

         if self._forced_value is not NoValue:
             self._forced_value = NoValue
         for i, (option, checked) in enumerate(self.options):
-            if option == str(value):
+            if option == _stringify(value):
                 self.selectedIndex = i
                 break
         else:
         self.selectedIndices = []
 
     def value__set(self, values):
-        str_values = [str(value) for value in values]
+        str_values = [_stringify(value) for value in values]
         self.selectedIndicies = []
         for i, (option, checked) in enumerate(self.options):
             if option in str_values:
 ## Utility functions
 ########################################
 
+def _stringify(value):
+    if isinstance(value, unicode):
+        return value
+    return str(value)
+
 def _popget(d, key, default=None):
     """
     Pop the key if found (else return default)