mirror of
				https://github.com/ansible-collections/community.general.git
				synced 2025-10-25 05:23:58 -07:00 
			
		
		
		
	Mcsalgado's change to use shlex.quote instead of pipes.quote (#18534)
* Replace pipes.quote for shlex_quote * More migration of pipes.quote to shlex_quote Note that we cannot yet move module code over. Modules have six-1.4 bundled which does not have shlex_quote. This shouldn't be a problem as the function is still importable from pipes.quote. It's just that this has become an implementation detail that makes us want to import from shlex instead. Once we get rid of the python2.4 dependency we can update to a newer version of bundled six module-side and then we're free to use shlex_quote everywhere.
This commit is contained in:
		
					parent
					
						
							
								5d043b65d3
							
						
					
				
			
			
				commit
				
					
						ed00741a01
					
				
			
		
					 16 changed files with 62 additions and 63 deletions
				
			
		|  | @ -21,13 +21,13 @@ | |||
| from __future__ import (absolute_import, division, print_function) | ||||
| __metaclass__ = type | ||||
| 
 | ||||
| import pipes | ||||
| from io import StringIO | ||||
| 
 | ||||
| from ansible.compat.tests import unittest | ||||
| from ansible.compat.tests.mock import patch, MagicMock | ||||
| 
 | ||||
| from ansible import constants as C | ||||
| from ansible.compat.six.moves import shlex_quote | ||||
| from ansible.errors import AnsibleError, AnsibleConnectionFailure, AnsibleFileNotFound | ||||
| from ansible.playbook.play_context import PlayContext | ||||
| from ansible.plugins.connection import ssh | ||||
|  | @ -311,7 +311,7 @@ class TestConnectionBaseClass(unittest.TestCase): | |||
|         # Test with C.DEFAULT_SCP_IF_SSH set to smart | ||||
|         # Test when SFTP works | ||||
|         C.DEFAULT_SCP_IF_SSH = 'smart' | ||||
|         expected_in_data = b' '.join((b'put', to_bytes(pipes.quote('/path/to/in/file')), to_bytes(pipes.quote('/path/to/dest/file')))) + b'\n' | ||||
|         expected_in_data = b' '.join((b'put', to_bytes(shlex_quote('/path/to/in/file')), to_bytes(shlex_quote('/path/to/dest/file')))) + b'\n' | ||||
|         conn.put_file('/path/to/in/file', '/path/to/dest/file') | ||||
|         conn._run.assert_called_with('some command to run', expected_in_data, checkrc=False) | ||||
| 
 | ||||
|  | @ -331,13 +331,13 @@ class TestConnectionBaseClass(unittest.TestCase): | |||
| 
 | ||||
|         # test with C.DEFAULT_SCP_IF_SSH disabled | ||||
|         C.DEFAULT_SCP_IF_SSH = False | ||||
|         expected_in_data = b' '.join((b'put', to_bytes(pipes.quote('/path/to/in/file')), to_bytes(pipes.quote('/path/to/dest/file')))) + b'\n' | ||||
|         expected_in_data = b' '.join((b'put', to_bytes(shlex_quote('/path/to/in/file')), to_bytes(shlex_quote('/path/to/dest/file')))) + b'\n' | ||||
|         conn.put_file('/path/to/in/file', '/path/to/dest/file') | ||||
|         conn._run.assert_called_with('some command to run', expected_in_data, checkrc=False) | ||||
| 
 | ||||
|         expected_in_data = b' '.join((b'put', | ||||
|             to_bytes(pipes.quote('/path/to/in/file/with/unicode-fö〩')), | ||||
|             to_bytes(pipes.quote('/path/to/dest/file/with/unicode-fö〩')))) + b'\n' | ||||
|             to_bytes(shlex_quote('/path/to/in/file/with/unicode-fö〩')), | ||||
|             to_bytes(shlex_quote('/path/to/dest/file/with/unicode-fö〩')))) + b'\n' | ||||
|         conn.put_file(u'/path/to/in/file/with/unicode-fö〩', u'/path/to/dest/file/with/unicode-fö〩') | ||||
|         conn._run.assert_called_with('some command to run', expected_in_data, checkrc=False) | ||||
| 
 | ||||
|  | @ -365,7 +365,7 @@ class TestConnectionBaseClass(unittest.TestCase): | |||
|         # Test with C.DEFAULT_SCP_IF_SSH set to smart | ||||
|         # Test when SFTP works | ||||
|         C.DEFAULT_SCP_IF_SSH = 'smart' | ||||
|         expected_in_data = b' '.join((b'get', to_bytes(pipes.quote('/path/to/in/file')), to_bytes(pipes.quote('/path/to/dest/file')))) + b'\n' | ||||
|         expected_in_data = b' '.join((b'get', to_bytes(shlex_quote('/path/to/in/file')), to_bytes(shlex_quote('/path/to/dest/file')))) + b'\n' | ||||
|         conn.fetch_file('/path/to/in/file', '/path/to/dest/file') | ||||
|         conn._run.assert_called_with('some command to run', expected_in_data, checkrc=False) | ||||
| 
 | ||||
|  | @ -385,13 +385,13 @@ class TestConnectionBaseClass(unittest.TestCase): | |||
| 
 | ||||
|         # test with C.DEFAULT_SCP_IF_SSH disabled | ||||
|         C.DEFAULT_SCP_IF_SSH = False | ||||
|         expected_in_data = b' '.join((b'get', to_bytes(pipes.quote('/path/to/in/file')), to_bytes(pipes.quote('/path/to/dest/file')))) + b'\n' | ||||
|         expected_in_data = b' '.join((b'get', to_bytes(shlex_quote('/path/to/in/file')), to_bytes(shlex_quote('/path/to/dest/file')))) + b'\n' | ||||
|         conn.fetch_file('/path/to/in/file', '/path/to/dest/file') | ||||
|         conn._run.assert_called_with('some command to run', expected_in_data, checkrc=False) | ||||
| 
 | ||||
|         expected_in_data = b' '.join((b'get', | ||||
|             to_bytes(pipes.quote('/path/to/in/file/with/unicode-fö〩')), | ||||
|             to_bytes(pipes.quote('/path/to/dest/file/with/unicode-fö〩')))) + b'\n' | ||||
|             to_bytes(shlex_quote('/path/to/in/file/with/unicode-fö〩')), | ||||
|             to_bytes(shlex_quote('/path/to/dest/file/with/unicode-fö〩')))) + b'\n' | ||||
|         conn.fetch_file(u'/path/to/in/file/with/unicode-fö〩', u'/path/to/dest/file/with/unicode-fö〩') | ||||
|         conn._run.assert_called_with('some command to run', expected_in_data, checkrc=False) | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue