Skip to content

Commit

Permalink
Merge pull request #11 from nomike/Fix-encoding-when-opening-files-
Browse files Browse the repository at this point in the history
Use autodetection for encodings on open statements.
  • Loading branch information
nomike authored Sep 18, 2024
2 parents 43ef423 + 4417529 commit 3aa6cb5
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions templatehelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# pylint: disable=invalid-name
config = None

with open("../config.yaml", encoding=locale.getencoding()) as file:
with open("../config.yaml", encoding=locale.getpreferredencoding()) as file:
config = yaml.load(file, Loader=yaml.SafeLoader)


Expand Down Expand Up @@ -82,7 +82,9 @@ def listdir(path):
"""
ignorelist = ['index', 'index.md', '*.scmsfasicon', '*.scmstarget']
if os.path.exists(os.path.join(pathprefix, path, '.scmsignore')):
with open(os.path.join(pathprefix, path, '.scmsignore'), encoding=locale.getencoding()) as scsmignore:
with open(
os.path.join(pathprefix, path, '.scmsignore'),
encoding=locale.getpreferredencoding()) as scsmignore:
ignorelist.extend([line.strip('\n') for line in scsmignore.readlines()])
dirlist = [
os.path.basename(f)
Expand Down Expand Up @@ -113,15 +115,19 @@ def listchildren(path):
"""
ignorelist = ['index', 'index.md', '*.scmsfasicon', '*.scmstarget']
if os.path.exists(os.path.join(pathprefix, path, '.scmsignore')):
with open(os.path.join(pathprefix, path, '.scmsignore'), encoding=locale.getencoding()) as scmsignore:
with open(
os.path.join(pathprefix, path, '.scmsignore'),
encoding=locale.getpreferredencoding()) as scmsignore:
ignorelist.extend([line.strip('\n') for line in scmsignore.readlines()])
dirlist = [
[os.path.basename(f), os.path.basename(f)]
for f in os.listdir(os.path.join(pathprefix, path))
if regex.match('^(?!\\.).*(?<!~)$', f) and not f in ignorelist
]
if os.path.exists(os.path.join(pathprefix, path, '.scmslinks')):
with open(os.path.join(pathprefix, path, '.scmslinks'), encoding=locale.getencoding()) as scmslinks:
with open(
os.path.join(pathprefix, path, '.scmslinks'),
encoding=locale.getpreferredencoding()) as scmslinks:
additional_links = json.load(scmslinks)
dirlist.extend(additional_links)
removeitems = []
Expand Down Expand Up @@ -157,7 +163,7 @@ def readfile(path, default=None):
"""
if not os.path.exists(path) and default:
return default
with open(path, 'rb') as requested_file:
with open(path, 'r', encoding=locale.getpreferredencoding()) as requested_file:
return requested_file.read()

def getfasicon(path):
Expand Down

0 comments on commit 3aa6cb5

Please sign in to comment.