Spyne. Set Array fixed number items -


i create model in spyne array attribute , need fix number items in array. i.e. model looks like:

class mymodel(complexmodel): __namespace__ = 'myns'  string_field = string(**{'min_occurs': 1, 'max_occurs': 1, 'nillable': false}) array_field = array(integer(**{'max_occurs': 16, 'min_occurs': 16, 'nillable': false}),                   **{'min_occurs': 1, 'max_occurs': 1, 'nillable': false}) 

so, mean need objects string attribute , array 16 integer items, code direct xml like:

<myns:mymodel>     <!--optional:-->     <myns:string_field>?</myns:string_field>     <myns:array_field>         <!--zero or more repetitions:-->         <myns:integer>?</myns:integer>     </myns:array_field> </myns:mymodel> 

there 1 integer item in myns:array_field instead 16. what's wrong in code or there possible set number of of array's items need to?

thanks.

two options:

  1. you can define constructor , set default values usual way. i.e.

    class mymodel(complexmodel):     __namespace__ = 'myns'      string_field = string(min_occurs=1, nillable=false)     array_field = array(integer(max_occurs=16, min_occurs=16, nillable=false),                  min_occurs=1, max_occurs=1, nillable=false)      def __init__(self):         self.array_field = [0] * 16 
  2. you can define default value array. here's working script:

    from lxml import etree spyne.model.complex import complexmodel, array spyne.model.primitive import string, integer  class mymodel(complexmodel):     __namespace__ = 'myns'      s = string(min_occurs=1, nillable=false)     = array(integer(max_occurs=16, min_occurs=16, nillable=false),          min_occurs=1, max_occurs=1, nillable=false, default=[0]*16)  spyne.util.xml import get_object_as_xml  print etree.tostring(get_object_as_xml(mymodel(s='some_string'), mymodel), pretty_print=true) 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -