From 89f550d048d80dd265f2933e453565689b8414c9 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Aug 29 2019 21:43:35 +0000 Subject: Use encoding from DESCRIPTION when reading it. --- diff --git a/r2spec/rpackage.py b/r2spec/rpackage.py index f5b5873..5114ea9 100644 --- a/r2spec/rpackage.py +++ b/r2spec/rpackage.py @@ -178,7 +178,7 @@ class RPackage(object): self.log.info('Loading "%s"', description) if os.path.exists(self.name) and os.path.isfile(description): try: - stream = open(description, 'r') + stream = open(description, 'rb') content = stream.read() stream.close() except IOError as err: @@ -186,6 +186,11 @@ class RPackage(object): 'An error occurred while reading the DESCRIPTION file: %s', description) self.log.debug('ERROR: %s', err) + encoding = re.search(b'^Encoding: (.+)$', content, re.MULTILINE) + if encoding is not None: + content = content.decode(encoding.group(1).decode().strip()) + else: + content = content.decode('ascii') key = None for row in content.split('\n'): if row.strip():