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

Source Code for Package suds.sax

  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 sax module contains a collection of classes that provide a 
 19  (D)ocument (O)bject (M)odel representation of an XML document. 
 20  The goal is to provide an easy, intuative interface for managing XML 
 21  documents.  Although, the term, DOM, is used above, this model is 
 22  B{far} better. 
 23   
 24  XML namespaces in suds are represented using a (2) element tuple 
 25  containing the prefix and the URI.  Eg: I{('tns', 'http://myns')} 
 26   
 27  @var encoder: A I{pluggable} XML special character processor used to 
 28      encode/decode strings. 
 29  @type encoder: L{Encoder} 
 30  """ 
 31   
 32  from suds.sax.enc import Encoder 
 33   
 34  # 
 35  # pluggable XML special character encoder. 
 36  # 
 37  encoder = Encoder() 
38 39 40 -def splitPrefix(name):
41 """ 42 Split the name into a tuple (I{prefix}, I{name}). The first element in 43 the tuple is I{None} when the name does't have a prefix. 44 @param name: A node name containing an optional prefix. 45 @type name: basestring 46 @return: A tuple containing the (2) parts of I{name} 47 @rtype: (I{prefix}, I{name}) 48 """ 49 if isinstance(name, basestring) \ 50 and ':' in name: 51 return tuple(name.split(':', 1)) 52 else: 53 return (None, name)
54
55 56 -class Namespace:
57 """ 58 The namespace class represents XML namespaces. 59 """ 60 61 default = (None, None) 62 xmlns = ('xml', 'http://www.w3.org/XML/1998/namespace') 63 xsdns = ('xs', 'http://www.w3.org/2001/XMLSchema') 64 xsins = ('xsi', 'http://www.w3.org/2001/XMLSchema-instance') 65 all = (xsdns, xsins) 66 67 @classmethod
68 - def create(cls, p=None, u=None):
69 return (p, u)
70 71 @classmethod
72 - def none(cls, ns):
73 return ( ns == cls.default )
74 75 @classmethod
76 - def xsd(cls, ns):
77 try: 78 return cls.w3(ns) and ns[1].endswith('XMLSchema') 79 except: 80 pass 81 return False
82 83 @classmethod
84 - def xsi(cls, ns):
85 try: 86 return cls.w3(ns) and ns[1].endswith('XMLSchema-instance') 87 except: 88 pass 89 return False
90 91 @classmethod
92 - def xs(cls, ns):
93 return ( cls.xsd(ns) or cls.xsi(ns) )
94 95 @classmethod
96 - def w3(cls, ns):
97 try: 98 return ns[1].startswith('http://www.w3.org') 99 except: 100 pass 101 return False
102 103 @classmethod
104 - def isns(cls, ns):
105 try: 106 return isinstance(ns, tuple) and len(ns) == len(cls.default) 107 except: 108 pass 109 return False
110