Skip to content

Commit 7d3f180

Browse files
committed
[_802] handle xml/config import
1 parent b9895ab commit 7d3f180

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

irods/message/__init__.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
from typing import Optional
1313
from warnings import warn
1414

15-
import defusedxml.ElementTree as ET_secure_xml
16-
1715
import irods.exception as ex
1816

1917
from . import quasixml as ET_quasi_xml
@@ -105,24 +103,18 @@ class BadXMLSpec(RuntimeError):
105103

106104
def current_XML_parser(get_module=False):
107105
d = getattr(_thrlocal, "xml_type", _default_XML)
108-
return d if not get_module else _XML_parsers[d]
106+
return d if not get_module else _XML_parser_for(d)
109107

110108

111109
def default_XML_parser(get_module=False):
112110
d = _default_XML
113-
return d if not get_module else _XML_parsers[d]
111+
return d if not get_module else _XML_parser_for(d)
114112

115113

116114
def string_for_XML_parser(parser_enum):
117115
return PARSER_TYPE_STRINGS[parser_enum]
118116

119117

120-
_XML_parsers = {
121-
XML_Parser_Type.STANDARD_XML: ET_xml,
122-
XML_Parser_Type.QUASI_XML: ET_quasi_xml,
123-
XML_Parser_Type.SECURE_XML: ET_secure_xml,
124-
}
125-
126118
_reversed_XML_strings_lookup = {v: k for k, v in _XML_strings.items()}
127119

128120

@@ -178,9 +170,9 @@ def ET(xml_type=(), server_version=None):
178170
_thrlocal.irods_server_version = tuple(
179171
server_version
180172
) # A default server version for Quasi-XML parsing is set (from the environment) and
181-
return _XML_parsers[
173+
return _XML_parser_for(
182174
current_XML_parser()
183-
] # applies to all threads in which ET() has not been called to update the value.
175+
) # applies to all threads in which ET() has not been called to update the value.
184176

185177

186178
logger = logging.getLogger(__name__)
@@ -1286,3 +1278,13 @@ def empty_gen_query_out(cols):
12861278
]
12871279
gqo = GenQueryResponse(rowCnt=0, attriCnt=len(cols), SqlResult_PI=sql_results)
12881280
return gqo
1281+
1282+
1283+
def _XML_parser_for(d: XML_Parser_Type):
1284+
import defusedxml.ElementTree as ET_secure_xml
1285+
return {
1286+
XML_Parser_Type.STANDARD_XML: ET_xml,
1287+
XML_Parser_Type.QUASI_XML: ET_quasi_xml,
1288+
XML_Parser_Type.SECURE_XML: ET_secure_xml,
1289+
}[d]
1290+

0 commit comments

Comments
 (0)