• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

contrib/opal/ZSI/build/lib/ZSI/__init__.py

00001 #! /usr/bin/env python
00002 # $Header$
00003 '''ZSI:  Zolera Soap Infrastructure.
00004 
00005 Copyright 2001, Zolera Systems, Inc.  All Rights Reserved.
00006 '''
00007 
00008 _copyright = """ZSI:  Zolera Soap Infrastructure.
00009 
00010 Copyright 2001, Zolera Systems, Inc.  All Rights Reserved.
00011 Copyright 2002-2003, Rich Salz. All Rights Reserved.
00012 
00013 Permission is hereby granted, free of charge, to any person obtaining a
00014 copy of this software and associated documentation files (the "Software"),
00015 to deal in the Software without restriction, including without limitation
00016 the rights to use, copy, modify, merge, publish, distribute, and/or
00017 sell copies of the Software, and to permit persons to whom the Software
00018 is furnished to do so, provided that the above copyright notice(s) and
00019 this permission notice appear in all copies of the Software and that
00020 both the above copyright notice(s) and this permission notice appear in
00021 supporting documentation.
00022 
00023 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00024 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00025 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
00026 OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
00027 INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
00028 OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
00029 OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00030 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
00031 OR PERFORMANCE OF THIS SOFTWARE.
00032 
00033 Except as contained in this notice, the name of a copyright holder
00034 shall not be used in advertising or otherwise to promote the sale, use
00035 or other dealings in this Software without prior written authorization
00036 of the copyright holder.
00037 
00038 
00039 Portions are also:
00040 
00041 Copyright (c) 2003, The Regents of the University of California,
00042 through Lawrence Berkeley National Laboratory (subject to receipt of
00043 any required approvals from the U.S. Dept. of Energy). All rights
00044 reserved. Redistribution and use in source and binary forms, with or
00045 without modification, are permitted provided that the following
00046 conditions are met:
00047 
00048 (1) Redistributions of source code must retain the above copyright
00049 notice, this list of conditions and the following disclaimer.
00050 (2) Redistributions in binary form must reproduce the above copyright
00051 notice, this list of conditions and the following disclaimer in the
00052 documentation and/or other materials provided with the distribution.
00053 (3) Neither the name of the University of California, Lawrence Berkeley
00054 National Laboratory, U.S. Dept. of Energy nor the names of its contributors
00055 may be used to endorse or promote products derived from this software without
00056 specific prior written permission.
00057 
00058 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00059 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
00060 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00061 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
00062 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00063 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00064 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00065 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00066 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00067 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00068 SUCH DAMAGE.
00069 
00070 You are under no obligation whatsoever to provide any bug fixes,
00071 patches, or upgrades to the features, functionality or performance of
00072 the source code ("Enhancements") to anyone; however, if you choose to
00073 make your Enhancements available either publicly, or directly to
00074 Lawrence Berkeley National Laboratory, without imposing a separate
00075 written license agreement for such Enhancements, then you hereby grant
00076 the following license: a non-exclusive, royalty-free perpetual license
00077 to install, use, modify, prepare derivative works, incorporate into
00078 other computer software, distribute, and sublicense such Enhancements
00079 or derivative works thereof, in binary and source code form.
00080 
00081 
00082 For wstools also:
00083 
00084 Zope Public License (ZPL) Version 2.0
00085 -----------------------------------------------
00086 
00087 This software is Copyright (c) Zope Corporation (tm) and
00088 Contributors. All rights reserved.
00089 
00090 This license has been certified as open source. It has also
00091 been designated as GPL compatible by the Free Software
00092 Foundation (FSF).
00093 
00094 Redistribution and use in source and binary forms, with or
00095 without modification, are permitted provided that the
00096 following conditions are met:
00097 
00098 1. Redistributions in source code must retain the above
00099    copyright notice, this list of conditions, and the following
00100    disclaimer.
00101 
00102 2. Redistributions in binary form must reproduce the above
00103    copyright notice, this list of conditions, and the following
00104    disclaimer in the documentation and/or other materials
00105    provided with the distribution.
00106 
00107 3. The name Zope Corporation (tm) must not be used to
00108    endorse or promote products derived from this software
00109    without prior written permission from Zope Corporation.
00110 
00111 4. The right to distribute this software or to use it for
00112    any purpose does not give you the right to use Servicemarks
00113    (sm) or Trademarks (tm) of Zope Corporation. Use of them is
00114    covered in a separate agreement (see
00115    http://www.zope.com/Marks).
00116 
00117 5. If any files are modified, you must cause the modified
00118    files to carry prominent notices stating that you changed
00119    the files and the date of any change.
00120 
00121 Disclaimer
00122 
00123   THIS SOFTWARE IS PROVIDED BY ZOPE CORPORATION ``AS IS''
00124   AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
00125   NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
00126   AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
00127   NO EVENT SHALL ZOPE CORPORATION OR ITS CONTRIBUTORS BE
00128   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00129   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00130   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00131   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00132   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00133   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
00134   OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00135   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00136   DAMAGE.
00137 
00138 
00139 This software consists of contributions made by Zope
00140 Corporation and many individuals on behalf of Zope
00141 Corporation.  Specific attributions are listed in the
00142 accompanying credits file.
00143 """
00144 
00145 ##
00146 ##  Stuff imported from elsewhere.
00147 from xml.dom import Node as _Node
00148 import types as _types
00149 
00150 ##
00151 ##  Public constants.
00152 from ZSI.wstools.Namespaces import ZSI_SCHEMA_URI
00153 UNICODE_ENCODING = 'utf-8'
00154 
00155 ##
00156 ##  Not public constants.
00157 _inttypes = [ _types.IntType, _types.LongType ]
00158 _floattypes = [ _types.FloatType ]
00159 _seqtypes = [ _types.TupleType, _types.ListType ]
00160 _stringtypes = [ _types.StringType, _types.UnicodeType ]
00161 
00162 ##
00163 ##  Low-level DOM oriented utilities; useful for typecode implementors.
00164 _attrs = lambda E: (E.attributes and E.attributes.values()) or []
00165 _children = lambda E: E.childNodes or []
00166 _child_elements = lambda E: [ n for n in (E.childNodes or [])
00167                         if n.nodeType == _Node.ELEMENT_NODE ]
00168 
00169 ##
00170 ##  Stuff imported from elsewhere.
00171 from ZSI.wstools.Namespaces import SOAP as _SOAP, SCHEMA as _SCHEMA, XMLNS as _XMLNS
00172 
00173 ##
00174 ##  Low-level DOM oriented utilities; useful for typecode implementors.
00175 _find_arraytype = lambda E: E.getAttributeNS(_SOAP.ENC, "arrayType")
00176 _find_encstyle = lambda E: E.getAttributeNS(_SOAP.ENV, "encodingStyle")
00177 try:
00178     from xml.dom import EMPTY_NAMESPACE
00179     _empty_nsuri_list = [ EMPTY_NAMESPACE ]
00180     #if '' not in _empty_nsuri_list: __empty_nsuri_list.append('')
00181     #if None not in _empty_nsuri_list: __empty_nsuri_list.append(None)
00182 except:
00183     _empty_nsuri_list = [ None, '' ]
00184 def _find_attr(E, attr):
00185     for nsuri in _empty_nsuri_list:
00186         try:
00187             v = E.getAttributeNS(nsuri, attr)
00188             if v: return v
00189         except: pass
00190     return None
00191 
00192 def _find_attrNS(E, namespaceURI, localName):
00193     '''namespaceURI
00194        localName
00195     '''
00196     try:
00197         v = E.getAttributeNS(namespaceURI, localName)
00198         if v: return v
00199     except: pass
00200     return None
00201 
00202 
00203 def _find_attrNodeNS(E, namespaceURI, localName):
00204     '''Must grab the attribute Node to distinquish between
00205     an unspecified attribute(None) and one set to empty string("").
00206        namespaceURI
00207        localName
00208     '''
00209     attr = E.getAttributeNodeNS(namespaceURI, localName)
00210     if attr is None: return None
00211     try:
00212         return attr.value
00213     except: pass
00214     return E.getAttributeNS(namespaceURI, localName)
00215 
00216 
00217 
00218 
00219 _find_href = lambda E: _find_attr(E, "href")
00220 _find_xsi_attr = lambda E, attr: \
00221                 E.getAttributeNS(_SCHEMA.XSI3, attr) \
00222                 or E.getAttributeNS(_SCHEMA.XSI1, attr) \
00223                 or E.getAttributeNS(_SCHEMA.XSI2, attr)
00224 _find_type = lambda E: _find_xsi_attr(E, "type")
00225 
00226 _find_xmlns_prefix = lambda E, attr: E.getAttributeNS(_XMLNS.BASE, attr)
00227 _find_default_namespace = lambda E: E.getAttributeNS(_XMLNS.BASE, None)
00228 
00229 #_textprotect = lambda s: s.replace('&', '&amp;').replace('<', '&lt;')
00230 
00231 _get_element_nsuri_name = lambda E: (E.namespaceURI, E.localName)
00232 
00233 _is_element = lambda E: E.nodeType == _Node.ELEMENT_NODE
00234 
00235 def _resolve_prefix(celt, prefix):
00236     '''resolve prefix to a namespaceURI.  If None or 
00237     empty str, return default namespace or None.
00238 
00239     Parameters:
00240       celt -- element node
00241       prefix -- xmlns:prefix, or empty str or None
00242     '''
00243     namespace = None
00244     while _is_element(celt):
00245         if prefix:
00246             namespaceURI = _find_xmlns_prefix(celt, prefix)
00247         else:
00248             namespaceURI = _find_default_namespace(celt)
00249         if namespaceURI: break
00250         celt = celt.parentNode
00251     else:
00252         if prefix:  
00253             raise EvaluateException, 'cant resolve xmlns:%s' %prefix
00254     return namespaceURI
00255 
00256 def _valid_encoding(elt):
00257     '''Does this node have a valid encoding?
00258     '''
00259     enc = _find_encstyle(elt)
00260     if not enc or enc == _SOAP.ENC: return 1
00261     for e in enc.split():
00262         if e.startswith(_SOAP.ENC):
00263             # XXX Is this correct?  Once we find a Sec5 compatible
00264             # XXX encoding, should we check that all the rest are from
00265             # XXX that same base?  Perhaps.  But since the if test above
00266             # XXX will surely get 99% of the cases, leave it for now.
00267             return 1
00268     return 0
00269 
00270 def _backtrace(elt, dom):
00271     '''Return a "backtrace" from the given element to the DOM root,
00272     in XPath syntax.
00273     '''
00274     s = ''
00275     while elt != dom:
00276         name, parent = elt.nodeName, elt.parentNode
00277         if parent is None: break
00278         matches = [ c for c in _child_elements(parent) 
00279                         if c.nodeName == name ]
00280         if len(matches) == 1:
00281             s = '/' + name + s
00282         else:
00283             i = matches.index(elt) + 1
00284             s = ('/%s[%d]' % (name, i)) + s
00285         elt = parent
00286     return s
00287 
00288 def _get_idstr(pyobj):
00289     '''Python 2.3.x generates a FutureWarning for negative IDs, so
00290     we use a different prefix character to ensure uniqueness, and
00291     call abs() to avoid the warning.'''
00292     x = id(pyobj)
00293     if x < 0:
00294         return 'x%x' % abs(x)
00295     return 'o%x' % x
00296 
00297 
00298 def _get_postvalue_from_absoluteURI(url):
00299     """Bug [ 1513000 ] POST Request-URI not limited to "abs_path"
00300     Request-URI = "*" | absoluteURI | abs_path | authority
00301     
00302     Not a complete solution, but it seems to work with all known
00303     implementations.  ValueError thrown if bad uri.
00304     """
00305     cache = _get_postvalue_from_absoluteURI.cache
00306     path = cache.get(url, '')
00307     if not path:
00308         scheme,authpath = url.split('://')
00309         s = authpath.split('/', 1)
00310         if len(s) == 2: path = '/%s' %s[1]
00311         if len(cache) > _get_postvalue_from_absoluteURI.MAXLEN:cache.clear()
00312         cache[url] = path
00313     return path
00314 _get_postvalue_from_absoluteURI.cache = {}
00315 _get_postvalue_from_absoluteURI.MAXLEN = 20
00316 
00317 
00318 ##
00319 ##  Exception classes.
00320 class ZSIException(Exception):
00321     '''Base class for all ZSI exceptions.
00322     '''
00323     pass
00324 
00325 class ParseException(ZSIException):
00326     '''Exception raised during parsing.
00327     '''
00328 
00329     def __init__(self, str, inheader, elt=None, dom=None):
00330         Exception.__init__(self)
00331         self.str, self.inheader, self.trace = str, inheader, None
00332         if elt and dom:
00333             self.trace = _backtrace(elt, dom)
00334 
00335     def __str__(self):
00336         if self.trace:
00337             return self.str + '\n[Element trace: ' + self.trace + ']'
00338         return self.str
00339 
00340     def __repr__(self):
00341         return "<%s.ParseException %s>" % (__name__, _get_idstr(self))
00342 
00343 
00344 class EvaluateException(ZSIException):
00345     '''Exception raised during data evaluation (serialization).
00346     '''
00347 
00348     def __init__(self, str, trace=None):
00349         Exception.__init__(self)
00350         self.str, self.trace = str, trace
00351 
00352     def __str__(self):
00353         if self.trace:
00354             return self.str + '\n[Element trace: ' + self.trace + ']'
00355         return self.str
00356 
00357     def __repr__(self):
00358         return "<%s.EvaluateException %s>" % (__name__, _get_idstr(self))
00359 
00360 class FaultException(ZSIException):
00361     '''Exception raised when a fault is received.
00362     '''
00363 
00364     def __init__(self, fault):
00365         self.fault = fault
00366 
00367     def __str__(self):
00368         return str(self.fault)
00369 
00370     def __repr__(self):
00371         return "<%s.FaultException %s>" % (__name__, _get_idstr(self))
00372 
00373 class WSActionException(ZSIException):
00374     '''Exception raised when WS-Address Action Header is incorrectly
00375     specified when received by client or server.
00376     '''
00377     pass
00378 
00379 ##
00380 ##  Importing the rest of ZSI.
00381 import version
00382 def Version():
00383     return version.Version
00384 
00385 from writer import SoapWriter
00386 from parse import ParsedSoap
00387 from fault import Fault, \
00388     FaultFromActor, FaultFromException, FaultFromFaultMessage, \
00389     FaultFromNotUnderstood, FaultFromZSIException
00390 import TC
00391 TC.RegisterType(TC.String, minOccurs=0, nillable=False)
00392 TC.RegisterType(TC.URI, minOccurs=0, nillable=False)
00393 TC.RegisterType(TC.Base64String, minOccurs=0, nillable=False)
00394 TC.RegisterType(TC.HexBinaryString, minOccurs=0, nillable=False)
00395 
00396 #TC.RegisterType(TC.Integer)
00397 #TC.RegisterType(TC.Decimal)
00398 for pyclass in (TC.IunsignedByte, TC.IunsignedShort, TC.IunsignedInt, TC.IunsignedLong,
00399     TC.Ibyte, TC.Ishort, TC.Iint, TC.Ilong, TC.InegativeInteger,
00400     TC.InonPositiveInteger, TC.InonNegativeInteger, TC.IpositiveInteger,
00401     TC.Iinteger, TC.FPfloat, TC.FPdouble, ):
00402 
00403     TC.RegisterType(pyclass, minOccurs=0, nillable=False)
00404 
00405 TC.RegisterType(TC.Boolean, minOccurs=0, nillable=False)
00406 TC.RegisterType(TC.Duration, minOccurs=0, nillable=False)
00407 TC.RegisterType(TC.gDateTime, minOccurs=0, nillable=False)
00408 TC.RegisterType(TC.gDate, minOccurs=0, nillable=False)
00409 TC.RegisterType(TC.gYearMonth, minOccurs=0, nillable=False)
00410 TC.RegisterType(TC.gYear, minOccurs=0, nillable=False)
00411 TC.RegisterType(TC.gMonthDay, minOccurs=0, nillable=False)
00412 TC.RegisterType(TC.gDay, minOccurs=0, nillable=False)
00413 TC.RegisterType(TC.gTime, minOccurs=0, nillable=False)
00414 TC.RegisterType(TC.Apache.Map, minOccurs=0, nillable=False)
00415 
00416 ##
00417 ## Register Wrappers for builtin types.
00418 ## TC.AnyElement wraps builtins so element name information can be saved
00419 ##
00420 import schema
00421 for i in [int,float,str,tuple,list,unicode]:
00422     schema._GetPyobjWrapper.RegisterBuiltin(i)
00423 
00424 ## Load up Wrappers for builtin types
00425 schema.RegisterAnyElement()
00426 
00427 
00428 #try:
00429 #    from ServiceProxy import *
00430 #except:
00431 #    pass
00432 
00433 if __name__ == '__main__': print _copyright

Generated on Wed Oct 20 2010 11:12:15 for APBS by  doxygen 1.7.2