Package suds :: Package umx :: Module attrlist
[hide private]
[frames] | no frames]

Source Code for Module suds.umx.attrlist

 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  Provides filtered attribute list classes. 
19  """ 
20   
21  from suds import * 
22  from suds.umx import * 
23  from suds.sax import Namespace 
24   
25   
26 -class AttrList:
27 """ 28 A filtered attribute list. 29 Items are included during iteration if they are in either the (xs) or 30 (xml) namespaces. 31 @ivar raw: The I{raw} attribute list. 32 @type raw: list 33 """
34 - def __init__(self, attributes):
35 """ 36 @param attributes: A list of attributes 37 @type attributes: list 38 """ 39 self.raw = attributes
40
41 - def real(self):
42 """ 43 Get list of I{real} attributes which exclude xs and xml attributes. 44 @return: A list of I{real} attributes. 45 @rtype: I{generator} 46 """ 47 for a in self.raw: 48 if self.skip(a): continue 49 yield a
50
51 - def rlen(self):
52 """ 53 Get the number of I{real} attributes which exclude xs and xml attributes. 54 @return: A count of I{real} attributes. 55 @rtype: L{int} 56 """ 57 n = 0 58 for a in self.real(): 59 n += 1 60 return n
61
62 - def lang(self):
63 """ 64 Get list of I{filtered} attributes which exclude xs. 65 @return: A list of I{filtered} attributes. 66 @rtype: I{generator} 67 """ 68 for a in self.raw: 69 if a.qname() == 'xml:lang': 70 return a.value 71 return None
72
73 - def skip(self, attr):
74 """ 75 Get whether to skip (filter-out) the specified attribute. 76 @param attr: An attribute. 77 @type attr: I{Attribute} 78 @return: True if should be skipped. 79 @rtype: bool 80 """ 81 ns = attr.namespace() 82 skip = ( 83 Namespace.xmlns[1], 84 'http://schemas.xmlsoap.org/soap/encoding/', 85 'http://schemas.xmlsoap.org/soap/envelope/', 86 'http://www.w3.org/2003/05/soap-envelope', 87 ) 88 return ( Namespace.xs(ns) or ns[1] in skip )
89