Skip to content

Commit 88bfd9c

Browse files
Use toolforge.load_private_yaml
Bug: T333728
1 parent 0faab61 commit 88bfd9c

File tree

2 files changed

+3
-28
lines changed

2 files changed

+3
-28
lines changed

{{cookiecutter.tool_identifier}}/app.py

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
# -*- coding: utf-8 -*-
22

3-
import decorator
43
import flask
54
{% if cookiecutter.set_up_mypy == "True" %}from flask.typing import ResponseReturnValue as RRV
65
{% endif %}from markupsafe import Markup
76
import mwapi{% if cookiecutter.set_up_mypy == "True" %} # type: ignore{% endif %}
87
import mwoauth{% if cookiecutter.set_up_mypy == "True" %} # type: ignore{% endif %}
9-
import os
108
import random
119
import requests_oauthlib{% if cookiecutter.set_up_mypy == "True" %} # type: ignore{% endif %}
12-
import stat
1310
import string
1411
import toolforge
1512
{% if cookiecutter.set_up_mypy == "True" %}from typing import Optional, Tuple
16-
{% endif %}import yaml
17-
13+
{% endif %}
1814

1915
app = flask.Flask(__name__)
2016

@@ -23,26 +19,8 @@
2319
email='{{ cookiecutter.user_email }}')
2420

2521

26-
@decorator.decorator
27-
def read_private(func, *args, **kwargs):
28-
try:
29-
f = args[0]
30-
fd = f.fileno()
31-
except AttributeError:
32-
pass
33-
except IndexError:
34-
pass
35-
else:
36-
mode = os.stat(fd).st_mode
37-
if (stat.S_IRGRP | stat.S_IROTH) & mode:
38-
name = getattr(f, "name", "config file")
39-
raise ValueError(f'{name} is readable to others, '
40-
'must be exclusively user-readable!')
41-
return func(*args, **kwargs)
42-
43-
4422
has_config = app.config.from_file('config.yaml',
45-
load=read_private(yaml.safe_load),
23+
load=toolforge.load_private_yaml,
4624
silent=True)
4725
if not has_config:
4826
print('config.yaml file not found, assuming local development setup')
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
decorator
21
{% if cookiecutter.set_up_flake8 == "True" %}flake8
32
{% endif %}flask >= 2.0.0
43
MarkupSafe
@@ -8,6 +7,4 @@ mwoauth
87
{% endif %}{% if cookiecutter.set_up_mypy == "True" %}mypy
98
{% endif %}PyYAML
109
requests_oauthlib
11-
toolforge{% if cookiecutter.set_up_mypy == "True" %}
12-
types-decorator
13-
types-PyYAML{% endif %}
10+
toolforge >= 6.1.0

0 commit comments

Comments
 (0)