mirror of
				https://github.com/ARM-software/devlib.git
				synced 2025-11-04 07:51:21 +00:00 
			
		
		
		
	Fix Python3 Byte and Regex Handling
Convert bytes to strings (utf-8 encoding) to make compatible with Python3 in arm.py Use the pattern property to extract the string from the regex pattern, to pass as a string to tty.expect. Drop problematic characters when decoding stdout and stderr in misc.py by setting errors='replace' in the string decode method.
This commit is contained in:
		
				
					committed by
					
						
						setrofim
					
				
			
			
				
	
			
			
			
						parent
						
							6abe6067da
						
					
				
				
					commit
					b06035fb12
				
			@@ -88,6 +88,9 @@ class VersatileExpressPlatform(Platform):
 | 
				
			|||||||
    def _init_android_target(self, target):
 | 
					    def _init_android_target(self, target):
 | 
				
			||||||
        if target.connection_settings.get('device') is None:
 | 
					        if target.connection_settings.get('device') is None:
 | 
				
			||||||
            addr = self._get_target_ip_address(target)
 | 
					            addr = self._get_target_ip_address(target)
 | 
				
			||||||
 | 
					            if sys.version_info[0] == 3:
 | 
				
			||||||
 | 
					                # Convert bytes to string for Python3 compatibility
 | 
				
			||||||
 | 
					                addr = addr.decode("utf-8")
 | 
				
			||||||
            target.connection_settings['device'] = addr + ':5555'
 | 
					            target.connection_settings['device'] = addr + ':5555'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _init_linux_target(self, target):
 | 
					    def _init_linux_target(self, target):
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -179,8 +179,9 @@ def check_output(command, timeout=None, ignore=None, inputtext=None, **kwargs):
 | 
				
			|||||||
    try:
 | 
					    try:
 | 
				
			||||||
        output, error = process.communicate(inputtext)
 | 
					        output, error = process.communicate(inputtext)
 | 
				
			||||||
        if sys.version_info[0] == 3:
 | 
					        if sys.version_info[0] == 3:
 | 
				
			||||||
            output = output.decode(sys.stdout.encoding)
 | 
					            # Currently errors=replace is needed as 0x8c throws an error
 | 
				
			||||||
            error =  error.decode(sys.stderr.encoding)
 | 
					            output = output.decode(sys.stdout.encoding, "replace")
 | 
				
			||||||
 | 
					            error =  error.decode(sys.stderr.encoding, "replace")
 | 
				
			||||||
    finally:
 | 
					    finally:
 | 
				
			||||||
        if timeout:
 | 
					        if timeout:
 | 
				
			||||||
            timer.cancel()
 | 
					            timer.cancel()
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user