On 03/21/12 15:52, Alex Railean wrote:
I've done some digging in complex.py and I saw that the XmlAttribute
class has a describe() function that does look for a "use" argument.
Is this not the solution?

ah. indeed. It looks like I've missed this.


class DigestAlgAndValueType(ComplexModel):
      DigestMethod = DigestMethodType
      DigestValue = DigestValueType.customize(min_occurs=1)
The call to customize() returns an object of DigestValueType and
overrides the min_occurs property with 1, right?

Why not just declare DigestValueType with min_occurs=1 from the very
beginning?

that's possible.

class DigestValueType(ComplexModel):
    __namespace__ = "some_ns"
    class Attributes(ComplexModel.Attributes):
        min_occurs=1





<xs:complexType name="DataType">
       <xs:simpleContent>
               <xs:extension base="xs:string">
                       <xs:attribute name="MimeType" type="xs:string" 
use="optional"/>
                       <xs:attribute name="Encoding" type="xs:string" 
use="optional"/>
               </xs:extension>
       </xs:simpleContent>
</xs:complexType>

You can't. Rpclib only supports simpleType extension via restrictions,
not attributes.
Ok, I will try to simplify the problem then.  Since those who will use
my server already have the WSDL, it is not critical for me to be able
to produce a WSDL that looks exactly like the one given in the
specifications.

However, it is critical for me to be able to receive such a request
and be able to handle it.

If I create a custom type like this, will it do the trick?

class DataType(ComplexModel):
     class Attributes(ComplexModel.Attributes):
         MimeType = XmlAttribute(String, use = 'optional')
         Encoding = XmlAttribute(String, use = 'optional')

Nope. the class Attributes has nothing to do with xml attributes. It used to be, but I could not think of a way to handle elements attributes with same name. So I decided to avoid the problem and decided to have attributes and elements put in one namespace. It's still named Attributes because of backwards compatibility. It's currently just a way to store metadata.

Anyway, you should do this:

class DataType(ComplexModel):
    MimeType = XmlAttribute(String, use = 'optional')
    Encoding = XmlAttribute(String, use = 'optional')

Here's what that generates:

<xs:complexType name="DataType">
<xs:sequence/>
<xs:attribute name="MimeType" type="xs:string" use="optional"/>
<xs:attribute name="Encoding" type="xs:string" use="optional"/>
</xs:complexType>
<xs:element name="DataType" type="s0:DataType"/>

Which is not what you want. However, If you use no validation or soft validation, you can receive fields like this:

<field_name type="xs:string" Encoding="this" MimeType="that>some_string</field_name>

lxml validation will just reject this, because the additional attributes are not in the schema. but soft validation should work because it ignores unknown fields.

Once you get the message, you'll have to dig the values out of ctx.in_body_doc using xpath or a similar method. xpath is a very simple way of processing xml data, and lxml offers great support for that, so i don't imagine it'll be an issue.




(2) how does rpclib handle 'namespace="##other"'?
Rpclib can't generate this schema, you'd have to come up with a patch to
the xml schema implementation that actually emits an<any/>  tag.
I've examined the source and this seems to be the place to tinker
with:  src\rpclib\interface\xml_schema\model\complex.py

But besides generating such a schema, there must also be a way to
represent such a structure in the custom type definition, which
happens here: rpclib\src\rpclib\model\complex.py

Can you confirm that this is the case?

Yes, these are correct.

In addition to that, it would be great if you could offer some
tips about implementing this. I am not yet familiar enough with the
guts of rpclib to be able to make such fundamental changes.


That will partly depend on the kind of API you want to offer. You'll most probably implement a class similar to XmlAttribute. The metaclass in ComplexModel scans cls_dict to extract rpclib-relevant attributes and puts them in the _type_info attribute. The Xml schema implementation in the rpclib.interface package uses this information to generate the schema document.

And I imagine the funky thing that'll make the code hard to follow there is cdict. It's a special kind of dict that accepts classes as keys and any data as value. It tries parent classes as keys if it can't find the given class itself. See this for more info: https://github.com/plq/rpclib/blob/f7dc3b87feaa97953eeb12a92c367f23314ac243/src/rpclib/util/cdict.py

Other than that, I think it's a fairly straightforward implementation. Regardless, I'm happy to answer your questions.

Best,
Burak
]


_______________________________________________
Soap mailing list
[email protected]
http://mail.python.org/mailman/listinfo/soap

Reply via email to