我正在使用spyne创建一个Web服务,这样我的代码如下:
class bndbox(ComplexModel):
xmin = Integer
ymin = Integer
xmax = Integer
ymax = Integer
score = Integer
class object(ComplexModel):
name = String
objects = Array(bndbox)
class SKUObjectsDetected(ComplexModel):
annotation = Array(object)
def add_SKUObject(skuobject):
#global sku_object_database
sku_object_database.append(skuobject)
class ObjectDetectionService(Service):
@srpc(Unicode, _returns=SKUObjectsDetected)
def find_objects(encoded_string):
.
.
.
return SKUObjectsDetected(annotation=sku_object_database)
工作正常。实际上回复如下:
<soap11env:Envelope xmlns:tns="object_detection_service" xmlns:soap11env="http://schemas.xmlsoap.org/soap/envelope/">
<soap11env:Body>
<tns:find_objectsResponse>
<tns:annotation>
<tns:object>
<tns:objects>
<tns:bndbox>
<tns:xmin>151</tns:xmin>
<tns:ymin>183</tns:ymin>
<tns:score>34</tns:score>
<tns:xmax>169</tns:xmax>
<tns:ymax>272</tns:ymax>
</tns:bndbox>
<tns:bndbox>
<tns:xmin>190</tns:xmin>
<tns:ymin>12</tns:ymin>
<tns:score>32</tns:score>
<tns:xmax>300</tns:xmax>
<tns:ymax>92</tns:ymax>
</tns:bndbox>
<tns:bndbox>
<tns:xmin>284</tns:xmin>
<tns:ymin>5</tns:ymin>
<tns:score>28</tns:score>
<tns:xmax>300</tns:xmax>
<tns:ymax>65</tns:ymax>
</tns:bndbox>
</tns:objects>
<tns:name>Car</tns:name>
</tns:object>
</tns:annotation>
</tns:find_objectsResponse>
</soap11env:Body>
</soap11env:Envelope>
但是,可以删除
<tns:objects>
标签吗?其他标签都很好,我只需删除这个即可。它对应于对象类中的对象数组。
而不是
Array(bndbox)
使用
bndbox.customize(max_occurs='unbounded')