diff --git a/AUTHORS b/AUTHORS index 7c5ef60..2b63043 100644 --- a/AUTHORS +++ b/AUTHORS @@ -11,6 +11,7 @@ Dmytro Katyukha Gerard Marull-Paretas Hark Joel Lehtonen +Justin Vieira kennedy Kristi ldos @@ -20,6 +21,7 @@ Michael Billington Michael Elsdörfer mrwunderbar666 Nathan Bookham +Omer Akram Patrick Kanzler primax79 Qian Linfeng diff --git a/src/escpos/capabilities.py b/src/escpos/capabilities.py index 0cf76e1..c4b6ab5 100644 --- a/src/escpos/capabilities.py +++ b/src/escpos/capabilities.py @@ -38,7 +38,7 @@ else: if full_load: logger.debug('Loading and pickling capabilities') with open(capabilities_path) as cp, open(pickle_path, 'wb') as pp: - CAPABILITIES = yaml.load(cp) + CAPABILITIES = yaml.safe_load(cp) pickle.dump(CAPABILITIES, pp, protocol=2) logger.debug('Finished loading capabilities took %.2fs', time.time() - t0) diff --git a/src/escpos/printer.py b/src/escpos/printer.py index f1c6145..319d773 100644 --- a/src/escpos/printer.py +++ b/src/escpos/printer.py @@ -68,19 +68,24 @@ class Usb(Escpos): self.idVendor = self.device.idVendor self.idProduct = self.device.idProduct - check_driver = None + # pyusb has three backends: libusb0, libusb1 and openusb but + # only libusb1 backend implements the methods is_kernel_driver_active() + # and detach_kernel_driver(). + # This helps enable this library to work on Windows. + if self.device.backend.__module__.endswith("libusb1"): + check_driver = None - try: - check_driver = self.device.is_kernel_driver_active(0) - except NotImplementedError: - pass - - if check_driver is None or check_driver: try: - self.device.detach_kernel_driver(0) - except usb.core.USBError as e: - if check_driver is not None: - print("Could not detatch kernel driver: {0}".format(str(e))) + check_driver = self.device.is_kernel_driver_active(0) + except NotImplementedError: + pass + + if check_driver is None or check_driver: + try: + self.device.detach_kernel_driver(0) + except usb.core.USBError as e: + if check_driver is not None: + print("Could not detatch kernel driver: {0}".format(str(e))) try: self.device.set_configuration()