Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

support for binary data types

  • Loading branch information...
commit ba627f539b633744cbfcbcca7a77698766af0fc9 1 parent 6646977
Anton Bobrov authored
Showing with 45 additions and 0 deletions.
  1. +26 −0 dropthesoap/schema/xs.py
  2. +19 −0 tests/test_schema.py
26 dropthesoap/schema/xs.py
View
@@ -428,6 +428,32 @@ def to_python(value):
return value
+class base64Binary(_FinalSimpleType):
+ namespace = namespace
+
+ @staticmethod
+ def from_python(value):
+ assert isinstance(value, str), 'Value should be a str not %s' % (type(value))
+ return value.encode('base64')
+
+ @staticmethod
+ def to_python(value):
+ return value.decode('base64')
+
+
+class hexBinary(_FinalSimpleType):
+ namespace = namespace
+
+ @staticmethod
+ def from_python(value):
+ assert isinstance(value, str), 'Value should be a str not %s' % (type(value))
+ return value.encode('hex')
+
+ @staticmethod
+ def to_python(value):
+ return value.decode('hex')
+
+
class dateTime(_FinalSimpleType):
namespace = namespace
19 tests/test_schema.py
View
@@ -199,6 +199,25 @@ def test_boolean():
obj = schema.fromstring(tostring(request))
assert obj.foo == False
+def test_binary_data():
+ schema = xs.schema(Namespace('http://boo', 'boo'))(
+ xs.element('Request')(xs.cts(
+ xs.element('foo', xs.hexBinary),
+ xs.element('boo', xs.base64Binary)))
+ )
+
+ data = '\x01\x02\x03'
+ request = schema['Request'].instance(foo=data, boo=data)
+ assert validate(schema, request)
+
+ string_request = tostring(request)
+ assert '010203' in string_request
+ assert 'AQID' in string_request
+
+ obj = schema.fromstring(string_request)
+ assert obj.foo == data
+ assert obj.boo == data
+
def test_dict_instantiation_for_aliased_types():
schema = xs.schema(Namespace('http://boo', 'boo'))(
xs.complexType('Point')(
Please sign in to comment.
Something went wrong with that request. Please try again.