Skip to content

Commit d7a4365

Browse files
committed
Remove cast to unicode
``` ************* Module saml2.saml src/saml2/saml.py:168:15: E0602: Undefined variable 'unicode' (undefined-variable) ``` There is no compatibility to python2 anymore. We can safely remove any such checks that tried to set the right types for the string object to catter for the differences in types between py2 and py3. Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent b853919 commit d7a4365

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/saml2/saml.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,16 @@ def clear_type(self):
160160

161161
def set_text(self, value, base64encode=False):
162162
def _wrong_type_value(xsd, value):
163-
msg = _str('Type and value do not match: {xsd}:{type}:{value}')
163+
msg = 'Type and value do not match: {xsd}:{type}:{value}'
164164
msg = msg.format(xsd=xsd, type=type(value), value=value)
165165
raise ValueError(msg)
166166

167167
# only work with six.string_types
168-
_str = unicode if six.PY2 else str
169168
if isinstance(value, six.binary_type):
170169
value = value.decode('utf-8')
171170

172171
type_to_xsd = {
173-
_str: 'string',
172+
str: 'string',
174173
int: 'integer',
175174
float: 'float',
176175
bool: 'boolean',
@@ -183,51 +182,51 @@ def _wrong_type_value(xsd, value):
183182
# - a function to turn that type into a text-value
184183
xsd_types_props = {
185184
'string': {
186-
'type': _str,
187-
'to_type': _str,
188-
'to_text': _str,
185+
'type': str,
186+
'to_type': str,
187+
'to_text': str,
189188
},
190189
'integer': {
191190
'type': int,
192191
'to_type': int,
193-
'to_text': _str,
192+
'to_text': str,
194193
},
195194
'short': {
196195
'type': int,
197196
'to_type': int,
198-
'to_text': _str,
197+
'to_text': str,
199198
},
200199
'int': {
201200
'type': int,
202201
'to_type': int,
203-
'to_text': _str,
202+
'to_text': str,
204203
},
205204
'long': {
206205
'type': int,
207206
'to_type': int,
208-
'to_text': _str,
207+
'to_text': str,
209208
},
210209
'float': {
211210
'type': float,
212211
'to_type': float,
213-
'to_text': _str,
212+
'to_text': str,
214213
},
215214
'double': {
216215
'type': float,
217216
'to_type': float,
218-
'to_text': _str,
217+
'to_text': str,
219218
},
220219
'boolean': {
221220
'type': bool,
222221
'to_type': lambda x: {
223222
'true': True,
224223
'false': False,
225-
}[_str(x).lower()],
226-
'to_text': lambda x: _str(x).lower(),
224+
}[str(x).lower()],
225+
'to_text': lambda x: str(x).lower(),
227226
},
228227
'base64Binary': {
229-
'type': _str,
230-
'to_type': _str,
228+
'type': str,
229+
'to_type': str,
231230
'to_text': (
232231
lambda x: base64.encodebytes(x.encode()) if base64encode else x
233232
),
@@ -264,7 +263,7 @@ def _wrong_type_value(xsd, value):
264263
to_text = xsd_type_props.get('to_text', str)
265264

266265
# cast to correct type before type-checking
267-
if type(value) is _str and valid_type is not _str:
266+
if type(value) is str and valid_type is not str:
268267
try:
269268
value = to_type(value)
270269
except (TypeError, ValueError, KeyError) as e:

0 commit comments

Comments
 (0)