Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding license clauses and fixing other formatting issues

  • Loading branch information...
commit 1e7ea501ceca767478d55cd82b85540d40ed8e29 1 parent 20435ea
Burak Arslan authored
Showing with 59 additions and 41 deletions.
  1. +31 −23 src/soaplib/test/test_xsd_gen.py
  2. +28 −18 src/soaplib/util/xsd_gen.py
View
54 src/soaplib/test/test_xsd_gen.py 100644 → 100755
@@ -1,3 +1,22 @@
+#!/usr/bin/env python
+#
+# soaplib - Copyright (C) Soaplib contributors.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+#
+
import os
from glob import glob
import unittest
@@ -10,37 +29,30 @@
class SimpleModel(ClassSerializer):
-
__namespace__ = "SimpleModel"
- text = String
+ text = String
class NestedModel(ClassSerializer):
-
__namespace__ = "NestedModel"
+
text = String
simple_model = SimpleModel
-
class DoubleNestedModel(ClassSerializer):
-
__namespace__ = "DoubleNestedModel"
+
some_text = String
nested = NestedModel
-
class TestXsdGen(unittest.TestCase):
-
-
def setUp(self):
self.xsd_gen = XSDGenerator()
-
def tearDown(self):
for f in glob('*.xsd'):
os.unlink(f)
-
def named_element_check(self, element):
name_found = False
for el in element.iter():
@@ -50,9 +62,7 @@ def named_element_check(self, element):
return name_found
-
def test_simple_xsd(self):
-
simple_xsd = self.xsd_gen.get_model_xsd(
SimpleModel,
pretty_print=False
@@ -61,14 +71,13 @@ def test_simple_xsd(self):
xsd_element = etree.XML(simple_xsd)
self.assertEquals(xsd_element.attrib['targetNamespace'],
- SimpleModel.get_namespace()
+ SimpleModel.get_namespace()
)
name_found = self.named_element_check(xsd_element)
self.assertTrue(name_found)
-
def test_nested_xsd(self):
nested_xsd = self.xsd_gen.get_model_xsd(
NestedModel,
@@ -78,11 +87,10 @@ def test_nested_xsd(self):
tree = etree.XML(nested_xsd)
self.assertEquals(
- tree.attrib['targetNamespace'],
- NestedModel.get_namespace()
+ tree.attrib['targetNamespace'],
+ NestedModel.get_namespace()
)
-
def test_double_nested_xsd(self):
double_xsd = self.xsd_gen.get_model_xsd(
DoubleNestedModel,
@@ -92,17 +100,14 @@ def test_double_nested_xsd(self):
tree = etree.XML(double_xsd)
self.assertEquals(
- tree.attrib['targetNamespace'],
- DoubleNestedModel.get_namespace()
+ tree.attrib['targetNamespace'],
+ DoubleNestedModel.get_namespace()
)
-
def test_xsd_file(self):
-
file_name = self.xsd_gen.write_model_xsd_file(SimpleModel, '.')
self.assertTrue(os.path.isfile(file_name))
-
def test_get_all_models(self):
ret_list = self.xsd_gen.get_all_models_xsd(DoubleNestedModel, pretty_print=True)
@@ -112,4 +117,7 @@ def test_write_all_models(self):
ret_list = self.xsd_gen.write_all_models(DoubleNestedModel, '.')
self.assertEquals(len(ret_list), 3)
for file in ret_list:
- self.assertTrue(os.path.isfile(file))
+ self.assertTrue(os.path.isfile(file))
+
+if __name__ == '__main__':
+ unittest.main()
View
46 src/soaplib/util/xsd_gen.py
@@ -1,3 +1,22 @@
+
+#
+# soaplib - Copyright (C) Soaplib contributors.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+#
+
import os.path
from lxml import etree
@@ -8,7 +27,6 @@
class XSDGenerator():
-
'''Class to support xsd generation for soaplib models.'''
# Simplified schema mapping used for building standalone XSDs without SOAP
@@ -23,7 +41,6 @@ class XSDGenerator():
__el_string = '{%s}element' % soaplib.ns_xsd
__imp_string = '{%s}import' % soaplib.ns_xsd
-
def __get_binding_service(self, model):
'''A factory method to create a simple service class.
@@ -40,7 +57,6 @@ def binding_method(self, model):
return BindingService
-
def __get_binding_application(self, binding_service):
'''Builds an instance of soaplib.Application
@@ -62,7 +78,6 @@ def __get_binding_application(self, binding_service):
return binding_application
-
def __get_nodes(self, model):
'''Builds and returns the scheame nodes as a python dictionary
@@ -72,8 +87,8 @@ def __get_nodes(self, model):
binding_service = self.__get_binding_service(model)
app = self.__get_binding_application(binding_service)
nodes = app.build_schema(types=None)
- return nodes
+ return nodes
def __get_model_node(self, model, nodes):
'''Iterate over a dict of Elements to locate the correct type'''
@@ -94,7 +109,6 @@ def __get_model_node(self, model, nodes):
return xsd_out
-
def __get_xsd_file_name(self, model, model_node):
'''Returns the correct xsd name for a single model.'''
@@ -112,7 +126,6 @@ def __get_xsd_file_name(self, model, model_node):
return '{0:>s}.xsd'.format(file_prefix)
-
def __write_xsd(self, encoding, file_path, xsd_out_node):
'''Writes the supplied schema node to file
@@ -132,7 +145,6 @@ def __write_xsd(self, encoding, file_path, xsd_out_node):
f.close()
-
def __clean_soap_nodes(self, element_dict):
'''Strips soap specific elements and returns a list of elements.'''
@@ -143,7 +155,6 @@ def __clean_soap_nodes(self, element_dict):
return out_elements
-
def get_model_xsd(self, model, encoding='utf-8', pretty_print=False):
'''Returns a string representation of an XSD for the specified model.
@@ -157,12 +168,11 @@ def get_model_xsd(self, model, encoding='utf-8', pretty_print=False):
xsd_out = self.__get_model_node(model, nodes)
return etree.tostring(
- xsd_out,
- pretty_print=pretty_print,
- encoding=encoding,
- xml_declaration=True
- )
-
+ xsd_out,
+ pretty_print=pretty_print,
+ encoding=encoding,
+ xml_declaration=True
+ )
def get_all_models_xsd(self, model, encoding='utf-8', pretty_print=False):
'''Returns all related models as a list of strings
@@ -179,8 +189,8 @@ def get_all_models_xsd(self, model, encoding='utf-8', pretty_print=False):
string_elements = []
for el in elements:
string_elements.append(
- etree.tostring(el, encoding=encoding, pretty_print=pretty_print)
- )
+ etree.tostring(el, encoding=encoding, pretty_print=pretty_print)
+ )
return string_elements
@@ -234,4 +244,4 @@ def write_all_models(self, model, path, encoding='utf-8'):
self.__write_xsd(encoding, file_path, v)
out_file_list.append(file_path)
- return out_file_list
+ return out_file_list
Please sign in to comment.
Something went wrong with that request. Please try again.