【问题标题】:Spyne - save the generated schema?Spyne - 保存生成的模式?
【发布时间】:2015-07-11 16:23:25
【问题描述】:

我有一个正常工作的 Spyne/SOAP/WSDL 服务器 - 如何保存它生成的架构?我希望能够将生成的架构与现有架构进行比较,但从日志中看起来,架构是作为临时文档生成的,然后被删除。

【问题讨论】:

  • 为什么投反对票?这是一个非常有效的问题。

标签: soap schema spyne


【解决方案1】:

我刚刚将这个功能添加到神经元中。

https://github.com/plq/neurons/blob/0f350bbdbcd0eda6a3132311a32548b7a8007b53/neurons/daemon/main.py#L106

这是一个更简洁的版本:

from lxml import etree

from spyne.interface.wsdl import Wsdl11
from spyne.test.sort_wsdl import sort_wsdl

app = Application(...) # a spyne.Application instance

# Hack to make WSDL generator happy
app.transport = "no_transport_at_all"

wsdl = Wsdl11(app.interface)

# A real URL can be passed here, if it's known in advance
wsdl.build_interface_document('hxxp://invalid_url')
doc = wsdl.get_interface_document()

# We need to do it via StringIO because sort_wsdl expects
# an ElementTree instance    
tree = etree.parse(StringIO(doc))
sort_wsdl(tree)

file_name = 'wsdl.%s.xml' % name

with open(file_name, 'w') as f:
    f.write(etree.tostring(elt, pretty_print=True))

如果您只需要 Xml Schema 文档,请改用 XmlSchema 类:

from spyne.interface.xml_schema import XmlSchema


app = Application(...) # a spyne.Application instance

document = XmlSchema(app.interface)
document.build_interface_document()

schemas = document.get_interface_document()

你有一个命名空间的字典:模式中的 schema_doc 对。

【讨论】:

    【解决方案2】:

    有一个 hacky 方法可以做到这一点,即在 Spyne 库中找到使用它后删除模式的代码并注释掉删除。然后,您可以获取架构(日志记录有助于指示它的位置),然后重新启用库代码。但是,如果有一些标志或控件生成一个模式并至少说“不要删除它,在这里给我保存一份副本......”,那就更好了。

    【讨论】:

      猜你喜欢
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-16
      • 2010-11-17
      • 1970-01-01
      相关资源
      最近更新 更多