Skip to content

Commit

Permalink
Clean up remaining legacy try: except ImportError: blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Oct 28, 2022
1 parent b951633 commit f7f3840
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 91 deletions.
20 changes: 3 additions & 17 deletions src/saml2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,14 @@
"""

import logging
from xml.etree import ElementTree

import defusedxml.ElementTree

from saml2.validate import valid_instance
from saml2.version import version as __version__


try:
from xml.etree import ElementTree as ElementTree

if ElementTree.VERSION < "1.3.0":
# cElementTree has no support for register_namespace
# neither _namespace_map, thus we sacrify performance
# for correctness
from xml.etree import ElementTree
except ImportError:
try:
import cElementTree as ElementTree
except ImportError:
from elementtree import ElementTree

import defusedxml.ElementTree


logger = logging.getLogger(__name__)

NAMESPACE = "urn:oasis:names:tc:SAML:2.0:assertion"
Expand Down
20 changes: 3 additions & 17 deletions src/saml2/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import logging
from urllib.parse import urlencode
from urllib.parse import urlparse
from xml.etree import ElementTree as ElementTree

import defusedxml.ElementTree

import saml2
from saml2.s_utils import deflate_and_base64_encode
Expand All @@ -26,23 +29,6 @@
from saml2.xmldsig import SIG_ALLOWED_ALG


try:
from xml.etree import ElementTree as ElementTree

if ElementTree.VERSION < "1.3.0":
# cElementTree has no support for register_namespace
# neither _namespace_map, thus we sacrify performance
# for correctness
from xml.etree import ElementTree
except ImportError:
try:
import cElementTree as ElementTree
except ImportError:
from elementtree import ElementTree

import defusedxml.ElementTree


logger = logging.getLogger(__name__)

NAMESPACE = "http://schemas.xmlsoap.org/soap/envelope/"
Expand Down
15 changes: 3 additions & 12 deletions src/saml2/soap.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,15 @@
"""
import logging
import re
from xml.etree import ElementTree as ElementTree

import defusedxml.ElementTree

from saml2 import create_class_from_element_tree
from saml2.samlp import NAMESPACE as SAMLP_NAMESPACE
from saml2.schema import soapenv


try:
from xml.etree import ElementTree as ElementTree
except ImportError:
try:
import cElementTree as ElementTree
except ImportError:
# noinspection PyUnresolvedReferences
from elementtree import ElementTree

import defusedxml.ElementTree


logger = logging.getLogger(__name__)


Expand Down
6 changes: 0 additions & 6 deletions tests/test_00_xmldsig.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@

import unittest


try:
pass
except ImportError:
pass

import ds_data

import saml2.xmldsig as ds
Expand Down
4 changes: 0 additions & 4 deletions tests/test_02_saml.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@

__author__ = "[email protected] (Roland Hedberg)"

try:
pass
except ImportError:
pass

import ds_data
from pytest import raises
Expand Down
12 changes: 1 addition & 11 deletions tests/test_03_saml2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python

from defusedxml.common import EntitiesForbidden
from pytest import raises
import saml2_data

Expand All @@ -16,17 +17,6 @@
from saml2.saml import SubjectLocality


try:
pass
except ImportError:
try:
pass
except ImportError:
pass

from defusedxml.common import EntitiesForbidden


ITEMS = {
NameID: [
"""<?xml version="1.0" encoding="utf-8"?>
Expand Down
5 changes: 0 additions & 5 deletions tests/test_04_samlp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@

__author__ = "[email protected] (Roland Hedberg)"

try:
pass
except ImportError:
pass

import samlp_data

import saml2
Expand Down
6 changes: 0 additions & 6 deletions tests/test_05_md.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@

__author__ = "[email protected] (Roland Hedberg)"


try:
pass
except ImportError:
pass

import ds_data
import md_data

Expand Down
14 changes: 1 addition & 13 deletions tests/test_43_soap.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
#!/usr/bin/env python

try:
from xml.etree import ElementTree as ElementTree

if ElementTree.VERSION < "1.3.0":
# cElementTree has no support for register_namespace
# neither _namespace_map, thus we sacrify performance
# for correctness
from xml.etree import ElementTree
except ImportError:
try:
import cElementTree as ElementTree
except ImportError:
from elementtree import ElementTree
from xml.etree import ElementTree as ElementTree

from defusedxml.common import EntitiesForbidden
from pytest import raises
Expand Down

0 comments on commit f7f3840

Please sign in to comment.