Changed parse_xsd2 to handle element groups, also modified to handle name clashed between elements and complexTypes who according to the standard occupy different namespaces. Ripple effects due to name changes on constructed classes has been taken care of

This commit is contained in:
Roland Hedberg
2010-08-20 09:01:43 +02:00
parent 027c08fdcd
commit 01f5400e8a
17 changed files with 2469 additions and 2030 deletions

View File

@@ -58,7 +58,7 @@ class Cache(object):
def get(self, subject_id, entity_id):
""" Get session information about a subject gotten from a
specified IdP.
specified IdP/AA.
:param subject_id: The identifier of the subject
:param entity_id: The identifier of the entity_id
@@ -75,11 +75,11 @@ class Cache(object):
else:
return info
def set( self, subject_id, entity_id, info, not_on_or_after=0):
def set(self, subject_id, entity_id, info, not_on_or_after=0):
""" Stores session information in the cache. Assumes that the subject_id
is unique within the context of the Service Provider.
:param subject_id: The subjects identifier
:param subject_id: The subject identifier
:param entity_id: The identifier of the entity_id/receiver of an
assertion
:param info: The session info, the assertion is part of this
@@ -93,7 +93,7 @@ class Cache(object):
self._db.sync()
def reset(self, subject_id, entity_id=None):
""" Scrap the assertions received from a IdP or an AA.about a special
""" Scrap the assertions received from a IdP or an AA about a special
subject.
:param subject_id: The subjects identifier
@@ -117,7 +117,8 @@ class Cache(object):
return self._db[subject_id].keys()
def receivers(self, subject_id):
""" Another name just to make it more logic in the IdP scenario """
""" Another name for entities() just to make it more logic in the IdP
scenario """
return self.entities(subject_id)
def active(self, subject_id, entity_id):

View File

@@ -10,7 +10,7 @@ from saml2 import md
NAMESPACE = "urn:oasis:names:tc:SAML:profiles:SSO:idp-discovery-protocol"
class DiscoveryResponse(md.IndexedEndpointType):
class DiscoveryResponse(md.IndexedEndpointType_):
"""The idpdisc:DiscoveryResponse element"""
c_tag = 'DiscoveryResponse'
c_namespace = NAMESPACE

File diff suppressed because it is too large Load Diff

View File

@@ -217,18 +217,30 @@ class MetaData(object):
entity[tag] = aads
def clear_from_source(self, source):
""" Remove all the metadata references I have gotten from this source
:param source: The matadata source
"""
for eid in self._import[source]:
del self.entity[eid]
def reload_entity(self, entity_id):
""" Reload metadata about an entity_id, means reload the whole
metadata file that this entity_id belonged to.
:param entity_id: The Entity ID
"""
for source, eids in self._import.items():
if entity_id in eids:
if source == "-":
return
self.clear_from_source(source)
if isinstance(source, basestring):
fil = open(source)
self.import_metadata( fil.read(), source)
self.import_metadata(fil.read(), source)
fil.close()
else:
self.import_external_metadata(source[0], source[1])
@@ -238,6 +250,8 @@ class MetaData(object):
certificates from a metadata file.
:param xml_str: The metadata as a XML string.
:param source: A name by which this source should be known, has to be
unique within this session.
"""
# now = time.gmtime()
@@ -269,6 +283,13 @@ class MetaData(object):
except KeyError:
self._import[source] = [entity_descr.entity_id]
# have I seen this entity_id before ? If so log and ignore it
if entity_descr.entity_id in self.entity:
print >> sys.stderr, \
"Duplicated Entity descriptor (entity id:%s)" % \
entity_descr.entity_id
continue
entity = self.entity[entity_descr.entity_id] = {}
entity["valid_until"] = entities_descr.valid_until
self._idp_metadata(entity_descr, entity, "idp_sso")
@@ -567,7 +588,7 @@ def do_key_descriptor(cert):
return md.KeyDescriptor(
key_info = ds.KeyInfo(
x509_data=ds.X509Data(
x509_certificate=ds.X509Certificate(text=cert)
x509_certificate=ds.X509DataType_X509Certificate(text=cert)
)
)
)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -658,7 +658,8 @@ def pre_signature_part(ident, public_key=None, identifier=None):
signature.id = "Signature%d" % identifier
if public_key:
x509_data = ds.X509Data(x509_certificate=[ds.X509Certificate(text=public_key)])
x509_data = ds.X509Data(x509_certificate=[ds.X509DataType_X509Certificate(
text=public_key)])
key_info = ds.KeyInfo(x509_data=x509_data)
signature.key_info = key_info

View File

@@ -1,5 +1,5 @@
../../tools/parse_xsd2.py -d defs_xmldsig.py xmldsig-core-schema.xsd > xd.py
../../tools/parse_xsd2.py -i xd xenc-schema.xsd > xe.py
../../tools/parse_xsd2.py -i xd -i xe -d defs_saml.py saml-schema-assertion-2.0.xsd.xml > sa.py
../../tools/parse_xsd2.py -i xd -i sa -d defs_samlp.py saml-schema-protocol-2.0.xsd.xml > sp.py
../../tools/parse_xsd2.py -i xd -i xe -d defs_saml.py saml-schema-assertion-2.0.xsd > sa.py
../../tools/parse_xsd2.py -i xd -i xe -i sa -d defs_samlp.py saml-schema-protocol-2.0.xsd > sp.py
../../tools/parse_xsd2.py -i xd -i xe -i sa saml-schema-metadata-2.0.xsd > sm.py

View File

@@ -2,4 +2,4 @@ cp xd.py ../xmldsig/__init__.py
sed 's/import xd as ds/import xmldsig as ds/' < xe.py > ../xmlenc/__init__.py
sed -e 's/import xd as ds/import xmldsig as ds/' -e 's/import xe as xenc/import xmlenc as xenc/' -e 's/AttributeValue(SamlBase)/AttributeValue(AttributeValueBase)/' < sa.py > ../saml2/saml.py
sed -e 's/import xd as ds/import xmldsig as ds/' -e 's/import sa as saml/from saml2 import saml/' < sp.py > ../saml2/samlp.py
sed -e 's/import xd as ds/import xmldsig as ds/' -e 's/import xe as xenc/import xmlenc as xenc/' -e 's/import sa as saml/from saml2 import saml/' < sm.py > md.py
sed -e 's/import xd as ds/import xmldsig as ds/' -e 's/import xe as xenc/import xmlenc as xenc/' -e 's/import sa as saml/from saml2 import saml/' < sm.py > ../saml2/md.py

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env python
#
# Generated Tue Aug 3 20:39:25 2010 by parse_xsd.py version 0.3.
# Generated Fri Aug 20 08:25:36 2010 by parse_xsd.py version 0.3.
#
import saml2
@@ -11,7 +11,7 @@ import xmldsig as ds
NAMESPACE = 'http://www.w3.org/2001/04/xmlenc#'
class KeySizeType(SamlBase):
class KeySizeType_(SamlBase):
"""The http://www.w3.org/2001/04/xmlenc#:KeySizeType element """
c_tag = 'KeySizeType'
@@ -22,24 +22,25 @@ class KeySizeType(SamlBase):
c_child_order = SamlBase.c_child_order[:]
c_cardinality = SamlBase.c_cardinality.copy()
def key_size_type_from_string(xml_string):
return saml2.create_class_from_xml_string(KeySizeType, xml_string)
def key_size_type__from_string(xml_string):
return saml2.create_class_from_xml_string(KeySizeType_, xml_string)
class CipherValue(SamlBase):
"""The http://www.w3.org/2001/04/xmlenc#:CipherValue element """
class CipherDataType_CipherValue(SamlBase):
c_tag = 'CipherValue'
c_namespace = NAMESPACE
c_value_type = 'base64Binary'
c_value_type = {'base': 'base64Binary'}
c_children = SamlBase.c_children.copy()
c_attributes = SamlBase.c_attributes.copy()
c_child_order = SamlBase.c_child_order[:]
c_cardinality = SamlBase.c_cardinality.copy()
def cipher_value_from_string(xml_string):
return saml2.create_class_from_xml_string(CipherValue, xml_string)
def cipher_data_type__cipher_value_from_string(xml_string):
return saml2.create_class_from_xml_string(CipherDataType_CipherValue, xml_string)
class TransformsType(SamlBase):
class TransformsType_(SamlBase):
"""The http://www.w3.org/2001/04/xmlenc#:TransformsType element """
c_tag = 'TransformsType'
@@ -65,50 +66,51 @@ class TransformsType(SamlBase):
)
self.transform=transform or []
def transforms_type_from_string(xml_string):
return saml2.create_class_from_xml_string(TransformsType, xml_string)
def transforms_type__from_string(xml_string):
return saml2.create_class_from_xml_string(TransformsType_, xml_string)
class KA_Nonce(SamlBase):
"""The http://www.w3.org/2001/04/xmlenc#:KA_Nonce element """
class AgreementMethodType_KA_Nonce(SamlBase):
c_tag = 'KA_Nonce'
c_namespace = NAMESPACE
c_value_type = 'base64Binary'
c_value_type = {'base': 'base64Binary'}
c_children = SamlBase.c_children.copy()
c_attributes = SamlBase.c_attributes.copy()
c_child_order = SamlBase.c_child_order[:]
c_cardinality = SamlBase.c_cardinality.copy()
def k_a__nonce_from_string(xml_string):
return saml2.create_class_from_xml_string(KA_Nonce, xml_string)
def agreement_method_type__k_a__nonce_from_string(xml_string):
return saml2.create_class_from_xml_string(AgreementMethodType_KA_Nonce, xml_string)
class OriginatorKeyInfo(ds.KeyInfoType):
"""The http://www.w3.org/2001/04/xmlenc#:OriginatorKeyInfo element """
class AgreementMethodType_OriginatorKeyInfo(ds.KeyInfoType_):
c_tag = 'OriginatorKeyInfo'
c_namespace = NAMESPACE
c_children = ds.KeyInfoType.c_children.copy()
c_attributes = ds.KeyInfoType.c_attributes.copy()
c_child_order = ds.KeyInfoType.c_child_order[:]
c_cardinality = ds.KeyInfoType.c_cardinality.copy()
c_children = ds.KeyInfoType_.c_children.copy()
c_attributes = ds.KeyInfoType_.c_attributes.copy()
c_child_order = ds.KeyInfoType_.c_child_order[:]
c_cardinality = ds.KeyInfoType_.c_cardinality.copy()
def originator_key_info_from_string(xml_string):
return saml2.create_class_from_xml_string(OriginatorKeyInfo, xml_string)
def agreement_method_type__originator_key_info_from_string(xml_string):
return saml2.create_class_from_xml_string(AgreementMethodType_OriginatorKeyInfo, xml_string)
class RecipientKeyInfo(ds.KeyInfoType):
"""The http://www.w3.org/2001/04/xmlenc#:RecipientKeyInfo element """
class AgreementMethodType_RecipientKeyInfo(ds.KeyInfoType_):
c_tag = 'RecipientKeyInfo'
c_namespace = NAMESPACE
c_children = ds.KeyInfoType.c_children.copy()
c_attributes = ds.KeyInfoType.c_attributes.copy()
c_child_order = ds.KeyInfoType.c_child_order[:]
c_cardinality = ds.KeyInfoType.c_cardinality.copy()
c_children = ds.KeyInfoType_.c_children.copy()
c_attributes = ds.KeyInfoType_.c_attributes.copy()
c_child_order = ds.KeyInfoType_.c_child_order[:]
c_cardinality = ds.KeyInfoType_.c_cardinality.copy()
def recipient_key_info_from_string(xml_string):
return saml2.create_class_from_xml_string(RecipientKeyInfo, xml_string)
def agreement_method_type__recipient_key_info_from_string(xml_string):
return saml2.create_class_from_xml_string(AgreementMethodType_RecipientKeyInfo, xml_string)
class AgreementMethodType(SamlBase):
class AgreementMethodType_(SamlBase):
"""The http://www.w3.org/2001/04/xmlenc#:AgreementMethodType element """
c_tag = 'AgreementMethodType'
@@ -117,11 +119,11 @@ class AgreementMethodType(SamlBase):
c_attributes = SamlBase.c_attributes.copy()
c_child_order = SamlBase.c_child_order[:]
c_cardinality = SamlBase.c_cardinality.copy()
c_children['{http://www.w3.org/2001/04/xmlenc#}KA_Nonce'] = ('k_a__nonce', KA_Nonce)
c_children['{http://www.w3.org/2001/04/xmlenc#}KA_Nonce'] = ('k_a__nonce', AgreementMethodType_KA_Nonce)
c_cardinality['k_a__nonce'] = {"min":0, "max":1}
c_children['{http://www.w3.org/2000/09/xmldsig#}OriginatorKeyInfo'] = ('originator_key_info', ds.KeyInfoType)
c_children['{http://www.w3.org/2001/04/xmlenc#}OriginatorKeyInfo'] = ('originator_key_info', AgreementMethodType_OriginatorKeyInfo)
c_cardinality['originator_key_info'] = {"min":0, "max":1}
c_children['{http://www.w3.org/2000/09/xmldsig#}RecipientKeyInfo'] = ('recipient_key_info', ds.KeyInfoType)
c_children['{http://www.w3.org/2001/04/xmlenc#}RecipientKeyInfo'] = ('recipient_key_info', AgreementMethodType_RecipientKeyInfo)
c_cardinality['recipient_key_info'] = {"min":0, "max":1}
c_attributes['Algorithm'] = ('algorithm', 'anyURI', True)
c_child_order.extend(['k_a__nonce', 'originator_key_info', 'recipient_key_info'])
@@ -145,10 +147,11 @@ class AgreementMethodType(SamlBase):
self.recipient_key_info=recipient_key_info
self.algorithm=algorithm
def agreement_method_type_from_string(xml_string):
return saml2.create_class_from_xml_string(AgreementMethodType, xml_string)
def agreement_method_type__from_string(xml_string):
return saml2.create_class_from_xml_string(AgreementMethodType_, xml_string)
class ReferenceType(SamlBase):
class ReferenceType_(SamlBase):
"""The http://www.w3.org/2001/04/xmlenc#:ReferenceType element """
c_tag = 'ReferenceType'
@@ -172,10 +175,11 @@ class ReferenceType(SamlBase):
)
self.uri=uri
def reference_type_from_string(xml_string):
return saml2.create_class_from_xml_string(ReferenceType, xml_string)
def reference_type__from_string(xml_string):
return saml2.create_class_from_xml_string(ReferenceType_, xml_string)
class EncryptionPropertyType(SamlBase):
class EncryptionPropertyType_(SamlBase):
"""The http://www.w3.org/2001/04/xmlenc#:EncryptionPropertyType element """
c_tag = 'EncryptionPropertyType'
@@ -202,37 +206,38 @@ class EncryptionPropertyType(SamlBase):
self.target=target
self.id=id
def encryption_property_type_from_string(xml_string):
return saml2.create_class_from_xml_string(EncryptionPropertyType, xml_string)
def encryption_property_type__from_string(xml_string):
return saml2.create_class_from_xml_string(EncryptionPropertyType_, xml_string)
class KeySize(KeySizeType):
"""The http://www.w3.org/2001/04/xmlenc#:KeySize element """
class EncryptionMethodType_KeySize(KeySizeType_):
c_tag = 'KeySize'
c_namespace = NAMESPACE
c_children = KeySizeType.c_children.copy()
c_attributes = KeySizeType.c_attributes.copy()
c_child_order = KeySizeType.c_child_order[:]
c_cardinality = KeySizeType.c_cardinality.copy()
c_children = KeySizeType_.c_children.copy()
c_attributes = KeySizeType_.c_attributes.copy()
c_child_order = KeySizeType_.c_child_order[:]
c_cardinality = KeySizeType_.c_cardinality.copy()
def key_size_from_string(xml_string):
return saml2.create_class_from_xml_string(KeySize, xml_string)
def encryption_method_type__key_size_from_string(xml_string):
return saml2.create_class_from_xml_string(EncryptionMethodType_KeySize, xml_string)
class OAEPparams(SamlBase):
"""The http://www.w3.org/2001/04/xmlenc#:OAEPparams element """
class EncryptionMethodType_OAEPparams(SamlBase):
c_tag = 'OAEPparams'
c_namespace = NAMESPACE
c_value_type = 'base64Binary'
c_value_type = {'base': 'base64Binary'}
c_children = SamlBase.c_children.copy()
c_attributes = SamlBase.c_attributes.copy()
c_child_order = SamlBase.c_child_order[:]
c_cardinality = SamlBase.c_cardinality.copy()
def oae_pparams_from_string(xml_string):
return saml2.create_class_from_xml_string(OAEPparams, xml_string)
def encryption_method_type__oae_pparams_from_string(xml_string):
return saml2.create_class_from_xml_string(EncryptionMethodType_OAEPparams, xml_string)
class EncryptionMethodType(SamlBase):
class EncryptionMethodType_(SamlBase):
"""The http://www.w3.org/2001/04/xmlenc#:EncryptionMethodType element """
c_tag = 'EncryptionMethodType'
@@ -241,9 +246,9 @@ class EncryptionMethodType(SamlBase):
c_attributes = SamlBase.c_attributes.copy()
c_child_order = SamlBase.c_child_order[:]
c_cardinality = SamlBase.c_cardinality.copy()
c_children['{http://www.w3.org/2001/04/xmlenc#}KeySize'] = ('key_size', KeySize)
c_children['{http://www.w3.org/2001/04/xmlenc#}KeySize'] = ('key_size', EncryptionMethodType_KeySize)
c_cardinality['key_size'] = {"min":0, "max":1}
c_children['{http://www.w3.org/2001/04/xmlenc#}OAEPparams'] = ('oae_pparams', OAEPparams)
c_children['{http://www.w3.org/2001/04/xmlenc#}OAEPparams'] = ('oae_pparams', EncryptionMethodType_OAEPparams)
c_cardinality['oae_pparams'] = {"min":0, "max":1}
c_attributes['Algorithm'] = ('algorithm', 'anyURI', True)
c_child_order.extend(['key_size', 'oae_pparams'])
@@ -265,23 +270,24 @@ class EncryptionMethodType(SamlBase):
self.oae_pparams=oae_pparams
self.algorithm=algorithm
def encryption_method_type_from_string(xml_string):
return saml2.create_class_from_xml_string(EncryptionMethodType, xml_string)
def encryption_method_type__from_string(xml_string):
return saml2.create_class_from_xml_string(EncryptionMethodType_, xml_string)
class Transforms(TransformsType):
"""The http://www.w3.org/2001/04/xmlenc#:Transforms element """
class CipherReferenceType_Transforms(TransformsType_):
c_tag = 'Transforms'
c_namespace = NAMESPACE
c_children = TransformsType.c_children.copy()
c_attributes = TransformsType.c_attributes.copy()
c_child_order = TransformsType.c_child_order[:]
c_cardinality = TransformsType.c_cardinality.copy()
c_children = TransformsType_.c_children.copy()
c_attributes = TransformsType_.c_attributes.copy()
c_child_order = TransformsType_.c_child_order[:]
c_cardinality = TransformsType_.c_cardinality.copy()
def transforms_from_string(xml_string):
return saml2.create_class_from_xml_string(Transforms, xml_string)
def cipher_reference_type__transforms_from_string(xml_string):
return saml2.create_class_from_xml_string(CipherReferenceType_Transforms, xml_string)
class CipherReferenceType(SamlBase):
class CipherReferenceType_(SamlBase):
"""The http://www.w3.org/2001/04/xmlenc#:CipherReferenceType element """
c_tag = 'CipherReferenceType'
@@ -290,7 +296,7 @@ class CipherReferenceType(SamlBase):
c_attributes = SamlBase.c_attributes.copy()
c_child_order = SamlBase.c_child_order[:]
c_cardinality = SamlBase.c_cardinality.copy()
c_children['{http://www.w3.org/2001/04/xmlenc#}Transforms'] = ('transforms', Transforms)
c_children['{http://www.w3.org/2001/04/xmlenc#}Transforms'] = ('transforms', CipherReferenceType_Transforms)
c_cardinality['transforms'] = {"min":0, "max":1}
c_attributes['URI'] = ('uri', 'anyURI', True)
c_child_order.extend(['transforms'])
@@ -310,61 +316,63 @@ class CipherReferenceType(SamlBase):
self.transforms=transforms
self.uri=uri
def cipher_reference_type_from_string(xml_string):
return saml2.create_class_from_xml_string(CipherReferenceType, xml_string)
def cipher_reference_type__from_string(xml_string):
return saml2.create_class_from_xml_string(CipherReferenceType_, xml_string)
class EncryptionMethod(EncryptionMethodType):
"""The http://www.w3.org/2001/04/xmlenc#:EncryptionMethod element """
class EncryptedType_EncryptionMethod(EncryptionMethodType_):
c_tag = 'EncryptionMethod'
c_namespace = NAMESPACE
c_children = EncryptionMethodType.c_children.copy()
c_attributes = EncryptionMethodType.c_attributes.copy()
c_child_order = EncryptionMethodType.c_child_order[:]
c_cardinality = EncryptionMethodType.c_cardinality.copy()
c_children = EncryptionMethodType_.c_children.copy()
c_attributes = EncryptionMethodType_.c_attributes.copy()
c_child_order = EncryptionMethodType_.c_child_order[:]
c_cardinality = EncryptionMethodType_.c_cardinality.copy()
def encryption_method_from_string(xml_string):
return saml2.create_class_from_xml_string(EncryptionMethod, xml_string)
def encrypted_type__encryption_method_from_string(xml_string):
return saml2.create_class_from_xml_string(EncryptedType_EncryptionMethod, xml_string)
class AgreementMethod(AgreementMethodType):
class AgreementMethod(AgreementMethodType_):
"""The http://www.w3.org/2001/04/xmlenc#:AgreementMethod element """
c_tag = 'AgreementMethod'
c_namespace = NAMESPACE
c_children = AgreementMethodType.c_children.copy()
c_attributes = AgreementMethodType.c_attributes.copy()
c_child_order = AgreementMethodType.c_child_order[:]
c_cardinality = AgreementMethodType.c_cardinality.copy()
c_children = AgreementMethodType_.c_children.copy()
c_attributes = AgreementMethodType_.c_attributes.copy()
c_child_order = AgreementMethodType_.c_child_order[:]
c_cardinality = AgreementMethodType_.c_cardinality.copy()
def agreement_method_from_string(xml_string):
return saml2.create_class_from_xml_string(AgreementMethod, xml_string)
class DataReference(ReferenceType):
"""The http://www.w3.org/2001/04/xmlenc#:DataReference element """
class ReferenceList_DataReference(ReferenceType_):
c_tag = 'DataReference'
c_namespace = NAMESPACE
c_children = ReferenceType.c_children.copy()
c_attributes = ReferenceType.c_attributes.copy()
c_child_order = ReferenceType.c_child_order[:]
c_cardinality = ReferenceType.c_cardinality.copy()
c_children = ReferenceType_.c_children.copy()
c_attributes = ReferenceType_.c_attributes.copy()
c_child_order = ReferenceType_.c_child_order[:]
c_cardinality = ReferenceType_.c_cardinality.copy()
def data_reference_from_string(xml_string):
return saml2.create_class_from_xml_string(DataReference, xml_string)
def reference_list__data_reference_from_string(xml_string):
return saml2.create_class_from_xml_string(ReferenceList_DataReference, xml_string)
class KeyReference(ReferenceType):
"""The http://www.w3.org/2001/04/xmlenc#:KeyReference element """
class ReferenceList_KeyReference(ReferenceType_):
c_tag = 'KeyReference'
c_namespace = NAMESPACE
c_children = ReferenceType.c_children.copy()
c_attributes = ReferenceType.c_attributes.copy()
c_child_order = ReferenceType.c_child_order[:]
c_cardinality = ReferenceType.c_cardinality.copy()
c_children = ReferenceType_.c_children.copy()
c_attributes = ReferenceType_.c_attributes.copy()
c_child_order = ReferenceType_.c_child_order[:]
c_cardinality = ReferenceType_.c_cardinality.copy()
def reference_list__key_reference_from_string(xml_string):
return saml2.create_class_from_xml_string(ReferenceList_KeyReference, xml_string)
def key_reference_from_string(xml_string):
return saml2.create_class_from_xml_string(KeyReference, xml_string)
class ReferenceList(SamlBase):
"""The http://www.w3.org/2001/04/xmlenc#:ReferenceList element """
@@ -375,9 +383,9 @@ class ReferenceList(SamlBase):
c_attributes = SamlBase.c_attributes.copy()
c_child_order = SamlBase.c_child_order[:]
c_cardinality = SamlBase.c_cardinality.copy()
c_children['{http://www.w3.org/2001/04/xmlenc#}DataReference'] = ('data_reference', [DataReference])
c_children['{http://www.w3.org/2001/04/xmlenc#}DataReference'] = ('data_reference', [ReferenceList_DataReference])
c_cardinality['data_reference'] = {"min":0}
c_children['{http://www.w3.org/2001/04/xmlenc#}KeyReference'] = ('key_reference', [KeyReference])
c_children['{http://www.w3.org/2001/04/xmlenc#}KeyReference'] = ('key_reference', [ReferenceList_KeyReference])
c_cardinality['key_reference'] = {"min":0}
c_child_order.extend(['data_reference', 'key_reference'])
@@ -399,33 +407,36 @@ class ReferenceList(SamlBase):
def reference_list_from_string(xml_string):
return saml2.create_class_from_xml_string(ReferenceList, xml_string)
class EncryptionProperty(EncryptionPropertyType):
class EncryptionProperty(EncryptionPropertyType_):
"""The http://www.w3.org/2001/04/xmlenc#:EncryptionProperty element """
c_tag = 'EncryptionProperty'
c_namespace = NAMESPACE
c_children = EncryptionPropertyType.c_children.copy()
c_attributes = EncryptionPropertyType.c_attributes.copy()
c_child_order = EncryptionPropertyType.c_child_order[:]
c_cardinality = EncryptionPropertyType.c_cardinality.copy()
c_children = EncryptionPropertyType_.c_children.copy()
c_attributes = EncryptionPropertyType_.c_attributes.copy()
c_child_order = EncryptionPropertyType_.c_child_order[:]
c_cardinality = EncryptionPropertyType_.c_cardinality.copy()
def encryption_property_from_string(xml_string):
return saml2.create_class_from_xml_string(EncryptionProperty, xml_string)
class CipherReference(CipherReferenceType):
class CipherReference(CipherReferenceType_):
"""The http://www.w3.org/2001/04/xmlenc#:CipherReference element """
c_tag = 'CipherReference'
c_namespace = NAMESPACE
c_children = CipherReferenceType.c_children.copy()
c_attributes = CipherReferenceType.c_attributes.copy()
c_child_order = CipherReferenceType.c_child_order[:]
c_cardinality = CipherReferenceType.c_cardinality.copy()
c_children = CipherReferenceType_.c_children.copy()
c_attributes = CipherReferenceType_.c_attributes.copy()
c_child_order = CipherReferenceType_.c_child_order[:]
c_cardinality = CipherReferenceType_.c_cardinality.copy()
def cipher_reference_from_string(xml_string):
return saml2.create_class_from_xml_string(CipherReference, xml_string)
class EncryptionPropertiesType(SamlBase):
class EncryptionPropertiesType_(SamlBase):
"""The http://www.w3.org/2001/04/xmlenc#:EncryptionPropertiesType element """
c_tag = 'EncryptionPropertiesType'
@@ -454,10 +465,11 @@ class EncryptionPropertiesType(SamlBase):
self.encryption_property=encryption_property or []
self.id=id
def encryption_properties_type_from_string(xml_string):
return saml2.create_class_from_xml_string(EncryptionPropertiesType, xml_string)
def encryption_properties_type__from_string(xml_string):
return saml2.create_class_from_xml_string(EncryptionPropertiesType_, xml_string)
class CipherDataType(SamlBase):
class CipherDataType_(SamlBase):
"""The http://www.w3.org/2001/04/xmlenc#:CipherDataType element """
c_tag = 'CipherDataType'
@@ -466,7 +478,7 @@ class CipherDataType(SamlBase):
c_attributes = SamlBase.c_attributes.copy()
c_child_order = SamlBase.c_child_order[:]
c_cardinality = SamlBase.c_cardinality.copy()
c_children['{http://www.w3.org/2001/04/xmlenc#}CipherValue'] = ('cipher_value', CipherValue)
c_children['{http://www.w3.org/2001/04/xmlenc#}CipherValue'] = ('cipher_value', CipherDataType_CipherValue)
c_cardinality['cipher_value'] = {"min":0, "max":1}
c_children['{http://www.w3.org/2001/04/xmlenc#}CipherReference'] = ('cipher_reference', CipherReference)
c_cardinality['cipher_reference'] = {"min":0, "max":1}
@@ -487,36 +499,39 @@ class CipherDataType(SamlBase):
self.cipher_value=cipher_value
self.cipher_reference=cipher_reference
def cipher_data_type_from_string(xml_string):
return saml2.create_class_from_xml_string(CipherDataType, xml_string)
def cipher_data_type__from_string(xml_string):
return saml2.create_class_from_xml_string(CipherDataType_, xml_string)
class EncryptionProperties(EncryptionPropertiesType):
class EncryptionProperties(EncryptionPropertiesType_):
"""The http://www.w3.org/2001/04/xmlenc#:EncryptionProperties element """
c_tag = 'EncryptionProperties'
c_namespace = NAMESPACE
c_children = EncryptionPropertiesType.c_children.copy()
c_attributes = EncryptionPropertiesType.c_attributes.copy()
c_child_order = EncryptionPropertiesType.c_child_order[:]
c_cardinality = EncryptionPropertiesType.c_cardinality.copy()
c_children = EncryptionPropertiesType_.c_children.copy()
c_attributes = EncryptionPropertiesType_.c_attributes.copy()
c_child_order = EncryptionPropertiesType_.c_child_order[:]
c_cardinality = EncryptionPropertiesType_.c_cardinality.copy()
def encryption_properties_from_string(xml_string):
return saml2.create_class_from_xml_string(EncryptionProperties, xml_string)
class CipherData(CipherDataType):
class CipherData(CipherDataType_):
"""The http://www.w3.org/2001/04/xmlenc#:CipherData element """
c_tag = 'CipherData'
c_namespace = NAMESPACE
c_children = CipherDataType.c_children.copy()
c_attributes = CipherDataType.c_attributes.copy()
c_child_order = CipherDataType.c_child_order[:]
c_cardinality = CipherDataType.c_cardinality.copy()
c_children = CipherDataType_.c_children.copy()
c_attributes = CipherDataType_.c_attributes.copy()
c_child_order = CipherDataType_.c_child_order[:]
c_cardinality = CipherDataType_.c_cardinality.copy()
def cipher_data_from_string(xml_string):
return saml2.create_class_from_xml_string(CipherData, xml_string)
class EncryptedType(SamlBase):
class EncryptedType_(SamlBase):
"""The http://www.w3.org/2001/04/xmlenc#:EncryptedType element """
c_tag = 'EncryptedType'
@@ -525,7 +540,7 @@ class EncryptedType(SamlBase):
c_attributes = SamlBase.c_attributes.copy()
c_child_order = SamlBase.c_child_order[:]
c_cardinality = SamlBase.c_cardinality.copy()
c_children['{http://www.w3.org/2001/04/xmlenc#}EncryptionMethod'] = ('encryption_method', EncryptionMethod)
c_children['{http://www.w3.org/2001/04/xmlenc#}EncryptionMethod'] = ('encryption_method', EncryptedType_EncryptionMethod)
c_cardinality['encryption_method'] = {"min":0, "max":1}
c_children['{http://www.w3.org/2000/09/xmldsig#}KeyInfo'] = ('key_info', ds.KeyInfo)
c_cardinality['key_info'] = {"min":0, "max":1}
@@ -565,48 +580,47 @@ class EncryptedType(SamlBase):
self.mime_type=mime_type
self.encoding=encoding
def encrypted_type_from_string(xml_string):
return saml2.create_class_from_xml_string(EncryptedType, xml_string)
class EncryptedDataType(EncryptedType):
class EncryptedDataType_(EncryptedType_):
"""The http://www.w3.org/2001/04/xmlenc#:EncryptedDataType element """
c_tag = 'EncryptedDataType'
c_namespace = NAMESPACE
c_children = EncryptedType.c_children.copy()
c_attributes = EncryptedType.c_attributes.copy()
c_child_order = EncryptedType.c_child_order[:]
c_cardinality = EncryptedType.c_cardinality.copy()
c_children = EncryptedType_.c_children.copy()
c_attributes = EncryptedType_.c_attributes.copy()
c_child_order = EncryptedType_.c_child_order[:]
c_cardinality = EncryptedType_.c_cardinality.copy()
def encrypted_data_type_from_string(xml_string):
return saml2.create_class_from_xml_string(EncryptedDataType, xml_string)
def encrypted_data_type__from_string(xml_string):
return saml2.create_class_from_xml_string(EncryptedDataType_, xml_string)
class CarriedKeyName(SamlBase):
"""The http://www.w3.org/2001/04/xmlenc#:CarriedKeyName element """
class EncryptedKeyType_CarriedKeyName(SamlBase):
c_tag = 'CarriedKeyName'
c_namespace = NAMESPACE
c_value_type = 'string'
c_value_type = {'base': 'string'}
c_children = SamlBase.c_children.copy()
c_attributes = SamlBase.c_attributes.copy()
c_child_order = SamlBase.c_child_order[:]
c_cardinality = SamlBase.c_cardinality.copy()
def carried_key_name_from_string(xml_string):
return saml2.create_class_from_xml_string(CarriedKeyName, xml_string)
def encrypted_key_type__carried_key_name_from_string(xml_string):
return saml2.create_class_from_xml_string(EncryptedKeyType_CarriedKeyName, xml_string)
class EncryptedKeyType(EncryptedType):
class EncryptedKeyType_(EncryptedType_):
"""The http://www.w3.org/2001/04/xmlenc#:EncryptedKeyType element """
c_tag = 'EncryptedKeyType'
c_namespace = NAMESPACE
c_children = EncryptedType.c_children.copy()
c_attributes = EncryptedType.c_attributes.copy()
c_child_order = EncryptedType.c_child_order[:]
c_cardinality = EncryptedType.c_cardinality.copy()
c_children = EncryptedType_.c_children.copy()
c_attributes = EncryptedType_.c_attributes.copy()
c_child_order = EncryptedType_.c_child_order[:]
c_cardinality = EncryptedType_.c_cardinality.copy()
c_children['{http://www.w3.org/2001/04/xmlenc#}ReferenceList'] = ('reference_list', ReferenceList)
c_cardinality['reference_list'] = {"min":0, "max":1}
c_children['{http://www.w3.org/2001/04/xmlenc#}CarriedKeyName'] = ('carried_key_name', CarriedKeyName)
c_children['{http://www.w3.org/2001/04/xmlenc#}CarriedKeyName'] = ('carried_key_name', EncryptedKeyType_CarriedKeyName)
c_cardinality['carried_key_name'] = {"min":0, "max":1}
c_attributes['Recipient'] = ('recipient', 'string', False)
c_child_order.extend(['reference_list', 'carried_key_name'])
@@ -627,7 +641,7 @@ class EncryptedKeyType(EncryptedType):
extension_elements=None,
extension_attributes=None,
):
EncryptedType.__init__(self,
EncryptedType_.__init__(self,
encryption_method=encryption_method,
key_info=key_info,
cipher_data=cipher_data,
@@ -644,101 +658,102 @@ class EncryptedKeyType(EncryptedType):
self.carried_key_name=carried_key_name
self.recipient=recipient
def encrypted_key_type_from_string(xml_string):
return saml2.create_class_from_xml_string(EncryptedKeyType, xml_string)
def encrypted_key_type__from_string(xml_string):
return saml2.create_class_from_xml_string(EncryptedKeyType_, xml_string)
class EncryptedData(EncryptedDataType):
class EncryptedData(EncryptedDataType_):
"""The http://www.w3.org/2001/04/xmlenc#:EncryptedData element """
c_tag = 'EncryptedData'
c_namespace = NAMESPACE
c_children = EncryptedDataType.c_children.copy()
c_attributes = EncryptedDataType.c_attributes.copy()
c_child_order = EncryptedDataType.c_child_order[:]
c_cardinality = EncryptedDataType.c_cardinality.copy()
c_children = EncryptedDataType_.c_children.copy()
c_attributes = EncryptedDataType_.c_attributes.copy()
c_child_order = EncryptedDataType_.c_child_order[:]
c_cardinality = EncryptedDataType_.c_cardinality.copy()
def encrypted_data_from_string(xml_string):
return saml2.create_class_from_xml_string(EncryptedData, xml_string)
class EncryptedKey(EncryptedKeyType):
class EncryptedKey(EncryptedKeyType_):
"""The http://www.w3.org/2001/04/xmlenc#:EncryptedKey element """
c_tag = 'EncryptedKey'
c_namespace = NAMESPACE
c_children = EncryptedKeyType.c_children.copy()
c_attributes = EncryptedKeyType.c_attributes.copy()
c_child_order = EncryptedKeyType.c_child_order[:]
c_cardinality = EncryptedKeyType.c_cardinality.copy()
c_children = EncryptedKeyType_.c_children.copy()
c_attributes = EncryptedKeyType_.c_attributes.copy()
c_child_order = EncryptedKeyType_.c_child_order[:]
c_cardinality = EncryptedKeyType_.c_cardinality.copy()
def encrypted_key_from_string(xml_string):
return saml2.create_class_from_xml_string(EncryptedKey, xml_string)
ELEMENT_FROM_STRING = {
EncryptedType.c_tag: encrypted_type_from_string,
EncryptionMethodType.c_tag: encryption_method_type_from_string,
KeySizeType.c_tag: key_size_type_from_string,
EncryptionMethodType_.c_tag: encryption_method_type__from_string,
KeySizeType_.c_tag: key_size_type__from_string,
CipherData.c_tag: cipher_data_from_string,
CipherDataType.c_tag: cipher_data_type_from_string,
CipherDataType_.c_tag: cipher_data_type__from_string,
CipherReference.c_tag: cipher_reference_from_string,
CipherReferenceType.c_tag: cipher_reference_type_from_string,
TransformsType.c_tag: transforms_type_from_string,
CipherReferenceType_.c_tag: cipher_reference_type__from_string,
TransformsType_.c_tag: transforms_type__from_string,
EncryptedData.c_tag: encrypted_data_from_string,
EncryptedDataType.c_tag: encrypted_data_type_from_string,
EncryptedDataType_.c_tag: encrypted_data_type__from_string,
EncryptedKey.c_tag: encrypted_key_from_string,
EncryptedKeyType.c_tag: encrypted_key_type_from_string,
EncryptedKeyType_.c_tag: encrypted_key_type__from_string,
AgreementMethod.c_tag: agreement_method_from_string,
AgreementMethodType.c_tag: agreement_method_type_from_string,
AgreementMethodType_.c_tag: agreement_method_type__from_string,
ReferenceList.c_tag: reference_list_from_string,
ReferenceType.c_tag: reference_type_from_string,
ReferenceType_.c_tag: reference_type__from_string,
EncryptionProperties.c_tag: encryption_properties_from_string,
EncryptionPropertiesType.c_tag: encryption_properties_type_from_string,
EncryptionPropertiesType_.c_tag: encryption_properties_type__from_string,
EncryptionProperty.c_tag: encryption_property_from_string,
EncryptionPropertyType.c_tag: encryption_property_type_from_string,
CipherValue.c_tag: cipher_value_from_string,
KA_Nonce.c_tag: k_a__nonce_from_string,
OriginatorKeyInfo.c_tag: originator_key_info_from_string,
RecipientKeyInfo.c_tag: recipient_key_info_from_string,
KeySize.c_tag: key_size_from_string,
OAEPparams.c_tag: oae_pparams_from_string,
Transforms.c_tag: transforms_from_string,
EncryptionMethod.c_tag: encryption_method_from_string,
DataReference.c_tag: data_reference_from_string,
KeyReference.c_tag: key_reference_from_string,
CarriedKeyName.c_tag: carried_key_name_from_string,
EncryptionPropertyType_.c_tag: encryption_property_type__from_string,
CipherDataType_CipherValue.c_tag: cipher_data_type__cipher_value_from_string,
AgreementMethodType_KA_Nonce.c_tag: agreement_method_type__k_a__nonce_from_string,
AgreementMethodType_OriginatorKeyInfo.c_tag: agreement_method_type__originator_key_info_from_string,
AgreementMethodType_RecipientKeyInfo.c_tag: agreement_method_type__recipient_key_info_from_string,
EncryptionMethodType_KeySize.c_tag: encryption_method_type__key_size_from_string,
EncryptionMethodType_OAEPparams.c_tag: encryption_method_type__oae_pparams_from_string,
CipherReferenceType_Transforms.c_tag: cipher_reference_type__transforms_from_string,
EncryptedType_EncryptionMethod.c_tag: encrypted_type__encryption_method_from_string,
ReferenceList_DataReference.c_tag: reference_list__data_reference_from_string,
ReferenceList_KeyReference.c_tag: reference_list__key_reference_from_string,
EncryptedKeyType_CarriedKeyName.c_tag: encrypted_key_type__carried_key_name_from_string,
}
ELEMENT_BY_TAG = {
'EncryptedType': EncryptedType,
'EncryptionMethodType': EncryptionMethodType,
'KeySizeType': KeySizeType,
'EncryptionMethodType': EncryptionMethodType_,
'KeySizeType': KeySizeType_,
'CipherData': CipherData,
'CipherDataType': CipherDataType,
'CipherDataType': CipherDataType_,
'CipherReference': CipherReference,
'CipherReferenceType': CipherReferenceType,
'TransformsType': TransformsType,
'CipherReferenceType': CipherReferenceType_,
'TransformsType': TransformsType_,
'EncryptedData': EncryptedData,
'EncryptedDataType': EncryptedDataType,
'EncryptedDataType': EncryptedDataType_,
'EncryptedKey': EncryptedKey,
'EncryptedKeyType': EncryptedKeyType,
'EncryptedKeyType': EncryptedKeyType_,
'AgreementMethod': AgreementMethod,
'AgreementMethodType': AgreementMethodType,
'AgreementMethodType': AgreementMethodType_,
'ReferenceList': ReferenceList,
'ReferenceType': ReferenceType,
'ReferenceType': ReferenceType_,
'EncryptionProperties': EncryptionProperties,
'EncryptionPropertiesType': EncryptionPropertiesType,
'EncryptionPropertiesType': EncryptionPropertiesType_,
'EncryptionProperty': EncryptionProperty,
'EncryptionPropertyType': EncryptionPropertyType,
'CipherValue': CipherValue,
'KA_Nonce': KA_Nonce,
'OriginatorKeyInfo': OriginatorKeyInfo,
'RecipientKeyInfo': RecipientKeyInfo,
'KeySize': KeySize,
'OAEPparams': OAEPparams,
'Transforms': Transforms,
'EncryptionMethod': EncryptionMethod,
'DataReference': DataReference,
'KeyReference': KeyReference,
'CarriedKeyName': CarriedKeyName,
'EncryptionPropertyType': EncryptionPropertyType_,
'CipherValue': CipherDataType_CipherValue,
'KA_Nonce': AgreementMethodType_KA_Nonce,
'OriginatorKeyInfo': AgreementMethodType_OriginatorKeyInfo,
'RecipientKeyInfo': AgreementMethodType_RecipientKeyInfo,
'KeySize': EncryptionMethodType_KeySize,
'OAEPparams': EncryptionMethodType_OAEPparams,
'Transforms': CipherReferenceType_Transforms,
'EncryptionMethod': EncryptedType_EncryptionMethod,
'DataReference': ReferenceList_DataReference,
'KeyReference': ReferenceList_KeyReference,
'CarriedKeyName': EncryptedKeyType_CarriedKeyName,
}
def factory(tag, **kwargs):

View File

@@ -70,17 +70,17 @@ class TestMgmtData:
class TestSPKISexp:
def setup_class(self):
self.spki_sexp = ds.SPKISexp()
self.spki_sexp = ds.SPKIDataType_SPKISexp()
def testAccessors(self):
"""Test for SPKISexp accessors"""
self.spki_sexp.text = "spki sexp"
new_spki_sexp = ds.spki_sexp_from_string(self.spki_sexp.to_string())
new_spki_sexp = ds.spki_data_type__spki_sexp_from_string(self.spki_sexp.to_string())
assert new_spki_sexp.text.strip() == "spki sexp"
def testUsingTestData(self):
"""Test for spki_sexp_from_string() using test data"""
new_spki_sexp = ds.spki_sexp_from_string(ds_data.TEST_SPKI_SEXP)
new_spki_sexp = ds.spki_data_type__spki_sexp_from_string(ds_data.TEST_SPKI_SEXP)
assert new_spki_sexp.text.strip() == "spki sexp"
@@ -92,13 +92,14 @@ class TestSPKIData:
def testAccessors(self):
"""Test for SPKIData accessors"""
self.spki_data.spki_sexp.append(
ds.spki_sexp_from_string(ds_data.TEST_SPKI_SEXP))
ds.spki_data_type__spki_sexp_from_string(ds_data.TEST_SPKI_SEXP))
new_spki_data = ds.spki_data_from_string(self.spki_data.to_string())
assert new_spki_data.spki_sexp[0].text.strip() == "spki sexp"
def testUsingTestData(self):
"""Test for spki_data_from_string() using test data"""
new_spki_data = ds.spki_data_from_string(ds_data.TEST_SPKI_DATA)
print new_spki_data
assert new_spki_data.spki_sexp[0].text.strip() == "spki sexp"
assert new_spki_data.spki_sexp[1].text.strip() == "spki sexp2"
@@ -110,19 +111,19 @@ class TestPGPData:
def testAccessors(self):
"""Test for PGPData accessors"""
self.pgp_data.pgp_key_id = ds.PGPKeyID(text="pgp key id")
self.pgp_data.pgp_key_packet = ds.PGPKeyPacket(text="pgp key packet")
self.pgp_data.pgp_key_id = ds.PGPDataType_PGPKeyID(text="pgp key id")
self.pgp_data.pgp_key_packet = ds.PGPDataType_PGPKeyPacket(text="pgp key packet")
new_pgp_data = ds.pgp_data_from_string(self.pgp_data.to_string())
assert isinstance(new_pgp_data.pgp_key_id, ds.PGPKeyID)
assert isinstance(new_pgp_data.pgp_key_packet, ds.PGPKeyPacket)
assert isinstance(new_pgp_data.pgp_key_id, ds.PGPDataType_PGPKeyID)
assert isinstance(new_pgp_data.pgp_key_packet, ds.PGPDataType_PGPKeyPacket)
assert new_pgp_data.pgp_key_id.text.strip() == "pgp key id"
assert new_pgp_data.pgp_key_packet.text.strip() == "pgp key packet"
def testUsingTestData(self):
"""Test for pgp_data_from_string() using test data"""
new_pgp_data = ds.pgp_data_from_string(ds_data.TEST_PGP_DATA)
assert isinstance(new_pgp_data.pgp_key_id, ds.PGPKeyID)
assert isinstance(new_pgp_data.pgp_key_packet, ds.PGPKeyPacket)
assert isinstance(new_pgp_data.pgp_key_id, ds.PGPDataType_PGPKeyID)
assert isinstance(new_pgp_data.pgp_key_packet, ds.PGPDataType_PGPKeyPacket)
assert new_pgp_data.pgp_key_id.text.strip() == "pgp key id"
assert new_pgp_data.pgp_key_packet.text.strip() == "pgp key packet"
@@ -130,14 +131,14 @@ class TestPGPData:
class TestX509IssuerSerial:
def setup_class(self):
self.x509_issuer_serial = ds.X509IssuerSerialType()
self.x509_issuer_serial = ds.X509IssuerSerialType_()
def testAccessors(self):
"""Test for X509SerialNumber accessors"""
self.x509_issuer_serial.x509_issuer_name = ds.X509IssuerName(
self.x509_issuer_serial.x509_issuer_name = ds.X509IssuerSerialType_X509IssuerName(
text="issuer name")
self.x509_issuer_serial.x509_serial_number = ds.X509SerialNumber(text="1")
new_x509_issuer_serial = ds.x509_issuer_serial_type_from_string(
self.x509_issuer_serial.x509_serial_number = ds.X509IssuerSerialType_X509SerialNumber(text="1")
new_x509_issuer_serial = ds.x509_issuer_serial_type__from_string(
self.x509_issuer_serial.to_string())
assert new_x509_issuer_serial.x509_issuer_name.text.strip() == \
"issuer name"
@@ -145,7 +146,7 @@ class TestX509IssuerSerial:
def testUsingTestData(self):
"""Test for x509_issuer_serial_from_string() using test data"""
new_x509_issuer_serial = ds.x509_issuer_serial_from_string(
new_x509_issuer_serial = ds.x509_data_type__x509_issuer_serial_from_string(
ds_data.TEST_X509_ISSUER_SERIAL)
assert new_x509_issuer_serial.x509_issuer_name.text.strip() == \
"issuer name"
@@ -159,52 +160,52 @@ class TestX509Data:
def testAccessors(self):
"""Test for X509Data accessors"""
st = ds.x509_issuer_serial_from_string(ds_data.TEST_X509_ISSUER_SERIAL)
st = ds.x509_data_type__x509_issuer_serial_from_string(ds_data.TEST_X509_ISSUER_SERIAL)
print st
self.x509_data.x509_issuer_serial= st
self.x509_data.x509_ski = ds.X509SKI(text="x509 ski")
self.x509_data.x509_subject_name = ds.X509SubjectName(
self.x509_data.x509_ski = ds.X509DataType_X509SKI(text="x509 ski")
self.x509_data.x509_subject_name = ds.X509DataType_X509SubjectName(
text="x509 subject name")
self.x509_data.x509_certificate = ds.X509Certificate(
self.x509_data.x509_certificate = ds.X509DataType_X509Certificate(
text="x509 certificate")
self.x509_data.x509_crl = ds.X509CRL(text="x509 crl")
self.x509_data.x509_crl = ds.X509DataType_X509CRL(text="x509 crl")
new_x509_data = ds.x509_data_from_string(self.x509_data.to_string())
print new_x509_data.keyswv()
print new_x509_data.__dict__.keys()
assert new_x509_data.x509_issuer_serial
assert isinstance(new_x509_data.x509_issuer_serial,
ds.X509IssuerSerialType)
ds.X509DataType_X509IssuerSerial)
assert new_x509_data.x509_ski.text.strip() == "x509 ski"
assert isinstance(new_x509_data.x509_ski, ds.X509SKI)
assert isinstance(new_x509_data.x509_ski, ds.X509DataType_X509SKI)
assert new_x509_data.x509_subject_name.text.strip() == \
"x509 subject name"
assert isinstance(new_x509_data.x509_subject_name,
ds.X509SubjectName)
ds.X509DataType_X509SubjectName)
assert new_x509_data.x509_certificate.text.strip() == \
"x509 certificate"
assert isinstance(new_x509_data.x509_certificate,
ds.X509Certificate)
ds.X509DataType_X509Certificate)
assert new_x509_data.x509_crl.text.strip() == "x509 crl"
assert isinstance(new_x509_data.x509_crl,ds.X509CRL)
assert isinstance(new_x509_data.x509_crl,ds.X509DataType_X509CRL)
def testUsingTestData(self):
"""Test for x509_data_from_string() using test data"""
new_x509_data = ds.x509_data_from_string(ds_data.TEST_X509_DATA)
assert isinstance(new_x509_data.x509_issuer_serial,
ds.X509IssuerSerial)
ds.X509DataType_X509IssuerSerial)
assert new_x509_data.x509_ski.text.strip() == "x509 ski"
assert isinstance(new_x509_data.x509_ski, ds.X509SKI)
assert isinstance(new_x509_data.x509_ski, ds.X509DataType_X509SKI)
assert new_x509_data.x509_subject_name.text.strip() == \
"x509 subject name"
assert isinstance(new_x509_data.x509_subject_name,
ds.X509SubjectName)
ds.X509DataType_X509SubjectName)
assert new_x509_data.x509_certificate.text.strip() == \
"x509 certificate"
assert isinstance(new_x509_data.x509_certificate,
ds.X509Certificate)
ds.X509DataType_X509Certificate)
assert new_x509_data.x509_crl.text.strip() == "x509 crl"
assert isinstance(new_x509_data.x509_crl,ds.X509CRL)
assert isinstance(new_x509_data.x509_crl,ds.X509DataType_X509CRL)
class TestTransform:
@@ -214,17 +215,17 @@ class TestTransform:
def testAccessors(self):
"""Test for Transform accessors"""
self.transform.x_path.append(ds.XPath(text="xpath"))
self.transform.x_path.append(ds.TransformType_XPath(text="xpath"))
self.transform.algorithm = ds.TRANSFORM_ENVELOPED
new_transform = ds.transform_from_string(self.transform.to_string())
assert isinstance(new_transform.x_path[0], ds.XPath)
assert isinstance(new_transform.x_path[0], ds.TransformType_XPath)
assert new_transform.x_path[0].text.strip() == "xpath"
assert new_transform.algorithm == ds.TRANSFORM_ENVELOPED
def testUsingTestData(self):
"""Test for transform_from_string() using test data"""
new_transform = ds.transform_from_string(ds_data.TEST_TRANSFORM)
assert isinstance(new_transform.x_path[0], ds.XPath)
assert isinstance(new_transform.x_path[0], ds.TransformType_XPath)
assert new_transform.x_path[0].text.strip() == "xpath"
assert new_transform.algorithm == ds.TRANSFORM_ENVELOPED
@@ -296,11 +297,11 @@ class TestRSAKeyValue:
def testAccessors(self):
"""Test for RSAKeyValue accessors"""
self.rsa_key_value.modulus = ds.Modulus(text="modulus")
self.rsa_key_value.exponent = ds.Exponent(text="exponent")
self.rsa_key_value.modulus = ds.RSAKeyValueType_Modulus(text="modulus")
self.rsa_key_value.exponent = ds.RSAKeyValueType_Exponent(text="exponent")
new_rsa_key_value = ds.rsa_key_value_from_string(self.rsa_key_value.to_string())
assert isinstance(new_rsa_key_value.modulus, ds.Modulus)
assert isinstance(new_rsa_key_value.exponent, ds.Exponent)
assert isinstance(new_rsa_key_value.modulus, ds.RSAKeyValueType_Modulus)
assert isinstance(new_rsa_key_value.exponent, ds.RSAKeyValueType_Exponent)
assert new_rsa_key_value.modulus.text.strip() == "modulus"
assert new_rsa_key_value.exponent.text.strip() == "exponent"
@@ -308,8 +309,8 @@ class TestRSAKeyValue:
"""Test for rsa_key_value_from_string() using test data"""
new_rsa_key_value = ds.rsa_key_value_from_string(
ds_data.TEST_RSA_KEY_VALUE)
assert isinstance(new_rsa_key_value.modulus, ds.Modulus)
assert isinstance(new_rsa_key_value.exponent, ds.Exponent)
assert isinstance(new_rsa_key_value.modulus, ds.RSAKeyValueType_Modulus)
assert isinstance(new_rsa_key_value.exponent, ds.RSAKeyValueType_Exponent)
assert new_rsa_key_value.modulus.text.strip() == "modulus"
assert new_rsa_key_value.exponent.text.strip() == "exponent"
@@ -321,21 +322,21 @@ class TestDSAKeyValue:
def testAccessors(self):
"""Test for DSAKeyValue accessors"""
self.dsa_key_value.p = ds.P(text="p")
self.dsa_key_value.q = ds.Q(text="q")
self.dsa_key_value.g = ds.G(text="g")
self.dsa_key_value.y = ds.Y(text="y")
self.dsa_key_value.j = ds.J(text="j")
self.dsa_key_value.seed = ds.Seed(text="seed")
self.dsa_key_value.pgen_counter = ds.PgenCounter(text="pgen counter")
self.dsa_key_value.p = ds.DSAKeyValueType_P(text="p")
self.dsa_key_value.q = ds.DSAKeyValueType_Q(text="q")
self.dsa_key_value.g = ds.DSAKeyValueType_G(text="g")
self.dsa_key_value.y = ds.DSAKeyValueType_Y(text="y")
self.dsa_key_value.j = ds.DSAKeyValueType_J(text="j")
self.dsa_key_value.seed = ds.DSAKeyValueType_Seed(text="seed")
self.dsa_key_value.pgen_counter = ds.DSAKeyValueType_PgenCounter(text="pgen counter")
new_dsa_key_value = ds.dsa_key_value_from_string(self.dsa_key_value.to_string())
assert isinstance(new_dsa_key_value.p, ds.P)
assert isinstance(new_dsa_key_value.q, ds.Q)
assert isinstance(new_dsa_key_value.g, ds.G)
assert isinstance(new_dsa_key_value.y, ds.Y)
assert isinstance(new_dsa_key_value.j, ds.J)
assert isinstance(new_dsa_key_value.seed, ds.Seed)
assert isinstance(new_dsa_key_value.pgen_counter, ds.PgenCounter)
assert isinstance(new_dsa_key_value.p, ds.DSAKeyValueType_P)
assert isinstance(new_dsa_key_value.q, ds.DSAKeyValueType_Q)
assert isinstance(new_dsa_key_value.g, ds.DSAKeyValueType_G)
assert isinstance(new_dsa_key_value.y, ds.DSAKeyValueType_Y)
assert isinstance(new_dsa_key_value.j, ds.DSAKeyValueType_J)
assert isinstance(new_dsa_key_value.seed, ds.DSAKeyValueType_Seed)
assert isinstance(new_dsa_key_value.pgen_counter, ds.DSAKeyValueType_PgenCounter)
assert new_dsa_key_value.p.text.strip() == "p"
assert new_dsa_key_value.q.text.strip() == "q"
assert new_dsa_key_value.g.text.strip() == "g"
@@ -348,13 +349,13 @@ class TestDSAKeyValue:
"""Test for dsa_key_value_from_string() using test data"""
new_dsa_key_value = ds.dsa_key_value_from_string(
ds_data.TEST_DSA_KEY_VALUE)
assert isinstance(new_dsa_key_value.p, ds.P)
assert isinstance(new_dsa_key_value.q, ds.Q)
assert isinstance(new_dsa_key_value.g, ds.G)
assert isinstance(new_dsa_key_value.y, ds.Y)
assert isinstance(new_dsa_key_value.j, ds.J)
assert isinstance(new_dsa_key_value.seed, ds.Seed)
assert isinstance(new_dsa_key_value.pgen_counter, ds.PgenCounter)
assert isinstance(new_dsa_key_value.p, ds.DSAKeyValueType_P)
assert isinstance(new_dsa_key_value.q, ds.DSAKeyValueType_Q)
assert isinstance(new_dsa_key_value.g, ds.DSAKeyValueType_G)
assert isinstance(new_dsa_key_value.y, ds.DSAKeyValueType_Y)
assert isinstance(new_dsa_key_value.j, ds.DSAKeyValueType_J)
assert isinstance(new_dsa_key_value.seed, ds.DSAKeyValueType_Seed)
assert isinstance(new_dsa_key_value.pgen_counter, ds.DSAKeyValueType_PgenCounter)
assert new_dsa_key_value.p.text.strip() == "p"
assert new_dsa_key_value.q.text.strip() == "q"
assert new_dsa_key_value.g.text.strip() == "g"
@@ -535,11 +536,11 @@ class TestSignatureMethod:
def testAccessors(self):
"""Test for SignatureMethod accessors"""
self.signature_method.algorithm = ds.SIG_RSA_SHA1
self.signature_method.hmac_output_length = ds.HMACOutputLength(text="8")
self.signature_method.hmac_output_length = ds.SignatureMethodType_HMACOutputLength(text="8")
new_signature_method = ds.signature_method_from_string(
self.signature_method.to_string())
assert isinstance(new_signature_method.hmac_output_length,
ds.HMACOutputLength)
ds.SignatureMethodType_HMACOutputLength)
assert new_signature_method.hmac_output_length.text.strip() == "8"
assert new_signature_method.algorithm == ds.SIG_RSA_SHA1
@@ -548,7 +549,7 @@ class TestSignatureMethod:
new_signature_method = ds.signature_method_from_string(
ds_data.TEST_SIGNATURE_METHOD)
assert isinstance(new_signature_method.hmac_output_length,
ds.HMACOutputLength)
ds.SignatureMethodType_HMACOutputLength)
assert new_signature_method.hmac_output_length.text.strip() == "8"
assert new_signature_method.algorithm == ds.SIG_RSA_SHA1

View File

@@ -729,13 +729,13 @@ class TestOneTimeUse:
def testAccessors(self):
"""Test for OneTimeUse accessors"""
assert isinstance(self.one_time_use, saml.OneTimeUse)
assert isinstance(self.one_time_use, saml.ConditionAbstractType)
assert isinstance(self.one_time_use, saml.ConditionAbstractType_)
def testUsingTestData(self):
"""Test one_time_use_from_string() using test data"""
one_time_use = saml.one_time_use_from_string(saml2_data.TEST_ONE_TIME_USE)
assert isinstance(one_time_use, saml.OneTimeUse)
assert isinstance(one_time_use, saml.ConditionAbstractType)
assert isinstance(one_time_use, saml.ConditionAbstractType_)
class TestProxyRestriction:
@@ -746,7 +746,7 @@ class TestProxyRestriction:
def testAccessors(self):
"""Test for ProxyRestriction accessors"""
assert isinstance(self.proxy_restriction, saml.ConditionAbstractType)
assert isinstance(self.proxy_restriction, saml.ConditionAbstractType_)
self.proxy_restriction.count = "2"
self.proxy_restriction.audience.append(saml.audience_from_string(
saml2_data.TEST_AUDIENCE))

View File

@@ -33,36 +33,36 @@ from saml2 import samlp
import xmldsig as ds
class TestRequestAbstractType:
def setup_class(self):
self.ar = samlp.RequestAbstractType()
def testAccessors(self):
"""Test for RequestAbstractType accessors"""
self.ar.id = "request id"
self.ar.version = saml2.VERSION
self.ar.issue_instant = "2007-09-14T01:05:02Z"
self.ar.destination = "http://www.example.com/Destination"
self.ar.consent = saml.CONSENT_UNSPECIFIED
self.ar.issuer = saml.Issuer()
self.ar.signature = ds.Signature()
self.ar.extensions = samlp.Extensions()
new_ar = samlp.request_abstract_type_from_string(self.ar.to_string())
assert new_ar.id == "request id"
assert new_ar.version == saml2.VERSION
assert new_ar.issue_instant == "2007-09-14T01:05:02Z"
assert new_ar.destination == "http://www.example.com/Destination"
assert new_ar.consent == saml.CONSENT_UNSPECIFIED
assert isinstance(new_ar.issuer, saml.Issuer)
assert isinstance(new_ar.signature, ds.Signature)
assert isinstance(new_ar.extensions, samlp.Extensions)
def testUsingTestData(self):
"""Test for request_abstract_type_from_string() using test data"""
# TODO:
pass
# class TestRequestAbstractType:
#
# def setup_class(self):
# self.ar = samlp.RequestAbstractType_()
#
# def testAccessors(self):
# """Test for RequestAbstractType accessors"""
# self.ar.id = "request id"
# self.ar.version = saml2.VERSION
# self.ar.issue_instant = "2007-09-14T01:05:02Z"
# self.ar.destination = "http://www.example.com/Destination"
# self.ar.consent = saml.CONSENT_UNSPECIFIED
# self.ar.issuer = saml.Issuer()
# self.ar.signature = ds.Signature()
# self.ar.extensions = samlp.Extensions()
#
# new_ar = samlp.request_abstract_type__from_string(self.ar.to_string())
# assert new_ar.id == "request id"
# assert new_ar.version == saml2.VERSION
# assert new_ar.issue_instant == "2007-09-14T01:05:02Z"
# assert new_ar.destination == "http://www.example.com/Destination"
# assert new_ar.consent == saml.CONSENT_UNSPECIFIED
# assert isinstance(new_ar.issuer, saml.Issuer)
# assert isinstance(new_ar.signature, ds.Signature)
# assert isinstance(new_ar.extensions, samlp.Extensions)
#
# def testUsingTestData(self):
# """Test for request_abstract_type_from_string() using test data"""
# # TODO:
# pass
class TestStatusDetail:
@@ -135,40 +135,40 @@ class TestStatus:
assert isinstance(new_status.status_message, samlp.StatusMessage)
assert isinstance(new_status.status_detail, samlp.StatusDetail)
class TestStatusResponseType:
def setup_class(self):
self.sr = samlp.StatusResponseType()
def testAccessors(self):
"""Test for StatusResponseType accessors"""
self.sr.id = "response id"
self.sr.in_response_to = "request id"
self.sr.version = saml2.VERSION
self.sr.issue_instant = "2007-09-14T01:05:02Z"
self.sr.destination = "http://www.example.com/Destination"
self.sr.consent = saml.CONSENT_UNSPECIFIED
self.sr.issuer = saml.Issuer()
self.sr.signature = ds.Signature()
self.sr.extensions = samlp.Extensions()
self.sr.status = samlp.Status()
new_sr = samlp.status_response_type_from_string(self.sr.to_string())
assert new_sr.id == "response id"
assert new_sr.in_response_to == "request id"
assert new_sr.version == saml2.VERSION
assert new_sr.issue_instant == "2007-09-14T01:05:02Z"
assert new_sr.destination == "http://www.example.com/Destination"
assert new_sr.consent == saml.CONSENT_UNSPECIFIED
assert isinstance(new_sr.issuer, saml.Issuer)
assert isinstance(new_sr.signature, ds.Signature)
assert isinstance(new_sr.extensions, samlp.Extensions)
assert isinstance(new_sr.status, samlp.Status)
def testUsingTestData(self):
"""Test for status_response_from_string() using test data"""
# TODO:
pass
# class TestStatusResponseType:
#
# def setup_class(self):
# self.sr = samlp.StatusResponseType()
#
# def testAccessors(self):
# """Test for StatusResponseType accessors"""
# self.sr.id = "response id"
# self.sr.in_response_to = "request id"
# self.sr.version = saml2.VERSION
# self.sr.issue_instant = "2007-09-14T01:05:02Z"
# self.sr.destination = "http://www.example.com/Destination"
# self.sr.consent = saml.CONSENT_UNSPECIFIED
# self.sr.issuer = saml.Issuer()
# self.sr.signature = ds.Signature()
# self.sr.extensions = samlp.Extensions()
# self.sr.status = samlp.Status()
#
# new_sr = samlp.status_response_type_from_string(self.sr.to_string())
# assert new_sr.id == "response id"
# assert new_sr.in_response_to == "request id"
# assert new_sr.version == saml2.VERSION
# assert new_sr.issue_instant == "2007-09-14T01:05:02Z"
# assert new_sr.destination == "http://www.example.com/Destination"
# assert new_sr.consent == saml.CONSENT_UNSPECIFIED
# assert isinstance(new_sr.issuer, saml.Issuer)
# assert isinstance(new_sr.signature, ds.Signature)
# assert isinstance(new_sr.extensions, samlp.Extensions)
# assert isinstance(new_sr.status, samlp.Status)
#
# def testUsingTestData(self):
# """Test for status_response_from_string() using test data"""
# # TODO:
# pass
class TestResponse:

View File

@@ -39,7 +39,7 @@ import md_data, ds_data
class TestEndpointType:
def setup_class(self):
self.endpoint = md.EndpointType()
self.endpoint = md.EndpointType_()
def testAccessors(self):
"""Test for EndpointType accessors"""
@@ -47,14 +47,14 @@ class TestEndpointType:
self.endpoint.location = "http://www.example.com/endpoint"
self.endpoint.response_location = "http://www.example.com/response"
print self.endpoint.__class__.c_attributes.items()
new_endpoint = md.endpoint_type_from_string(self.endpoint.to_string())
new_endpoint = md.endpoint_type__from_string(self.endpoint.to_string())
assert new_endpoint.binding == saml2.BINDING_HTTP_POST
assert new_endpoint.location == "http://www.example.com/endpoint"
assert new_endpoint.response_location == "http://www.example.com/response"
def testUsingTestData(self):
"""Test for endpoint_type_from_string() using test data."""
new_endpoint = md.endpoint_type_from_string(md_data.TEST_ENDPOINT)
new_endpoint = md.endpoint_type__from_string(md_data.TEST_ENDPOINT)
assert new_endpoint.binding == saml2.BINDING_HTTP_POST
assert new_endpoint.location == "http://www.example.com/endpoint"
assert new_endpoint.response_location == "http://www.example.com/response"
@@ -63,7 +63,7 @@ class TestEndpointType:
class TestIndexedEndpointType:
def setup_class(self):
self.i_e = md.IndexedEndpointType()
self.i_e = md.IndexedEndpointType_()
def testAccessors(self):
"""Test for IndexedEndpointType accessors"""
@@ -72,7 +72,7 @@ class TestIndexedEndpointType:
self.i_e.response_location = "http://www.example.com/response"
self.i_e.index = "1"
self.i_e.is_default = "false"
new_i_e = md.indexed_endpoint_type_from_string(self.i_e.to_string())
new_i_e = md.indexed_endpoint_type__from_string(self.i_e.to_string())
assert new_i_e.binding == saml2.BINDING_HTTP_POST
assert new_i_e.location == "http://www.example.com/endpoint"
assert new_i_e.response_location == "http://www.example.com/response"
@@ -81,7 +81,7 @@ class TestIndexedEndpointType:
def testUsingTestData(self):
"""Test for indexed_endpoint_type_from_string() using test data."""
new_i_e = md.indexed_endpoint_type_from_string(md_data.TEST_INDEXED_ENDPOINT)
new_i_e = md.indexed_endpoint_type__from_string(md_data.TEST_INDEXED_ENDPOINT)
assert new_i_e.binding == saml2.BINDING_HTTP_POST
assert new_i_e.location == "http://www.example.com/endpoint"
assert new_i_e.response_location == "http://www.example.com/response"
@@ -424,55 +424,55 @@ class TestRoleDescriptor:
assert isinstance(new_role_descriptor.contact_person[0],
md.ContactPerson)
class TestSSODescriptor:
def setup_class(self):
self.sso_descriptor = md.SSODescriptorType()
def testAccessors(self):
"""Test for SSODescriptorType accessors"""
self.sso_descriptor.id = "ID"
self.sso_descriptor.valid_until = "2008-09-14T01:05:02Z"
self.sso_descriptor.cache_duration = "10:00:00:00"
self.sso_descriptor.protocol_support_enumeration = samlp.NAMESPACE
self.sso_descriptor.error_url = "http://www.example.com/errorURL"
self.sso_descriptor.signature = ds.Signature()
self.sso_descriptor.extensions = md.Extensions()
self.sso_descriptor.key_descriptor.append(md.key_descriptor_from_string(
md_data.TEST_KEY_DESCRIPTOR))
self.sso_descriptor.organization = md.Organization()
self.sso_descriptor.contact_person.append(md.ContactPerson())
self.sso_descriptor.artifact_resolution_service.append(
md.ArtifactResolutionService())
self.sso_descriptor.single_logout_service.append(
md.SingleLogoutService())
self.sso_descriptor.manage_name_id_service.append(
md.ManageNameIDService())
self.sso_descriptor.name_id_format.append(
md.NameIDFormat())
new_sso_descriptor = md.sso_descriptor_type_from_string(
self.sso_descriptor.to_string())
assert new_sso_descriptor.id == "ID"
assert new_sso_descriptor.valid_until == "2008-09-14T01:05:02Z"
assert new_sso_descriptor.cache_duration == "10:00:00:00"
assert new_sso_descriptor.protocol_support_enumeration == samlp.NAMESPACE
assert new_sso_descriptor.error_url == "http://www.example.com/errorURL"
assert isinstance(new_sso_descriptor.signature, ds.Signature)
assert isinstance(new_sso_descriptor.extensions, md.Extensions)
assert isinstance(new_sso_descriptor.key_descriptor[0],
md.KeyDescriptor)
assert isinstance(new_sso_descriptor.organization, md.Organization)
assert isinstance(new_sso_descriptor.contact_person[0],
md.ContactPerson)
assert isinstance(new_sso_descriptor.artifact_resolution_service[0],
md.ArtifactResolutionService)
assert isinstance(new_sso_descriptor.single_logout_service[0],
md.SingleLogoutService)
assert isinstance(new_sso_descriptor.manage_name_id_service[0],
md.ManageNameIDService)
assert isinstance(new_sso_descriptor.name_id_format[0],
md.NameIDFormat)
# class TestSSODescriptor:
# def setup_class(self):
# self.sso_descriptor = md.SSODescriptorType_()
#
# def testAccessors(self):
# """Test for SSODescriptorType accessors"""
# self.sso_descriptor.id = "ID"
# self.sso_descriptor.valid_until = "2008-09-14T01:05:02Z"
# self.sso_descriptor.cache_duration = "10:00:00:00"
# self.sso_descriptor.protocol_support_enumeration = samlp.NAMESPACE
# self.sso_descriptor.error_url = "http://www.example.com/errorURL"
# self.sso_descriptor.signature = ds.Signature()
# self.sso_descriptor.extensions = md.Extensions()
# self.sso_descriptor.key_descriptor.append(md.key_descriptor_from_string(
# md_data.TEST_KEY_DESCRIPTOR))
# self.sso_descriptor.organization = md.Organization()
# self.sso_descriptor.contact_person.append(md.ContactPerson())
# self.sso_descriptor.artifact_resolution_service.append(
# md.ArtifactResolutionService())
# self.sso_descriptor.single_logout_service.append(
# md.SingleLogoutService())
# self.sso_descriptor.manage_name_id_service.append(
# md.ManageNameIDService())
# self.sso_descriptor.name_id_format.append(
# md.NameIDFormat())
#
# new_sso_descriptor = md.sso_descriptor_type__from_string(
# self.sso_descriptor.to_string())
# assert new_sso_descriptor.id == "ID"
# assert new_sso_descriptor.valid_until == "2008-09-14T01:05:02Z"
# assert new_sso_descriptor.cache_duration == "10:00:00:00"
# assert new_sso_descriptor.protocol_support_enumeration == samlp.NAMESPACE
# assert new_sso_descriptor.error_url == "http://www.example.com/errorURL"
# assert isinstance(new_sso_descriptor.signature, ds.Signature)
# assert isinstance(new_sso_descriptor.extensions, md.Extensions)
# assert isinstance(new_sso_descriptor.key_descriptor[0],
# md.KeyDescriptor)
# assert isinstance(new_sso_descriptor.organization, md.Organization)
# assert isinstance(new_sso_descriptor.contact_person[0],
# md.ContactPerson)
# assert isinstance(new_sso_descriptor.artifact_resolution_service[0],
# md.ArtifactResolutionService)
# assert isinstance(new_sso_descriptor.single_logout_service[0],
# md.SingleLogoutService)
# assert isinstance(new_sso_descriptor.manage_name_id_service[0],
# md.ManageNameIDService)
# assert isinstance(new_sso_descriptor.name_id_format[0],
# md.NameIDFormat)
#
class TestArtifactResolutionService:
@@ -811,14 +811,14 @@ class TestRequestedAttribute:
def testAccessors(self):
"""Test for RequestedAttribute accessors"""
assert isinstance(self.requested_attribute, saml.AttributeType)
assert isinstance(self.requested_attribute, saml.AttributeType_)
assert isinstance(self.requested_attribute, md.RequestedAttribute)
assert self.requested_attribute.is_required is None
self.requested_attribute.is_required = "true"
new_requested_attribute = md.requested_attribute_from_string(
self.requested_attribute.to_string())
assert new_requested_attribute.is_required == "true"
assert isinstance(new_requested_attribute, saml.AttributeType)
assert isinstance(new_requested_attribute, saml.AttributeType_)
assert isinstance(new_requested_attribute, md.RequestedAttribute)
def testUsingTestData(self):
@@ -826,7 +826,7 @@ class TestRequestedAttribute:
new_requested_attribute = md.requested_attribute_from_string(
md_data.TEST_REQUESTED_ATTRIBUTE)
assert new_requested_attribute.is_required == "true"
assert isinstance(new_requested_attribute, saml.AttributeType)
assert isinstance(new_requested_attribute, saml.AttributeType_)
assert isinstance(new_requested_attribute, md.RequestedAttribute)

View File

@@ -9,14 +9,16 @@ def _eq(l1,l2):
BASIC_NF = 'urn:oasis:names:tc:SAML:2.0:attrname-format:basic'
URI_NF = 'urn:oasis:names:tc:SAML:2.0:attrname-format:uri'
SAML1 = 'urn:mace:shibboleth:1.0:attributeNamespace:uri'
class TestAC():
def setup_class(self):
self.acs = attribute_converter.ac_factory("attributemaps")
def test_setup(self):
assert len(self.acs) == 2
assert _eq([a.name_format for a in self.acs],[BASIC_NF, URI_NF] )
print self.acs
assert len(self.acs) == 3
assert _eq([a.name_format for a in self.acs],[BASIC_NF, URI_NF, SAML1] )
def test_ava_fro_1(self):

View File

@@ -97,11 +97,56 @@ def _mod_typ(prop):
try:
(mod, typ) = prop.ref
except ValueError:
typ = prop.ref
if prop.class_name:
typ = prop.class_name
else:
typ = prop.ref
mod = None
return (mod, typ)
def _mod_cname(prop, cdict):
if hasattr(prop, "scoped"):
cname = prop.class_name
mod = None
else:
(mod, typ) = _mod_typ(prop)
if not mod:
cname = cdict[typ].class_name
else:
cname = typ
return (mod, cname)
def leading_uppercase(string):
try:
return string[0].upper()+string[1:]
except IndexError:
return string
except TypeError:
return ""
def leading_lowercase(string):
try:
return string[0].lower()+string[1:]
except IndexError:
return string
except TypeError:
return ""
def rm_duplicates(lista):
res = []
for item in lista:
if item not in res:
res.append(item)
return res
def klass_namn(obj):
if obj.class_name:
return obj.class_name
else:
return obj.name
class PyObj(object):
def __init__(self, name=None, pyname=None, root=None):
self.name = name
@@ -111,6 +156,7 @@ class PyObj(object):
self.superior = []
self.value_type = ""
self.properties = ([], [])
self.abstract = False
if pyname:
self.pyname = pyname
@@ -135,6 +181,15 @@ class PyObj(object):
else:
return "c_children['%s'] = ('%s', %s)" % (
key, prop.pyname, typ)
def knamn(self, sup, cdict):
try:
cname = cdict[sup].class_name
except AttributeError:
(namespace,tag) = cdict[sup].name.split('.')
ctag = self.root.modul[namespace].factory(tag).__class__.__name__
cname = '%s.%s' % (namespace,ctag)
return cname
def class_definition(self, target_namespace, cdict=None, ignore=None):
line = []
@@ -148,18 +203,37 @@ class PyObj(object):
try:
superior = self.superior
sups = []
for sup in superior:
imps[sup] = [
c.pyname for c in cdict[sup].properties[0] if c.pyname]
try:
cname = cdict[sup].class_name
except AttributeError:
cname = cdict[sup].name
(namespace,tag) = cname.split('.')
ctag = self.root.modul[namespace].factory(tag).__class__.__name__
cname = '%s.%s' % (namespace,ctag)
klass = self.knamn(sup, cdict)
sups.append(klass)
imps[klass] = []
for c in cdict[sup].properties[0]:
if c.pyname and c.pyname not in imps[klass]:
imps[klass].append(c.pyname)
except AttributeError:
superior = []
sups = []
c_name = klass_namn(self)
if not superior:
line.append("class %s(SamlBase):" % (self.name,))
line.append("class %s(SamlBase):" % (c_name,))
else:
line.append("class %s(%s):" % (self.name, ",".join(superior)))
line.append("class %s(%s):" % (c_name, ",".join(sups)))
line.append("%s\"\"\"The %s:%s element \"\"\"" % (INDENT,
if hasattr(self, 'scoped'):
pass
else:
line.append("%s\"\"\"The %s:%s element \"\"\"" % (INDENT,
target_namespace,
self.name))
line.append("")
@@ -180,7 +254,7 @@ class PyObj(object):
for var, cps in CLASS_PROP:
line.append("%s%s = SamlBase.%s%s" % (INDENT, var, var, cps))
else:
for sup in self.superior:
for sup in sups:
for var, cps in CLASS_PROP:
line.append("%s%s = %s.%s%s" % (INDENT, var, sup, var,
cps))
@@ -203,9 +277,9 @@ class PyObj(object):
args.append((prop.pyname, prop.pyname, None))
elif isinstance(prop, PyElement):
(mod, typ) = _mod_typ(prop)
(mod, cname) = _mod_cname(prop, cdict)
if prop.max == "unbounded":
lista = True
pmax = 0 # just has to be different from 1
@@ -218,7 +292,8 @@ class PyObj(object):
else:
line.append("%s%s" % (INDENT, self.child_spec(
target_namespace, prop,
mod, typ, lista)))
mod, cname,
lista)))
pmin = int(getattr(prop, 'min', 1))
@@ -245,17 +320,21 @@ class PyObj(object):
if args:
if inh:
imps[self.superior[0]] = [c.pyname for c in inh if c.pyname]
cname = self.knamn(self.superior[0], cdict)
imps = {cname: [c.pyname for c in inh if c.pyname]}
line.append("")
line.extend(def_init(imps, args))
line.extend(base_init(imps))
line.extend(initialize(args))
line.append("")
line.append("def %s_from_string(xml_string):" % self.pyname)
line.append(
"%sreturn saml2.create_class_from_xml_string(%s, xml_string)" % (
INDENT,self.name))
if not self.abstract or not self.class_name.endswith("_"):
line.append("def %s_from_string(xml_string):" % pyify(
self.class_name))
line.append(
"%sreturn saml2.create_class_from_xml_string(%s, xml_string)" % (
INDENT,self.class_name))
line.append("")
self.done = True
return "\n".join(line)
@@ -274,6 +353,14 @@ def pyobj_factory(name, value_type, elms=None):
if name not in [c.name for c in elms]:
elms.append(pyobj)
return pyobj
def pyelement_factory(name, value_type, elms=None):
obj = PyElement(name, pyify(name))
obj.value_type = value_type
if elms:
if name not in [c.name for c in elms]:
elms.append(obj)
return obj
def rm_duplicates(properties):
keys = []
@@ -285,10 +372,26 @@ def rm_duplicates(properties):
clist.append(prop)
keys.append(prop.name)
return clist
def expand_groups(properties, cdict):
res = []
for prop in properties:
if isinstance(prop, PyGroup):
# only own, what about inherited ? Not on groups ?
cname = prop.ref[1]
res.extend(cdict[cname].properties[0])
else:
res.append(prop)
return res
class PyElement(PyObj):
def __init__(self, name=None, pyname=None, root=None):
def __init__(self, name=None, pyname=None, root=None, parent=""):
PyObj.__init__(self, name, pyname, root)
if parent:
self.class_name = "%s_%s" % (leading_uppercase(parent),self.name)
else:
self.class_name = leading_uppercase(self.name)
self.ref = None
self.min = 1
self.max = 1
@@ -307,18 +410,20 @@ class PyElement(PyObj):
try:
(mod, typ) = self.type
if not mod:
if not cdict[typ].done:
return ([cdict[typ]], [])
cname = leading_uppercase(typ)
if not cdict[cname].done:
return ([cdict[cname]], [])
except ValueError:
pass
except TypeError: # could be a ref then or a PyObj instance
if isinstance(self.type, PyObj):
pass
if isinstance(self.type, PyType):
return self.type.undefined(cdict)
elif isinstance(self.ref, tuple):
pass
else:
if not cdict[self.ref].done:
return ([cdict[self.ref]], [])
cname = leading_uppercase(self.ref)
if not cdict[cname].done:
return ([cdict[cname]], [])
return ([], [])
def text(self, target_namespace, cdict, child=True, ignore=[]):
@@ -343,44 +448,56 @@ class PyElement(PyObj):
ignore)
if not child:
req = [req]
cdict[self.name] = self
cdict[self.name].done = True
if child:
cdict[self.name].local = True
if not hasattr(self, 'scoped'):
cdict[self.name] = self
cdict[self.name].done = True
if child:
cdict[self.name].local = True
self.type = (None, self.name)
else:
imp_name = "%s.%s" % (mod, typ)
# Will raise exception if class can't be found
cname = self.root.modul[mod].factory(typ).__class__.__name__
imp_name = "%s.%s" % (mod, cname)
if imp_name not in cdict:
# create import object so I can get the properties from it
# later
impo = pyobj_factory(imp_name, None, None)
impo = pyelement_factory(imp_name, None, None)
impo.properties = [_import_attrs(self.root.modul[mod], typ,
self.root),[]]
impo.class_name = imp_name
cdict[imp_name] = impo
impo.done = True
if child:
impo.local = True
# and now for this object
self.superior = [imp_name]
text = self.class_definition(target_namespace, cdict)
text = self.class_definition(target_namespace, cdict,
ignore=ignore)
except ValueError: # Simple type element
if self.type:
pyobj = pyobj_factory(self.name, self.type, self.root.elems)
self.type = self.name
cdict[self.name] = pyobj
text = pyobj.class_definition(target_namespace, cdict)
# pyobj = pyelement_factory(self.name, self.type, self.root.elems)
# if hasattr(self, 'scoped'):
# pyobj.class_name = self.class_name
# else:
# self.type = self.name
# cdict[self.name] = pyobj
text = self.class_definition(target_namespace, cdict,
ignore=ignore)
if child:
pyobj.local = True
pyobj.done = True
self.local = True
self.done = True
except TypeError: # could be a ref then or a PyObj instance
if isinstance(self.type, PyObj):
pyobj = self.type
pyobj.name = self.name
pyobj.pyname = self.pyname
pyobj.class_name = self.class_name
cdict[self.name] = pyobj
return pyobj.text(target_namespace, cdict)
return pyobj.text(target_namespace, cdict, ignore=ignore)
elif isinstance(self.ref, tuple):
(mod, typ) = self.ref
if mod:
@@ -393,7 +510,8 @@ class PyElement(PyObj):
typ,mod))
elif not child:
self.superior = [typ]
text = self.class_definition(target_namespace, cdict)
text = self.class_definition(target_namespace, cdict,
ignore=ignore)
else:
if not cdict[self.ref].done:
raise MissingPrerequisite(self.ref)
@@ -438,6 +556,7 @@ class PyType(PyObj):
def __init__(self, name=None, pyname=None, root=None, superior=None,
internal=True, namespace=None):
PyObj.__init__(self, name, pyname, root)
self.class_name = leading_uppercase(self.name + '_')
self.properties = ([], [])
if superior:
self.superior = [superior]
@@ -480,7 +599,7 @@ class PyType(PyObj):
rm_duplicates(inherited_properties))
(own, inh) = self.properties
own = rm_duplicates(own)
own = rm_duplicates(expand_groups(own, cdict))
self.properties = (own, inh)
for prop in own:
if not prop.name: # Ignore
@@ -554,6 +673,27 @@ class PyAttributeGroup(object):
self.root = root
self.properties = []
class PyGroup(object):
def __init__(self, name, root):
self.name = name
self.root = root
self.properties = []
self.done = False
def text(self,target_namespace, _dict, _child, ignore):
return ([], [])
def undefined(self, cdict):
undef = ([], [])
(own, _) = self.properties
for prop in own:
if not prop.name: # Ignore
continue
if not prop.done:
undef[1].append(prop)
return undef
# -----------------------------------------------------------------------------
def verify_import(modul, tag):
try:
@@ -627,7 +767,7 @@ class Simple(object):
self.default = None
self.fixed = None
self.xmlns_map = []
self.name = None
self.name = ""
self.type = None
self.use = None
self.ref = None
@@ -635,15 +775,15 @@ class Simple(object):
for attribute, value in elem.attrib.iteritems():
self.__setattr__(attribute, value)
def collect(self, top, sup, argv=None):
def collect(self, top, sup, argv=None, parent=""):
argv_copy = sd_copy(argv)
rval = self.repr(top, sup, argv_copy)
rval = self.repr(top, sup, argv_copy, parent=parent)
if rval:
return ([rval], [])
else:
return ([], [])
def repr(self, _top=None, _sup=None, _argv=None, _child=True):
def repr(self, _top=None, _sup=None, _argv=None, _child=True, parent=""):
return None
def elements(self, _top):
@@ -652,16 +792,16 @@ class Simple(object):
class Any(Simple):
def repr(self, _top=None, _sup=None, _argv=None, _child=True):
def repr(self, _top=None, _sup=None, _argv=None, _child=True, parent=""):
return PyAny()
class AnyAttribute(Simple):
def repr(self, _top=None, _sup=None, _argv=None, _child=True):
def repr(self, _top=None, _sup=None, _argv=None, _child=True, parent=""):
return PyAny()
class Attribute(Simple):
def repr(self, top=None, sup=None, _argv=None, _child=True):
def repr(self, top=None, sup=None, _argv=None, _child=True, parent=""):
# default, fixed, use, type
if (DEBUG):
@@ -685,6 +825,13 @@ class Attribute(Simple):
name = self.name
pyname = pyify(name)
ref = False
except ValueError: # self.ref exists but does not split into two parts
ref = True
if "" == top.target_namespace:
name = self.ref
pyname = pyify(name)
else: # referering to what
raise Exception("Strange reference: %s" % self.ref)
objekt = PyAttribute(name, pyname, external=external, root=top)
@@ -824,7 +971,7 @@ class Complex(object):
except AttributeError:
pass
def collect(self, top, sup, argv=None):
def collect(self, top, sup, argv=None, parent=""):
if self._own or self._inherited:
return (self._own, self._inherited)
@@ -835,7 +982,7 @@ class Complex(object):
argv_copy = sd_copy(argv)
for part in self.parts:
(own, inh) = part.collect(top, sup, argv_copy)
(own, inh) = part.collect(top, sup, argv_copy, parent=parent)
self._own.extend(own)
self._inherited.extend(inh)
@@ -862,9 +1009,25 @@ class Complex(object):
return res
def repr(self, _top=None, _sup=None, _argv=None, _child=True):
def repr(self, _top=None, _sup=None, _argv=None, _child=True, parent=""):
return None
def min_max(cls, objekt, argv):
try:
objekt.max = argv["maxOccurs"]
if cls.maxOccurs != 1:
objekt.max = cls.maxOccurs
except (KeyError, TypeError):
objekt.max = cls.maxOccurs
try:
objekt.min = argv["minOccurs"]
if cls.minOccurs != 1:
objekt.min = cls.minOccurs
except (KeyError, TypeError):
objekt.min = cls.minOccurs
class Element(Complex):
def __str__(self):
return "%s" % (self.__dict__,)
@@ -893,13 +1056,13 @@ class Element(Complex):
return (namespace, name, ctyp, xns, ref)
def collect(self, top, sup, argv=None):
def collect(self, top, sup, argv=None, parent=""):
""" means this element is part of a larger object, hence a property of
that object """
try:
argv_copy = sd_copy(argv)
return ([self.repr(top, sup, argv_copy)], [])
return ([self.repr(top, sup, argv_copy, parent=parent)], [])
except AttributeError, exc:
print "!!!!", exc
return ([], [])
@@ -913,7 +1076,7 @@ class Element(Complex):
else:
return []
def repr(self, top=None, sup=None, argv=None, child=True):
def repr(self, top=None, sup=None, argv=None, child=True, parent=""):
#<element ref='xenc:ReferenceList' ...
#<element name='Transforms' type='xenc:TransformsType' ...
#<element name='CarriedKeyName' type='string' ...
@@ -931,19 +1094,7 @@ class Element(Complex):
objekt = PyElement(myname, root=top)
try:
objekt.max = argv["maxOccurs"]
if self.maxOccurs != 1:
objekt.max = self.maxOccurs
except (KeyError, TypeError):
objekt.max = self.maxOccurs
try:
objekt.min = argv["minOccurs"]
if self.minOccurs != 1:
objekt.min = self.minOccurs
except (KeyError, TypeError):
objekt.min = self.minOccurs
min_max(self, objekt, argv)
try:
(namespace, superkl) = self.ref.split(":")
@@ -958,32 +1109,45 @@ class Element(Complex):
except AttributeError, exc:
if (DEBUG):
print "#===>", exc
try:
typ = self.type
try:
(namespace, klass) = typ.split(":")
if self.xmlns_map[namespace] == top.target_namespace:
objekt.type = (None, klass)
elif self.xmlns_map[namespace] == XMLSCHEMA:
objekt.type = klass
else:
objekt.type = (namespace, klass)
except ValueError:
objekt.type = typ
typ = self.type
try:
(namespace, klass) = typ.split(":")
if self.xmlns_map[namespace] == top.target_namespace:
objekt.type = (None, klass)
elif self.xmlns_map[namespace] == XMLSCHEMA:
objekt.type = klass
objekt.value_type = {"base": klass}
else:
objekt.type = (namespace, klass)
except ValueError:
objekt.type = typ
objekt.value_type = {"base": typ}
except AttributeError, exc:
# neither type nor reference, definitely local
if hasattr(self, "parts") and len(self.parts) == 1:
if isinstance(self.parts[0], ComplexType):
objekt.type = self.parts[0].repr(top, sup)
objekt.type = self.parts[0].repr(top, sup,
parent=self.name)
objekt.scoped = True
else:
if (DEBUG):
print "$", self
raise Exception()
raise
if parent:
objekt.class_name = "%s_%s" % (
leading_uppercase(parent),
objekt.name)
objekt.scoped = True
return objekt
class SimpleType(Complex):
def repr(self, top=None, _sup=None, _argv=None, _child=True):
def repr(self, top=None, _sup=None, _argv=None, _child=True, parent=""):
obj = PyType(self.name, root=top)
try:
if len(self.parts) == 1:
@@ -1011,7 +1175,7 @@ class SimpleType(Complex):
return obj
class Sequence(Complex):
def collect(self, top, sup, argv=None):
def collect(self, top, sup, argv=None, parent=""):
argv_copy = sd_copy(argv)
for key, val in self.__dict__.items():
if key not in ['xmlns_map'] and not key.startswith("_"):
@@ -1019,7 +1183,7 @@ class Sequence(Complex):
if DEBUG:
print "#Sequence: %s" % argv
return Complex.collect(self, top, sup, argv_copy)
return Complex.collect(self, top, sup, argv_copy, parent)
class SimpleContent(Complex):
pass
@@ -1028,7 +1192,7 @@ class ComplexContent(Complex):
pass
class Extension(Complex):
def collect(self, top, sup, argv=None):
def collect(self, top, sup, argv=None, parent=""):
if self._own or self._inherited:
return (self._own, self._inherited)
@@ -1056,7 +1220,7 @@ class Extension(Complex):
argv_copy = sd_copy(argv)
for part in self.parts:
#print "### ", part
(own, inh) = part.collect(top, sup, argv_copy)
(own, inh) = part.collect(top, sup, argv_copy, parent)
if own:
if len(own) == 1 and isinstance(own[0], PyAttribute):
own[0].base = base
@@ -1067,7 +1231,7 @@ class Extension(Complex):
return (self._own, self._inherited)
class Choice(Complex):
def collect(self, top, sup, argv=None):
def collect(self, top, sup, argv=None, parent=""):
argv_copy = sd_copy(argv)
for key, val in self.__dict__.items():
if key not in ['xmlns_map'] and not key.startswith("_"):
@@ -1078,7 +1242,7 @@ class Choice(Complex):
if DEBUG:
print "#Choice: %s" % argv
return Complex.collect(self, top, sup, argv_copy)
return Complex.collect(self, top, sup, argv_copy, parent=parent)
class Restriction(Complex):
pass
@@ -1086,10 +1250,7 @@ class Restriction(Complex):
# values = [enum.value for enum in self.parts]
class ComplexType(Complex):
def repr(self, top=None, sup=None, _argv=None, _child=True):
if (DEBUG):
print "# -- repr on %s [%s/%s]" % (self.name, self.repr_done,
self._generated)
def repr(self, top=None, sup=None, _argv=None, _child=True, parent=""):
if self.repr_done:
return
@@ -1106,16 +1267,14 @@ class ComplexType(Complex):
if namespace and \
ext.xmlns_map[namespace] == top.target_namespace:
new_sup = name
elif namespace and ext.xmlns_map[namespace] == XMLSCHEMA:
new_sup = None
else:
new_sup = ext.base
if ":" in new_sup:
new_sup = ".".join(new_sup.split(":"))
else:
cti = get_type_def(new_sup, top.parts)
if cti and not cti.repr_done:
cti.repr(top, sup)
elif namespace and ext.xmlns_map[namespace] == XMLSCHEMA:
new_sup = None
else:
#cname = top.modul[namespace].factory(name).__class__.__name__
new_sup = "%s.%s" % (namespace, name)
#print "#Superior: %s" % new_sup
if new_sup:
@@ -1132,7 +1291,18 @@ class ComplexType(Complex):
namespace=top.target_namespace, root=top)
try:
self._class.properties = self.collect(top, sup)
self._class.abstract = self.abstract
except AttributeError:
pass
try:
if not parent:
try:
parent = self.name
except AttributeError:
parent = ""
self._class.properties = self.collect(top, sup, parent=parent)
except ValueError:
pass
@@ -1142,7 +1312,50 @@ class Annotation(Complex):
pass
class Group(Complex):
pass
def collect(self, top, sup, argv=None, parent=""):
""" means this element is part of a larger object, hence a property of
that object """
try:
objekt = PyGroup("", root=top)
(namespace, tag) = self.ref.split(":")
if namespace in self.xmlns_map:
if self.xmlns_map[namespace] == top.target_namespace:
objekt.ref = (None, tag.replace("-","_"))
else:
raise Exception(
"Reference to group in other XSD file, not supported")
else:
raise Exception("Missing namespace definition")
return ([objekt], [])
except AttributeError, exc:
print "!!!!", exc
return ([], [])
def repr(self, top=None, sup=None, argv=None, _child=True, parent=""):
self._class = objekt = PyGroup(self.name, root=top)
min_max(self, objekt, argv)
try:
argv_copy = sd_copy(argv)
c_own = []
c_inherited = []
for part in self.parts:
#print "### ", part
(own, inh) = part.collect(top, sup, argv_copy)
if own:
# if len(own) == 1 and isinstance(own[0], PyAttribute):
# own[0].base = base
c_own.extend(own)
c_inherited.extend(inh)
objekt.properties = (c_own, c_inherited)
except ValueError:
pass
return objekt
class Unique(Complex):
pass
@@ -1154,7 +1367,7 @@ class Field(Complex):
pass
class AttributeGroup(Complex):
def collect(self, top, sup, argv=None):
def collect(self, top, sup, argv=None, parent=""):
try:
(_namespace, typ) = self.ref.split(":")
cti = get_type_def(typ, top.parts)
@@ -1167,11 +1380,11 @@ class AttributeGroup(Complex):
for prop in self.parts:
if isinstance(prop, Attribute):
self._own.append(prop.repr(top, sup, argv_copy))
self._own.append(prop.repr(top, sup, argv_copy, parent))
return (self._own, self._inherited)
def repr(self, top=None, sup=None, _argv=None, _child=True):
def repr(self, top=None, sup=None, _argv=None, _child=True, parent=""):
self._class = PyAttributeGroup(self.name, root=top)
try:
@@ -1268,6 +1481,7 @@ def sort_elements(els):
def output(elem, target_namespace, eldict, ignore=[]):
done = 0
try:
(preps, text) = elem.text(target_namespace, eldict, False, ignore)
except TypeError:
@@ -1319,7 +1533,10 @@ class Schema(Complex):
self.elems = []
self.attrgrp = []
self.defs = []
self.target_namespace = self.targetNamespace
try:
self.target_namespace = self.targetNamespace
except AttributeError:
self.target_namespace = ""
for def_file in defs:
self.defs.append(open(def_file).read())
@@ -1345,15 +1562,15 @@ class Schema(Complex):
signif.append(elem)
if len(signif) == 1:
prop = signif[0]
(mod, typ) = _mod_typ(prop)
(mod, cname) = _mod_cname(prop, eldict)
if prop.max == "unbounded":
lista = True
else:
lista = False
spec = key.child_spec(self.target_namespace, prop, mod,
typ, lista)
lines = ["%s.%s" % (key.name, spec)]
cname, lista)
lines = ["%s.%s" % (key.class_name, spec)]
res = (key, prop, lines)
break
if res[0]:
@@ -1362,7 +1579,7 @@ class Schema(Complex):
if sups:
for sup in sups:
if sup.name == ref:
lines.append("%s.%s" % (key.name, spec))
lines.append("%s.%s" % (key.class_name, spec))
break
else:
pass
@@ -1375,7 +1592,7 @@ class Schema(Complex):
not_done = 0
undone = 0
for elem in self.elems:
if elem.done:
if isinstance(elem, PyGroup) or elem.done:
continue
undone += 1
not_done += output(elem, self.target_namespace, eldict)
@@ -1431,83 +1648,70 @@ class Schema(Complex):
print "ELEMENT_FROM_STRING = {"
for elem in self.elems:
if isinstance(elem, PyAttribute):
if isinstance(elem, PyAttribute) or isinstance(elem, PyGroup):
continue
print "%s%s.c_tag: %s_from_string," % (INDENT, elem.name,
elem.pyname)
if elem.abstract:
continue
print "%s%s.c_tag: %s_from_string," % (INDENT, elem.class_name,
pyify(elem.class_name))
print "}"
print
print "ELEMENT_BY_TAG = {"
for elem in self.elems:
if isinstance(elem, PyAttribute):
if isinstance(elem, PyAttribute) or isinstance(elem, PyGroup):
continue
print "%s'%s': %s," % (INDENT, elem.name, elem.name)
if elem.abstract:
continue
lcen = elem.name
print "%s'%s': %s," % (INDENT, lcen, elem.class_name)
print "}"
print
print "def factory(tag, **kwargs):"
print " return ELEMENT_BY_TAG[tag](**kwargs)"
print
# for elem in self.elems:
# if elem.done:
# continue
# else:
# print elem.name
#
# # And lastly the elements
# print eldict.keys()
# print self.elems
# -----------------------------------------------------------------------------
ELEMENTFUNCTION = {
"{http://www.w3.org/2001/XMLSchema}element": Element,
"{http://www.w3.org/2001/XMLSchema}complexType": ComplexType,
"{http://www.w3.org/2001/XMLSchema}sequence": Sequence,
"{http://www.w3.org/2001/XMLSchema}any": Any,
"{http://www.w3.org/2001/XMLSchema}anyAttribute": AnyAttribute,
"{http://www.w3.org/2001/XMLSchema}simpleContent": SimpleContent,
"{http://www.w3.org/2001/XMLSchema}extension": Extension,
"{http://www.w3.org/2001/XMLSchema}union": Union,
"{http://www.w3.org/2001/XMLSchema}restriction": Restriction,
"{http://www.w3.org/2001/XMLSchema}enumeration": Enumeration,
"{http://www.w3.org/2001/XMLSchema}import": Import,
"{http://www.w3.org/2001/XMLSchema}annotation": Annotation,
"{http://www.w3.org/2001/XMLSchema}attributeGroup":AttributeGroup,
"{http://www.w3.org/2001/XMLSchema}attribute":Attribute,
"{http://www.w3.org/2001/XMLSchema}choice": Choice,
"{http://www.w3.org/2001/XMLSchema}complexContent": ComplexContent,
"{http://www.w3.org/2001/XMLSchema}documentation": Documentation,
"{http://www.w3.org/2001/XMLSchema}simpleType": SimpleType,
"{http://www.w3.org/2001/XMLSchema}maxLength": MaxLength,
"{http://www.w3.org/2001/XMLSchema}list": List,
"{http://www.w3.org/2000/10/XMLSchema}element": Element,
"{http://www.w3.org/2000/10/XMLSchema}complexType": ComplexType,
"{http://www.w3.org/2000/10/XMLSchema}sequence": Sequence,
"{http://www.w3.org/2000/10/XMLSchema}any": Any,
"{http://www.w3.org/2000/10/XMLSchema}anyAttribute": AnyAttribute,
"{http://www.w3.org/2000/10/XMLSchema}simpleContent": SimpleContent,
"{http://www.w3.org/2000/10/XMLSchema}extension": Extension,
"{http://www.w3.org/2000/10/XMLSchema}union": Union,
"{http://www.w3.org/2000/10/XMLSchema}restriction": Restriction,
"{http://www.w3.org/2000/10/XMLSchema}enumeration": Enumeration,
"{http://www.w3.org/2000/10/XMLSchema}import": Import,
"{http://www.w3.org/2000/10/XMLSchema}annotation": Annotation,
"{http://www.w3.org/2000/10/XMLSchema}attributeGroup":AttributeGroup,
"{http://www.w3.org/2000/10/XMLSchema}attribute":Attribute,
"{http://www.w3.org/2000/10/XMLSchema}choice": Choice,
"{http://www.w3.org/2000/10/XMLSchema}complexContent": ComplexContent,
"{http://www.w3.org/2000/10/XMLSchema}documentation": Documentation,
"{http://www.w3.org/2000/10/XMLSchema}simpleType": SimpleType,
"{http://www.w3.org/2000/10/XMLSchema}maxLength": MaxLength,
"{http://www.w3.org/2000/10/XMLSchema}list": List,
"{http://www.w3.org/2000/10/XMLSchema}unique": Unique,
"{http://www.w3.org/2000/10/XMLSchema}group": Group,
"{http://www.w3.org/2000/10/XMLSchema}selector": Selector,
"{http://www.w3.org/2000/10/XMLSchema}field": Field,
NAMESPACE_BASE = ["http://www.w3.org/2001/XMLSchema",
"http://www.w3.org/2000/10/XMLSchema"]
_MAP = {
"element": Element,
"complexType": ComplexType,
"sequence": Sequence,
"any": Any,
"anyAttribute": AnyAttribute,
"simpleContent": SimpleContent,
"extension": Extension,
"union": Union,
"restriction": Restriction,
"enumeration": Enumeration,
"import": Import,
"annotation": Annotation,
"attributeGroup":AttributeGroup,
"attribute":Attribute,
"choice": Choice,
"complexContent": ComplexContent,
"documentation": Documentation,
"simpleType": SimpleType,
"maxLength": MaxLength,
"list": List,
"unique": Unique,
"group": Group,
"selector": Selector,
"field": Field,
}
ELEMENTFUNCTION = {}
for namespace in NAMESPACE_BASE:
for key, func in _MAP.items():
ELEMENTFUNCTION["{%s}%s" % (namespace,key)] = func
def evaluate(typ, elem):
try:
return ELEMENTFUNCTION[typ](elem)