mirror of
				https://github.com/ansible-collections/community.general.git
				synced 2025-10-25 05:23:58 -07:00 
			
		
		
		
	Fix for to_text and to_bytes error handlers
* surrogate_then_strict doesn't exist.  Switch to surrogate_or_strict
  instead.
* Found some bugs in the _text.py implementation
  * The composed error handlers (error handlers which are made up of two
    or more python encoding error handlers) had a wrong string in it,
    'surrogate_or_escape' doesn't exist.  Replaced that with
    'surrogate_or_replace' which is the correct handler name.
  * Left comment about the implicit conditions that are part of the
    surrogate_then_replace code path
Fixes #23865
Fixes #23861
	
	
This commit is contained in:
		
					parent
					
						
							
								9986639681
							
						
					
				
			
			
				commit
				
					
						fc5d71de0d
					
				
			
		
					 3 changed files with 16 additions and 13 deletions
				
			
		|  | @ -1011,7 +1011,7 @@ class AnsibleModule(object): | |||
|         return context | ||||
| 
 | ||||
|     def user_and_group(self, path, expand=True): | ||||
|         b_path = to_bytes(path, errors='surrogate_then_strict') | ||||
|         b_path = to_bytes(path, errors='surrogate_or_strict') | ||||
|         if expand: | ||||
|             b_path = os.path.expanduser(os.path.expandvars(b_path)) | ||||
|         st = os.lstat(b_path) | ||||
|  | @ -1105,10 +1105,10 @@ class AnsibleModule(object): | |||
|         return changed | ||||
| 
 | ||||
|     def set_owner_if_different(self, path, owner, changed, diff=None, expand=True): | ||||
|         b_path = to_bytes(path, errors='surrogate_then_strict') | ||||
|         b_path = to_bytes(path, errors='surrogate_or_strict') | ||||
|         if expand: | ||||
|             b_path = os.path.expanduser(os.path.expandvars(b_path)) | ||||
|         path = to_text(b_path, errors='surrogate_then_strict') | ||||
|         path = to_text(b_path, errors='surrogate_or_strict') | ||||
|         if owner is None: | ||||
|             return changed | ||||
|         orig_uid, orig_gid = self.user_and_group(path, expand) | ||||
|  | @ -1139,10 +1139,10 @@ class AnsibleModule(object): | |||
|         return changed | ||||
| 
 | ||||
|     def set_group_if_different(self, path, group, changed, diff=None, expand=True): | ||||
|         b_path = to_bytes(path, errors='surrogate_then_strict') | ||||
|         b_path = to_bytes(path, errors='surrogate_or_strict') | ||||
|         if expand: | ||||
|             b_path = os.path.expanduser(os.path.expandvars(b_path)) | ||||
|         path = to_text(b_path, errors='surrogate_then_strict') | ||||
|         path = to_text(b_path, errors='surrogate_or_strict') | ||||
|         if group is None: | ||||
|             return changed | ||||
|         orig_uid, orig_gid = self.user_and_group(b_path, expand) | ||||
|  | @ -1173,10 +1173,10 @@ class AnsibleModule(object): | |||
|         return changed | ||||
| 
 | ||||
|     def set_mode_if_different(self, path, mode, changed, diff=None, expand=True): | ||||
|         b_path = to_bytes(path, errors='surrogate_then_strict') | ||||
|         b_path = to_bytes(path, errors='surrogate_or_strict') | ||||
|         if expand: | ||||
|             b_path = os.path.expanduser(os.path.expandvars(b_path)) | ||||
|         path = to_text(b_path, errors='surrogate_then_strict') | ||||
|         path = to_text(b_path, errors='surrogate_or_strict') | ||||
|         path_stat = os.lstat(b_path) | ||||
| 
 | ||||
|         if mode is None: | ||||
|  | @ -1253,10 +1253,10 @@ class AnsibleModule(object): | |||
|         if attributes is None: | ||||
|             return changed | ||||
| 
 | ||||
|         b_path = to_bytes(path, errors='surrogate_then_strict') | ||||
|         b_path = to_bytes(path, errors='surrogate_or_strict') | ||||
|         if expand: | ||||
|             b_path = os.path.expanduser(os.path.expandvars(b_path)) | ||||
|         path = to_text(b_path, errors='surrogate_then_strict') | ||||
|         path = to_text(b_path, errors='surrogate_or_strict') | ||||
| 
 | ||||
|         existing = self.get_file_attributes(b_path) | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue