@@ -1861,6 +1861,57 @@ def test_access_through_resc_hierarchy__243(self):
18611861 finally :
18621862 s .resources .remove ('parent' )
18631863
1864+ @unittest .skipIf (set (os .environ .keys ()) & {'PYTHON_IRODSCLIENT_CONFIG__CONNECTIONS__XML_PARSER_DEFAULT' ,
1865+ 'PYTHON_IRODSCLIENT_CONFIGURATION_PATH' , 'PYTHON_IRODSCLIENT_DEFAULT_XML' },
1866+ "skipping due to possible overwriting of test-apropos settings by a configuration file or environment setting" )
1867+ def test_temporary_xml_mode_change_with_operation_as_proof__issue_586 (self ):
1868+ from irods .helpers import (xml_mode , home_collection )
1869+ sess = irods .test .helpers .make_session ()
1870+ hc = home_collection (sess )
1871+ odd_name = '{hc}/\1 ' .format (** locals ())
1872+
1873+ # Currently 'STANDARD_XML' is the default, and 'QUASI_XML' is a convenient alternative to use when
1874+ # object names are used which contain special characters (e.g. '\1') hostile to standard XML parsers.
1875+ default_xml_parser = 'STANDARD_XML'
1876+
1877+ from irods .message import (current_XML_parser , string_for_XML_parser )
1878+ active_xml_parser_for_thread = lambda : string_for_XML_parser (current_XML_parser ())
1879+
1880+ self .assertEqual (active_xml_parser_for_thread (), default_xml_parser )
1881+
1882+ with xml_mode ('QUASI_XML' ):
1883+ sess .data_objects .create (odd_name )
1884+
1885+ # Test that the xml parser setting isn't permanently changed
1886+ self .assertEqual (active_xml_parser_for_thread (), default_xml_parser )
1887+
1888+ try :
1889+ if default_xml_parser == 'STANDARD_XML' :
1890+ with self .assertRaises (xml .etree .ElementTree .ParseError ):
1891+ sess .collections .get (hc ).data_objects
1892+ finally :
1893+ with xml_mode ('QUASI_XML' ):
1894+ sess .data_objects .unlink (odd_name , force = True )
1895+
1896+ def test_temporary_xml_mode_changes_have_desired_thread_limited_effect__issue_586 (self ):
1897+ from irods .message import (current_XML_parser , string_for_XML_parser )
1898+ active_xml_parser_for_thread = lambda : string_for_XML_parser (current_XML_parser ())
1899+ from concurrent .futures import ThreadPoolExecutor
1900+ from irods .helpers import xml_mode
1901+ original_xml_parser = active_xml_parser_for_thread ()
1902+ other_xml_parser = list ({'STANDARD_XML' , 'QUASI_XML' , 'SECURE_XML' } - {original_xml_parser })[0 ]
1903+
1904+ self .assertNotEqual (other_xml_parser , original_xml_parser )
1905+
1906+ with xml_mode (other_xml_parser ):
1907+ # Test that this thread is the only one affected, and that in it we get 'QUASI_XML' when we call
1908+ # current_XML_parser(), i.e. the function used internally by ET() to retrieve the current parser module.
1909+ self .assertEqual (other_xml_parser , active_xml_parser_for_thread ())
1910+ self .assertEqual (original_xml_parser , ThreadPoolExecutor (max_workers = 1 ).submit (active_xml_parser_for_thread ).result ())
1911+
1912+ self .assertEqual (active_xml_parser_for_thread (), original_xml_parser )
1913+
1914+
18641915 def test_register_with_xml_special_chars (self ):
18651916 test_dir = helpers .irods_shared_tmp_dir ()
18661917 loc_server = self .sess .host in ('localhost' , socket .gethostname ())
0 commit comments