1   
  2   
  3   
  4   
  5   
  6   
  7   
  8   
  9   
 10   
 11   
 12   
 13   
 14   
 15   
 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   
 36   
 37  encoder = Encoder() 
 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   
 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): 
  70       
 71      @classmethod 
 74       
 75      @classmethod 
 77          try: 
 78              return cls.w3(ns) and ns[1].endswith('XMLSchema') 
 79          except: 
 80              pass 
 81          return False 
  82       
 83      @classmethod 
 85          try: 
 86              return cls.w3(ns) and ns[1].endswith('XMLSchema-instance') 
 87          except: 
 88              pass 
 89          return False 
  90       
 91      @classmethod 
 93          return ( cls.xsd(ns) or cls.xsi(ns) ) 
  94   
 95      @classmethod 
 97          try: 
 98              return ns[1].startswith('http://www.w3.org') 
 99          except: 
100              pass 
101          return False 
 102       
103      @classmethod 
105          try: 
106              return isinstance(ns, tuple) and len(ns) == len(cls.default) 
107          except: 
108              pass 
109          return False 
  110