Skip to content

Commit

Permalink
get{,ASCII}StringDescriptor: Export str.decode's "error" argument.
Browse files Browse the repository at this point in the history
  • Loading branch information
vpelletier committed Dec 29, 2016
1 parent 92072b4 commit c48d3bd
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions usb1/__init__.py
Expand Up @@ -1302,11 +1302,11 @@ def getSupportedLanguageList(self):
for offset in xrange(1, cast(descriptor_string, POINTER(c_ubyte))[0] // 2)
]

def getStringDescriptor(self, descriptor, lang_id):
def getStringDescriptor(self, descriptor, lang_id, errors='strict'):
"""
Fetch description string for given descriptor and in given language.
Use getSupportedLanguageList to know which languages are available.
Return value is an unicode string.
Return value is a unicode string.
Return None if there is no such descriptor on device.
"""
descriptor_string, _ = create_binary_buffer(STRING_LENGTH)
Expand All @@ -1319,13 +1319,13 @@ def getStringDescriptor(self, descriptor, lang_id):
except USBErrorNotFound:
# pylint: enable=undefined-variable
return None
return descriptor_string.value.decode('UTF-16-LE')
return descriptor_string.value.decode('UTF-16-LE', errors=errors)

def getASCIIStringDescriptor(self, descriptor):
def getASCIIStringDescriptor(self, descriptor, errors='strict'):
"""
Fetch description string for given descriptor in first available
language.
Return value is an ASCII string.
Return value is a unicode string.
Return None if there is no such descriptor on device.
"""
descriptor_string, _ = create_binary_buffer(STRING_LENGTH)
Expand All @@ -1338,7 +1338,7 @@ def getASCIIStringDescriptor(self, descriptor):
except USBErrorNotFound:
# pylint: enable=undefined-variable
return None
return descriptor_string.value.decode('ASCII')
return descriptor_string.value.decode('ASCII', errors=errors)

# Sync I/O

Expand Down

0 comments on commit c48d3bd

Please sign in to comment.