33#
44# Generated Mon May 2 14:23:33 2011 by parse_xsd.py version 0.4.
55#
6+ import base64
7+
68from saml2 .validate import valid_ipv4 , MustValueError
79from saml2 .validate import valid_ipv6
810from saml2 .validate import ShouldValueError
8183SCM_SENDER_VOUCHES = "urn:oasis:names:tc:SAML:2.0:cm:sender-vouches"
8284SCM_BEARER = "urn:oasis:names:tc:SAML:2.0:cm:bearer"
8385
84- # -----------------------------------------------------------------------------
8586XSD = "xs:"
8687NS_SOAP_ENC = "http://schemas.xmlsoap.org/soap/encoding/"
8788
88- # -----------------------------------------------------------------------------
89+
90+ _b64_decode_fn = getattr (base64 , 'decodebytes' , base64 .decodestring )
91+ _b64_encode_fn = getattr (base64 , 'encodebytes' , base64 .encodestring )
8992
9093
9194def _decode_attribute_value (typ , text ):
@@ -96,11 +99,9 @@ def _decode_attribute_value(typ, text):
9699 if typ == XSD + "float" or typ == XSD + "double" :
97100 return str (float (text ))
98101 if typ == XSD + "boolean" :
99- return "%s" % (text == "true" or text == "True " )
102+ return str (text . lower () == "true" )
100103 if typ == XSD + "base64Binary" :
101- import base64
102-
103- return base64 .decodestring (text )
104+ return _b64_decode_fn (text )
104105 raise ValueError ("type %s not supported" % type )
105106
106107
@@ -124,9 +125,7 @@ def _verify_value_type(typ, val):
124125 else :
125126 raise ValueError ("Faulty boolean value" )
126127 if typ == XSD + "base64Binary" :
127- import base64
128-
129- return base64 .decodestring (val .encode ('utf-8' ))
128+ return _b64_decode_fn (val .encode ())
130129
131130
132131class AttributeValueBase (SamlBase ):
@@ -181,7 +180,6 @@ def set_type(self, typ):
181180 except AttributeError :
182181 self ._extatt ['xmlns:xs' ] = XS_NAMESPACE
183182
184-
185183 def get_type (self ):
186184 try :
187185 return self .extension_attributes [XSI_TYPE ]
@@ -204,13 +202,11 @@ def clear_type(self):
204202 def set_text (self , val , base64encode = False ):
205203 typ = self .get_type ()
206204 if base64encode :
207- import base64
208-
209- val = base64 .encodestring (val )
205+ val = _b64_encode_fn (val )
210206 self .set_type ("xs:base64Binary" )
211207 else :
212208 if isinstance (val , six .binary_type ):
213- val = val .decode ('utf-8' )
209+ val = val .decode ()
214210 if isinstance (val , six .string_types ):
215211 if not typ :
216212 self .set_type ("xs:string" )
0 commit comments