home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2012 January / maximum-cd-2012-01.iso / DiscContents / digsby_setup.exe / lib / ZSI / generate / utility.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-10-05  |  5.9 KB  |  165 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import re
  5. from ZSI import EvaluateException
  6. from ZSI.TCcompound import Struct
  7. from ZSI.generate import WsdlGeneratorError, Wsdl2PythonError
  8. from ZSI.wstools.Utility import SplitQName
  9. from ZSI.wstools.Namespaces import SCHEMA
  10.  
  11. NCName_to_ModuleName = lambda name: re.sub('\\.', '_', TextProtect(name))
  12.  
  13. NCName_to_ClassName = lambda name: re.sub('\\.', '_', TextProtect(name))
  14.  
  15. TextProtect = lambda s: re.sub('[-./:# ]', '_', s)
  16.  
  17. TextProtectAttributeName = lambda name: TextProtect('_%s' % name)
  18.  
  19. Namespace2ModuleName = lambda ns: TextProtect(ns.lstrip('http://').rstrip('.xsd').replace('_ws_', '')).rstrip('_')
  20.  
  21. def GetModuleBaseNameFromWSDL(wsdl):
  22.     if not wsdl.name:
  23.         pass
  24.     base_name = wsdl.services[0].name
  25.     base_name = SplitQName(base_name)[1]
  26.     if base_name is None:
  27.         return None
  28.     return NCName_to_ModuleName(base_name)
  29.  
  30.  
  31. def namespace_name(cls, ns, recommended):
  32.     if recommended is None:
  33.         return 'ns%s' % len(cls.alias_list)
  34.     i = 1
  35.     alias = recommended
  36.     while alias in cls.alias_list:
  37.         alias = recommended + str(i)
  38.         continue
  39.         recommended is None
  40.     return alias
  41.  
  42.  
  43. class NamespaceAliasDict:
  44.     alias_dict = { }
  45.     alias_list = []
  46.     
  47.     def add(cls, ns, recommended = None):
  48.         if cls.alias_dict.has_key(ns):
  49.             return None
  50.         cls.alias_dict[ns] = (Namespace2ModuleName(ns), '%s' % namespace_name(cls, ns, recommended))
  51.         cls.alias_list.append(ns)
  52.  
  53.     add = classmethod(add)
  54.     
  55.     def getModuleName(cls, ns):
  56.         if cls.alias_dict.has_key(ns):
  57.             return cls.alias_dict[ns][0]
  58.         msg = 'failed to find import for schema "%s"' % ns + 'possibly missing @schemaLocation attribute.'
  59.         if ns in SCHEMA.XSD_LIST:
  60.             msg = 'missing built-in typecode for schema "%s"' % ns
  61.         
  62.         raise WsdlGeneratorError, msg
  63.  
  64.     getModuleName = classmethod(getModuleName)
  65.     
  66.     def getAlias(cls, ns):
  67.         if cls.alias_dict.has_key(ns):
  68.             return cls.alias_dict[ns][1]
  69.         msg = 'failed to find import for schema "%s"' % ns + 'possibly missing @schemaLocation attribute.'
  70.         if ns in SCHEMA.XSD_LIST:
  71.             msg = 'missing built-in typecode for schema "%s"' % ns
  72.         
  73.         raise WsdlGeneratorError, msg
  74.  
  75.     getAlias = classmethod(getAlias)
  76.     
  77.     def getNSList(cls):
  78.         return tuple(cls.alias_list)
  79.  
  80.     getNSList = classmethod(getNSList)
  81.  
  82.  
  83. class StringWriter:
  84.     
  85.     def __init__(self, val = None):
  86.         self.data = []
  87.         if val:
  88.             self.data.append(val)
  89.         
  90.  
  91.     
  92.     def set(self, val):
  93.         if self.data:
  94.             self.data = None
  95.             self.data = []
  96.         
  97.         self.data.append(val)
  98.  
  99.     
  100.     def write(self, val):
  101.         self.data.append(val)
  102.  
  103.     
  104.     def getvalue(self):
  105.         if self.data:
  106.             return ''.join(self.data)
  107.         return ''
  108.  
  109.     
  110.     def __iadd__(self, val):
  111.         self.data.append(val)
  112.         return self
  113.  
  114.     
  115.     def __str__(self):
  116.         return self.getvalue()
  117.  
  118.  
  119.  
  120. class MessageContainer:
  121.     pass
  122.  
  123.  
  124. def GetPartsSubNames(args, wsdl):
  125.     do_extended = True
  126.     WriteServiceModule = WriteServiceModule
  127.     SchemaDescription = SchemaDescription
  128.     import wsdl2python
  129.     wsm = WriteServiceModule(wsdl, do_extended = do_extended)
  130.     wsm.gatherNamespaces()
  131.     toReturn = []
  132.     for arg in args:
  133.         argSubnames = []
  134.         for l in wsm.usedNamespaces.values():
  135.             for schema in l:
  136.                 sd = SchemaDescription(do_extended = do_extended)
  137.                 sd.fromSchema(schema)
  138.                 argNamespace = arg.element[0]
  139.                 if sd.targetNamespace == argNamespace:
  140.                     for i in sd.items:
  141.                         argElementType = arg.element[1]
  142.                         if str(argElementType) == str(i.content.name):
  143.                             argSubnames = []
  144.                             if i.content.mgContent != None:
  145.                                 for c in i.content.mgContent:
  146.                                     nValue = 'None'
  147.                                     if c.isWildCard():
  148.                                         nValue = 'any'
  149.                                     elif c.attributes.has_key('name'):
  150.                                         nValue = c.attributes['name']
  151.                                     elif c.attributes.has_key('ref'):
  152.                                         nValue = c.attributes['ref'][1]
  153.                                     
  154.                                     argSubnames.append(nValue)
  155.                                 
  156.                             
  157.                         i.content.mgContent != None
  158.                     
  159.             
  160.         
  161.         toReturn.append(argSubnames)
  162.     
  163.     return toReturn
  164.  
  165.