Christophe de Vienne avatar Christophe de Vienne committed f930e96 Merge

Merged in cmcdaniel/wsme/empty_strings3 (pull request #11: restxml empty string fixes)

Comments (0)

Files changed (4)

         for item in element.findall('item')))
+def unicode_fromxml(datatype, element):
+    if element.get('nil') == 'true':
+        return None
+    return wsme.types.text(element.text) if element.text else six.u('')
 def date_fromxml(datatype, element):
     if element.get('nil') == 'true':


         assert type(value) == wsme.types.text
         return value
+    @expose(wsme.types.text)
+    @validate(wsme.types.text)
+    def settextnone(self, value):
+        print(repr(value))
+        assert type(value) == type(None)
+        return value
     def setbool(self, value):
         assert'argtypes/settext', value=u('\xe3\x81\xae'),
                         _rt=wsme.types.text) == u('\xe3\x81\xae')
+    def test_settext_empty(self):
+        assert'argtypes/settext', value=u(''),
+                        _rt=wsme.types.text) == u('')
+    def test_settext_none(self):
+        assert'argtypes/settextnone', value=None,
+                        _rt=wsme.types.text) == None
     def test_setint(self):
         r ='argtypes/setint', value=3, _rt=int)
         assert r == 3, r


         el.text = six.text_type(obj)
     elif type(obj) in (, datetime.time, datetime.datetime):
         el.text = obj.isoformat()
+    elif type(obj) == type(None):
+        el.set('nil', 'true')
     elif hasattr(datatype, '_wsme_attributes'):
         for attr in datatype._wsme_attributes:
             name =
             return parse_isotime(el.text)
         if datatype == datetime.datetime:
             return parse_isodatetime(el.text)
+        if datatype == wsme.types.text:
+            return datatype(el.text if el.text else u(''))
         if datatype == bool:
             return el.text.lower() != 'false'
         if datatype is None:


         spore = json.loads(spore)
-        assert len(spore['methods']) == 45, str(len(spore['methods']))
+        assert len(spore['methods']) == 46, str(len(spore['methods']))
         m = spore['methods']['argtypes_setbytesarray']
         assert m['path'] == 'argtypes/setbytesarray', m['path']
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.