From e92f00cdf34226aaafa495b1a925373b7b0a0e83 Mon Sep 17 00:00:00 2001 From: Patrick Kanzler Date: Mon, 30 Jan 2017 16:12:37 +0100 Subject: [PATCH] fix AttributeError when executing close When self.device is already None an AttributeError will occur. This is relevant to #189. --- src/escpos/printer.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/escpos/printer.py b/src/escpos/printer.py index 55e2555..ab1021b 100644 --- a/src/escpos/printer.py +++ b/src/escpos/printer.py @@ -211,8 +211,9 @@ class Network(Escpos): def close(self): """ Close TCP connection """ - self.device.shutdown(socket.SHUT_RDWR) - self.device.close() + if self.device is not None: + self.device.shutdown(socket.SHUT_RDWR) + self.device.close() class File(Escpos): @@ -263,8 +264,9 @@ class File(Escpos): def close(self): """ Close system file """ - self.device.flush() - self.device.close() + if self.device is not None: + self.device.flush() + self.device.close() class Dummy(Escpos):