X-Git-Url: https://git.ayoreis.com/Adafruit_Blinka-hackapet.git/blobdiff_plain/528442e29f61287f55e0afe2923b187d151aa8b2..8f9a43ce8fb327a7e4dcabcf8df296a25236e495:/src/adafruit_blinka/microcontroller/generic_linux/sysfs_pin.py diff --git a/src/adafruit_blinka/microcontroller/generic_linux/sysfs_pin.py b/src/adafruit_blinka/microcontroller/generic_linux/sysfs_pin.py index 50c27a7..86c9a5f 100644 --- a/src/adafruit_blinka/microcontroller/generic_linux/sysfs_pin.py +++ b/src/adafruit_blinka/microcontroller/generic_linux/sysfs_pin.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries +# +# SPDX-License-Identifier: MIT """ Much code from https://github.com/vsergeev/python-periphery/blob/master/periphery/gpio.py Copyright (c) 2015-2019 vsergeev / Ivan (Vanya) A. Sergeev @@ -8,6 +11,7 @@ import os import errno import time + # pylint: disable=unnecessary-pass class GPIOError(IOError): """Base class for GPIO errors.""" @@ -132,7 +136,7 @@ class Pin: if not os.path.isdir(gpio_path): # Export the line try: - with open("/sys/class/gpio/export", "w") as f_export: + with open("/sys/class/gpio/export", "w", encoding="utf-8") as f_export: f_export.write("{:d}\n".format(self.id)) except IOError as e: raise GPIOError(e.errno, "Exporting GPIO: " + e.strerror) from IOError @@ -155,7 +159,9 @@ class Pin: # permission rule application after export for i in range(self.GPIO_OPEN_RETRIES): try: - with open(os.path.join(gpio_path, "direction"), "w") as f_direction: + with open( + os.path.join(gpio_path, "direction"), "w", encoding="utf-8" + ) as f_direction: f_direction.write(direction.lower() + "\n") break except IOError as e: @@ -170,7 +176,9 @@ class Pin: else: # Write direction try: - with open(os.path.join(gpio_path, "direction"), "w") as f_direction: + with open( + os.path.join(gpio_path, "direction"), "w", encoding="utf-8" + ) as f_direction: f_direction.write(direction.lower() + "\n") except IOError as e: raise GPIOError( @@ -268,7 +276,7 @@ class Pin: gpio_path = "/sys/class/gpio/{:s}/label".format(self.chip_name) try: - with open(gpio_path, "r") as f_label: + with open(gpio_path, "r", encoding="utf-8") as f_label: label = f_label.read() except (GPIOError, IOError) as e: if isinstance(e, IOError): @@ -287,7 +295,9 @@ class Pin: def _get_direction(self): # Read direction try: - with open(os.path.join(self._path, "direction"), "r") as f_direction: + with open( + os.path.join(self._path, "direction"), "r", encoding="utf-8" + ) as f_direction: direction = f_direction.read() except IOError as e: raise GPIOError( @@ -304,7 +314,9 @@ class Pin: # Write direction try: - with open(os.path.join(self._path, "direction"), "w") as f_direction: + with open( + os.path.join(self._path, "direction"), "w", encoding="utf-8" + ) as f_direction: f_direction.write(direction.lower() + "\n") except IOError as e: raise GPIOError(