Package suds :: Package xsd
[hide private]
[frames] | no frames]

Source Code for Package suds.xsd

 1  # This program is free software; you can redistribute it and/or modify 
 2  # it under the terms of the (LGPL) GNU Lesser General Public License as 
 3  # published by the Free Software Foundation; either version 3 of the  
 4  # License, or (at your option) any later version. 
 5  # 
 6  # This program is distributed in the hope that it will be useful, 
 7  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 8  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 9  # GNU Library Lesser General Public License for more details at 
10  # ( http://www.gnu.org/licenses/lgpl.html ). 
11  # 
12  # You should have received a copy of the GNU Lesser General Public License 
13  # along with this program; if not, write to the Free Software 
14  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
15  # written by: Jeff Ortel ( jortel@redhat.com ) 
16   
17  """ 
18  The I{schema} module provides a intelligent representation of 
19  an XSD schema.  The I{raw} model is the XML tree and the I{model} 
20  is the denormalized, objectified and intelligent view of the schema. 
21  Most of the I{value-add} provided by the model is centered around 
22  tranparent referenced type resolution and targeted denormalization. 
23  """ 
24   
25  from logging import getLogger 
26  from suds import * 
27  from suds.sax import Namespace, splitPrefix 
28   
29  log = getLogger(__name__) 
30   
31   
32 -def qualify(ref, resolvers, defns=Namespace.default):
33 """ 34 Get a reference that is I{qualified} by namespace. 35 @param ref: A referenced schema type name. 36 @type ref: str 37 @param resolvers: A list of objects to be used to resolve types. 38 @type resolvers: [L{sax.element.Element},] 39 @param defns: An optional target namespace used to qualify references 40 when no prefix is specified. 41 @type defns: A default namespace I{tuple: (prefix,uri)} used when ref not prefixed. 42 @return: A qualified reference. 43 @rtype: (name, namespace-uri) 44 """ 45 ns = None 46 p, n = splitPrefix(ref) 47 if p is not None: 48 if not isinstance(resolvers, (list, tuple)): 49 resolvers = (resolvers,) 50 for r in resolvers: 51 resolved = r.resolvePrefix(p) 52 if resolved[1] is not None: 53 ns = resolved 54 break 55 if ns is None: 56 raise Exception('prefix (%s) not resolved' % p) 57 else: 58 ns = defns 59 return (n, ns[1])
60
61 -def isqref(object):
62 """ 63 Get whether the object is a I{qualified reference}. 64 @param object: An object to be tested. 65 @type object: I{any} 66 @rtype: boolean 67 @see: L{qualify} 68 """ 69 return (\ 70 isinstance(object, tuple) and \ 71 len(object) == 2 and \ 72 isinstance(object[0], basestring) and \ 73 isinstance(object[1], basestring))
74 75
76 -class Filter:
77 - def __init__(self, inclusive=False, *items):
78 self.inclusive = inclusive 79 self.items = items
80 - def __contains__(self, x):
81 if self.inclusive: 82 result = ( x in self.items ) 83 else: 84 result = ( x not in self.items ) 85 return result
86