From: <bov...@us...> - 2006-10-17 19:32:28
|
Revision: 1267 http://svn.sourceforge.net/pywebsvcs/?rev=1267&view=rev Author: boverhof Date: 2006-10-17 12:32:22 -0700 (Tue, 17 Oct 2006) Log Message: ----------- M ZSI/TC.py M ZSI/writer.py M doc/c06-tc.tex M doc/c07-writer.tex -- updates to doc, removed some comments and unused code. Modified Paths: -------------- trunk/zsi/ZSI/TC.py trunk/zsi/ZSI/writer.py trunk/zsi/doc/c06-tc.tex trunk/zsi/doc/c07-writer.tex Modified: trunk/zsi/ZSI/TC.py =================================================================== --- trunk/zsi/ZSI/TC.py 2006-10-13 23:35:29 UTC (rev 1266) +++ trunk/zsi/ZSI/TC.py 2006-10-17 19:32:22 UTC (rev 1267) @@ -615,8 +615,15 @@ def serialize(self, elt, sw, pyobj, name=None, orig=None, **kw): '''Handles the start and end tags, and attributes. callout to get_formatted_content to get the textNode value. - sw -- - pyobj -- processed content. + Parameters: + elt -- ElementProxy/DOM element + sw -- SoapWriter instance + pyobj -- processed content + + KeyWord Parameters: + name -- substitute name, (nspname,name) or name + orig -- + ''' objid = _get_idstr(pyobj) ns,n = self.get_name(name, objid) Modified: trunk/zsi/ZSI/writer.py =================================================================== --- trunk/zsi/ZSI/writer.py 2006-10-13 23:35:29 UTC (rev 1266) +++ trunk/zsi/ZSI/writer.py 2006-10-17 19:32:22 UTC (rev 1267) @@ -26,7 +26,7 @@ Instance Data: memo -- memory for id/href envelope -- add Envelope? - encoding -- + encodingStyle -- header -- add SOAP Header? outputclass -- ElementProxy class. ''' @@ -35,8 +35,7 @@ nsdict={}, outputclass=None, **kw): '''Initialize. ''' - if outputclass is None: - outputclass=ElementProxy + outputclass = outputclass or ElementProxy if not issubclass(outputclass, MessageInterface): raise TypeError, 'outputclass must subclass MessageInterface' @@ -54,13 +53,14 @@ return str(self.dom) def getSOAPHeader(self): - if self.header is True or self.header is False: + if self.header in (True, False): return None return self.header def serialize_header(self, pyobj, typecode=None, **kw): '''Serialize a Python object in SOAP-ENV:Header, make - sure everything in Header unique (no #href). + sure everything in Header unique (no #href). Must call + serialize first to create a document. Parameters: pyobjs -- instances to serialize in SOAP Header @@ -71,11 +71,13 @@ #header = self.dom.getElement(soap_env, 'Header') header = self._header if header is None: - header = self._header = self.dom.createAppendElement(soap_env, 'Header') + header = self._header = self.dom.createAppendElement(soap_env, + 'Header') typecode = getattr(pyobj, 'typecode', typecode) if typecode is None: - raise RuntimeError, 'typecode is required to serialize pyobj in header' + raise RuntimeError( + 'typecode is required to serialize pyobj in header') helt = typecode.serialize(header, self, pyobj, **kw) @@ -108,21 +110,18 @@ self.dom.createDocument(None,None) if typecode is None: typecode = pyobj.__class__.typecode - if TypeCode.typechecks and type(pyobj) == types.InstanceType and \ - not hasattr(typecode, 'pyclass'): - pass - # XXX XML ... - #raise TypeError('Serializing Python object with other than Struct.') kw = kw.copy() - - # TODO: FIX THIS... - #if root in [ 0, 1 ]: - # kw['attrtext'] = ' SOAP-ENC:root="%d"' % root if self.body is None: - typecode.serialize(self.dom, self, pyobj, **kw) + elt = typecode.serialize(self.dom, self, pyobj, **kw) else: - typecode.serialize(self.body, self, pyobj, **kw) + elt = typecode.serialize(self.body, self, pyobj, **kw) + + if root is not None: + if root not in [ 0, 1 ]: + raise ValueError, "SOAP-ENC root attribute not in [0,1]" + elt.setAttributeNS(SOAP.ENC, 'root', root) + return self def writeNSdict(self, nsdict): Modified: trunk/zsi/doc/c06-tc.tex =================================================================== --- trunk/zsi/doc/c06-tc.tex 2006-10-13 23:35:29 UTC (rev 1266) +++ trunk/zsi/doc/c06-tc.tex 2006-10-17 19:32:22 UTC (rev 1267) @@ -92,6 +92,14 @@ a \samp{(namespace, name)} tuple. \end{memberdesc} +\begin{memberdesc}{attribute_typecode_dict} +This is a class attribute. +This is a dict of \samp{(URI, NCName)} tuple keys, the values of each is a +typecode. This is how attribute declarations other than SOAP and XMLSchema +attribute declarations (eg. \code{xsi:type}, \code{id}, \code{href}, etc) are +represented. +\end{memberdesc} + \begin{memberdesc}{logger} This is a class attribute. logger instance for this class. Modified: trunk/zsi/doc/c07-writer.tex =================================================================== --- trunk/zsi/doc/c07-writer.tex 2006-10-13 23:35:29 UTC (rev 1266) +++ trunk/zsi/doc/c07-writer.tex 2006-10-17 19:32:22 UTC (rev 1267) @@ -14,36 +14,29 @@ \lineii{\code{xsi}}{\code{http://www.w3.org/2001/XMLSchema-instance}} \end{tableii} -\begin{classdesc}{SoapWriter}{out\optional{, **keywords}} -The \code{out} parameter is an object that has a \method{write()} -method for generating the output. - +\begin{classdesc}{SoapWriter}{optional{**keywords}} The following keyword arguments may be used: \begin{tableiii}{l|c|p{30em}}{textrm}{Keyword}{Default}{Description} -\lineiii{\code{encoding}}{\code{SOAP-ENC} value}{If not \code{None}, then +\lineiii{\code{encodingStyle}}{None}{If not \code{None}, then use the specified value as the value for the SOAP \code{encodingStyle} attribute. \versionadded{1.2}} -\lineiii{\code{envelope}}{\code{1}}{Write the SOAP envelope elements. +\lineiii{\code{envelope}}{\code{True}}{Create a SOAP Envelope \versionadded{1.2}} \lineiii{\code{nsdict}}{\code{\{\}}}{Dictionary of namespaces to declare -in the SOAP \code{Body}. -Note that earlier versions of ZSI put the declarations on the SOAP -\code{Envelope}; they have been moved to the \code{Body} for greater -interoperability.} -\lineiii{\code{header}}{\code{None}}{A sequence of elements to output in -the SOAP \code{Header}. -It may also be a text string, in which case it is output as-is, and should -therefore be XML text.} +in the SOAP \code{Envelope}} +\lineiii{\code{header}}{\code{True}}{create a SOAP \code{Header} element} +\lineiii{\code{outputclass}}{\code{ElementProxy}}{wrapper around DOM or other +XML library.} \end{tableiii} \end{classdesc} -Creating a \class{SoapWriter} object with a \class{StringIO} object for -the \code{out} parameter and \code{envelope} set to false results in an -object that can be used for serializing objects into a string. +Creating a \class{SoapWriter} object with \code{envelope} set to \code{False} +results in an object that can be used for serializing objects into a string. -\begin{methoddesc}{serialize}{pyobj\optional{, typecode\optional{, root=None\optional{, **keywords}}}} +\begin{methoddesc}{serialize}{pyobj\optional{, typecode=None\optional{, +root=None\optional{, header_pyobjs=None\optional{, **keywords}}}}} This method serializes the \code{pyobj} Python object as directed by the \code{typecode} typecode object. If \code{typecode} is omitted, then \code{pyobj} should be a Python @@ -58,16 +51,18 @@ method. \end{methoddesc} -\begin{methoddesc}{close}{\optional{trailer=None\optional{, nsdict=None}}} -Close off the SOAP message, finishing all the pending serializations. -If \code{trailer} is a string or list of elements, it is output after the -close-tag for the \code{Body}. -The \method{close()} method of the originally provided out object is NOT called. -(If it were, and the original \code{out} object were a \class{StringIO} -object, there would be no way to collect the data.) -This method will be invoked automatically if the object is deleted. +\begin{methoddesc}{close}{} +Invokes all the callbacks, if any. The \function{close} operations can only +happen once, if invoked a second time it will just return. This method will be +invoked automatically if the object is deleted. \end{methoddesc} + +\begin{methoddesc}{__str__}{} +Invokes the \function{close} method, and returns a string representation of the +serialized object. Assumes that \function{serialize} has been invoked. +\end{methoddesc} + The following methods are primarily useful for those writing new typecodes. \begin{methoddesc}{AddCallback}{func, arg} @@ -84,24 +79,15 @@ \end{methoddesc} \begin{methoddesc}{Known}{obj} -If \code{obj} has been seen before (based on its Python \code{id}), -return \code{1}. -Otherwise, remember \code{obj} and return \code{0}. +If \code{obj} has been seen before (based on its Python \code{id}), return +\code{1}. Otherwise, remember \code{obj} and return \code{0}. \end{methoddesc} \begin{methoddesc}{ReservedNS}{prefix, uri} -Returns true if the specified namespace \code{prefix} and -\code{uri} -collide with those used by the implementation. +Returns true if the specified namespace \code{prefix} and \code{uri} collide +with those used by the implementation. \end{methoddesc} -\begin{methoddesc}{write}{arg} -This is a convenience method that calls \method{self.out.write()} -on \code{arg}, with the addition that if \code{arg} is a sequence, -it iterates over the sequence, writing each item (that isn't \code{None}) -in turn. -\end{methoddesc} - \begin{methoddesc}{writeNSDict}{nsdict} Outputs \code{nsdict} as a namespace dictionary. It is assumed that an XML start-element is pending on the output This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |