usbinfo/darwin.py
def _sanitize_xml(data):
    """Takes an plist (xml) and checks <string> defintions for control characters.

       If a control character is found, the string is converted to hexidecimal.
       For ST-Link devices, this properly displays the serial number, which 
       is eroneously encoded as binary data, which causes the plistlib XML parser
       to crash.

       Returns the same document, with any mis-encoded <string> values converted 
       to ascii hex."""
    output = []

    data = data.decode('utf-8')

    for i, line in enumerate(data.split('\n')):
        chunk = line
        match = re.match(sanitize_pattern, chunk)
        if match:
            start = match.group(1)
            middle = match.group(2)
            end = match.group(3)
            needs_patch = False
            # Inspect the line and see if it has invalid characters.
            byte_list = bytearray([ord(byte) for byte in middle])
            for byte in byte_list:
                if byte < 32:
                    needs_patch = True
            if needs_patch:
                middle = ''.join(['%02X' % byte for byte in byte_list])
                new_line = '{start}{middle}{end}'.format(start=start,
                                                         middle=middle,
                                                         end=end)
                output.append(new_line)
            else:
                output.append(line)
        else:
            output.append(line)
    output = '\n'.join([line for line in output])

    return output.encode('utf-8')
Takes an plist (xml) and checks <string> defintions for control characters.

       If a control character is found, the string is converted to hexidecimal.
       For ST-Link devices, this properly displays the serial number, which 
       is eroneously encoded as binary data, which causes the plistlib XML parser
       to crash.

       Returns the same document, with any mis-encoded <string> values converted 
       to ascii hex.
Takes an plist (xml) and checks  defintions for control characters.
If a control character is found, the string is converted to hexidecimal.
For ST-Link devices, this properly displays the serial number, which
is eroneously encoded as binary data, which causes the plistlib XML parser
to crash.

Returns the same document, with any mis-encoded  values converted
to ascii hex.
Takes an plist ( xml ) and checks defintions for control characters . If a control character is found the string is converted to hexidecimal . For ST - Link devices this properly displays the serial number which is eroneously encoded as binary data which causes the plistlib XML parser to crash . Returns the same document with any mis - encoded values converted to ascii hex .
def _sanitize_xml(data):
    output = []
    data = data.decode('utf-8')
    for i, line in enumerate(data.split('\n')):
        chunk = line
        match = re.match(sanitize_pattern, chunk)
        if match:
            start = match.group(1)
            middle = match.group(2)
            end = match.group(3)
            needs_patch = False
            byte_list = bytearray([ord(byte) for byte in middle])
            for byte in byte_list:
                if byte < 32:
                    needs_patch = True
            if needs_patch:
                middle = ''.join(['%02X' % byte for byte in byte_list])
                new_line = '{start}{middle}{end}'.format(start=start,
                                                         middle=middle,
                                                         end=end)
                output.append(new_line)
            else:
                output.append(line)
        else:
            output.append(line)
    output = '\n'.join([line for line in output])
    return output.encode('utf-8')
def _sanitize_xml ( data ) : output = [ ] data = data . decode ( 'utf-8' ) for i , line in enumerate ( data . split ( '\n' ) ) : chunk = line match = re . match ( sanitize_pattern , chunk ) if match : start = match . group ( 1 ) middle = match . group ( 2 ) end = match . group ( 3 ) needs_patch = False byte_list = bytearray ( [ ord ( byte ) for byte in middle ] ) for byte in byte_list : if byte < 32 : needs_patch = True if needs_patch : middle = '' . join ( [ '%02X' % byte for byte in byte_list ] ) new_line = '{start}{middle}{end}' . format ( start = start , middle = middle , end = end ) output . append ( new_line ) else : output . append ( line ) else : output . append ( line ) output = '\n' . join ( [ line for line in output ] ) return output . encode ( 'utf-8' )
Takes an plist (xml) and checks <string> defintions for control characters.
Takes an plist ( xml ) and checks <string > defintions for control characters .
"""Takes an plist (xml) and checks <string> defintions for control characters.

       If a control character is found, the string is converted to hexidecimal.
       For ST-Link devices, this properly displays the serial number, which 
       is eroneously encoded as binary data, which causes the plistlib XML parser
       to crash.

       Returns the same document, with any mis-encoded <string> values converted 
       to ascii hex.""" # Inspect the line and see if it has invalid characters.
data