Rename the unicode methode of ReturnUnicode in cas.py to prevent clash in spnhinx autodoc with unicode type

This commit is contained in:
Valentin Samir 2016-07-20 18:29:34 +02:00
parent cec0cadb7a
commit 8caf9156aa

View file

@ -36,7 +36,7 @@ class CASError(ValueError):
class ReturnUnicode(object): class ReturnUnicode(object):
@staticmethod @staticmethod
def unicode(string, charset): def u(string, charset):
if not isinstance(string, six.text_type): if not isinstance(string, six.text_type):
return string.decode(charset) return string.decode(charset)
else: else:
@ -157,7 +157,7 @@ class CASClientV1(CASClientBase, ReturnUnicode):
charset = content_type.split("charset=")[-1] charset = content_type.split("charset=")[-1]
else: else:
charset = "ascii" charset = "ascii"
user = self.unicode(page.readline().strip(), charset) user = self.u(page.readline().strip(), charset)
return user, None, None return user, None, None
else: else:
return None, None, None return None, None, None
@ -202,18 +202,18 @@ class CASClientV2(CASClientBase, ReturnUnicode):
def parse_attributes_xml_element(cls, element, charset): def parse_attributes_xml_element(cls, element, charset):
attributes = dict() attributes = dict()
for attribute in element: for attribute in element:
tag = cls.self.unicode(attribute.tag, charset).split(u"}").pop() tag = cls.self.u(attribute.tag, charset).split(u"}").pop()
if tag in attributes: if tag in attributes:
if isinstance(attributes[tag], list): if isinstance(attributes[tag], list):
attributes[tag].append(cls.unicode(attribute.text, charset)) attributes[tag].append(cls.u(attribute.text, charset))
else: else:
attributes[tag] = [attributes[tag]] attributes[tag] = [attributes[tag]]
attributes[tag].append(cls.unicode(attribute.text, charset)) attributes[tag].append(cls.u(attribute.text, charset))
else: else:
if tag == u'attraStyle': if tag == u'attraStyle':
pass pass
else: else:
attributes[tag] = cls.unicode(attribute.text, charset) attributes[tag] = cls.u(attribute.text, charset)
return attributes return attributes
@classmethod @classmethod
@ -238,9 +238,9 @@ class CASClientV2(CASClientBase, ReturnUnicode):
if tree[0].tag.endswith('authenticationSuccess'): if tree[0].tag.endswith('authenticationSuccess'):
for element in tree[0]: for element in tree[0]:
if element.tag.endswith('user'): if element.tag.endswith('user'):
user = cls.unicode(element.text, charset) user = cls.u(element.text, charset)
elif element.tag.endswith('proxyGrantingTicket'): elif element.tag.endswith('proxyGrantingTicket'):
pgtiou = cls.unicode(element.text, charset) pgtiou = cls.u(element.text, charset)
elif element.tag.endswith('attributes'): elif element.tag.endswith('attributes'):
attributes = cls.parse_attributes_xml_element(element, charset) attributes = cls.parse_attributes_xml_element(element, charset)
return user, attributes, pgtiou return user, attributes, pgtiou
@ -255,15 +255,15 @@ class CASClientV3(CASClientV2, SingleLogoutMixin):
def parse_attributes_xml_element(cls, element, charset): def parse_attributes_xml_element(cls, element, charset):
attributes = dict() attributes = dict()
for attribute in element: for attribute in element:
tag = cls.unicode(attribute.tag, charset).split(u"}").pop() tag = cls.u(attribute.tag, charset).split(u"}").pop()
if tag in attributes: if tag in attributes:
if isinstance(attributes[tag], list): if isinstance(attributes[tag], list):
attributes[tag].append(cls.unicode(attribute.text, charset)) attributes[tag].append(cls.u(attribute.text, charset))
else: else:
attributes[tag] = [attributes[tag]] attributes[tag] = [attributes[tag]]
attributes[tag].append(cls.unicode(attribute.text, charset)) attributes[tag].append(cls.u(attribute.text, charset))
else: else:
attributes[tag] = cls.unicode(attribute.text, charset) attributes[tag] = cls.u(attribute.text, charset)
return attributes return attributes
@classmethod @classmethod
@ -323,25 +323,25 @@ class CASClientWithSAMLV1(CASClientV2, SingleLogoutMixin):
# User is validated # User is validated
name_identifier = tree.find('.//' + SAML_1_0_ASSERTION_NS + 'NameIdentifier') name_identifier = tree.find('.//' + SAML_1_0_ASSERTION_NS + 'NameIdentifier')
if name_identifier is not None: if name_identifier is not None:
user = self.unicode(name_identifier.text, charset) user = self.u(name_identifier.text, charset)
attrs = tree.findall('.//' + SAML_1_0_ASSERTION_NS + 'Attribute') attrs = tree.findall('.//' + SAML_1_0_ASSERTION_NS + 'Attribute')
for at in attrs: for at in attrs:
if self.username_attribute in list(at.attrib.values()): if self.username_attribute in list(at.attrib.values()):
user = self.unicode( user = self.u(
at.find(SAML_1_0_ASSERTION_NS + 'AttributeValue').text, at.find(SAML_1_0_ASSERTION_NS + 'AttributeValue').text,
charset charset
) )
attributes[u'uid'] = user attributes[u'uid'] = user
values = at.findall(SAML_1_0_ASSERTION_NS + 'AttributeValue') values = at.findall(SAML_1_0_ASSERTION_NS + 'AttributeValue')
key = self.unicode(at.attrib['AttributeName'], charset) key = self.u(at.attrib['AttributeName'], charset)
if len(values) > 1: if len(values) > 1:
values_array = [] values_array = []
for v in values: for v in values:
values_array.append(self.unicode(v.text, charset)) values_array.append(self.u(v.text, charset))
attributes[key] = values_array attributes[key] = values_array
else: else:
attributes[key] = self.unicode(values[0].text, charset) attributes[key] = self.u(values[0].text, charset)
return user, attributes, None return user, attributes, None
finally: finally:
page.close() page.close()