Merge branch '1.0-maintenance'

This commit is contained in:
David Lord 2018-04-29 19:11:36 -07:00
commit 1fa9185c7e
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
12 changed files with 153 additions and 37 deletions

View file

@ -27,9 +27,11 @@ from ._compat import integer_types, reraise, string_types, text_type
from .config import Config, ConfigAttribute
from .ctx import AppContext, RequestContext, _AppCtxGlobals
from .globals import _request_ctx_stack, g, request, session
from .helpers import _PackageBoundObject, \
_endpoint_from_view_func, find_package, get_env, get_debug_flag, \
get_flashed_messages, locked_cached_property, url_for
from .helpers import (
_PackageBoundObject,
_endpoint_from_view_func, find_package, get_env, get_debug_flag,
get_flashed_messages, locked_cached_property, url_for, get_load_dotenv
)
from .logging import create_logger
from .sessions import SecureCookieSessionInterface
from .signals import appcontext_tearing_down, got_request_exception, \
@ -904,7 +906,7 @@ class Flask(_PackageBoundObject):
explain_ignored_app_run()
return
if load_dotenv:
if get_load_dotenv(load_dotenv):
cli.load_dotenv()
# if set, let env vars override previous values
@ -1663,8 +1665,14 @@ class Flask(_PackageBoundObject):
trap_bad_request = self.config['TRAP_BAD_REQUEST_ERRORS']
# if unset, trap based on debug mode
if (trap_bad_request is None and self.debug) or trap_bad_request:
# if unset, trap key errors in debug mode
if (
trap_bad_request is None and self.debug
and isinstance(e, BadRequestKeyError)
):
return True
if trap_bad_request:
return isinstance(e, BadRequest)
return False
@ -1923,7 +1931,7 @@ class Flask(_PackageBoundObject):
status = headers = None
# unpack tuple returns
if isinstance(rv, (tuple, list)):
if isinstance(rv, tuple):
len_rv = len(rv)
# a 3-tuple is unpacked directly

View file

@ -49,12 +49,10 @@ class BlueprintSetupState(object):
url_prefix = self.options.get('url_prefix')
if url_prefix is None:
url_prefix = self.blueprint.url_prefix
if url_prefix:
url_prefix = url_prefix.rstrip('/')
#: The prefix that should be used for all URLs defined on the
#: blueprint.
if url_prefix and url_prefix[-1] == '/':
url_prefix = url_prefix[:-1]
self.url_prefix = url_prefix
#: A dictionary with URL defaults that is added to each and every
@ -67,8 +65,8 @@ class BlueprintSetupState(object):
to the application. The endpoint is automatically prefixed with the
blueprint's name.
"""
if self.url_prefix:
rule = self.url_prefix + rule
if self.url_prefix is not None:
rule = '/'.join((self.url_prefix, rule.lstrip('/')))
options.setdefault('subdomain', self.subdomain)
if endpoint is None:
endpoint = _endpoint_from_view_func(view_func)

View file

@ -28,7 +28,7 @@ from werkzeug.utils import import_string
from . import __version__
from ._compat import getargspec, iteritems, reraise, text_type
from .globals import current_app
from .helpers import get_debug_flag, get_env
from .helpers import get_debug_flag, get_env, get_load_dotenv
try:
import dotenv
@ -544,7 +544,7 @@ class FlaskGroup(AppGroup):
# script that is loaded here also attempts to start a server.
os.environ['FLASK_RUN_FROM_CLI'] = 'true'
if self.load_dotenv:
if get_load_dotenv(self.load_dotenv):
load_dotenv()
obj = kwargs.get('obj')
@ -583,12 +583,11 @@ def load_dotenv(path=None):
.. versionadded:: 1.0
"""
if dotenv is None:
if path or os.path.exists('.env') or os.path.exists('.flaskenv'):
click.secho(
' * Tip: There are .env files present.'
' Do "pip install python-dotenv" to use them',
' Do "pip install python-dotenv" to use them.',
fg='yellow')
return

View file

@ -68,6 +68,21 @@ def get_debug_flag():
return val.lower() not in ('0', 'false', 'no')
def get_load_dotenv(default=True):
"""Get whether the user has disabled loading dotenv files by setting
:envvar:`FLASK_SKIP_DOTENV`. The default is ``True``, load the
files.
:param default: What to return if the env var isn't set.
"""
val = os.environ.get('FLASK_SKIP_DOTENV')
if not val:
return default
return val.lower() in ('0', 'false', 'no')
def _endpoint_from_view_func(view_func):
"""Internal helper that returns the default endpoint for a given
function. This always is the function name.