home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / ZSI / generate / containers.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  76.6 KB  |  2,389 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import types
  5. import warnings
  6. from utility import StringWriter, TextProtect, TextProtectAttributeName, GetPartsSubNames
  7. from utility import NamespaceAliasDict as NAD, NCName_to_ClassName as NC_to_CN
  8. import ZSI
  9. from ZSI.TC import _is_xsd_or_soap_ns
  10. from ZSI.wstools import XMLSchema, WSDLTools
  11. from ZSI.wstools.Namespaces import SCHEMA, SOAP, WSDL
  12. from ZSI.wstools.logging import getLogger as _GetLogger
  13. from ZSI.typeinterpreter import BaseTypeInterpreter
  14. from ZSI.generate import WSISpec, WSInteropError, Wsdl2PythonError, WsdlGeneratorError, WSDLFormatError
  15. ID1 = '    '
  16. ID2 = 2 * ID1
  17. ID3 = 3 * ID1
  18. ID4 = 4 * ID1
  19. ID5 = 5 * ID1
  20. ID6 = 6 * ID1
  21. KW = {
  22.     'ID1': ID1,
  23.     'ID2': ID2,
  24.     'ID3': ID3,
  25.     'ID4': ID4,
  26.     'ID5': ID5,
  27.     'ID6': ID6 }
  28. DEC = '_Dec'
  29. DEF = '_Def'
  30.  
  31. type_class_name = lambda n: '%s%s' % (NC_to_CN(n), DEF)
  32.  
  33. element_class_name = lambda n: '%s%s' % (NC_to_CN(n), DEC)
  34.  
  35. def IsRPC(item):
  36.     if not isinstance(item, WSDLTools.OperationBinding):
  37.         raise TypeError, 'IsRPC takes 1 argument of type WSDLTools.OperationBinding'
  38.     isinstance(item, WSDLTools.OperationBinding)
  39.     soapbinding = item.getBinding().findBinding(WSDLTools.SoapBinding)
  40.     sob = item.findBinding(WSDLTools.SoapOperationBinding)
  41.     style = soapbinding.style
  42.     if sob is not None:
  43.         if not sob.style:
  44.             pass
  45.         style = soapbinding.style
  46.     
  47.     return style == 'rpc'
  48.  
  49.  
  50. def IsLiteral(item):
  51.     if not isinstance(item, WSDLTools.MessageRoleBinding):
  52.         raise TypeError, 'IsLiteral takes 1 argument of type WSDLTools.MessageRoleBinding'
  53.     isinstance(item, WSDLTools.MessageRoleBinding)
  54.     sbb = None
  55.     if item.type == 'input' or item.type == 'output':
  56.         sbb = item.findBinding(WSDLTools.SoapBodyBinding)
  57.     
  58.     if sbb is None:
  59.         raise ValueError, 'Missing soap:body binding.'
  60.     sbb is None
  61.     return sbb.use == 'literal'
  62.  
  63.  
  64. def SetTypeNameFunc(func):
  65.     global type_class_name
  66.     type_class_name = func
  67.  
  68.  
  69. def SetElementNameFunc(func):
  70.     global element_class_name
  71.     element_class_name = func
  72.  
  73.  
  74. def GetClassNameFromSchemaItem(item, do_extended = False):
  75.     alias = NAD.getAlias(item.getTargetNamespace())
  76.     if item.isDefinition() is True:
  77.         return '%s.%s' % (alias, NC_to_CN('%s' % type_class_name(item.getAttributeName())))
  78.  
  79.  
  80. def FromMessageGetSimpleElementDeclaration(message):
  81.     if len(message.parts) == 1 and message.parts[0].element is not None:
  82.         part = message.parts[0]
  83.         (nsuri, name) = part.element
  84.         wsdl = message.getWSDL()
  85.         types = wsdl.types
  86.         if types.has_key(nsuri) and types[nsuri].elements.has_key(name):
  87.             e = types[nsuri].elements[name]
  88.             if isinstance(e, XMLSchema.ElementDeclaration) is True and e.getAttribute('type'):
  89.                 typ = e.getAttribute('type')
  90.                 bt = BaseTypeInterpreter()
  91.                 ptype = bt.get_pythontype(typ[1], typ[0])
  92.                 return ptype
  93.         
  94.     
  95.  
  96.  
  97. class AttributeMixIn:
  98.     attribute_typecode = 'self.attribute_typecode_dict'
  99.     built_in_refs = [
  100.         (SOAP.ENC, 'arrayType')]
  101.     
  102.     def _setAttributes(self, attributes):
  103.         atd = self.attribute_typecode
  104.         atd_list = formatted_attribute_list = []
  105.         if not attributes:
  106.             return formatted_attribute_list
  107.         atd_list.append('# attribute handling code')
  108.         idx = 0
  109.         while idx < len(attributes):
  110.             a = attributes[idx]
  111.             idx += 1
  112.             if a.isWildCard() and a.isDeclaration():
  113.                 atd_list.append('%s[("%s","anyAttribute")] = ZSI.TC.AnyElement()' % (atd, SCHEMA.XSD3))
  114.                 continue
  115.             attributes
  116.             if a.isDeclaration():
  117.                 tdef = a.getTypeDefinition('type')
  118.                 if tdef is not None:
  119.                     tc = '%s.%s(None)' % (NAD.getAlias(tdef.getTargetNamespace()), self.mangle(type_class_name(tdef.getAttributeName())))
  120.                 else:
  121.                     t = a.getAttribute('type')
  122.                     
  123.                     try:
  124.                         tc = BTI.get_typeclass(t[1], t[0])
  125.                     except:
  126.                         tc = ZSI.TC.String
  127.  
  128.                     if tc is not None:
  129.                         tc = '%s()' % tc
  130.                     
  131.                 key = None
  132.                 if a.getAttribute('form') == 'qualified':
  133.                     key = '("%s","%s")' % (a.getTargetNamespace(), a.getAttribute('name'))
  134.                 elif a.getAttribute('form') == 'unqualified':
  135.                     key = '"%s"' % a.getAttribute('name')
  136.                 else:
  137.                     raise ContainerError, 'attribute form must be un/qualified %s' % a.getAttribute('form')
  138.                 (a.getAttribute('form') == 'qualified').append('%s[%s] = %s' % (atd, key, tc))
  139.                 continue
  140.             if a.isReference() and a.isAttributeGroup():
  141.                 for ga in a.getAttributeGroup().getAttributeContent():
  142.                     attributes += (ga,)
  143.                 
  144.             if a.isReference():
  145.                 
  146.                 try:
  147.                     ga = a.getAttributeDeclaration()
  148.                 except XMLSchema.SchemaError:
  149.                     key = a.getAttribute('ref')
  150.                     self.logger.debug('No schema item for attribute ref (%s, %s)' % key)
  151.                     if key in self.built_in_refs:
  152.                         continue
  153.                     
  154.                     raise 
  155.  
  156.                 tp = None
  157.                 if ga is not None:
  158.                     tp = ga.getTypeDefinition('type')
  159.                     key = '("%s","%s")' % (ga.getTargetNamespace(), ga.getAttribute('name'))
  160.                 
  161.                 if ga is None:
  162.                     key = '("%s","%s")' % (a.getAttribute('ref').getTargetNamespace(), a.getAttribute('ref').getName())
  163.                     atd_list.append('%s[%s] = ZSI.TC.String()' % (atd, key))
  164.                 elif tp is None:
  165.                     
  166.                     try:
  167.                         (namespace, typeName) = ga.getAttribute('type')
  168.                     except TypeError:
  169.                         ex = None
  170.                         atd_list.append('%s[%s] = ZSI.TC.String()' % (atd, key))
  171.  
  172.                     atd_list.append('%s[%s] = %s()' % (atd, key, BTI.get_typeclass(typeName, namespace)))
  173.                 else:
  174.                     typeName = tp.getAttribute('name')
  175.                     namespace = tp.getTargetNamespace()
  176.                     alias = NAD.getAlias(namespace)
  177.                     key = '("%s","%s")' % (ga.getTargetNamespace(), ga.getAttribute('name'))
  178.                     atd_list.append('%s[%s] = %s.%s(None)' % (atd, key, alias, type_class_name(typeName)))
  179.             ga is None
  180.             raise TypeError, 'expecting an attribute: %s' % a.getItemTrace()
  181.         return formatted_attribute_list
  182.  
  183.  
  184.  
  185. class ContainerError(Exception):
  186.     pass
  187.  
  188.  
  189. class ContainerBase:
  190.     func_aname = staticmethod(TextProtectAttributeName)
  191.     logger = _GetLogger('ContainerBase')
  192.     
  193.     def __init__(self):
  194.         self.content = StringWriter('\n')
  195.         self._ContainerBase__setup = False
  196.         self.ns = None
  197.  
  198.     
  199.     def __str__(self):
  200.         return self.getvalue()
  201.  
  202.     
  203.     def mangle(self, s):
  204.         return TextProtect(s)
  205.  
  206.     
  207.     def write(self, s):
  208.         self.content.write(s)
  209.  
  210.     
  211.     def writeArray(self, a):
  212.         self.content.write('\n'.join(a))
  213.  
  214.     
  215.     def _setContent(self):
  216.         raise NotImplementedError, 'abstract method not implemented'
  217.  
  218.     
  219.     def getvalue(self):
  220.         if not self._ContainerBase__setup:
  221.             self._setContent()
  222.             self._ContainerBase__setup = True
  223.         
  224.         return self.content.getvalue()
  225.  
  226.     
  227.     def getNSAlias(self):
  228.         if self.ns is not None:
  229.             return NAD.getAlias(self.ns)
  230.         raise ContainerError, 'no self.ns attr defined in %s' % self.__class__
  231.  
  232.     
  233.     def getNSModuleName(self):
  234.         if self.ns:
  235.             return NAD.getModuleName(self.ns)
  236.         raise ContainerError, 'no self.ns attr defined in %s' % self.__class__
  237.  
  238.     
  239.     def getAttributeName(self, name):
  240.         if self.func_aname is None:
  241.             return name
  242.         f = self.func_aname
  243.         return f(name)
  244.  
  245.  
  246.  
  247. class ServiceContainerBase(ContainerBase):
  248.     clientClassSuffix = 'SOAP'
  249.     logger = _GetLogger('ServiceContainerBase')
  250.  
  251.  
  252. class ServiceHeaderContainer(ServiceContainerBase):
  253.     imports = [
  254.         '\nimport urlparse, types',
  255.         'from ZSI.TCcompound import ComplexType, Struct',
  256.         'from ZSI import client',
  257.         'from ZSI.schema import GED, GTD',
  258.         'import ZSI']
  259.     logger = _GetLogger('ServiceHeaderContainer')
  260.     
  261.     def __init__(self, do_extended = False):
  262.         ServiceContainerBase.__init__(self)
  263.         self.basic = self.imports[:]
  264.         self.types = None
  265.         self.messages = None
  266.         self.extras = []
  267.         self.do_extended = do_extended
  268.  
  269.     
  270.     def setTypesModuleName(self, module):
  271.         self.types = module
  272.  
  273.     
  274.     def setMessagesModuleName(self, module):
  275.         self.messages = module
  276.  
  277.     
  278.     def appendImport(self, statement):
  279.         if type(statement) in (list, tuple):
  280.             self.extras += statement
  281.         else:
  282.             self.extras.append(statement)
  283.  
  284.     
  285.     def _setContent(self):
  286.         if self.messages:
  287.             self.write('from %s import *' % self.messages)
  288.         
  289.         if self.types:
  290.             self.write('from %s import *' % self.types)
  291.         
  292.         imports = self.basic[:]
  293.         imports += self.extras
  294.         self.writeArray(imports)
  295.  
  296.  
  297.  
  298. class ServiceLocatorContainer(ServiceContainerBase):
  299.     logger = _GetLogger('ServiceLocatorContainer')
  300.     
  301.     def __init__(self):
  302.         ServiceContainerBase.__init__(self)
  303.         self.serviceName = None
  304.         self.portInfo = []
  305.         self.locatorName = None
  306.         self.portMethods = []
  307.  
  308.     
  309.     def setUp(self, service):
  310.         self.serviceName = service.name
  311.         for p in service.ports:
  312.             
  313.             try:
  314.                 ab = p.getAddressBinding()
  315.             except WSDLTools.WSDLError:
  316.                 ex = None
  317.                 self.logger.warning('Skip port(%s), missing address binding' % p.name)
  318.                 continue
  319.  
  320.             if isinstance(ab, WSDLTools.SoapAddressBinding) is False:
  321.                 self.logger.warning('Skip port(%s), not a SOAP-1.1 address binding' % p.name)
  322.                 continue
  323.             
  324.             self.portInfo.append((NC_to_CN(p.name), NC_to_CN(p.getBinding().name), ab.location))
  325.         
  326.  
  327.     
  328.     def getLocatorName(self):
  329.         return self.locatorName
  330.  
  331.     
  332.     def getPortMethods(self):
  333.         return self.portMethods
  334.  
  335.     
  336.     def _setContent(self):
  337.         if not self.serviceName:
  338.             raise ContainerError, 'no service name defined!'
  339.         self.serviceName
  340.         self.serviceName = self.mangle(self.serviceName)
  341.         self.locatorName = '%sLocator' % self.serviceName
  342.         locator = [
  343.             '# Locator',
  344.             'class %s:' % self.locatorName]
  345.         self.portMethods = []
  346.         kwargs = KW.copy()
  347.         for port, bind, addr in self.portInfo:
  348.             method = 'get%s' % port
  349.             kwargs.update(dict(port = port, bind = bind, addr = addr, service = self.serviceName, suffix = self.clientClassSuffix, method = method))
  350.             locator += [
  351.                 '%(ID1)s%(port)s_address = "%(addr)s"' % kwargs,
  352.                 '%(ID1)sdef get%(port)sAddress(self):' % kwargs,
  353.                 '%(ID2)sreturn %(service)sLocator.%(port)s_address' % kwargs,
  354.                 '%(ID1)sdef %(method)s(self, url=None, **kw):' % kwargs,
  355.                 '%(ID2)sreturn %(bind)s%(suffix)s(url or %(service)sLocator.%(port)s_address, **kw)' % kwargs]
  356.             self.portMethods.append(method)
  357.         
  358.         self.writeArray(locator)
  359.  
  360.  
  361.  
  362. class ServiceOperationContainer(ServiceContainerBase):
  363.     logger = _GetLogger('ServiceOperationContainer')
  364.     
  365.     def __init__(self, useWSA = False, do_extended = False):
  366.         ServiceContainerBase.__init__(self)
  367.         self.useWSA = useWSA
  368.         self.do_extended = do_extended
  369.  
  370.     
  371.     def hasInput(self):
  372.         return self.inputName is not None
  373.  
  374.     
  375.     def hasOutput(self):
  376.         return self.outputName is not None
  377.  
  378.     
  379.     def isRPC(self):
  380.         return IsRPC(self.binding_operation)
  381.  
  382.     
  383.     def isLiteral(self, input = True):
  384.         msgrole = self.binding_operation.input
  385.         if input is False:
  386.             msgrole = self.binding_operation.output
  387.         
  388.         return IsLiteral(msgrole)
  389.  
  390.     
  391.     def isSimpleType(self, input = True):
  392.         if input is False:
  393.             return self.outputSimpleType
  394.         return self.inputSimpleType
  395.  
  396.     
  397.     def getOperation(self):
  398.         return self.port.operations.get(self.name)
  399.  
  400.     
  401.     def getBOperation(self):
  402.         return self.port.get(self.name)
  403.  
  404.     
  405.     def getOperationName(self):
  406.         return self.name
  407.  
  408.     
  409.     def setUp(self, item):
  410.         if not isinstance(item, WSDLTools.OperationBinding):
  411.             raise TypeError, 'Expecting WSDLTools Operation instance'
  412.         isinstance(item, WSDLTools.OperationBinding)
  413.         if not item.input:
  414.             raise WSDLFormatError('No <input/> in <binding name="%s"><operation name="%s">' % (item.getBinding().name, item.name))
  415.         item.input
  416.         self.name = None
  417.         self.port = None
  418.         self.soapaction = None
  419.         self.inputName = None
  420.         self.outputName = None
  421.         self.inputSimpleType = None
  422.         self.outputSimpleType = None
  423.         self.inputAction = None
  424.         self.outputAction = None
  425.         self.port = port = item.getBinding().getPortType()
  426.         self._wsdl = item.getWSDL()
  427.         self.name = name = item.name
  428.         self.binding_operation = bop = item
  429.         self.soap_input_headers = None
  430.         self.soap_output_headers = None
  431.         op = port.operations.get(name)
  432.         if op is None:
  433.             raise WSDLFormatError('<portType name="%s"/> no match for <binding name="%s"><operation name="%s">' % (port.name, item.getBinding().name, item.name))
  434.         op is None
  435.         soap_bop = bop.findBinding(WSDLTools.SoapOperationBinding)
  436.         if soap_bop is None:
  437.             raise SOAPBindingError, 'expecting SOAP Bindings'
  438.         soap_bop is None
  439.         self.soapaction = soap_bop.soapAction
  440.         sbody = bop.input.findBinding(WSDLTools.SoapBodyBinding)
  441.         if not sbody:
  442.             raise SOAPBindingError('Missing <binding name="%s"><operation name="%s"><input><soap:body>' % (port.binding.name, bop.name))
  443.         sbody
  444.         self.encodingStyle = None
  445.         if sbody.use == 'encoded':
  446.             self.encodingStyle = sbody.encodingStyle
  447.         
  448.         self.inputName = op.getInputMessage().name
  449.         self.inputSimpleType = FromMessageGetSimpleElementDeclaration(op.getInputMessage())
  450.         self.inputAction = op.getInputAction()
  451.         self.soap_input_headers = bop.input.findBindings(WSDLTools.SoapHeaderBinding)
  452.         if bop.output is not None:
  453.             sbody = bop.output.findBinding(WSDLTools.SoapBodyBinding)
  454.             if not item.output:
  455.                 raise WSDLFormatError, 'Operation %s, no match for output binding' % name
  456.             item.output
  457.             self.outputName = op.getOutputMessage().name
  458.             self.outputSimpleType = FromMessageGetSimpleElementDeclaration(op.getOutputMessage())
  459.             self.outputAction = op.getOutputAction()
  460.             self.soap_output_headers = bop.output.findBindings(WSDLTools.SoapHeaderBinding)
  461.         
  462.  
  463.     
  464.     def _setContent(self):
  465.         kwstring = 'kw = {}'
  466.         tCheck = 'if isinstance(request, %s) is False:' % self.inputName
  467.         bindArgs = ''
  468.         if self.encodingStyle is not None:
  469.             bindArgs = 'encodingStyle="%s", ' % self.encodingStyle
  470.         
  471.         if self.useWSA:
  472.             wsactionIn = 'wsaction = "%s"' % self.inputAction
  473.             wsactionOut = 'wsaction = "%s"' % self.outputAction
  474.             bindArgs += 'wsaction=wsaction, endPointReference=self.endPointReference, '
  475.             responseArgs = ', wsaction=wsaction'
  476.         else:
  477.             wsactionIn = '# no input wsaction'
  478.             wsactionOut = '# no output wsaction'
  479.             responseArgs = ''
  480.         bindArgs += '**kw)'
  481.         if self.do_extended:
  482.             inputName = self.getOperation().getInputMessage().name
  483.             wrap_str = ''
  484.             partsList = self.getOperation().getInputMessage().parts.values()
  485.             
  486.             try:
  487.                 subNames = GetPartsSubNames(partsList, self._wsdl)
  488.             except TypeError:
  489.                 ex = None
  490.                 raise Wsdl2PythonError, 'Extended generation failure: only supports doc/lit, ' + 'and all element attributes (<message><part element=' + '"my:GED"></message>) must refer to single global ' + 'element declaration with complexType content.  ' + '\n\n**** TRY WITHOUT EXTENDED ****\n'
  491.  
  492.             args = []
  493.             for pa in subNames:
  494.                 args += pa
  495.             
  496.             for arg in args:
  497.                 wrap_str += '%srequest.%s = %s\n' % (ID2, self.getAttributeName(arg), self.mangle(arg))
  498.             
  499.             argsStr = ','.join(args)
  500.             if len(argsStr) > 1:
  501.                 argsStr = ', ' + argsStr
  502.             
  503.             method = [
  504.                 '%s# op: %s' % (ID1, self.getOperation().getInputMessage()),
  505.                 '%sdef %s(self%s):' % (ID1, self.name, argsStr),
  506.                 '\n%srequest = %s()' % (ID2, self.inputName),
  507.                 '%s' % wrap_str,
  508.                 '%s%s' % (ID2, kwstring),
  509.                 '%s%s' % (ID2, wsactionIn),
  510.                 '%sself.binding.Send(None, None, request, soapaction="%s", %s' % (ID2, self.soapaction, bindArgs)]
  511.         elif self.soap_input_headers:
  512.             method = [
  513.                 '%s# op: %s' % (ID1, self.name),
  514.                 '%sdef %s(self, request, soapheaders=(), **kw):' % (ID1, self.name),
  515.                 '%s%s' % (ID2, tCheck),
  516.                 '%sraise TypeError, "%%s incorrect request type" %% (%s)' % (ID3, 'request.__class__'),
  517.                 '%s%s' % (ID2, wsactionIn),
  518.                 '%s# TODO: Check soapheaders' % ID2,
  519.                 '%sself.binding.Send(None, None, request, soapaction="%s", soapheaders=soapheaders, %s' % (ID2, self.soapaction, bindArgs)]
  520.         else:
  521.             method = [
  522.                 '%s# op: %s' % (ID1, self.name),
  523.                 '%sdef %s(self, request, **kw):' % (ID1, self.name),
  524.                 '%s%s' % (ID2, tCheck),
  525.                 '%sraise TypeError, "%%s incorrect request type" %% (%s)' % (ID3, 'request.__class__'),
  526.                 '%s%s' % (ID2, wsactionIn),
  527.                 '%sself.binding.Send(None, None, request, soapaction="%s", %s' % (ID2, self.soapaction, bindArgs)]
  528.         if not self.outputName:
  529.             method.append('%s#check for soap, assume soap:fault' % (ID2,))
  530.             method.append('%sif self.binding.IsSOAP(): self.binding.Receive(None, **kw)' % (ID2,))
  531.             self.writeArray(method)
  532.             return None
  533.         response = [
  534.             '%s%s' % (ID2, wsactionOut)]
  535.         if self.isRPC() and not self.isLiteral():
  536.             response.append('%stypecode = Struct(pname=None, ofwhat=%s.typecode.ofwhat, pyclass=%s.typecode.pyclass)' % (ID2, self.outputName, self.outputName))
  537.             response.append('%sresponse = self.binding.Receive(typecode%s)' % (ID2, responseArgs))
  538.         else:
  539.             response.append('%sresponse = self.binding.Receive(%s.typecode%s)' % (ID2, self.outputName, responseArgs))
  540.         if self.soap_output_headers:
  541.             sh = '['
  542.             for shb in self.soap_output_headers:
  543.                 shb.message
  544.                 shb.part
  545.                 
  546.                 try:
  547.                     msg = self._wsdl.messages[shb.message]
  548.                     part = msg.parts[shb.part]
  549.                     if part.element is not None:
  550.                         sh += 'GED%s,' % str(part.element)
  551.                     else:
  552.                         warnings.warn('skipping soap output header in Message "%s"' % str(msg))
  553.                 continue
  554.                 raise WSDLFormatError('failure processing output header typecodes, ' + 'could not find message "%s" or its part "%s"' % (shb.message, shb.part))
  555.                 continue
  556.  
  557.             
  558.             sh += ']'
  559.             if len(sh) > 2:
  560.                 response.append('%sself.soapheaders = self.binding.ps.ParseHeaderElements(%s)' % (ID2, sh))
  561.             
  562.         
  563.         if self.outputSimpleType:
  564.             response.append('%sreturn %s(response)' % (ID2, self.outputName))
  565.         elif self.do_extended:
  566.             partsList = self.getOperation().getOutputMessage().parts.values()
  567.             subNames = GetPartsSubNames(partsList, self._wsdl)
  568.             args = []
  569.             for pa in subNames:
  570.                 args += pa
  571.             
  572.             for arg in args:
  573.                 response.append('%s%s = response.%s' % (ID2, self.mangle(arg), self.getAttributeName(arg)))
  574.             
  575.             margs = ','.join(args)
  576.             response.append('%sreturn %s' % (ID2, margs))
  577.         else:
  578.             response.append('%sreturn response' % ID2)
  579.         method += response
  580.         self.writeArray(method)
  581.  
  582.  
  583.  
  584. class BindingDescription(ServiceContainerBase):
  585.     readerclass = None
  586.     writerclass = None
  587.     operationclass = ServiceOperationContainer
  588.     logger = _GetLogger('BindingDescription')
  589.     
  590.     def __init__(self, useWSA = False, do_extended = False, wsdl = None):
  591.         ServiceContainerBase.__init__(self)
  592.         self.useWSA = useWSA
  593.         self.rProp = None
  594.         self.operations = None
  595.         self.do_extended = do_extended
  596.         self._wsdl = wsdl
  597.  
  598.     
  599.     def setReaderClass(cls, className):
  600.         cls.readerclass = className
  601.  
  602.     setReaderClass = classmethod(setReaderClass)
  603.     
  604.     def setWriterClass(cls, className):
  605.         cls.writerclass = className
  606.  
  607.     setWriterClass = classmethod(setWriterClass)
  608.     
  609.     def setOperationClass(cls, className):
  610.         cls.operationclass = className
  611.  
  612.     setOperationClass = classmethod(setOperationClass)
  613.     
  614.     def setUp(self, item):
  615.         portType = item.getPortType()
  616.         self._kwargs = KW.copy()
  617.         self._kwargs['bind'] = NC_to_CN(item.name)
  618.         self.operations = []
  619.         self.rProp = portType.getResourceProperties()
  620.         soap_binding = item.findBinding(WSDLTools.SoapBinding)
  621.         if soap_binding is None:
  622.             raise Wsdl2PythonError, 'Binding(%s) missing WSDLTools.SoapBinding' % item.name
  623.         soap_binding is None
  624.         for bop in item.operations:
  625.             soap_bop = bop.findBinding(WSDLTools.SoapOperationBinding)
  626.             if soap_bop is None:
  627.                 self.logger.warning('Skip Binding(%s) operation(%s) no SOAP Binding Operation' % (item.name, bop.name))
  628.                 continue
  629.             
  630.             if bop.input is not None:
  631.                 soapBodyBind = bop.input.findBinding(WSDLTools.SoapBodyBinding)
  632.                 if soapBodyBind is None:
  633.                     self.logger.warning('Skip Binding(%s) operation(%s) Bindings(%s) not supported' % (item.name, bop.name, bop.extensions))
  634.                     continue
  635.                 
  636.             
  637.             op = portType.operations.get(bop.name)
  638.             if op is None:
  639.                 raise Wsdl2PythonError, 'no matching portType/Binding operation(%s)' % bop.name
  640.             op is None
  641.             c = self.operationclass(useWSA = self.useWSA, do_extended = self.do_extended)
  642.             c.setUp(bop)
  643.             self.operations.append(c)
  644.         
  645.  
  646.     
  647.     def _setContent(self):
  648.         if self.useWSA is True:
  649.             args = 'endPointReference=None, **kw'
  650.             epr = 'self.endPointReference = endPointReference'
  651.         else:
  652.             args = '**kw'
  653.             epr = '# no ws-addressing'
  654.         if self.rProp:
  655.             rp = 'kw.setdefault("ResourceProperties", ("%s","%s"))' % (self.rProp[0], self.rProp[1])
  656.         else:
  657.             rp = '# no resource properties'
  658.         kwargs = self._kwargs
  659.         kwargs.update(dict(suffix = self.clientClassSuffix, args = args, epr = epr, rp = rp, readerclass = self.readerclass, writerclass = self.writerclass))
  660.         methods = [
  661.             '# Methods',
  662.             'class %(bind)s%(suffix)s:' % kwargs,
  663.             '%(ID1)sdef __init__(self, url, %(args)s):' % kwargs,
  664.             '%(ID2)skw.setdefault("readerclass", %(readerclass)s)' % kwargs,
  665.             '%(ID2)skw.setdefault("writerclass", %(writerclass)s)' % kwargs,
  666.             '%(ID2)s%(rp)s' % kwargs,
  667.             '%(ID2)sself.binding = client.Binding(url=url, **kw)' % kwargs,
  668.             '%(ID2)s%(epr)s' % kwargs]
  669.         for op in self.operations:
  670.             methods += [
  671.                 op.getvalue()]
  672.         
  673.         self.writeArray(methods)
  674.  
  675.  
  676. ServiceOperationsClassContainer = BindingDescription
  677.  
  678. class MessageContainerInterface:
  679.     logger = _GetLogger('MessageContainerInterface')
  680.     
  681.     def setUp(self, port, soc, input):
  682.         raise NotImplementedError, 'Message container must implemented setUp.'
  683.  
  684.  
  685.  
  686. class ServiceDocumentLiteralMessageContainer(ServiceContainerBase, MessageContainerInterface):
  687.     logger = _GetLogger('ServiceDocumentLiteralMessageContainer')
  688.     
  689.     def __init__(self, do_extended = False):
  690.         ServiceContainerBase.__init__(self)
  691.         self.do_extended = do_extended
  692.  
  693.     
  694.     def setUp(self, port, soc, input):
  695.         content = self.content
  696.         simple = self._simple = soc.isSimpleType(soc.getOperationName())
  697.         name = soc.getOperationName()
  698.         operation = port.getBinding().getPortType().operations.get(name)
  699.         bop = port.getBinding().operations.get(name)
  700.         soapBodyBind = None
  701.         if input is True:
  702.             soapBodyBind = bop.input.findBinding(WSDLTools.SoapBodyBinding)
  703.             message = operation.getInputMessage()
  704.         else:
  705.             soapBodyBind = bop.output.findBinding(WSDLTools.SoapBodyBinding)
  706.             message = operation.getOutputMessage()
  707.         if len(message.parts) == 0:
  708.             raise Wsdl2PythonError, 'must specify part for doc/lit msg'
  709.         len(message.parts) == 0
  710.         p = None
  711.         if soapBodyBind.parts is not None:
  712.             if len(soapBodyBind.parts) > 1:
  713.                 raise Wsdl2PythonError, 'not supporting multiple parts in soap body'
  714.             len(soapBodyBind.parts) > 1
  715.             if len(soapBodyBind.parts) == 0:
  716.                 return None
  717.             p = message.parts.get(soapBodyBind.parts[0])
  718.         
  719.         if not p:
  720.             pass
  721.         p = message.parts[0]
  722.         if p.type:
  723.             raise Wsdl2PythonError, 'no doc/lit suport for <part type>'
  724.         p.type
  725.         if not p.element:
  726.             return None
  727.         self.ns = p.element[0]
  728.         content.ns = p.element[0]
  729.         content.pName = p.element[1]
  730.         content.mName = message.name
  731.  
  732.     
  733.     def _setContent(self):
  734.         
  735.         try:
  736.             simple = self._simple
  737.         except AttributeError:
  738.             raise RuntimeError, 'call setUp first'
  739.  
  740.         kw = KW.copy()
  741.         kw.update(dict(message = self.content.mName, nsuri = self.content.ns, name = self.content.pName))
  742.         self.writeArray([
  743.             '%(message)s = GED("%(nsuri)s", "%(name)s").pyclass' % kw])
  744.  
  745.  
  746.  
  747. class ServiceRPCEncodedMessageContainer(ServiceContainerBase, MessageContainerInterface):
  748.     logger = _GetLogger('ServiceRPCEncodedMessageContainer')
  749.     
  750.     def setUp(self, port, soc, input):
  751.         name = soc.getOperationName()
  752.         bop = port.getBinding().operations.get(name)
  753.         op = port.getBinding().getPortType().operations.get(name)
  754.         self.input = input
  755.         self.op = op
  756.         self.bop = bop
  757.  
  758.     
  759.     def _setContent(self):
  760.         
  761.         try:
  762.             self.op
  763.         except AttributeError:
  764.             raise RuntimeError, 'call setUp first'
  765.  
  766.         pname = self.op.name
  767.         msgRole = self.op.input
  768.         msgRoleB = self.bop.input
  769.         if self.input is False:
  770.             pname = '%sResponse' % self.op.name
  771.             msgRole = self.op.output
  772.             msgRoleB = self.bop.output
  773.         
  774.         sbody = msgRoleB.findBinding(WSDLTools.SoapBodyBinding)
  775.         if not sbody or not (sbody.namespace):
  776.             raise WSInteropError, WSISpec.R2717
  777.         not (sbody.namespace)
  778.         encodingStyle = sbody.encodingStyle
  779.         namespace = sbody.namespace
  780.         tcb = MessageTypecodeContainer(tuple(msgRole.getMessage().parts.list))
  781.         ofwhat = '[%s]' % tcb.getTypecodeList()
  782.         pyclass = msgRole.getMessage().name
  783.         fdict = KW.copy()
  784.         fdict['nspname'] = sbody.namespace
  785.         fdict['pname'] = pname
  786.         fdict['pyclass'] = None
  787.         fdict['ofwhat'] = ofwhat
  788.         fdict['encoded'] = namespace
  789.         fdict['typecode'] = 'Struct(pname=("%(nspname)s","%(pname)s"), ofwhat=%(ofwhat)s, pyclass=%(pyclass)s, encoded="%(encoded)s")'
  790.         message = [
  791.             'class %(pyclass)s:',
  792.             '%(ID1)sdef __init__(self, **kw):',
  793.             '%(ID2)s"""Keyword parameters:']
  794.         idx = len(message)
  795.         for a, p in zip(tcb.getAttributeNames(), tcb.getParameterNames()):
  796.             message.insert(idx, '%(ID2)s' + p + ' -- part ' + p)
  797.             message.append('%(ID2)sself.' + a + ' =  kw.get("%s")' % p)
  798.             idx += 1
  799.         
  800.         message.insert(idx, '%(ID2)s"""')
  801.         if TypecodeContainerBase.metaclass is None:
  802.             fdict['pyclass'] = pyclass
  803.             fdict['typecode'] = fdict['typecode'] % fdict
  804.             message.append('%(pyclass)s.typecode = %(typecode)s')
  805.         else:
  806.             fdict['typecode'] = fdict['typecode'] % fdict
  807.             fdict['pyclass'] = pyclass
  808.             fdict['metaclass'] = TypecodeContainerBase.metaclass
  809.             message.insert(0, '_%(pyclass)sTypecode = %(typecode)s')
  810.             message.insert(2, '%(ID1)stypecode = _%(pyclass)sTypecode')
  811.             message.insert(3, '%(ID1)s__metaclass__ = %(metaclass)s')
  812.             message.append('%(pyclass)s.typecode.pyclass = %(pyclass)s')
  813.         self.writeArray((map,)((lambda l: l % fdict), message))
  814.  
  815.  
  816.  
  817. class ServiceRPCLiteralMessageContainer(ServiceContainerBase, MessageContainerInterface):
  818.     logger = _GetLogger('ServiceRPCLiteralMessageContainer')
  819.     
  820.     def setUp(self, port, soc, input):
  821.         name = soc.getOperationName()
  822.         bop = port.getBinding().operations.get(name)
  823.         op = port.getBinding().getPortType().operations.get(name)
  824.         self.op = op
  825.         self.bop = bop
  826.         self.input = input
  827.  
  828.     
  829.     def _setContent(self):
  830.         
  831.         try:
  832.             self.op
  833.         except AttributeError:
  834.             raise RuntimeError, 'call setUp first'
  835.  
  836.         operation = self.op
  837.         input = self.input
  838.         pname = operation.name
  839.         msgRole = operation.input
  840.         msgRoleB = self.bop.input
  841.         if input is False:
  842.             pname = '%sResponse' % operation.name
  843.             msgRole = operation.output
  844.             msgRoleB = self.bop.output
  845.         
  846.         sbody = msgRoleB.findBinding(WSDLTools.SoapBodyBinding)
  847.         if not sbody or not (sbody.namespace):
  848.             raise WSInteropError, WSISpec.R2717
  849.         not (sbody.namespace)
  850.         namespace = sbody.namespace
  851.         tcb = MessageTypecodeContainer(tuple(msgRole.getMessage().parts.list))
  852.         ofwhat = '[%s]' % tcb.getTypecodeList()
  853.         pyclass = msgRole.getMessage().name
  854.         fdict = KW.copy()
  855.         fdict['nspname'] = sbody.namespace
  856.         fdict['pname'] = pname
  857.         fdict['pyclass'] = None
  858.         fdict['ofwhat'] = ofwhat
  859.         fdict['encoded'] = namespace
  860.         fdict['typecode'] = 'Struct(pname=("%(nspname)s","%(pname)s"), ofwhat=%(ofwhat)s, pyclass=%(pyclass)s, encoded="%(encoded)s")'
  861.         message = [
  862.             'class %(pyclass)s:',
  863.             '%(ID1)sdef __init__(self, **kw):',
  864.             '%(ID2)s"""Keyword parameters:']
  865.         idx = len(message)
  866.         for a, p in zip(tcb.getAttributeNames(), tcb.getParameterNames()):
  867.             message.insert(idx, '%(ID2)s' + p + ' -- part ' + p)
  868.             message.append('%(ID2)sself.' + a + ' =  kw.get("%s")' % p)
  869.             idx += 1
  870.         
  871.         message.insert(idx, '%(ID2)s"""')
  872.         if TypecodeContainerBase.metaclass is None:
  873.             fdict['pyclass'] = pyclass
  874.             fdict['typecode'] = fdict['typecode'] % fdict
  875.             message.append('%(pyclass)s.typecode = %(typecode)s')
  876.         else:
  877.             fdict['typecode'] = fdict['typecode'] % fdict
  878.             fdict['pyclass'] = pyclass
  879.             fdict['metaclass'] = TypecodeContainerBase.metaclass
  880.             message.insert(0, '_%(pyclass)sTypecode = %(typecode)s')
  881.             message.insert(2, '%(ID1)stypecode = _%(pyclass)sTypecode')
  882.             message.insert(3, '%(ID1)s__metaclass__ = %(metaclass)s')
  883.             message.append('%(pyclass)s.typecode.pyclass = %(pyclass)s')
  884.         self.writeArray((map,)((lambda l: l % fdict), message))
  885.  
  886.  
  887. TypesContainerBase = ContainerBase
  888.  
  889. class TypesHeaderContainer(TypesContainerBase):
  890.     imports = [
  891.         'import ZSI',
  892.         'import ZSI.TCcompound',
  893.         'from ZSI.schema import LocalElementDeclaration, ElementDeclaration, TypeDefinition, GTD, GED']
  894.     logger = _GetLogger('TypesHeaderContainer')
  895.     
  896.     def _setContent(self):
  897.         self.writeArray(TypesHeaderContainer.imports)
  898.  
  899.  
  900. NamespaceClassContainerBase = TypesContainerBase
  901.  
  902. class NamespaceClassHeaderContainer(NamespaceClassContainerBase):
  903.     logger = _GetLogger('NamespaceClassHeaderContainer')
  904.     
  905.     def _setContent(self):
  906.         head = [
  907.             '#' * 30,
  908.             '# targetNamespace',
  909.             '# %s' % self.ns,
  910.             '#' * 30 + '\n',
  911.             'class %s:' % self.getNSAlias(),
  912.             '%stargetNamespace = "%s"' % (ID1, self.ns)]
  913.         self.writeArray(head)
  914.  
  915.  
  916.  
  917. class NamespaceClassFooterContainer(NamespaceClassContainerBase):
  918.     logger = _GetLogger('NamespaceClassFooterContainer')
  919.     
  920.     def _setContent(self):
  921.         foot = [
  922.             '# end class %s (tns: %s)' % (self.getNSAlias(), self.ns)]
  923.         self.writeArray(foot)
  924.  
  925.  
  926. BTI = BaseTypeInterpreter()
  927.  
  928. class TypecodeContainerBase(TypesContainerBase):
  929.     mixed_content_aname = 'text'
  930.     attributes_aname = 'attrs'
  931.     metaclass = None
  932.     lazy = False
  933.     logger = _GetLogger('TypecodeContainerBase')
  934.     
  935.     def __init__(self, do_extended = False, extPyClasses = None):
  936.         TypesContainerBase.__init__(self)
  937.         self.name = None
  938.         self.allOptional = False
  939.         self.mgContent = None
  940.         self.contentFlattened = False
  941.         self.elementAttrs = []
  942.         self.tcListElements = []
  943.         self.tcListSet = False
  944.         self.localTypes = []
  945.         self.parentClass = None
  946.         self.mixed = False
  947.         self.extraFlags = ''
  948.         self.attrComponents = None
  949.         self.do_extended = do_extended
  950.         if extPyClasses is None:
  951.             self.extPyClasses = { }
  952.         else:
  953.             self.extPyClasses = extPyClasses
  954.  
  955.     
  956.     def getvalue(self):
  957.         out = ContainerBase.getvalue(self)
  958.         for item in self.localTypes:
  959.             content = None
  960.             etp = item.content
  961.             qName = item.getAttribute('type')
  962.             if not qName:
  963.                 etp = item.content
  964.                 local = True
  965.             else:
  966.                 etp = item.getTypeDefinition('type')
  967.             if etp is None:
  968.                 if local is True:
  969.                     content = ElementLocalComplexTypeContainer(do_extended = self.do_extended)
  970.                 else:
  971.                     content = ElementSimpleTypeContainer()
  972.             elif etp.isLocal() is False:
  973.                 content = ElementGlobalDefContainer()
  974.             elif etp.isSimple() is True:
  975.                 content = ElementLocalSimpleTypeContainer()
  976.             elif etp.isComplex():
  977.                 content = ElementLocalComplexTypeContainer(do_extended = self.do_extended)
  978.             else:
  979.                 raise Wsdl2PythonError, 'Unknown element declaration: %s' % item.getItemTrace()
  980.             (etp is None).setUp(item)
  981.             out += '\n\n'
  982.             if self.parentClass:
  983.                 content.parentClass = '%s.%s' % (self.parentClass, self.getClassName())
  984.             else:
  985.                 content.parentClass = '%s.%s' % (self.getNSAlias(), self.getClassName())
  986.             for l in content.getvalue().split('\n'):
  987.                 if l:
  988.                     out += '%s%s\n' % (ID1, l)
  989.                     continue
  990.                 out += '\n'
  991.             
  992.             out += '\n\n'
  993.         
  994.         return out
  995.  
  996.     
  997.     def getAttributeName(self, name):
  998.         if self.func_aname is None:
  999.             return name
  1000.         f = self.func_aname
  1001.         return f(name)
  1002.  
  1003.     
  1004.     def getMixedTextAName(self):
  1005.         return self.getAttributeName(self.mixed_content_aname)
  1006.  
  1007.     
  1008.     def getClassName(self):
  1009.         if not self.name:
  1010.             raise ContainerError, 'self.name not defined!'
  1011.         self.name
  1012.         if not hasattr(self.__class__, 'type'):
  1013.             raise ContainerError, 'container type not defined!'
  1014.         hasattr(self.__class__, 'type')
  1015.         if self.__class__.type == DEF:
  1016.             classname = type_class_name(self.name)
  1017.         elif self.__class__.type == DEC:
  1018.             classname = element_class_name(self.name)
  1019.         
  1020.         return self.mangle(classname)
  1021.  
  1022.     
  1023.     def hasExtPyClass(self):
  1024.         if self.name in self.extPyClasses:
  1025.             return True
  1026.         return False
  1027.  
  1028.     
  1029.     def getPyClass(self):
  1030.         if self.hasExtPyClass():
  1031.             classInfo = self.extPyClasses[self.name]
  1032.             return '.'.join(classInfo)
  1033.         return 'Holder'
  1034.  
  1035.     
  1036.     def getPyClassDefinition(self):
  1037.         kw = KW.copy()
  1038.         if self.hasExtPyClass():
  1039.             classInfo = self.extPyClasses[self.name]
  1040.             kw['classInfo'] = classInfo[0]
  1041.             return [
  1042.                 '%(ID3)simport %(classInfo)s' % kw]
  1043.         kw['pyclass'] = self.getPyClass()
  1044.         definition = []
  1045.         definition.append('%(ID3)sclass %(pyclass)s:' % kw)
  1046.         if self.metaclass is not None:
  1047.             kw['type'] = self.metaclass
  1048.             definition.append('%(ID4)s__metaclass__ = %(type)s' % kw)
  1049.         
  1050.         definition.append('%(ID4)stypecode = self' % kw)
  1051.         definition.append('%(ID4)sdef __init__(self):' % kw)
  1052.         definition.append('%(ID5)s# pyclass' % kw)
  1053.         self._setUpElements()
  1054.         for el in self.elementAttrs:
  1055.             kw['element'] = el
  1056.             definition.append('%(ID2)s%(element)s' % kw)
  1057.         
  1058.         definition.append('%(ID5)sreturn' % kw)
  1059.         if self.name is not None:
  1060.             kw['name'] = self.name
  1061.             definition.append('%(ID3)s%(pyclass)s.__name__ = "%(name)s_Holder"' % kw)
  1062.         
  1063.         return definition
  1064.  
  1065.     
  1066.     def nsuriLogic(self):
  1067.         if self.parentClass:
  1068.             return 'ns = %s.%s.schema' % (self.parentClass, self.getClassName())
  1069.         return 'ns = %s.%s.schema' % (self.getNSAlias(), self.getClassName())
  1070.  
  1071.     
  1072.     def schemaTag(self):
  1073.         if self.ns is not None:
  1074.             return 'schema = "%s"' % self.ns
  1075.         raise ContainerError, 'failed to set schema targetNamespace(%s)' % self.__class__
  1076.  
  1077.     
  1078.     def typeTag(self):
  1079.         if self.name is not None:
  1080.             return 'type = (schema, "%s")' % self.name
  1081.         raise ContainerError, 'failed to set type name(%s)' % self.__class__
  1082.  
  1083.     
  1084.     def literalTag(self):
  1085.         if self.name is not None:
  1086.             return 'literal = "%s"' % self.name
  1087.         raise ContainerError, 'failed to set element name(%s)' % self.__class__
  1088.  
  1089.     
  1090.     def getExtraFlags(self):
  1091.         if self.mixed:
  1092.             self.extraFlags += 'mixed=True, mixed_aname="%s", ' % self.getMixedTextAName()
  1093.         
  1094.         return self.extraFlags
  1095.  
  1096.     
  1097.     def simpleConstructor(self, superclass = None):
  1098.         if superclass:
  1099.             return '%s.__init__(self, **kw)' % superclass
  1100.         return 'def __init__(self, **kw):'
  1101.  
  1102.     
  1103.     def pnameConstructor(self, superclass = None):
  1104.         if superclass:
  1105.             return '%s.__init__(self, pname, **kw)' % superclass
  1106.         return 'def __init__(self, pname, **kw):'
  1107.  
  1108.     
  1109.     def _setUpElements(self):
  1110.         self.logger.debug('_setUpElements: %s' % self._item.getItemTrace())
  1111.         if hasattr(self, '_done'):
  1112.             return None
  1113.         self._done = True
  1114.         flat = []
  1115.         content = self.mgContent
  1116.         if type(self.mgContent) is not tuple:
  1117.             mg = self.mgContent
  1118.             if not mg.isModelGroup():
  1119.                 mg = mg.content
  1120.             
  1121.             content = mg.content
  1122.             if mg.isAll():
  1123.                 flat = content
  1124.                 content = []
  1125.             elif mg.isModelGroup() and mg.isDefinition():
  1126.                 mg = mg.content
  1127.                 content = mg.content
  1128.             
  1129.         
  1130.         idx = 0
  1131.         content = list(content)
  1132.         while idx < len(content):
  1133.             c = orig = content[idx]
  1134.             if c.isElement():
  1135.                 flat.append(c)
  1136.                 idx += 1
  1137.                 continue
  1138.             
  1139.             if c.isReference() and c.isModelGroup():
  1140.                 c = c.getModelGroupReference()
  1141.             
  1142.             if c.isDefinition() and c.isModelGroup():
  1143.                 c = c.content
  1144.             
  1145.             if c.isSequence() or c.isChoice():
  1146.                 begIdx = idx
  1147.                 endIdx = begIdx + len(c.content)
  1148.                 for i in range(begIdx, endIdx):
  1149.                     content.insert(i, c.content[i - begIdx])
  1150.                 
  1151.                 content.remove(orig)
  1152.                 continue
  1153.             
  1154.             raise ContainerError, 'unexpected schema item: %s' % c.getItemTrace()
  1155.         for c in flat:
  1156.             if c.isDeclaration() and c.isElement():
  1157.                 defaultValue = 'None'
  1158.                 parent = c
  1159.                 defs = []
  1160.                 while defs.count(parent) <= 1:
  1161.                     maxOccurs = parent.getAttribute('maxOccurs')
  1162.                     if maxOccurs == 'unbounded' or int(maxOccurs) > 1:
  1163.                         defaultValue = '[]'
  1164.                         break
  1165.                     
  1166.                     parent = parent._parent()
  1167.                     if not parent.isModelGroup():
  1168.                         break
  1169.                     
  1170.                     if parent.isReference():
  1171.                         parent = parent.getModelGroupReference()
  1172.                     
  1173.                     if parent.isDefinition():
  1174.                         parent = parent.content
  1175.                         defs.append(parent)
  1176.                         continue
  1177.                 if None == c.getAttribute('name') and c.isWildCard():
  1178.                     e = '%sself.%s = %s' % (ID3, self.getAttributeName('any'), defaultValue)
  1179.                 else:
  1180.                     e = '%sself.%s = %s' % (ID3, self.getAttributeName(c.getAttribute('name')), defaultValue)
  1181.                 self.elementAttrs.append(e)
  1182.                 continue
  1183.             
  1184.             if c.isReference():
  1185.                 e = '%sself._%s = None' % (ID3, self.mangle(c.getAttribute('ref')[1]))
  1186.                 self.elementAttrs.append(e)
  1187.                 continue
  1188.             
  1189.             raise ContainerError, 'unexpected item: %s' % c.getItemTrace()
  1190.         
  1191.  
  1192.     
  1193.     def _setTypecodeList(self):
  1194.         self.logger.debug('_setTypecodeList(%r): %s' % (self.mgContent, self._item.getItemTrace()))
  1195.         flat = []
  1196.         content = self.mgContent
  1197.         if type(content) is not tuple:
  1198.             mg = content
  1199.             if not mg.isModelGroup():
  1200.                 raise Wsdl2PythonErr('Expecting ModelGroup: %s' % mg.getItemTrace())
  1201.             mg.isModelGroup()
  1202.             self.logger.debug('ModelGroup(%r) contents(%r): %s' % (mg, mg.content, mg.getItemTrace()))
  1203.             if mg.isReference():
  1204.                 raise RuntimeError('Unexpected modelGroup reference: %s' % mg.getItemTrace())
  1205.             mg.isReference()
  1206.             if mg.isDefinition():
  1207.                 mg = mg.content
  1208.             
  1209.             if mg.isAll():
  1210.                 flat = mg.content
  1211.                 content = []
  1212.             elif mg.isSequence():
  1213.                 content = mg.content
  1214.             elif mg.isChoice():
  1215.                 content = mg.content
  1216.             else:
  1217.                 raise RuntimeError('Unknown schema item')
  1218.         mg.isAll()
  1219.         idx = 0
  1220.         content = list(content)
  1221.         self.logger.debug('content: %r' % content)
  1222.         while idx < len(content):
  1223.             c = orig = content[idx]
  1224.             if c.isElement():
  1225.                 flat.append(c)
  1226.                 idx += 1
  1227.                 continue
  1228.             
  1229.             if c.isReference() and c.isModelGroup():
  1230.                 c = c.getModelGroupReference()
  1231.             
  1232.             if c.isDefinition() and c.isModelGroup():
  1233.                 c = c.content
  1234.             
  1235.             if c.isSequence() or c.isChoice():
  1236.                 begIdx = idx
  1237.                 endIdx = begIdx + len(c.content)
  1238.                 for i in range(begIdx, endIdx):
  1239.                     content.insert(i, c.content[i - begIdx])
  1240.                 
  1241.                 content.remove(orig)
  1242.                 continue
  1243.             
  1244.             raise ContainerError, 'unexpected schema item: %s' % c.getItemTrace()
  1245.         self.logger.debug('flat: %r' % list(flat))
  1246.         for c in flat:
  1247.             tc = TcListComponentContainer()
  1248.             (min, max, nil) = self._getOccurs(c)
  1249.             min = None
  1250.             max = None
  1251.             maxOccurs = 1
  1252.             parent = c
  1253.             defs = []
  1254.             while defs.count(parent) <= 1:
  1255.                 max = parent.getAttribute('maxOccurs')
  1256.                 if max == 'unbounded':
  1257.                     maxOccurs = '"%s"' % max
  1258.                     break
  1259.                 
  1260.                 maxOccurs = int(max) * maxOccurs
  1261.                 parent = parent._parent()
  1262.                 if not parent.isModelGroup():
  1263.                     break
  1264.                 
  1265.                 if parent.isReference():
  1266.                     parent = parent.getModelGroupReference()
  1267.                 
  1268.                 if parent.isDefinition():
  1269.                     parent = parent.content
  1270.                     defs.append(parent)
  1271.                     continue
  1272.             del defs
  1273.             parent = c
  1274.             while None:
  1275.                 minOccurs = int(parent.getAttribute('minOccurs'))
  1276.                 if minOccurs == 0 or parent.isChoice():
  1277.                     minOccurs = 0
  1278.                     break
  1279.                 
  1280.                 parent = parent._parent()
  1281.                 if not parent.isModelGroup():
  1282.                     minOccurs = int(c.getAttribute('minOccurs'))
  1283.                     break
  1284.                 
  1285.                 if parent.isReference():
  1286.                     parent = parent.getModelGroupReference()
  1287.                 
  1288.                 if parent.isDefinition():
  1289.                     parent = parent.content
  1290.                     continue
  1291.                 continue
  1292.                 tc.setOccurs(minOccurs, maxOccurs, nil)
  1293.                 processContents = self._getProcessContents(c)
  1294.                 tc.setProcessContents(processContents)
  1295.                 if c.isDeclaration() and c.isElement():
  1296.                     global_type = c.getAttribute('type')
  1297.                     content = getattr(c, 'content', None)
  1298.                     if c.isLocal() and c.isQualified() is False:
  1299.                         tc.unQualified()
  1300.                     
  1301.                     if c.isWildCard():
  1302.                         tc.setStyleAnyElement()
  1303.                     elif global_type is not None:
  1304.                         tc.name = c.getAttribute('name')
  1305.                         ns = global_type[0]
  1306.                         if ns in SCHEMA.XSD_LIST:
  1307.                             tpc = BTI.get_typeclass(global_type[1], global_type[0])
  1308.                             tc.klass = tpc
  1309.                         else:
  1310.                             tc.setGlobalType(*global_type)
  1311.                         del ns
  1312.                     elif content is not None and content.isLocal() and content.isComplex():
  1313.                         tc.name = c.getAttribute('name')
  1314.                         tc.klass = 'self.__class__.%s' % element_class_name(tc.name)
  1315.                         tc.setStyleElementReference()
  1316.                         self.localTypes.append(c)
  1317.                     elif content is not None and content.isLocal() and content.isSimple():
  1318.                         tc.name = c.getAttribute('name')
  1319.                         tc.klass = 'self.__class__.%s' % element_class_name(tc.name)
  1320.                         tc.setStyleElementReference()
  1321.                         self.localTypes.append(c)
  1322.                     else:
  1323.                         raise ContainerError, 'unexpected item: %s' % c.getItemTrace()
  1324.             content.isSimple()
  1325.             if c.isReference():
  1326.                 ref = c.getAttribute('ref')
  1327.                 tc.setStyleElementReference()
  1328.                 tc.setGlobalType(*ref)
  1329.             else:
  1330.                 raise ContainerError, 'unexpected item: %s' % c.getItemTrace()
  1331.             c.isReference().tcListElements.append(tc)
  1332.         
  1333.  
  1334.     
  1335.     def getTypecodeList(self):
  1336.         if not self.tcListSet:
  1337.             self._setTypecodeList()
  1338.             self.tcListSet = True
  1339.         
  1340.         list = []
  1341.         for e in self.tcListElements:
  1342.             list.append(str(e))
  1343.         
  1344.         return ', '.join(list)
  1345.  
  1346.     
  1347.     def _getOccurs(self, e):
  1348.         nillable = e.getAttribute('nillable')
  1349.         if nillable == 'true':
  1350.             nillable = True
  1351.         else:
  1352.             nillable = False
  1353.         maxOccurs = e.getAttribute('maxOccurs')
  1354.         if maxOccurs == 'unbounded':
  1355.             maxOccurs = '"%s"' % maxOccurs
  1356.         
  1357.         minOccurs = e.getAttribute('minOccurs')
  1358.         if self.allOptional is True:
  1359.             minOccurs = '0'
  1360.             maxOccurs = '"unbounded"'
  1361.         
  1362.         return (minOccurs, maxOccurs, nillable)
  1363.  
  1364.     
  1365.     def _getProcessContents(self, e):
  1366.         processContents = e.getAttribute('processContents')
  1367.         return processContents
  1368.  
  1369.     
  1370.     def getBasesLogic(self, indent):
  1371.         
  1372.         try:
  1373.             prefix = NAD.getAlias(self.sKlassNS)
  1374.         except WsdlGeneratorError:
  1375.             ex = None
  1376.             raise 
  1377.  
  1378.         bases = []
  1379.         bases.append('if %s.%s not in %s.%s.__bases__:' % (NAD.getAlias(self.sKlassNS), type_class_name(self.sKlass), self.getNSAlias(), self.getClassName()))
  1380.         bases.append('%sbases = list(%s.%s.__bases__)' % (ID1, self.getNSAlias(), self.getClassName()))
  1381.         bases.append('%sbases.insert(0, %s.%s)' % (ID1, NAD.getAlias(self.sKlassNS), type_class_name(self.sKlass)))
  1382.         bases.append('%s%s.%s.__bases__ = tuple(bases)' % (ID1, self.getNSAlias(), self.getClassName()))
  1383.         s = ''
  1384.         for b in bases:
  1385.             s += '%s%s\n' % (indent, b)
  1386.         
  1387.         return s
  1388.  
  1389.  
  1390.  
  1391. class MessageTypecodeContainer(TypecodeContainerBase):
  1392.     logger = _GetLogger('MessageTypecodeContainer')
  1393.     
  1394.     def __init__(self, parts = None):
  1395.         TypecodeContainerBase.__init__(self)
  1396.         self.mgContent = parts
  1397.  
  1398.     
  1399.     def _getOccurs(self, e):
  1400.         minOccurs = maxOccurs = '1'
  1401.         nillable = True
  1402.         return (minOccurs, maxOccurs, nillable)
  1403.  
  1404.     
  1405.     def _setTypecodeList(self):
  1406.         self.logger.debug('_setTypecodeList: %s' % str(self.mgContent))
  1407.         for p in self.mgContent:
  1408.             (min, max, nil) = self._getOccurs(p)
  1409.             if p.element:
  1410.                 raise WSInteropError, WSISpec.R2203
  1411.             p.element
  1412.             if p.type:
  1413.                 (nsuri, name) = p.type
  1414.                 tc = RPCMessageTcListComponentContainer(qualified = False)
  1415.                 tc.setOccurs(min, max, nil)
  1416.                 tc.name = p.name
  1417.                 if nsuri in [
  1418.                     SOAP.ENC12,
  1419.                     SOAP.ENC] + SCHEMA.XSD_LIST:
  1420.                     tpc = BTI.get_typeclass(name, nsuri)
  1421.                     tc.klass = tpc
  1422.                 else:
  1423.                     tc.klass = '%s.%s' % (NAD.getAlias(nsuri), type_class_name(name))
  1424.             else:
  1425.                 raise ContainerError, 'part must define an element or type attribute'
  1426.             p.type.tcListElements.append(tc)
  1427.         
  1428.  
  1429.     
  1430.     def getTypecodeList(self):
  1431.         if not self.tcListSet:
  1432.             self._setTypecodeList()
  1433.             self.tcListSet = True
  1434.         
  1435.         list = []
  1436.         for e in self.tcListElements:
  1437.             list.append(str(e))
  1438.         
  1439.         return ', '.join(list)
  1440.  
  1441.     
  1442.     def getAttributeNames(self):
  1443.         return (map,)((lambda e: self.getAttributeName(e.name)), self.tcListElements)
  1444.  
  1445.     
  1446.     def getParameterNames(self):
  1447.         return map((lambda e: e.name), self.tcListElements)
  1448.  
  1449.     
  1450.     def setParts(self, parts):
  1451.         self.mgContent = parts
  1452.  
  1453.  
  1454.  
  1455. class TcListComponentContainer(ContainerBase):
  1456.     logger = _GetLogger('TcListComponentContainer')
  1457.     
  1458.     def __init__(self, qualified = True):
  1459.         ContainerBase.__init__(self)
  1460.         self.qualified = qualified
  1461.         self.name = None
  1462.         self.klass = None
  1463.         self.global_type = None
  1464.         self.min = None
  1465.         self.max = None
  1466.         self.nil = None
  1467.         self.style = None
  1468.         self.setStyleElementDeclaration()
  1469.  
  1470.     
  1471.     def setOccurs(self, min, max, nil):
  1472.         self.min = min
  1473.         self.max = max
  1474.         self.nil = nil
  1475.  
  1476.     
  1477.     def setProcessContents(self, processContents):
  1478.         self.processContents = processContents
  1479.  
  1480.     
  1481.     def setGlobalType(self, namespace, name):
  1482.         self.global_type = (namespace, name)
  1483.  
  1484.     
  1485.     def setStyleElementDeclaration(self):
  1486.         self.style = 'standard'
  1487.  
  1488.     
  1489.     def setStyleElementReference(self):
  1490.         self.style = 'ref'
  1491.  
  1492.     
  1493.     def setStyleAnyElement(self):
  1494.         self.name = 'any'
  1495.         self.style = 'anyElement'
  1496.  
  1497.     
  1498.     def unQualified(self):
  1499.         self.qualified = False
  1500.  
  1501.     
  1502.     def _getOccurs(self):
  1503.         return 'minOccurs=%s, maxOccurs=%s, nillable=%s' % (self.min, self.max, self.nil)
  1504.  
  1505.     
  1506.     def _getProcessContents(self):
  1507.         return 'processContents="%s"' % self.processContents
  1508.  
  1509.     
  1510.     def _getvalue(self):
  1511.         kw = {
  1512.             'occurs': self._getOccurs(),
  1513.             'aname': self.getAttributeName(self.name),
  1514.             'klass': self.klass,
  1515.             'lazy': TypecodeContainerBase.lazy,
  1516.             'typed': 'typed=False',
  1517.             'encoded': 'encoded=kw.get("encoded")' }
  1518.         gt = self.global_type
  1519.         if gt is not None:
  1520.             (kw['nsuri'], kw['type']) = gt
  1521.         
  1522.         if self.style == 'standard':
  1523.             kw['pname'] = '"%s"' % self.name
  1524.             if self.qualified is True:
  1525.                 kw['pname'] = '(ns,"%s")' % self.name
  1526.             
  1527.             if gt is None:
  1528.                 return '%(klass)s(pname=%(pname)s, aname="%(aname)s", %(occurs)s, %(typed)s, %(encoded)s)' % kw
  1529.             return 'GTD("%(nsuri)s","%(type)s",lazy=%(lazy)s)(pname=%(pname)s, aname="%(aname)s", %(occurs)s, %(typed)s, %(encoded)s)' % kw
  1530.         if self.style == 'ref':
  1531.             if gt is None:
  1532.                 return '%(klass)s(%(occurs)s, %(encoded)s)' % kw
  1533.             return 'GED("%(nsuri)s","%(type)s",lazy=%(lazy)s, isref=True)(%(occurs)s, %(encoded)s)' % kw
  1534.         kw['process'] = self._getProcessContents()
  1535.         if self.style == 'anyElement':
  1536.             return 'ZSI.TC.AnyElement(aname="%(aname)s", %(occurs)s, %(process)s)' % kw
  1537.         raise RuntimeError, 'Must set style for typecode list generation'
  1538.  
  1539.     
  1540.     def __str__(self):
  1541.         return self._getvalue()
  1542.  
  1543.  
  1544.  
  1545. class RPCMessageTcListComponentContainer(TcListComponentContainer):
  1546.     logger = _GetLogger('RPCMessageTcListComponentContainer')
  1547.     
  1548.     def __init__(self, qualified = True, encoded = None):
  1549.         TcListComponentContainer.__init__(self, qualified = qualified)
  1550.         self._encoded = encoded
  1551.  
  1552.     
  1553.     def _getvalue(self):
  1554.         encoded = self._encoded
  1555.         if encoded is not None:
  1556.             encoded = '"%s"' % self._encoded
  1557.         
  1558.         if self.style == 'standard':
  1559.             pname = '"%s"' % self.name
  1560.             if self.qualified is True:
  1561.                 pname = '(ns,"%s")' % self.name
  1562.             
  1563.             return '%s(pname=%s, aname="%s", typed=False, encoded=%s, %s)' % (self.klass, pname, self.getAttributeName(self.name), encoded, self._getOccurs())
  1564.         if self.style == 'ref':
  1565.             return '%s(encoded=%s, %s)' % (self.klass, encoded, self._getOccurs())
  1566.         if self.style == 'anyElement':
  1567.             return 'ZSI.TC.AnyElement(aname="%s", %s, %s)' % (self.getAttributeName(self.name), self._getOccurs(), self._getProcessContents())
  1568.         raise RuntimeError('Must set style(%s) for typecode list generation' % self.style)
  1569.  
  1570.  
  1571.  
  1572. class ElementSimpleTypeContainer(TypecodeContainerBase):
  1573.     type = DEC
  1574.     logger = _GetLogger('ElementSimpleTypeContainer')
  1575.     
  1576.     def _substitutionGroupTag(self):
  1577.         value = self.substitutionGroup
  1578.         if not value:
  1579.             return 'substitutionGroup = None'
  1580.         (nsuri, ncname) = value
  1581.         return 'substitutionGroup = ("%s","%s")' % (nsuri, ncname)
  1582.  
  1583.     
  1584.     def _setContent(self):
  1585.         aname = self.getAttributeName(self.name)
  1586.         pyclass = self.pyclass
  1587.         if pyclass == 'bool':
  1588.             pyclass = 'int'
  1589.         
  1590.         kw = KW.copy()
  1591.         kw.update(dict(aname = aname, ns = self.ns, name = self.name, substitutionGroup = self._substitutionGroupTag(), subclass = self.sKlass, literal = self.literalTag(), schema = self.schemaTag(), init = self.simpleConstructor(), klass = self.getClassName(), element = 'ElementDeclaration'))
  1592.         if self.local:
  1593.             kw['element'] = 'LocalElementDeclaration'
  1594.         
  1595.         element = (map,)((lambda i: i % kw), [
  1596.             '%(ID1)sclass %(klass)s(%(subclass)s, %(element)s):',
  1597.             '%(ID2)s%(literal)s',
  1598.             '%(ID2)s%(schema)s',
  1599.             '%(ID2)s%(init)s',
  1600.             '%(ID3)skw["pname"] = ("%(ns)s","%(name)s")',
  1601.             '%(ID3)skw["aname"] = "%(aname)s"'])
  1602.         app = element.append
  1603.         if pyclass is not None:
  1604.             app('%sclass IHolder(%s): typecode=self' % (ID3, pyclass))
  1605.             app('%skw["pyclass"] = IHolder' % ID3)
  1606.             app('%sIHolder.__name__ = "%s_immutable_holder"' % (ID3, aname))
  1607.         
  1608.         app('%s%s' % (ID3, self.simpleConstructor(self.sKlass)))
  1609.         self.writeArray(element)
  1610.  
  1611.     
  1612.     def setUp(self, tp):
  1613.         self._item = tp
  1614.         self.local = tp.isLocal()
  1615.         
  1616.         try:
  1617.             self.name = tp.getAttribute('name')
  1618.             self.substitutionGroup = tp.getAttribute('substitutionGroup')
  1619.             self.ns = tp.getTargetNamespace()
  1620.             qName = tp.getAttribute('type')
  1621.         except Exception:
  1622.             ex = None
  1623.             raise Wsdl2PythonError('Error occured processing element: %s' % tp.getItemTrace(), *ex.args)
  1624.  
  1625.         if qName is None:
  1626.             raise Wsdl2PythonError('Missing QName for element type attribute: %s' % tp.getItemTrace())
  1627.         qName is None
  1628.         tns = qName.getTargetNamespace()
  1629.         local = qName.getName()
  1630.         self.sKlass = BTI.get_typeclass(local, tns)
  1631.         if self.sKlass is None:
  1632.             raise Wsdl2PythonError('No built-in typecode for type definition("%s","%s"): %s' % (tns, local, tp.getItemTrace()))
  1633.         self.sKlass is None
  1634.         
  1635.         try:
  1636.             self.pyclass = BTI.get_pythontype(None, None, typeclass = self.sKlass)
  1637.         except Exception:
  1638.             ex = None
  1639.             raise Wsdl2PythonError('Error occured processing element: %s' % tp.getItemTrace(), *ex.args)
  1640.  
  1641.  
  1642.  
  1643.  
  1644. class ElementLocalSimpleTypeContainer(TypecodeContainerBase):
  1645.     type = DEC
  1646.     logger = _GetLogger('ElementLocalSimpleTypeContainer')
  1647.     
  1648.     def _setContent(self):
  1649.         kw = KW.copy()
  1650.         kw.update(dict(aname = self.getAttributeName(self.name), ns = self.ns, name = self.name, subclass = self.sKlass, literal = self.literalTag(), schema = self.schemaTag(), init = self.simpleConstructor(), klass = self.getClassName(), element = 'ElementDeclaration', baseinit = self.simpleConstructor(self.sKlass)))
  1651.         if self.local:
  1652.             kw['element'] = 'LocalElementDeclaration'
  1653.         
  1654.         element = (map,)((lambda i: i % kw), [
  1655.             '%(ID1)sclass %(klass)s(%(subclass)s, %(element)s):',
  1656.             '%(ID2)s%(literal)s',
  1657.             '%(ID2)s%(schema)s',
  1658.             '%(ID2)s%(init)s',
  1659.             '%(ID3)skw["pname"] = ("%(ns)s","%(name)s")',
  1660.             '%(ID3)skw["aname"] = "%(aname)s"',
  1661.             '%(ID3)s%(baseinit)s'])
  1662.         app = element.append
  1663.         pyclass = self.pyclass
  1664.         if pyclass is not None:
  1665.             if pyclass == 'bool':
  1666.                 pyclass = 'int'
  1667.             
  1668.             kw['pyclass'] = pyclass
  1669.             app('%(ID3)sclass IHolder(%(pyclass)s): typecode=self' % kw)
  1670.             app('%(ID3)sself.pyclass = IHolder' % kw)
  1671.             app('%(ID3)sIHolder.__name__ = "%(aname)s_immutable_holder"' % kw)
  1672.         
  1673.         self.writeArray(element)
  1674.  
  1675.     
  1676.     def _setup_pyclass(self):
  1677.         
  1678.         try:
  1679.             self.pyclass = BTI.get_pythontype(None, None, typeclass = self.sKlass)
  1680.         except Exception:
  1681.             ex = None
  1682.             raise Wsdl2PythonError('Error occured processing element: %s' % self._item.getItemTrace(), *ex.args)
  1683.  
  1684.  
  1685.     
  1686.     def setUp(self, tp):
  1687.         self._item = tp
  1688.         self.local = tp.isLocal()
  1689.         self.name = tp.getAttribute('name')
  1690.         self.ns = tp.getTargetNamespace()
  1691.         content = tp.content.content
  1692.         if content.isRestriction():
  1693.             
  1694.             try:
  1695.                 base = content.getTypeDefinition()
  1696.             except XMLSchema.SchemaError:
  1697.                 ex = None
  1698.                 base = None
  1699.  
  1700.             qName = content.getAttributeBase()
  1701.             if base is None:
  1702.                 self.sKlass = BTI.get_typeclass(qName[1], qName[0])
  1703.                 self._setup_pyclass()
  1704.                 return None
  1705.             raise Wsdl2PythonError, 'unsupported local simpleType restriction: %s' % tp.content.getItemTrace()
  1706.         content.isRestriction()
  1707.         if content.isList():
  1708.             
  1709.             try:
  1710.                 base = content.getTypeDefinition()
  1711.             except XMLSchema.SchemaError:
  1712.                 ex = None
  1713.                 base = None
  1714.  
  1715.             if base is None:
  1716.                 qName = content.getItemType()
  1717.                 self.sKlass = BTI.get_typeclass(qName[1], qName[0])
  1718.                 self._setup_pyclass()
  1719.                 return None
  1720.             raise Wsdl2PythonError, 'unsupported local simpleType List: %s' % tp.content.getItemTrace()
  1721.         content.isList()
  1722.         if content.isUnion():
  1723.             raise Wsdl2PythonError, 'unsupported local simpleType Union: %s' % tp.content.getItemTrace()
  1724.         content.isUnion()
  1725.         raise Wsdl2PythonError, 'unexpected schema item: %s' % tp.content.getItemTrace()
  1726.  
  1727.  
  1728.  
  1729. class ElementLocalComplexTypeContainer(TypecodeContainerBase, AttributeMixIn):
  1730.     type = DEC
  1731.     logger = _GetLogger('ElementLocalComplexTypeContainer')
  1732.     
  1733.     def _setContent(self):
  1734.         kw = KW.copy()
  1735.         
  1736.         try:
  1737.             kw.update(dict(klass = self.getClassName(), subclass = 'ZSI.TCcompound.ComplexType', element = 'ElementDeclaration', literal = self.literalTag(), schema = self.schemaTag(), init = self.simpleConstructor(), ns = self.ns, name = self.name, aname = self.getAttributeName(self.name), nsurilogic = self.nsuriLogic(), ofwhat = self.getTypecodeList(), atypecode = self.attribute_typecode, pyclass = self.getPyClass()))
  1738.         except Exception:
  1739.             ex = None
  1740.             args = [
  1741.                 'Failure processing an element w/local complexType: %s' % self._item.getItemTrace()]
  1742.             args += ex.args
  1743.             ex.args = tuple(args)
  1744.             raise 
  1745.  
  1746.         if self.local:
  1747.             kw['element'] = 'LocalElementDeclaration'
  1748.         
  1749.         element = [
  1750.             '%(ID1)sclass %(klass)s(%(subclass)s, %(element)s):',
  1751.             '%(ID2)s%(literal)s',
  1752.             '%(ID2)s%(schema)s',
  1753.             '%(ID2)s%(init)s',
  1754.             '%(ID3)s%(nsurilogic)s',
  1755.             '%(ID3)sTClist = [%(ofwhat)s]',
  1756.             '%(ID3)skw["pname"] = ("%(ns)s","%(name)s")',
  1757.             '%(ID3)skw["aname"] = "%(aname)s"',
  1758.             '%(ID3)s%(atypecode)s = {}',
  1759.             '%(ID3)sZSI.TCcompound.ComplexType.__init__(self,None,TClist,inorder=0,**kw)']
  1760.         for l in self.attrComponents:
  1761.             element.append('%(ID3)s' + str(l))
  1762.         
  1763.         element += self.getPyClassDefinition()
  1764.         element.append('%(ID3)sself.pyclass = %(pyclass)s' % kw)
  1765.         self.writeArray((map,)((lambda l: l % kw), element))
  1766.  
  1767.     
  1768.     def setUp(self, tp):
  1769.         self._item = tp
  1770.         self.name = tp.getAttribute('name')
  1771.         self.ns = tp.getTargetNamespace()
  1772.         self.local = tp.isLocal()
  1773.         complex = tp.content
  1774.         if complex is None:
  1775.             self.mgContent = ()
  1776.             return None
  1777.         if complex.content is None:
  1778.             self.mgContent = ()
  1779.             self.attrComponents = self._setAttributes(complex.getAttributeContent())
  1780.             return None
  1781.         is_simple = complex.content.isSimple()
  1782.         if is_simple and complex.content.content.isExtension():
  1783.             self.mgContent = ()
  1784.             self.attrComponents = self._setAttributes(complex.getAttributeContent())
  1785.             return None
  1786.         if is_simple and complex.content.content.isRestriction():
  1787.             self.mgContent = ()
  1788.             self.attrComponents = self._setAttributes(complex.getAttributeContent())
  1789.             return None
  1790.         if is_simple:
  1791.             raise ContainerError, 'not implemented local complexType/simpleContent: %s' % tp.getItemTrace()
  1792.         is_simple
  1793.         is_complex = complex.content.isComplex()
  1794.         if is_complex and complex.content.content is None:
  1795.             self.mgContent = ()
  1796.             self.attrComponents = self._setAttributes(complex.getAttributeContent())
  1797.             return None
  1798.         if is_complex and complex.content.content.isExtension() and complex.content.content.content is not None and complex.content.content.content.isModelGroup():
  1799.             self.mgContent = complex.content.content.content.content
  1800.             self.attrComponents = self._setAttributes(complex.content.content.getAttributeContent())
  1801.             return None
  1802.         if is_complex and complex.content.content.isRestriction() and complex.content.content.content is not None and complex.content.content.content.isModelGroup():
  1803.             self.mgContent = complex.content.content.content.content
  1804.             self.attrComponents = self._setAttributes(complex.content.content.getAttributeContent())
  1805.             return None
  1806.         if is_complex:
  1807.             self.mgContent = ()
  1808.             self.attrComponents = self._setAttributes(complex.getAttributeContent())
  1809.             return None
  1810.         if complex.content.isModelGroup():
  1811.             self.mgContent = complex.content.content
  1812.             self.attrComponents = self._setAttributes(complex.getAttributeContent())
  1813.             return None
  1814.         self.mgContent = ()
  1815.         self.attrComponents = self._setAttributes(complex.getAttributeContent())
  1816.  
  1817.  
  1818.  
  1819. class ElementGlobalDefContainer(TypecodeContainerBase):
  1820.     type = DEC
  1821.     logger = _GetLogger('ElementGlobalDefContainer')
  1822.     
  1823.     def _substitutionGroupTag(self):
  1824.         value = self.substitutionGroup
  1825.         if not value:
  1826.             return 'substitutionGroup = None'
  1827.         (nsuri, ncname) = value
  1828.         return 'substitutionGroup = ("%s","%s")' % (nsuri, ncname)
  1829.  
  1830.     
  1831.     def _setContent(self):
  1832.         kw = KW.copy()
  1833.         
  1834.         try:
  1835.             kw.update(dict(klass = self.getClassName(), element = 'ElementDeclaration', literal = self.literalTag(), substitutionGroup = self._substitutionGroupTag(), schema = self.schemaTag(), init = self.simpleConstructor(), ns = self.ns, name = self.name, aname = self.getAttributeName(self.name), baseslogic = self.getBasesLogic(ID3), alias = NAD.getAlias(self.sKlassNS), subclass = type_class_name(self.sKlass)))
  1836.         except Exception:
  1837.             ex = None
  1838.             args = [
  1839.                 'Failure processing an element w/local complexType: %s' % self._item.getItemTrace()]
  1840.             args += ex.args
  1841.             ex.args = tuple(args)
  1842.             raise 
  1843.  
  1844.         if self.local:
  1845.             kw['element'] = 'LocalElementDeclaration'
  1846.         
  1847.         element = [
  1848.             '%(ID1)sclass %(klass)s(%(element)s):',
  1849.             '%(ID2)s%(literal)s',
  1850.             '%(ID2)s%(schema)s',
  1851.             '%(ID2)s%(substitutionGroup)s',
  1852.             '%(ID2)s%(init)s',
  1853.             '%(ID3)skw["pname"] = ("%(ns)s","%(name)s")',
  1854.             '%(ID3)skw["aname"] = "%(aname)s"',
  1855.             '%(baseslogic)s',
  1856.             '%(ID3)s%(alias)s.%(subclass)s.__init__(self, **kw)',
  1857.             '%(ID3)sif self.pyclass is not None: self.pyclass.__name__ = "%(klass)s_Holder"']
  1858.         self.writeArray((map,)((lambda l: l % kw), element))
  1859.  
  1860.     
  1861.     def setUp(self, element):
  1862.         self._item = element
  1863.         self.local = element.isLocal()
  1864.         self.name = element.getAttribute('name')
  1865.         self.substitutionGroup = element.getAttribute('substitutionGroup')
  1866.         self.ns = element.getTargetNamespace()
  1867.         tp = element.getTypeDefinition('type')
  1868.         self.sKlass = tp.getAttribute('name')
  1869.         self.sKlassNS = tp.getTargetNamespace()
  1870.  
  1871.  
  1872.  
  1873. class ComplexTypeComplexContentContainer(TypecodeContainerBase, AttributeMixIn):
  1874.     type = DEF
  1875.     logger = _GetLogger('ComplexTypeComplexContentContainer')
  1876.     
  1877.     def __init__(self, do_extended = False):
  1878.         TypecodeContainerBase.__init__(self, do_extended = do_extended)
  1879.  
  1880.     
  1881.     def setUp(self, tp):
  1882.         self._item = tp
  1883.         self.extType = None
  1884.         self.restriction = False
  1885.         self.extension = False
  1886.         self._kw_array = None
  1887.         self._is_array = False
  1888.         self.name = tp.getAttribute('name')
  1889.         self.ns = tp.getTargetNamespace()
  1890.         derivation = tp.content.content
  1891.         
  1892.         try:
  1893.             base = derivation.getTypeDefinition('base')
  1894.         except XMLSchema.SchemaError:
  1895.             ex = None
  1896.             base = None
  1897.  
  1898.         if base is None:
  1899.             base = derivation.getAttributeQName('base')
  1900.             if base is None:
  1901.                 raise ContainerError, 'Unsupported derivation: %s' % derivation.getItemTrace()
  1902.             base is None
  1903.             if base != (SOAP.ENC, 'Array') and base != (SOAP.ENC12, 'Array') and base != (SCHEMA.XSD3, 'anyType'):
  1904.                 raise ContainerError, 'Unsupported base(%s): %s' % (base, derivation.getItemTrace())
  1905.             base != (SCHEMA.XSD3, 'anyType')
  1906.         
  1907.         if base in ((SOAP.ENC, 'Array'), (SOAP.ENC12, 'Array')):
  1908.             self.logger.debug('Derivation of soapenc:Array')
  1909.             self._is_array = True
  1910.             self._kw_array = {
  1911.                 'atype': None,
  1912.                 'id3': ID3,
  1913.                 'ofwhat': None }
  1914.             self.sKlass = BTI.get_typeclass(base[1], base[0])
  1915.             self.sKlassNS = base[0]
  1916.             for a in derivation.getAttributeContent():
  1917.                 if a.isReference() is False:
  1918.                     continue
  1919.                 
  1920.                 if a.getAttribute('ref') not in ((SOAP.ENC, 'arrayType'), (SOAP.ENC12, 'arrayType')):
  1921.                     continue
  1922.                 
  1923.                 attr = a.getAttributeQName((WSDL.BASE, 'arrayType'))
  1924.                 if attr is None:
  1925.                     warnings.warn('soapenc:array derivation declares attribute reference ("%s","%s"), does not define attribute ("%s","%s")' % (SOAP.ENC, 'arrayType', WSDL.BASE, 'arrayType'))
  1926.                     break
  1927.                 
  1928.                 self._kw_array['atype'] = attr
  1929.                 qname = self._kw_array.get('atype')
  1930.                 if a is not None:
  1931.                     ncname = qname[1].strip('[]')
  1932.                     namespace = qname[0]
  1933.                     
  1934.                     try:
  1935.                         ofwhat = a.getSchemaItem(XMLSchema.TYPES, namespace, ncname)
  1936.                     except XMLSchema.SchemaError:
  1937.                         ex = None
  1938.                         ofwhat = None
  1939.  
  1940.                     if ofwhat is None:
  1941.                         self._kw_array['ofwhat'] = BTI.get_typeclass(ncname, namespace)
  1942.                     else:
  1943.                         self._kw_array['ofwhat'] = GetClassNameFromSchemaItem(ofwhat, do_extended = self.do_extended)
  1944.                     if self._kw_array['ofwhat'] is None:
  1945.                         raise ContainerError, 'For Array could not resolve ofwhat typecode(%s,%s): %s' % (namespace, ncname, derivation.getItemTrace())
  1946.                     self._kw_array['ofwhat'] is None
  1947.                     self.logger.debug('Attribute soapenc:arrayType="%s"' % str(self._kw_array['ofwhat']))
  1948.                     break
  1949.                     continue
  1950.             
  1951.         elif isinstance(base, XMLSchema.XMLSchemaComponent):
  1952.             self.sKlass = base.getAttribute('name')
  1953.             self.sKlassNS = base.getTargetNamespace()
  1954.         else:
  1955.             self.sKlass = base.getName()
  1956.             self.sKlassNS = base.getTargetNamespace()
  1957.         attrs = []
  1958.         if derivation.isRestriction():
  1959.             self.restriction = True
  1960.             self.extension = False
  1961.             if not derivation.getAttributeContent():
  1962.                 pass
  1963.             attrs += ()
  1964.         else:
  1965.             self.restriction = False
  1966.             self.extension = True
  1967.             if not tp.getAttributeContent():
  1968.                 pass
  1969.             attrs += ()
  1970.             if isinstance(derivation, XMLSchema.XMLSchemaComponent):
  1971.                 if not derivation.getAttributeContent():
  1972.                     pass
  1973.                 attrs += ()
  1974.             
  1975.         if attrs:
  1976.             self.extType = derivation
  1977.         
  1978.         if derivation.content is not None and derivation.content.isModelGroup():
  1979.             group = derivation.content
  1980.             if group.isReference():
  1981.                 group = group.getModelGroupReference()
  1982.             
  1983.             self.mgContent = group.content
  1984.         elif derivation.content:
  1985.             raise Wsdl2PythonError, 'expecting model group, not: %s' % derivation.content.getItemTrace()
  1986.         else:
  1987.             self.mgContent = ()
  1988.         self.attrComponents = self._setAttributes(tuple(attrs))
  1989.  
  1990.     
  1991.     def _setContent(self):
  1992.         kw = KW.copy()
  1993.         definition = []
  1994.         if self._is_array:
  1995.             if _is_xsd_or_soap_ns(self.sKlassNS) is False and self.sKlass == 'Array':
  1996.                 raise ContainerError, 'unknown type: (%s,%s)' % (self.sKlass, self.sKlassNS)
  1997.             self.sKlass == 'Array'
  1998.             definition += [
  1999.                 '%sclass %s(ZSI.TC.Array, TypeDefinition):' % (ID1, self.getClassName()),
  2000.                 '%s#complexType/complexContent base="SOAP-ENC:Array"' % ID2,
  2001.                 '%s%s' % (ID2, self.schemaTag()),
  2002.                 '%s%s' % (ID2, self.typeTag()),
  2003.                 '%s%s' % (ID2, self.pnameConstructor())]
  2004.             append = definition.append
  2005.             if self._kw_array.get('ofwhat') is None:
  2006.                 append("%s%s.__init__(self, None, None, pname=pname, childnames='item', undeclared=True, **kw)" % (ID3, self.sKlass))
  2007.             else:
  2008.                 append('%(id3)sofwhat = %(ofwhat)s(None, typed=False)' % self._kw_array)
  2009.                 append('%(id3)satype = %(atype)s' % self._kw_array)
  2010.                 append("%s%s.__init__(self, atype, ofwhat, pname=pname, childnames='item', **kw)" % (ID3, self.sKlass))
  2011.             self.writeArray(definition)
  2012.             return None
  2013.         definition += [
  2014.             '%sclass %s(TypeDefinition):' % (ID1, self.getClassName()),
  2015.             '%s%s' % (ID2, self.schemaTag()),
  2016.             '%s%s' % (ID2, self.typeTag()),
  2017.             '%s%s' % (ID2, self.pnameConstructor()),
  2018.             '%s%s' % (ID3, self.nsuriLogic()),
  2019.             '%sTClist = [%s]' % (ID3, self.getTypecodeList())]
  2020.         definition.append('%(ID3)sattributes = %(atc)s = attributes or {}' % {
  2021.             'ID3': ID3,
  2022.             'atc': self.attribute_typecode })
  2023.         isAnyType = (self.sKlassNS, self.sKlass) == (SCHEMA.XSD3, 'anyType')
  2024.         if isAnyType:
  2025.             del definition[0]
  2026.             definition.insert(0, '%sclass %s(ZSI.TC.ComplexType, TypeDefinition):' % (ID1, self.getClassName()))
  2027.             definition.insert(1, '%s#complexType/complexContent restrict anyType' % ID2)
  2028.         
  2029.         definition.append('%sif extend: TClist += ofwhat' % ID3)
  2030.         definition.append('%sif restrict: TClist = ofwhat' % ID3)
  2031.         if len(self.attrComponents) > 0:
  2032.             definition.append('%selse:' % ID3)
  2033.             for l in self.attrComponents:
  2034.                 definition.append('%s%s' % (ID4, l))
  2035.             
  2036.         
  2037.         if isAnyType:
  2038.             definition.append('%sZSI.TC.ComplexType.__init__(self, None, TClist, pname=pname, **kw)' % ID3)
  2039.             definition += self.getPyClassDefinition()
  2040.             kw['pyclass'] = self.getPyClass()
  2041.             definition.append('%(ID3)sself.pyclass = %(pyclass)s' % kw)
  2042.             self.writeArray(definition)
  2043.             return None
  2044.         definition.append('%s' % self.getBasesLogic(ID3))
  2045.         prefix = NAD.getAlias(self.sKlassNS)
  2046.         typeClassName = type_class_name(self.sKlass)
  2047.         if self.restriction:
  2048.             definition.append('%s%s.%s.__init__(self, pname, ofwhat=TClist, restrict=True, **kw)' % (ID3, prefix, typeClassName))
  2049.             definition.insert(1, '%s#complexType/complexContent restriction' % ID2)
  2050.             self.writeArray(definition)
  2051.             return None
  2052.         if self.extension:
  2053.             definition.append('%s%s.%s.__init__(self, pname, ofwhat=TClist, extend=True, attributes=attributes, **kw)' % (ID3, prefix, typeClassName))
  2054.             definition.insert(1, '%s#complexType/complexContent extension' % ID2)
  2055.             self.writeArray(definition)
  2056.             return None
  2057.         raise Wsdl2PythonError, 'ComplexContent must be a restriction or extension'
  2058.  
  2059.     
  2060.     def pnameConstructor(self, superclass = None):
  2061.         if superclass:
  2062.             return '%s.__init__(self, pname, ofwhat=(), extend=False, restrict=False, attributes=None, **kw)' % superclass
  2063.         return 'def __init__(self, pname, ofwhat=(), extend=False, restrict=False, attributes=None, **kw):'
  2064.  
  2065.  
  2066.  
  2067. class ComplexTypeContainer(TypecodeContainerBase, AttributeMixIn):
  2068.     type = DEF
  2069.     logger = _GetLogger('ComplexTypeContainer')
  2070.     
  2071.     def setUp(self, tp, empty = False):
  2072.         self._item = tp
  2073.         self.name = tp.getAttribute('name')
  2074.         self.ns = tp.getTargetNamespace()
  2075.         self.mixed = tp.isMixed()
  2076.         self.mgContent = ()
  2077.         self.attrComponents = self._setAttributes(tp.getAttributeContent())
  2078.         self._item = tp
  2079.         if empty:
  2080.             return None
  2081.         model = tp.content
  2082.         if model.isReference():
  2083.             model = model.getModelGroupReference()
  2084.         
  2085.         if model is None:
  2086.             return None
  2087.         if model.content is None:
  2088.             return None
  2089.         self.mgContent = model
  2090.  
  2091.     
  2092.     def _setContent(self):
  2093.         
  2094.         try:
  2095.             definition = [
  2096.                 '%sclass %s(ZSI.TCcompound.ComplexType, TypeDefinition):' % (ID1, self.getClassName()),
  2097.                 '%s%s' % (ID2, self.schemaTag()),
  2098.                 '%s%s' % (ID2, self.typeTag()),
  2099.                 '%s%s' % (ID2, self.pnameConstructor()),
  2100.                 '%s%s' % (ID3, self.nsuriLogic()),
  2101.                 '%sTClist = [%s]' % (ID3, self.getTypecodeList())]
  2102.         except Exception:
  2103.             ex = None
  2104.             args = [
  2105.                 'Failure processing %s' % self._item.getItemTrace()]
  2106.             args += ex.args
  2107.             ex.args = tuple(args)
  2108.             raise 
  2109.  
  2110.         definition.append('%s%s = attributes or {}' % (ID3, self.attribute_typecode))
  2111.         definition.append('%sif extend: TClist += ofwhat' % ID3)
  2112.         definition.append('%sif restrict: TClist = ofwhat' % ID3)
  2113.         if len(self.attrComponents) > 0:
  2114.             definition.append('%selse:' % ID3)
  2115.             for l in self.attrComponents:
  2116.                 definition.append('%s%s' % (ID4, l))
  2117.             
  2118.         
  2119.         definition.append('%sZSI.TCcompound.ComplexType.__init__(self, None, TClist, pname=pname, inorder=0, %s**kw)' % (ID3, self.getExtraFlags()))
  2120.         definition += self.getPyClassDefinition()
  2121.         kw = KW.copy()
  2122.         kw['pyclass'] = self.getPyClass()
  2123.         definition.append('%(ID3)sself.pyclass = %(pyclass)s' % kw)
  2124.         self.writeArray(definition)
  2125.  
  2126.     
  2127.     def pnameConstructor(self, superclass = None):
  2128.         if superclass:
  2129.             return '%s.__init__(self, pname, ofwhat=(), attributes=None, extend=False, restrict=False, **kw)' % superclass
  2130.         return 'def __init__(self, pname, ofwhat=(), attributes=None, extend=False, restrict=False, **kw):'
  2131.  
  2132.  
  2133.  
  2134. class SimpleTypeContainer(TypecodeContainerBase):
  2135.     type = DEF
  2136.     logger = _GetLogger('SimpleTypeContainer')
  2137.     
  2138.     def __init__(self):
  2139.         TypecodeContainerBase.__init__(self)
  2140.  
  2141.     
  2142.     def setUp(self, tp):
  2143.         raise NotImplementedError, 'abstract method not implemented'
  2144.  
  2145.     
  2146.     def _setContent(self, tp):
  2147.         raise NotImplementedError, 'abstract method not implemented'
  2148.  
  2149.     
  2150.     def getPythonType(self):
  2151.         pyclass = eval(str(self.sKlass))
  2152.         if issubclass(pyclass, ZSI.TC.String):
  2153.             return 'str'
  2154.         if issubclass(pyclass, ZSI.TC.Ilong) or issubclass(pyclass, ZSI.TC.IunsignedLong):
  2155.             return 'long'
  2156.         if issubclass(pyclass, ZSI.TC.Boolean) or issubclass(pyclass, ZSI.TC.Integer):
  2157.             return 'int'
  2158.         if issubclass(pyclass, ZSI.TC.Decimal):
  2159.             return 'float'
  2160.         if issubclass(pyclass, ZSI.TC.Gregorian) or issubclass(pyclass, ZSI.TC.Duration):
  2161.             return 'tuple'
  2162.  
  2163.     
  2164.     def getPyClassDefinition(self):
  2165.         definition = []
  2166.         pt = self.getPythonType()
  2167.         if pt is not None:
  2168.             definition.append('%sclass %s(%s):' % (ID3, self.getPyClass(), pt))
  2169.             definition.append('%stypecode = self' % ID4)
  2170.         
  2171.         return definition
  2172.  
  2173.  
  2174.  
  2175. class RestrictionContainer(SimpleTypeContainer):
  2176.     logger = _GetLogger('RestrictionContainer')
  2177.     
  2178.     def setUp(self, tp):
  2179.         self._item = tp
  2180.         if tp.content is None:
  2181.             raise Wsdl2PythonError, 'empty simpleType defintion: %s' % tp.getItemTrace()
  2182.         tp.content is None
  2183.         self.name = tp.getAttribute('name')
  2184.         self.ns = tp.getTargetNamespace()
  2185.         self.sKlass = None
  2186.         base = tp.content.getAttribute('base')
  2187.         if base is not None:
  2188.             
  2189.             try:
  2190.                 item = tp.content.getTypeDefinition('base')
  2191.             except XMLSchema.SchemaError:
  2192.                 ex = None
  2193.                 item = None
  2194.  
  2195.             if item is None:
  2196.                 self.sKlass = BTI.get_typeclass(base.getName(), base.getTargetNamespace())
  2197.                 if self.sKlass is not None:
  2198.                     return None
  2199.                 raise Wsdl2PythonError('no built-in type nor schema instance type for base attribute("%s","%s"): %s' % (base.getTargetNamespace(), base.getName(), tp.getItemTrace()))
  2200.             item is None
  2201.             base = item.content.getAttribute('base')
  2202.             self.sKlass = BTI.get_typeclass(base.getName(), base.getTargetNamespace())
  2203.             if self.sKlass is not None:
  2204.                 return None
  2205.             raise Wsdl2PythonError, 'Not Supporting simpleType/Restriction w/User-Defined Base: %s %s' % (tp.getItemTrace(), item.getItemTrace())
  2206.         base is not None
  2207.         sc = tp.content.getSimpleTypeContent()
  2208.         if sc is not None:
  2209.             if sc.isSimple() is sc.isSimple() and sc.isLocal() is sc.isLocal():
  2210.                 pass
  2211.             elif sc.isLocal() is sc.isDefinition():
  2212.                 base = None
  2213.                 if sc.content.isRestriction() is True:
  2214.                     
  2215.                     try:
  2216.                         item = tp.content.getTypeDefinition('base')
  2217.                     except XMLSchema.SchemaError:
  2218.                         ex = None
  2219.  
  2220.                     if item is None:
  2221.                         base = sc.content.getAttribute('base')
  2222.                         if base is not None:
  2223.                             self.sKlass = BTI.get_typeclass(base.getTargetNamespace(), base.getName())
  2224.                             return None
  2225.                         raise Wsdl2PythonError, 'Not Supporting simpleType/Restriction w/User-Defined Base: ' % item.getItemTrace()
  2226.                     item is None
  2227.                     raise Wsdl2PythonError, 'Not Supporting simpleType/Restriction w/User-Defined Base: ' % item.getItemTrace()
  2228.                 sc.content.isRestriction() is True
  2229.                 if sc.content.isList() is True:
  2230.                     raise Wsdl2PythonError, 'iction base in subtypes: %s' % sc.getItemTrace()
  2231.                 sc.content.isList() is True
  2232.                 if sc.content.isUnion() is True:
  2233.                     raise Wsdl2PythonError, 'could not get restriction base in subtypes: %s' % sc.getItemTrace()
  2234.                 sc.content.isUnion() is True
  2235.                 return None
  2236.         raise Wsdl2PythonError, 'No Restriction @base/simpleType: %s' % tp.getItemTrace()
  2237.  
  2238.     
  2239.     def _setContent(self):
  2240.         definition = [
  2241.             '%sclass %s(%s, TypeDefinition):' % (ID1, self.getClassName(), self.sKlass),
  2242.             '%s%s' % (ID2, self.schemaTag()),
  2243.             '%s%s' % (ID2, self.typeTag()),
  2244.             '%s%s' % (ID2, self.pnameConstructor())]
  2245.         if self.getPythonType() is None:
  2246.             definition.append('%s%s.__init__(self, pname, **kw)' % (ID3, self.sKlass))
  2247.         else:
  2248.             definition.append('%s%s.__init__(self, pname, pyclass=None, **kw)' % (ID3, self.sKlass))
  2249.             definition += self.getPyClassDefinition()
  2250.             kw = KW.copy()
  2251.             kw['pyclass'] = self.getPyClass()
  2252.             definition.append('%(ID3)sself.pyclass = %(pyclass)s' % kw)
  2253.         self.writeArray(definition)
  2254.  
  2255.  
  2256.  
  2257. class ComplexTypeSimpleContentContainer(SimpleTypeContainer, AttributeMixIn):
  2258.     type = DEF
  2259.     logger = _GetLogger('ComplexTypeSimpleContentContainer')
  2260.     
  2261.     def setUp(self, tp):
  2262.         self._item = tp
  2263.         simple = tp.content
  2264.         dv = simple.content
  2265.         self.name = tp.getAttribute('name')
  2266.         self.ns = tp.getTargetNamespace()
  2267.         self.content.attributeContent = dv.getAttributeContent()
  2268.         base = dv.getAttribute('base')
  2269.         if base is not None:
  2270.             self.sKlass = BTI.get_typeclass(base[1], base[0])
  2271.             if not self.sKlass:
  2272.                 self.sKlass = base[1]
  2273.                 self.sKlassNS = base[0]
  2274.             
  2275.             self.attrComponents = self._setAttributes(self.content.attributeContent)
  2276.             return None
  2277.         raise Wsdl2PythonError, 'simple content derivation bad base attribute: ' % tp.getItemTrace()
  2278.  
  2279.     
  2280.     def _setContent(self):
  2281.         if type(self.sKlass) in (types.ClassType, type):
  2282.             definition = [
  2283.                 '%sclass %s(%s, TypeDefinition):' % (ID1, self.getClassName(), self.sKlass),
  2284.                 '%s# ComplexType/SimpleContent derivation of built-in type' % ID2,
  2285.                 '%s%s' % (ID2, self.schemaTag()),
  2286.                 '%s%s' % (ID2, self.typeTag()),
  2287.                 '%s%s' % (ID2, self.pnameConstructor()),
  2288.                 '%sif getattr(self, "attribute_typecode_dict", None) is None: %s = {}' % (ID3, self.attribute_typecode)]
  2289.             for l in self.attrComponents:
  2290.                 definition.append('%s%s' % (ID3, l))
  2291.             
  2292.             definition.append('%s%s.__init__(self, pname, **kw)' % (ID3, self.sKlass))
  2293.             if self.getPythonType() is not None:
  2294.                 definition += self.getPyClassDefinition()
  2295.                 kw = KW.copy()
  2296.                 kw['pyclass'] = self.getPyClass()
  2297.                 definition.append('%(ID3)sself.pyclass = %(pyclass)s' % kw)
  2298.             
  2299.             self.writeArray(definition)
  2300.             return None
  2301.         definition = [
  2302.             '%sclass %s(TypeDefinition):' % (ID1, self.getClassName()),
  2303.             '%s# ComplexType/SimpleContent derivation of user-defined type' % ID2,
  2304.             '%s%s' % (ID2, self.schemaTag()),
  2305.             '%s%s' % (ID2, self.typeTag()),
  2306.             '%s%s' % (ID2, self.pnameConstructor()),
  2307.             '%s%s' % (ID3, self.nsuriLogic()),
  2308.             '%s' % self.getBasesLogic(ID3),
  2309.             '%sif getattr(self, "attribute_typecode_dict", None) is None: %s = {}' % (ID3, self.attribute_typecode)]
  2310.         for l in self.attrComponents:
  2311.             definition.append('%s%s' % (ID3, l))
  2312.         
  2313.         definition.append('%s%s.%s.__init__(self, pname, **kw)' % (ID3, NAD.getAlias(self.sKlassNS), type_class_name(self.sKlass)))
  2314.         self.writeArray(definition)
  2315.  
  2316.     
  2317.     def getPyClassDefinition(self):
  2318.         definition = []
  2319.         pt = self.getPythonType()
  2320.         if pt is not None:
  2321.             definition.append('%sclass %s(%s):' % (ID3, self.getPyClass(), pt))
  2322.             if self.metaclass is not None:
  2323.                 definition.append('%s__metaclass__ = %s' % (ID4, self.metaclass))
  2324.             
  2325.             definition.append('%stypecode = self' % ID4)
  2326.         
  2327.         return definition
  2328.  
  2329.  
  2330.  
  2331. class UnionContainer(SimpleTypeContainer):
  2332.     type = DEF
  2333.     logger = _GetLogger('UnionContainer')
  2334.     
  2335.     def __init__(self):
  2336.         SimpleTypeContainer.__init__(self)
  2337.         self.memberTypes = None
  2338.  
  2339.     
  2340.     def setUp(self, tp):
  2341.         self._item = tp
  2342.         if tp.content.isUnion() is False:
  2343.             raise ContainerError, 'content must be a Union: %s' % tp.getItemTrace()
  2344.         tp.content.isUnion() is False
  2345.         self.name = tp.getAttribute('name')
  2346.         self.ns = tp.getTargetNamespace()
  2347.         self.sKlass = 'ZSI.TC.Union'
  2348.         self.memberTypes = tp.content.getAttribute('memberTypes')
  2349.  
  2350.     
  2351.     def _setContent(self):
  2352.         definition = [
  2353.             '%sclass %s(%s, TypeDefinition):' % (ID1, self.getClassName(), self.sKlass),
  2354.             '%smemberTypes = %s' % (ID2, self.memberTypes),
  2355.             '%s%s' % (ID2, self.schemaTag()),
  2356.             '%s%s' % (ID2, self.typeTag()),
  2357.             '%s%s' % (ID2, self.pnameConstructor()),
  2358.             '%s%s' % (ID3, self.pnameConstructor(self.sKlass))]
  2359.         self.writeArray(definition)
  2360.  
  2361.  
  2362.  
  2363. class ListContainer(SimpleTypeContainer):
  2364.     type = DEF
  2365.     logger = _GetLogger('ListContainer')
  2366.     
  2367.     def setUp(self, tp):
  2368.         self._item = tp
  2369.         if tp.content.isList() is False:
  2370.             raise ContainerError, 'content must be a List: %s' % tp.getItemTrace()
  2371.         tp.content.isList() is False
  2372.         self.name = tp.getAttribute('name')
  2373.         self.ns = tp.getTargetNamespace()
  2374.         self.sKlass = 'ZSI.TC.List'
  2375.         self.itemType = tp.content.getAttribute('itemType')
  2376.  
  2377.     
  2378.     def _setContent(self):
  2379.         definition = [
  2380.             '%sclass %s(%s, TypeDefinition):' % (ID1, self.getClassName(), self.sKlass),
  2381.             '%sitemType = %s' % (ID2, self.itemType),
  2382.             '%s%s' % (ID2, self.schemaTag()),
  2383.             '%s%s' % (ID2, self.typeTag()),
  2384.             '%s%s' % (ID2, self.pnameConstructor()),
  2385.             '%s%s' % (ID3, self.pnameConstructor(self.sKlass))]
  2386.         self.writeArray(definition)
  2387.  
  2388.  
  2389.