Skip to content

Commit ca04d1d

Browse files
committed
Make some staticmethods classmethods instead
1 parent 53db80d commit ca04d1d

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

src/onelogin/saml2/idp_metadata_parser.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class OneLogin_Saml2_IdPMetadataParser(object):
2525
A class that contain methods related to obtaining and parsing metadata from IdP
2626
"""
2727

28-
@staticmethod
29-
def get_metadata(url, validate_cert=True):
28+
@classmethod
29+
def get_metadata(cls, url, validate_cert=True):
3030
"""
3131
Gets the metadata XML from the provided URL
3232
:param url: Url where the XML of the Identity Provider Metadata is published.
@@ -63,8 +63,8 @@ def get_metadata(url, validate_cert=True):
6363

6464
return xml
6565

66-
@staticmethod
67-
def parse_remote(url, validate_cert=True, entity_id=None, **kwargs):
66+
@classmethod
67+
def parse_remote(cls, url, validate_cert=True, entity_id=None, **kwargs):
6868
"""
6969
Gets the metadata XML from the provided URL and parse it, returning a dict with extracted data
7070
:param url: Url where the XML of the Identity Provider Metadata is published.
@@ -80,11 +80,12 @@ def parse_remote(url, validate_cert=True, entity_id=None, **kwargs):
8080
:returns: settings dict with extracted data
8181
:rtype: dict
8282
"""
83-
idp_metadata = OneLogin_Saml2_IdPMetadataParser.get_metadata(url, validate_cert)
84-
return OneLogin_Saml2_IdPMetadataParser.parse(idp_metadata, entity_id=entity_id, **kwargs)
83+
idp_metadata = cls.get_metadata(url, validate_cert)
84+
return cls.parse(idp_metadata, entity_id=entity_id, **kwargs)
8585

86-
@staticmethod
86+
@classmethod
8787
def parse(
88+
cls,
8889
idp_metadata,
8990
required_sso_binding=OneLogin_Saml2_Constants.BINDING_HTTP_REDIRECT,
9091
required_slo_binding=OneLogin_Saml2_Constants.BINDING_HTTP_REDIRECT,

src/onelogin/saml2/logout_request.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ def get_nameid_data(request, key=None):
203203

204204
return name_id_data
205205

206-
@staticmethod
207-
def get_nameid(request, key=None):
206+
@classmethod
207+
def get_nameid(cls, request, key=None):
208208
"""
209209
Gets the NameID of the Logout Request Message
210210
:param request: Logout Request Message
@@ -214,11 +214,11 @@ def get_nameid(request, key=None):
214214
:return: Name ID Value
215215
:rtype: string
216216
"""
217-
name_id = OneLogin_Saml2_Logout_Request.get_nameid_data(request, key)
217+
name_id = cls.get_nameid_data(request, key)
218218
return name_id['Value']
219219

220-
@staticmethod
221-
def get_nameid_format(request, key=None):
220+
@classmethod
221+
def get_nameid_format(cls, request, key=None):
222222
"""
223223
Gets the NameID Format of the Logout Request Message
224224
:param request: Logout Request Message
@@ -229,7 +229,7 @@ def get_nameid_format(request, key=None):
229229
:rtype: string
230230
"""
231231
name_id_format = None
232-
name_id_data = OneLogin_Saml2_Logout_Request.get_nameid_data(request, key)
232+
name_id_data = cls.get_nameid_data(request, key)
233233
if name_id_data and 'Format' in name_id_data.keys():
234234
name_id_format = name_id_data['Format']
235235
return name_id_format
@@ -326,7 +326,7 @@ def is_valid(self, request_data, raise_exceptions=False):
326326
)
327327

328328
# Check issuer
329-
issuer = OneLogin_Saml2_Logout_Request.get_issuer(root)
329+
issuer = self.get_issuer(root)
330330
if issuer is not None and issuer != idp_entity_id:
331331
raise OneLogin_Saml2_ValidationError(
332332
'Invalid issuer in the Logout Request (expected %(idpEntityId)s, got %(issuer)s)' %

src/onelogin/saml2/metadata.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class OneLogin_Saml2_Metadata(object):
3434
TIME_VALID = 172800 # 2 days
3535
TIME_CACHED = 604800 # 1 week
3636

37-
@staticmethod
38-
def builder(sp, authnsign=False, wsign=False, valid_until=None, cache_duration=None, contacts=None, organization=None):
37+
@classmethod
38+
def builder(cls, sp, authnsign=False, wsign=False, valid_until=None, cache_duration=None, contacts=None, organization=None):
3939
"""
4040
Builds the metadata of the SP
4141
@@ -61,7 +61,7 @@ def builder(sp, authnsign=False, wsign=False, valid_until=None, cache_duration=N
6161
:type organization: dict
6262
"""
6363
if valid_until is None:
64-
valid_until = int(time()) + OneLogin_Saml2_Metadata.TIME_VALID
64+
valid_until = int(time()) + cls.TIME_VALID
6565
if not isinstance(valid_until, basestring):
6666
if isinstance(valid_until, datetime):
6767
valid_until_time = valid_until.timetuple()
@@ -72,7 +72,7 @@ def builder(sp, authnsign=False, wsign=False, valid_until=None, cache_duration=N
7272
valid_until_str = valid_until
7373

7474
if cache_duration is None:
75-
cache_duration = OneLogin_Saml2_Metadata.TIME_CACHED
75+
cache_duration = cls.TIME_CACHED
7676
if not isinstance(cache_duration, compat.str_type):
7777
cache_duration_str = 'PT%sS' % cache_duration # Period of Time x Seconds
7878
else:
@@ -228,8 +228,8 @@ def __add_x509_key_descriptors(root, cert, signing):
228228
x509_certificate.text = OneLogin_Saml2_Utils.format_cert(cert, False)
229229
key_descriptor.set('use', ('encryption', 'signing')[signing])
230230

231-
@staticmethod
232-
def add_x509_key_descriptors(metadata, cert=None, add_encryption=True):
231+
@classmethod
232+
def add_x509_key_descriptors(cls, metadata, cert=None, add_encryption=True):
233233
"""
234234
Adds the x509 descriptors (sign/encryption) to the metadata
235235
The same cert will be used for sign/encrypt
@@ -260,6 +260,6 @@ def add_x509_key_descriptors(metadata, cert=None, add_encryption=True):
260260
raise Exception('Malformed metadata.')
261261

262262
if add_encryption:
263-
OneLogin_Saml2_Metadata.__add_x509_key_descriptors(sp_sso_descriptor, cert, False)
264-
OneLogin_Saml2_Metadata.__add_x509_key_descriptors(sp_sso_descriptor, cert, True)
263+
cls.__add_x509_key_descriptors(sp_sso_descriptor, cert, False)
264+
cls.__add_x509_key_descriptors(sp_sso_descriptor, cert, True)
265265
return OneLogin_Saml2_XML.to_string(root)

0 commit comments

Comments
 (0)