repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
briancappello/flask-unchained | flask_unchained/bundles/controller/__init__.py | ControllerBundle.after_init_app | def after_init_app(self, app: FlaskUnchained):
"""
Configure an after request hook to set the ``csrf_token`` in the cookie.
"""
from flask_wtf.csrf import generate_csrf
# send CSRF token in the cookie
@app.after_request
def set_csrf_cookie(response):
... | python | def after_init_app(self, app: FlaskUnchained):
"""
Configure an after request hook to set the ``csrf_token`` in the cookie.
"""
from flask_wtf.csrf import generate_csrf
# send CSRF token in the cookie
@app.after_request
def set_csrf_cookie(response):
... | [
"def",
"after_init_app",
"(",
"self",
",",
"app",
":",
"FlaskUnchained",
")",
":",
"from",
"flask_wtf",
".",
"csrf",
"import",
"generate_csrf",
"# send CSRF token in the cookie",
"@",
"app",
".",
"after_request",
"def",
"set_csrf_cookie",
"(",
"response",
")",
":"... | Configure an after request hook to set the ``csrf_token`` in the cookie. | [
"Configure",
"an",
"after",
"request",
"hook",
"to",
"set",
"the",
"csrf_token",
"in",
"the",
"cookie",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/controller/__init__.py#L57-L69 | train |
briancappello/flask-unchained | flask_unchained/commands/shell.py | shell | def shell():
"""
Runs a shell in the app context. If ``IPython`` is installed, it will
be used, otherwise the default Python shell is used.
"""
ctx = _get_shell_ctx()
try:
import IPython
IPython.embed(header=_get_shell_banner(), user_ns=ctx)
except ImportError:
import... | python | def shell():
"""
Runs a shell in the app context. If ``IPython`` is installed, it will
be used, otherwise the default Python shell is used.
"""
ctx = _get_shell_ctx()
try:
import IPython
IPython.embed(header=_get_shell_banner(), user_ns=ctx)
except ImportError:
import... | [
"def",
"shell",
"(",
")",
":",
"ctx",
"=",
"_get_shell_ctx",
"(",
")",
"try",
":",
"import",
"IPython",
"IPython",
".",
"embed",
"(",
"header",
"=",
"_get_shell_banner",
"(",
")",
",",
"user_ns",
"=",
"ctx",
")",
"except",
"ImportError",
":",
"import",
... | Runs a shell in the app context. If ``IPython`` is installed, it will
be used, otherwise the default Python shell is used. | [
"Runs",
"a",
"shell",
"in",
"the",
"app",
"context",
".",
"If",
"IPython",
"is",
"installed",
"it",
"will",
"be",
"used",
"otherwise",
"the",
"default",
"Python",
"shell",
"is",
"used",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/commands/shell.py#L10-L21 | train |
briancappello/flask-unchained | flask_unchained/bundles/security/views/security_controller.py | SecurityController.login | def login(self):
"""
View function to log a user in. Supports html and json requests.
"""
form = self._get_form('SECURITY_LOGIN_FORM')
if form.validate_on_submit():
try:
self.security_service.login_user(form.user, form.remember.data)
except... | python | def login(self):
"""
View function to log a user in. Supports html and json requests.
"""
form = self._get_form('SECURITY_LOGIN_FORM')
if form.validate_on_submit():
try:
self.security_service.login_user(form.user, form.remember.data)
except... | [
"def",
"login",
"(",
"self",
")",
":",
"form",
"=",
"self",
".",
"_get_form",
"(",
"'SECURITY_LOGIN_FORM'",
")",
"if",
"form",
".",
"validate_on_submit",
"(",
")",
":",
"try",
":",
"self",
".",
"security_service",
".",
"login_user",
"(",
"form",
".",
"us... | View function to log a user in. Supports html and json requests. | [
"View",
"function",
"to",
"log",
"a",
"user",
"in",
".",
"Supports",
"html",
"and",
"json",
"requests",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/security/views/security_controller.py#L39-L73 | train |
briancappello/flask-unchained | flask_unchained/bundles/security/views/security_controller.py | SecurityController.logout | def logout(self):
"""
View function to log a user out. Supports html and json requests.
"""
if current_user.is_authenticated:
self.security_service.logout_user()
if request.is_json:
return '', HTTPStatus.NO_CONTENT
self.flash(_('flask_unchained.b... | python | def logout(self):
"""
View function to log a user out. Supports html and json requests.
"""
if current_user.is_authenticated:
self.security_service.logout_user()
if request.is_json:
return '', HTTPStatus.NO_CONTENT
self.flash(_('flask_unchained.b... | [
"def",
"logout",
"(",
"self",
")",
":",
"if",
"current_user",
".",
"is_authenticated",
":",
"self",
".",
"security_service",
".",
"logout_user",
"(",
")",
"if",
"request",
".",
"is_json",
":",
"return",
"''",
",",
"HTTPStatus",
".",
"NO_CONTENT",
"self",
"... | View function to log a user out. Supports html and json requests. | [
"View",
"function",
"to",
"log",
"a",
"user",
"out",
".",
"Supports",
"html",
"and",
"json",
"requests",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/security/views/security_controller.py#L76-L88 | train |
briancappello/flask-unchained | flask_unchained/bundles/security/views/security_controller.py | SecurityController.register | def register(self):
"""
View function to register user. Supports html and json requests.
"""
form = self._get_form('SECURITY_REGISTER_FORM')
if form.validate_on_submit():
user = self.security_service.user_manager.create(**form.to_dict())
self.security_serv... | python | def register(self):
"""
View function to register user. Supports html and json requests.
"""
form = self._get_form('SECURITY_REGISTER_FORM')
if form.validate_on_submit():
user = self.security_service.user_manager.create(**form.to_dict())
self.security_serv... | [
"def",
"register",
"(",
"self",
")",
":",
"form",
"=",
"self",
".",
"_get_form",
"(",
"'SECURITY_REGISTER_FORM'",
")",
"if",
"form",
".",
"validate_on_submit",
"(",
")",
":",
"user",
"=",
"self",
".",
"security_service",
".",
"user_manager",
".",
"create",
... | View function to register user. Supports html and json requests. | [
"View",
"function",
"to",
"register",
"user",
".",
"Supports",
"html",
"and",
"json",
"requests",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/security/views/security_controller.py#L93-L105 | train |
briancappello/flask-unchained | flask_unchained/bundles/security/views/security_controller.py | SecurityController.send_confirmation_email | def send_confirmation_email(self):
"""
View function which sends confirmation token and instructions to a user.
"""
form = self._get_form('SECURITY_SEND_CONFIRMATION_FORM')
if form.validate_on_submit():
self.security_service.send_email_confirmation_instructions(form.u... | python | def send_confirmation_email(self):
"""
View function which sends confirmation token and instructions to a user.
"""
form = self._get_form('SECURITY_SEND_CONFIRMATION_FORM')
if form.validate_on_submit():
self.security_service.send_email_confirmation_instructions(form.u... | [
"def",
"send_confirmation_email",
"(",
"self",
")",
":",
"form",
"=",
"self",
".",
"_get_form",
"(",
"'SECURITY_SEND_CONFIRMATION_FORM'",
")",
"if",
"form",
".",
"validate_on_submit",
"(",
")",
":",
"self",
".",
"security_service",
".",
"send_email_confirmation_inst... | View function which sends confirmation token and instructions to a user. | [
"View",
"function",
"which",
"sends",
"confirmation",
"token",
"and",
"instructions",
"to",
"a",
"user",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/security/views/security_controller.py#L109-L126 | train |
briancappello/flask-unchained | flask_unchained/bundles/security/views/security_controller.py | SecurityController.confirm_email | def confirm_email(self, token):
"""
View function to confirm a user's token from the confirmation email send to them.
Supports html and json requests.
"""
expired, invalid, user = \
self.security_utils_service.confirm_email_token_status(token)
if not user or i... | python | def confirm_email(self, token):
"""
View function to confirm a user's token from the confirmation email send to them.
Supports html and json requests.
"""
expired, invalid, user = \
self.security_utils_service.confirm_email_token_status(token)
if not user or i... | [
"def",
"confirm_email",
"(",
"self",
",",
"token",
")",
":",
"expired",
",",
"invalid",
",",
"user",
"=",
"self",
".",
"security_utils_service",
".",
"confirm_email_token_status",
"(",
"token",
")",
"if",
"not",
"user",
"or",
"invalid",
":",
"invalid",
"=",
... | View function to confirm a user's token from the confirmation email send to them.
Supports html and json requests. | [
"View",
"function",
"to",
"confirm",
"a",
"user",
"s",
"token",
"from",
"the",
"confirmation",
"email",
"send",
"to",
"them",
".",
"Supports",
"html",
"and",
"json",
"requests",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/security/views/security_controller.py#L130-L168 | train |
briancappello/flask-unchained | flask_unchained/bundles/security/views/security_controller.py | SecurityController.forgot_password | def forgot_password(self):
"""
View function to request a password recovery email with a reset token.
Supports html and json requests.
"""
form = self._get_form('SECURITY_FORGOT_PASSWORD_FORM')
if form.validate_on_submit():
self.security_service.send_reset_pas... | python | def forgot_password(self):
"""
View function to request a password recovery email with a reset token.
Supports html and json requests.
"""
form = self._get_form('SECURITY_FORGOT_PASSWORD_FORM')
if form.validate_on_submit():
self.security_service.send_reset_pas... | [
"def",
"forgot_password",
"(",
"self",
")",
":",
"form",
"=",
"self",
".",
"_get_form",
"(",
"'SECURITY_FORGOT_PASSWORD_FORM'",
")",
"if",
"form",
".",
"validate_on_submit",
"(",
")",
":",
"self",
".",
"security_service",
".",
"send_reset_password_instructions",
"... | View function to request a password recovery email with a reset token.
Supports html and json requests. | [
"View",
"function",
"to",
"request",
"a",
"password",
"recovery",
"email",
"with",
"a",
"reset",
"token",
".",
"Supports",
"html",
"and",
"json",
"requests",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/security/views/security_controller.py#L174-L193 | train |
briancappello/flask-unchained | flask_unchained/bundles/security/views/security_controller.py | SecurityController.reset_password | def reset_password(self, token):
"""
View function verify a users reset password token from the email we sent to them.
It also handles the form for them to set a new password.
Supports html and json requests.
"""
expired, invalid, user = \
self.security_utils_... | python | def reset_password(self, token):
"""
View function verify a users reset password token from the email we sent to them.
It also handles the form for them to set a new password.
Supports html and json requests.
"""
expired, invalid, user = \
self.security_utils_... | [
"def",
"reset_password",
"(",
"self",
",",
"token",
")",
":",
"expired",
",",
"invalid",
",",
"user",
"=",
"self",
".",
"security_utils_service",
".",
"reset_password_token_status",
"(",
"token",
")",
"if",
"invalid",
":",
"self",
".",
"flash",
"(",
"_",
"... | View function verify a users reset password token from the email we sent to them.
It also handles the form for them to set a new password.
Supports html and json requests. | [
"View",
"function",
"verify",
"a",
"users",
"reset",
"password",
"token",
"from",
"the",
"email",
"we",
"sent",
"to",
"them",
".",
"It",
"also",
"handles",
"the",
"form",
"for",
"them",
"to",
"set",
"a",
"new",
"password",
".",
"Supports",
"html",
"and",... | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/security/views/security_controller.py#L198-L242 | train |
briancappello/flask-unchained | flask_unchained/bundles/security/views/security_controller.py | SecurityController.change_password | def change_password(self):
"""
View function for a user to change their password.
Supports html and json requests.
"""
form = self._get_form('SECURITY_CHANGE_PASSWORD_FORM')
if form.validate_on_submit():
self.security_service.change_password(
c... | python | def change_password(self):
"""
View function for a user to change their password.
Supports html and json requests.
"""
form = self._get_form('SECURITY_CHANGE_PASSWORD_FORM')
if form.validate_on_submit():
self.security_service.change_password(
c... | [
"def",
"change_password",
"(",
"self",
")",
":",
"form",
"=",
"self",
".",
"_get_form",
"(",
"'SECURITY_CHANGE_PASSWORD_FORM'",
")",
"if",
"form",
".",
"validate_on_submit",
"(",
")",
":",
"self",
".",
"security_service",
".",
"change_password",
"(",
"current_us... | View function for a user to change their password.
Supports html and json requests. | [
"View",
"function",
"for",
"a",
"user",
"to",
"change",
"their",
"password",
".",
"Supports",
"html",
"and",
"json",
"requests",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/security/views/security_controller.py#L247-L270 | train |
briancappello/flask-unchained | flask_unchained/bundles/security/extensions/security.py | Security._get_pwd_context | def _get_pwd_context(self, app: FlaskUnchained) -> CryptContext:
"""
Get the password hashing context.
"""
pw_hash = app.config.SECURITY_PASSWORD_HASH
schemes = app.config.SECURITY_PASSWORD_SCHEMES
if pw_hash not in schemes:
allowed = (', '.join(schemes[:-1]) ... | python | def _get_pwd_context(self, app: FlaskUnchained) -> CryptContext:
"""
Get the password hashing context.
"""
pw_hash = app.config.SECURITY_PASSWORD_HASH
schemes = app.config.SECURITY_PASSWORD_SCHEMES
if pw_hash not in schemes:
allowed = (', '.join(schemes[:-1]) ... | [
"def",
"_get_pwd_context",
"(",
"self",
",",
"app",
":",
"FlaskUnchained",
")",
"->",
"CryptContext",
":",
"pw_hash",
"=",
"app",
".",
"config",
".",
"SECURITY_PASSWORD_HASH",
"schemes",
"=",
"app",
".",
"config",
".",
"SECURITY_PASSWORD_SCHEMES",
"if",
"pw_hash... | Get the password hashing context. | [
"Get",
"the",
"password",
"hashing",
"context",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/security/extensions/security.py#L215-L226 | train |
briancappello/flask-unchained | flask_unchained/bundles/security/extensions/security.py | Security._get_serializer | def _get_serializer(self, app: FlaskUnchained, name: str) -> URLSafeTimedSerializer:
"""
Get a URLSafeTimedSerializer for the given serialization context name.
:param app: the :class:`FlaskUnchained` instance
:param name: Serialization context. One of ``confirm``, ``login``,
`... | python | def _get_serializer(self, app: FlaskUnchained, name: str) -> URLSafeTimedSerializer:
"""
Get a URLSafeTimedSerializer for the given serialization context name.
:param app: the :class:`FlaskUnchained` instance
:param name: Serialization context. One of ``confirm``, ``login``,
`... | [
"def",
"_get_serializer",
"(",
"self",
",",
"app",
":",
"FlaskUnchained",
",",
"name",
":",
"str",
")",
"->",
"URLSafeTimedSerializer",
":",
"salt",
"=",
"app",
".",
"config",
".",
"get",
"(",
"'SECURITY_%s_SALT'",
"%",
"name",
".",
"upper",
"(",
")",
")... | Get a URLSafeTimedSerializer for the given serialization context name.
:param app: the :class:`FlaskUnchained` instance
:param name: Serialization context. One of ``confirm``, ``login``,
``remember``, or ``reset``
:return: URLSafeTimedSerializer | [
"Get",
"a",
"URLSafeTimedSerializer",
"for",
"the",
"given",
"serialization",
"context",
"name",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/security/extensions/security.py#L228-L238 | train |
briancappello/flask-unchained | flask_unchained/bundles/security/extensions/security.py | Security._request_loader | def _request_loader(self, request: Request) -> Union[User, AnonymousUser]:
"""
Attempt to load the user from the request token.
"""
header_key = self.token_authentication_header
args_key = self.token_authentication_key
token = request.args.get(args_key, request.headers.ge... | python | def _request_loader(self, request: Request) -> Union[User, AnonymousUser]:
"""
Attempt to load the user from the request token.
"""
header_key = self.token_authentication_header
args_key = self.token_authentication_key
token = request.args.get(args_key, request.headers.ge... | [
"def",
"_request_loader",
"(",
"self",
",",
"request",
":",
"Request",
")",
"->",
"Union",
"[",
"User",
",",
"AnonymousUser",
"]",
":",
"header_key",
"=",
"self",
".",
"token_authentication_header",
"args_key",
"=",
"self",
".",
"token_authentication_key",
"toke... | Attempt to load the user from the request token. | [
"Attempt",
"to",
"load",
"the",
"user",
"from",
"the",
"request",
"token",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/security/extensions/security.py#L260-L279 | train |
briancappello/flask-unchained | flask_unchained/commands/unchained.py | bundles | def bundles(ctx):
"""
List discovered bundles.
"""
bundles = _get_bundles(ctx.obj.data['env'])
print_table(('Name', 'Location'),
[(bundle.name, f'{bundle.__module__}.{bundle.__class__.__name__}')
for bundle in bundles]) | python | def bundles(ctx):
"""
List discovered bundles.
"""
bundles = _get_bundles(ctx.obj.data['env'])
print_table(('Name', 'Location'),
[(bundle.name, f'{bundle.__module__}.{bundle.__class__.__name__}')
for bundle in bundles]) | [
"def",
"bundles",
"(",
"ctx",
")",
":",
"bundles",
"=",
"_get_bundles",
"(",
"ctx",
".",
"obj",
".",
"data",
"[",
"'env'",
"]",
")",
"print_table",
"(",
"(",
"'Name'",
",",
"'Location'",
")",
",",
"[",
"(",
"bundle",
".",
"name",
",",
"f'{bundle.__mo... | List discovered bundles. | [
"List",
"discovered",
"bundles",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/commands/unchained.py#L16-L23 | train |
briancappello/flask-unchained | flask_unchained/click.py | argument | def argument(*param_decls, cls=None, **attrs):
"""
Arguments are positional parameters to a command. They generally
provide fewer features than options but can have infinite ``nargs``
and are required by default.
:param param_decls: the parameter declarations for this option or
... | python | def argument(*param_decls, cls=None, **attrs):
"""
Arguments are positional parameters to a command. They generally
provide fewer features than options but can have infinite ``nargs``
and are required by default.
:param param_decls: the parameter declarations for this option or
... | [
"def",
"argument",
"(",
"*",
"param_decls",
",",
"cls",
"=",
"None",
",",
"*",
"*",
"attrs",
")",
":",
"return",
"click",
".",
"argument",
"(",
"*",
"param_decls",
",",
"cls",
"=",
"cls",
"or",
"Argument",
",",
"*",
"*",
"attrs",
")"
] | Arguments are positional parameters to a command. They generally
provide fewer features than options but can have infinite ``nargs``
and are required by default.
:param param_decls: the parameter declarations for this option or
argument. This is a list of flags or argument
... | [
"Arguments",
"are",
"positional",
"parameters",
"to",
"a",
"command",
".",
"They",
"generally",
"provide",
"fewer",
"features",
"than",
"options",
"but",
"can",
"have",
"infinite",
"nargs",
"and",
"are",
"required",
"by",
"default",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/click.py#L390-L427 | train |
briancappello/flask-unchained | flask_unchained/click.py | option | def option(*param_decls, cls=None, **attrs):
"""
Options are usually optional values on the command line and
have some extra features that arguments don't have.
:param param_decls: the parameter declarations for this option or
argument. This is a list of flags or argument
... | python | def option(*param_decls, cls=None, **attrs):
"""
Options are usually optional values on the command line and
have some extra features that arguments don't have.
:param param_decls: the parameter declarations for this option or
argument. This is a list of flags or argument
... | [
"def",
"option",
"(",
"*",
"param_decls",
",",
"cls",
"=",
"None",
",",
"*",
"*",
"attrs",
")",
":",
"return",
"click",
".",
"option",
"(",
"*",
"param_decls",
",",
"cls",
"=",
"cls",
"or",
"Option",
",",
"*",
"*",
"attrs",
")"
] | Options are usually optional values on the command line and
have some extra features that arguments don't have.
:param param_decls: the parameter declarations for this option or
argument. This is a list of flags or argument
names.
:param show_default: contro... | [
"Options",
"are",
"usually",
"optional",
"values",
"on",
"the",
"command",
"line",
"and",
"have",
"some",
"extra",
"features",
"that",
"arguments",
"don",
"t",
"have",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/click.py#L430-L464 | train |
briancappello/flask-unchained | flask_unchained/bundles/api/apispec.py | APISpec._openapi_json | def _openapi_json(self):
"""Serve JSON spec file"""
# We don't use Flask.jsonify here as it would sort the keys
# alphabetically while we want to preserve the order.
from pprint import pprint
pprint(self.to_dict())
return current_app.response_class(json.dumps(self.to_dict... | python | def _openapi_json(self):
"""Serve JSON spec file"""
# We don't use Flask.jsonify here as it would sort the keys
# alphabetically while we want to preserve the order.
from pprint import pprint
pprint(self.to_dict())
return current_app.response_class(json.dumps(self.to_dict... | [
"def",
"_openapi_json",
"(",
"self",
")",
":",
"# We don't use Flask.jsonify here as it would sort the keys",
"# alphabetically while we want to preserve the order.",
"from",
"pprint",
"import",
"pprint",
"pprint",
"(",
"self",
".",
"to_dict",
"(",
")",
")",
"return",
"curr... | Serve JSON spec file | [
"Serve",
"JSON",
"spec",
"file"
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/api/apispec.py#L59-L66 | train |
briancappello/flask-unchained | flask_unchained/bundles/api/apispec.py | APISpec._openapi_redoc | def _openapi_redoc(self):
"""
Expose OpenAPI spec with ReDoc
The ReDoc script URL can be specified as ``API_REDOC_SOURCE_URL``
"""
return render_template('openapi/redoc.html',
title=self.app.config.API_TITLE or self.app.name,
... | python | def _openapi_redoc(self):
"""
Expose OpenAPI spec with ReDoc
The ReDoc script URL can be specified as ``API_REDOC_SOURCE_URL``
"""
return render_template('openapi/redoc.html',
title=self.app.config.API_TITLE or self.app.name,
... | [
"def",
"_openapi_redoc",
"(",
"self",
")",
":",
"return",
"render_template",
"(",
"'openapi/redoc.html'",
",",
"title",
"=",
"self",
".",
"app",
".",
"config",
".",
"API_TITLE",
"or",
"self",
".",
"app",
".",
"name",
",",
"redoc_url",
"=",
"self",
".",
"... | Expose OpenAPI spec with ReDoc
The ReDoc script URL can be specified as ``API_REDOC_SOURCE_URL`` | [
"Expose",
"OpenAPI",
"spec",
"with",
"ReDoc"
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/api/apispec.py#L68-L76 | train |
briancappello/flask-unchained | flask_unchained/bundles/api/apispec.py | APISpec.register_converter | def register_converter(self, converter, conv_type, conv_format=None):
"""
Register custom path parameter converter
:param BaseConverter converter: Converter.
Subclass of werkzeug's BaseConverter
:param str conv_type: Parameter type
:param str conv_format: Parameter f... | python | def register_converter(self, converter, conv_type, conv_format=None):
"""
Register custom path parameter converter
:param BaseConverter converter: Converter.
Subclass of werkzeug's BaseConverter
:param str conv_type: Parameter type
:param str conv_format: Parameter f... | [
"def",
"register_converter",
"(",
"self",
",",
"converter",
",",
"conv_type",
",",
"conv_format",
"=",
"None",
")",
":",
"self",
".",
"flask_plugin",
".",
"register_converter",
"(",
"converter",
",",
"conv_type",
",",
"conv_format",
")"
] | Register custom path parameter converter
:param BaseConverter converter: Converter.
Subclass of werkzeug's BaseConverter
:param str conv_type: Parameter type
:param str conv_format: Parameter format (optional) | [
"Register",
"custom",
"path",
"parameter",
"converter"
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/api/apispec.py#L78-L87 | train |
briancappello/flask-unchained | flask_unchained/bundles/api/decorators.py | list_loader | def list_loader(*decorator_args, model):
"""
Decorator to automatically query the database for all records of a model.
:param model: The model class to query
"""
def wrapped(fn):
@wraps(fn)
def decorated(*args, **kwargs):
return fn(model.query.all())
return decor... | python | def list_loader(*decorator_args, model):
"""
Decorator to automatically query the database for all records of a model.
:param model: The model class to query
"""
def wrapped(fn):
@wraps(fn)
def decorated(*args, **kwargs):
return fn(model.query.all())
return decor... | [
"def",
"list_loader",
"(",
"*",
"decorator_args",
",",
"model",
")",
":",
"def",
"wrapped",
"(",
"fn",
")",
":",
"@",
"wraps",
"(",
"fn",
")",
"def",
"decorated",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"fn",
"(",
"model",
... | Decorator to automatically query the database for all records of a model.
:param model: The model class to query | [
"Decorator",
"to",
"automatically",
"query",
"the",
"database",
"for",
"all",
"records",
"of",
"a",
"model",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/api/decorators.py#L7-L21 | train |
briancappello/flask-unchained | flask_unchained/bundles/api/decorators.py | post_loader | def post_loader(*decorator_args, serializer):
"""
Decorator to automatically instantiate a model from json request data
:param serializer: The ModelSerializer to use to load data from the request
"""
def wrapped(fn):
@wraps(fn)
def decorated(*args, **kwargs):
return fn(*... | python | def post_loader(*decorator_args, serializer):
"""
Decorator to automatically instantiate a model from json request data
:param serializer: The ModelSerializer to use to load data from the request
"""
def wrapped(fn):
@wraps(fn)
def decorated(*args, **kwargs):
return fn(*... | [
"def",
"post_loader",
"(",
"*",
"decorator_args",
",",
"serializer",
")",
":",
"def",
"wrapped",
"(",
"fn",
")",
":",
"@",
"wraps",
"(",
"fn",
")",
"def",
"decorated",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"fn",
"(",
"*",
... | Decorator to automatically instantiate a model from json request data
:param serializer: The ModelSerializer to use to load data from the request | [
"Decorator",
"to",
"automatically",
"instantiate",
"a",
"model",
"from",
"json",
"request",
"data"
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/api/decorators.py#L68-L82 | train |
briancappello/flask-unchained | flask_unchained/bundles/sqlalchemy/commands.py | reset_command | def reset_command(force):
"""Drop database tables and run migrations."""
if not force:
exit('Cancelled.')
click.echo('Dropping DB tables.')
drop_all()
click.echo('Running DB migrations.')
alembic.upgrade(migrate.get_config(None), 'head')
click.echo('Done.') | python | def reset_command(force):
"""Drop database tables and run migrations."""
if not force:
exit('Cancelled.')
click.echo('Dropping DB tables.')
drop_all()
click.echo('Running DB migrations.')
alembic.upgrade(migrate.get_config(None), 'head')
click.echo('Done.') | [
"def",
"reset_command",
"(",
"force",
")",
":",
"if",
"not",
"force",
":",
"exit",
"(",
"'Cancelled.'",
")",
"click",
".",
"echo",
"(",
"'Dropping DB tables.'",
")",
"drop_all",
"(",
")",
"click",
".",
"echo",
"(",
"'Running DB migrations.'",
")",
"alembic",... | Drop database tables and run migrations. | [
"Drop",
"database",
"tables",
"and",
"run",
"migrations",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/sqlalchemy/commands.py#L43-L54 | train |
tanbro/pyyaml-include | src/yamlinclude/constructor.py | YamlIncludeConstructor.load | def load(self, loader, pathname, recursive=False, encoding=None):
"""Once add the constructor to PyYAML loader class,
Loader will use this function to include other YAML fils
on parsing ``"!include"`` tag
:param loader: Instance of PyYAML's loader class
:param str pathname: path... | python | def load(self, loader, pathname, recursive=False, encoding=None):
"""Once add the constructor to PyYAML loader class,
Loader will use this function to include other YAML fils
on parsing ``"!include"`` tag
:param loader: Instance of PyYAML's loader class
:param str pathname: path... | [
"def",
"load",
"(",
"self",
",",
"loader",
",",
"pathname",
",",
"recursive",
"=",
"False",
",",
"encoding",
"=",
"None",
")",
":",
"if",
"not",
"encoding",
":",
"encoding",
"=",
"self",
".",
"_encoding",
"or",
"self",
".",
"DEFAULT_ENCODING",
"if",
"s... | Once add the constructor to PyYAML loader class,
Loader will use this function to include other YAML fils
on parsing ``"!include"`` tag
:param loader: Instance of PyYAML's loader class
:param str pathname: pathname can be either absolute (like /usr/src/Python-1.5/Makefile) or relative (... | [
"Once",
"add",
"the",
"constructor",
"to",
"PyYAML",
"loader",
"class",
"Loader",
"will",
"use",
"this",
"function",
"to",
"include",
"other",
"YAML",
"fils",
"on",
"parsing",
"!include",
"tag"
] | f0e6490399aaf7c02321000fe5cdccfa8f63cf66 | https://github.com/tanbro/pyyaml-include/blob/f0e6490399aaf7c02321000fe5cdccfa8f63cf66/src/yamlinclude/constructor.py#L96-L133 | train |
tanbro/pyyaml-include | src/yamlinclude/constructor.py | YamlIncludeConstructor.add_to_loader_class | def add_to_loader_class(cls, loader_class=None, tag=None, **kwargs):
# type: (type(yaml.Loader), str, **str)-> YamlIncludeConstructor
"""
Create an instance of the constructor, and add it to the YAML `Loader` class
:param loader_class: The `Loader` class add constructor to.
... | python | def add_to_loader_class(cls, loader_class=None, tag=None, **kwargs):
# type: (type(yaml.Loader), str, **str)-> YamlIncludeConstructor
"""
Create an instance of the constructor, and add it to the YAML `Loader` class
:param loader_class: The `Loader` class add constructor to.
... | [
"def",
"add_to_loader_class",
"(",
"cls",
",",
"loader_class",
"=",
"None",
",",
"tag",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"# type: (type(yaml.Loader), str, **str)-> YamlIncludeConstructor",
"if",
"tag",
"is",
"None",
":",
"tag",
"=",
"''",
"tag",
... | Create an instance of the constructor, and add it to the YAML `Loader` class
:param loader_class: The `Loader` class add constructor to.
.. attention:: This parameter **SHOULD** be a **class type**, **NOT** object.
It's one of following:
- :class:`yaml.BaseLoader`
... | [
"Create",
"an",
"instance",
"of",
"the",
"constructor",
"and",
"add",
"it",
"to",
"the",
"YAML",
"Loader",
"class"
] | f0e6490399aaf7c02321000fe5cdccfa8f63cf66 | https://github.com/tanbro/pyyaml-include/blob/f0e6490399aaf7c02321000fe5cdccfa8f63cf66/src/yamlinclude/constructor.py#L136-L189 | train |
briancappello/flask-unchained | flask_unchained/commands/utils.py | print_table | def print_table(column_names: IterableOfStrings,
rows: IterableOfTuples,
column_alignments: Optional[IterableOfStrings] = None,
primary_column_idx: int = 0,
) -> None:
"""
Prints a table of information to the console. Automatically determines if th... | python | def print_table(column_names: IterableOfStrings,
rows: IterableOfTuples,
column_alignments: Optional[IterableOfStrings] = None,
primary_column_idx: int = 0,
) -> None:
"""
Prints a table of information to the console. Automatically determines if th... | [
"def",
"print_table",
"(",
"column_names",
":",
"IterableOfStrings",
",",
"rows",
":",
"IterableOfTuples",
",",
"column_alignments",
":",
"Optional",
"[",
"IterableOfStrings",
"]",
"=",
"None",
",",
"primary_column_idx",
":",
"int",
"=",
"0",
",",
")",
"->",
"... | Prints a table of information to the console. Automatically determines if the
console is wide enough, and if not, displays the information in list form.
:param column_names: The heading labels
:param rows: A list of lists
:param column_alignments: An optional list of strings, using either '<' or '>'
... | [
"Prints",
"a",
"table",
"of",
"information",
"to",
"the",
"console",
".",
"Automatically",
"determines",
"if",
"the",
"console",
"is",
"wide",
"enough",
"and",
"if",
"not",
"displays",
"the",
"information",
"in",
"list",
"form",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/commands/utils.py#L10-L80 | train |
briancappello/flask-unchained | flask_mail.py | Connection.send | def send(self, message, envelope_from=None):
"""Verifies and sends message.
:param message: Message instance.
:param envelope_from: Email address to be used in MAIL FROM command.
"""
assert message.send_to, "No recipients have been added"
assert message.sender, (
... | python | def send(self, message, envelope_from=None):
"""Verifies and sends message.
:param message: Message instance.
:param envelope_from: Email address to be used in MAIL FROM command.
"""
assert message.send_to, "No recipients have been added"
assert message.sender, (
... | [
"def",
"send",
"(",
"self",
",",
"message",
",",
"envelope_from",
"=",
"None",
")",
":",
"assert",
"message",
".",
"send_to",
",",
"\"No recipients have been added\"",
"assert",
"message",
".",
"sender",
",",
"(",
"\"The message does not specify a sender and a default... | Verifies and sends message.
:param message: Message instance.
:param envelope_from: Email address to be used in MAIL FROM command. | [
"Verifies",
"and",
"sends",
"message",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_mail.py#L228-L266 | train |
briancappello/flask-unchained | flask_mail.py | _MailMixin.connect | def connect(self):
"""
Opens a connection to the mail host.
"""
app = getattr(self, "app", None) or current_app
try:
return Connection(app.extensions['mail'])
except KeyError:
raise RuntimeError("The curent application was"
... | python | def connect(self):
"""
Opens a connection to the mail host.
"""
app = getattr(self, "app", None) or current_app
try:
return Connection(app.extensions['mail'])
except KeyError:
raise RuntimeError("The curent application was"
... | [
"def",
"connect",
"(",
"self",
")",
":",
"app",
"=",
"getattr",
"(",
"self",
",",
"\"app\"",
",",
"None",
")",
"or",
"current_app",
"try",
":",
"return",
"Connection",
"(",
"app",
".",
"extensions",
"[",
"'mail'",
"]",
")",
"except",
"KeyError",
":",
... | Opens a connection to the mail host. | [
"Opens",
"a",
"connection",
"to",
"the",
"mail",
"host",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_mail.py#L633-L642 | train |
briancappello/flask-unchained | flask_mail.py | Mail.init_app | def init_app(self, app):
"""Initializes your mail settings from the application settings.
You can use this if you want to set up your Mail instance
at configuration time.
:param app: Flask application instance
"""
state = self.init_mail(app.config, app.debug, app.testin... | python | def init_app(self, app):
"""Initializes your mail settings from the application settings.
You can use this if you want to set up your Mail instance
at configuration time.
:param app: Flask application instance
"""
state = self.init_mail(app.config, app.debug, app.testin... | [
"def",
"init_app",
"(",
"self",
",",
"app",
")",
":",
"state",
"=",
"self",
".",
"init_mail",
"(",
"app",
".",
"config",
",",
"app",
".",
"debug",
",",
"app",
".",
"testing",
")",
"# register extension with app",
"app",
".",
"extensions",
"=",
"getattr",... | Initializes your mail settings from the application settings.
You can use this if you want to set up your Mail instance
at configuration time.
:param app: Flask application instance | [
"Initializes",
"your",
"mail",
"settings",
"from",
"the",
"application",
"settings",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_mail.py#L691-L704 | train |
briancappello/flask-unchained | flask_unchained/bundle.py | _DeferredBundleFunctions.url_defaults | def url_defaults(self, fn):
"""
Callback function for URL defaults for this bundle. It's called
with the endpoint and values and should update the values passed
in place.
"""
self._defer(lambda bp: bp.url_defaults(fn))
return fn | python | def url_defaults(self, fn):
"""
Callback function for URL defaults for this bundle. It's called
with the endpoint and values and should update the values passed
in place.
"""
self._defer(lambda bp: bp.url_defaults(fn))
return fn | [
"def",
"url_defaults",
"(",
"self",
",",
"fn",
")",
":",
"self",
".",
"_defer",
"(",
"lambda",
"bp",
":",
"bp",
".",
"url_defaults",
"(",
"fn",
")",
")",
"return",
"fn"
] | Callback function for URL defaults for this bundle. It's called
with the endpoint and values and should update the values passed
in place. | [
"Callback",
"function",
"for",
"URL",
"defaults",
"for",
"this",
"bundle",
".",
"It",
"s",
"called",
"with",
"the",
"endpoint",
"and",
"values",
"and",
"should",
"update",
"the",
"values",
"passed",
"in",
"place",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundle.py#L113-L120 | train |
briancappello/flask-unchained | flask_unchained/bundle.py | _DeferredBundleFunctions.url_value_preprocessor | def url_value_preprocessor(self, fn):
"""
Registers a function as URL value preprocessor for this
bundle. It's called before the view functions are called and
can modify the url values provided.
"""
self._defer(lambda bp: bp.url_value_preprocessor(fn))
return fn | python | def url_value_preprocessor(self, fn):
"""
Registers a function as URL value preprocessor for this
bundle. It's called before the view functions are called and
can modify the url values provided.
"""
self._defer(lambda bp: bp.url_value_preprocessor(fn))
return fn | [
"def",
"url_value_preprocessor",
"(",
"self",
",",
"fn",
")",
":",
"self",
".",
"_defer",
"(",
"lambda",
"bp",
":",
"bp",
".",
"url_value_preprocessor",
"(",
"fn",
")",
")",
"return",
"fn"
] | Registers a function as URL value preprocessor for this
bundle. It's called before the view functions are called and
can modify the url values provided. | [
"Registers",
"a",
"function",
"as",
"URL",
"value",
"preprocessor",
"for",
"this",
"bundle",
".",
"It",
"s",
"called",
"before",
"the",
"view",
"functions",
"are",
"called",
"and",
"can",
"modify",
"the",
"url",
"values",
"provided",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundle.py#L122-L129 | train |
briancappello/flask-unchained | flask_unchained/bundle.py | _DeferredBundleFunctions.errorhandler | def errorhandler(self, code_or_exception):
"""
Registers an error handler that becomes active for this bundle
only. Please be aware that routing does not happen local to a
bundle so an error handler for 404 usually is not handled by
a bundle unless it is caused inside a view fun... | python | def errorhandler(self, code_or_exception):
"""
Registers an error handler that becomes active for this bundle
only. Please be aware that routing does not happen local to a
bundle so an error handler for 404 usually is not handled by
a bundle unless it is caused inside a view fun... | [
"def",
"errorhandler",
"(",
"self",
",",
"code_or_exception",
")",
":",
"def",
"decorator",
"(",
"fn",
")",
":",
"self",
".",
"_defer",
"(",
"lambda",
"bp",
":",
"bp",
".",
"register_error_handler",
"(",
"code_or_exception",
",",
"fn",
")",
")",
"return",
... | Registers an error handler that becomes active for this bundle
only. Please be aware that routing does not happen local to a
bundle so an error handler for 404 usually is not handled by
a bundle unless it is caused inside a view function. Another
special case is the 500 internal server... | [
"Registers",
"an",
"error",
"handler",
"that",
"becomes",
"active",
"for",
"this",
"bundle",
"only",
".",
"Please",
"be",
"aware",
"that",
"routing",
"does",
"not",
"happen",
"local",
"to",
"a",
"bundle",
"so",
"an",
"error",
"handler",
"for",
"404",
"usua... | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundle.py#L131-L145 | train |
briancappello/flask-unchained | flask_unchained/bundles/controller/routes.py | controller | def controller(url_prefix_or_controller_cls: Union[str, Type[Controller]],
controller_cls: Optional[Type[Controller]] = None,
*,
rules: Optional[Iterable[Union[Route, RouteGenerator]]] = None,
) -> RouteGenerator:
"""
This function is used to register ... | python | def controller(url_prefix_or_controller_cls: Union[str, Type[Controller]],
controller_cls: Optional[Type[Controller]] = None,
*,
rules: Optional[Iterable[Union[Route, RouteGenerator]]] = None,
) -> RouteGenerator:
"""
This function is used to register ... | [
"def",
"controller",
"(",
"url_prefix_or_controller_cls",
":",
"Union",
"[",
"str",
",",
"Type",
"[",
"Controller",
"]",
"]",
",",
"controller_cls",
":",
"Optional",
"[",
"Type",
"[",
"Controller",
"]",
"]",
"=",
"None",
",",
"*",
",",
"rules",
":",
"Opt... | This function is used to register a controller class's routes.
Example usage::
routes = lambda: [
controller(SiteController),
]
Or with the optional prefix argument::
routes = lambda: [
controller('/products', ProductController),
]
Specify ``rules... | [
"This",
"function",
"is",
"used",
"to",
"register",
"a",
"controller",
"class",
"s",
"routes",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/controller/routes.py#L20-L75 | train |
briancappello/flask-unchained | flask_unchained/unchained.py | Unchained.service | def service(self, name: str = None):
"""
Decorator to mark something as a service.
"""
if self._services_initialized:
from warnings import warn
warn('Services have already been initialized. Please register '
f'{name} sooner.')
return l... | python | def service(self, name: str = None):
"""
Decorator to mark something as a service.
"""
if self._services_initialized:
from warnings import warn
warn('Services have already been initialized. Please register '
f'{name} sooner.')
return l... | [
"def",
"service",
"(",
"self",
",",
"name",
":",
"str",
"=",
"None",
")",
":",
"if",
"self",
".",
"_services_initialized",
":",
"from",
"warnings",
"import",
"warn",
"warn",
"(",
"'Services have already been initialized. Please register '",
"f'{name} sooner.'",
")",... | Decorator to mark something as a service. | [
"Decorator",
"to",
"mark",
"something",
"as",
"a",
"service",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/unchained.py#L127-L140 | train |
briancappello/flask-unchained | flask_unchained/unchained.py | Unchained.register_service | def register_service(self, name: str, service: Any):
"""
Method to register a service.
"""
if not isinstance(service, type):
if hasattr(service, '__class__'):
_ensure_service_name(service.__class__, name)
self.services[name] = service
r... | python | def register_service(self, name: str, service: Any):
"""
Method to register a service.
"""
if not isinstance(service, type):
if hasattr(service, '__class__'):
_ensure_service_name(service.__class__, name)
self.services[name] = service
r... | [
"def",
"register_service",
"(",
"self",
",",
"name",
":",
"str",
",",
"service",
":",
"Any",
")",
":",
"if",
"not",
"isinstance",
"(",
"service",
",",
"type",
")",
":",
"if",
"hasattr",
"(",
"service",
",",
"'__class__'",
")",
":",
"_ensure_service_name"... | Method to register a service. | [
"Method",
"to",
"register",
"a",
"service",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/unchained.py#L142-L158 | train |
briancappello/flask-unchained | flask_unchained/unchained.py | Unchained.before_request | def before_request(self, fn):
"""
Registers a function to run before each request.
For example, this can be used to open a database connection, or to load
the logged in user from the session.
The function will be called without any arguments. If it returns a
non-None va... | python | def before_request(self, fn):
"""
Registers a function to run before each request.
For example, this can be used to open a database connection, or to load
the logged in user from the session.
The function will be called without any arguments. If it returns a
non-None va... | [
"def",
"before_request",
"(",
"self",
",",
"fn",
")",
":",
"self",
".",
"_defer",
"(",
"lambda",
"app",
":",
"app",
".",
"before_request",
"(",
"fn",
")",
")",
"return",
"fn"
] | Registers a function to run before each request.
For example, this can be used to open a database connection, or to load
the logged in user from the session.
The function will be called without any arguments. If it returns a
non-None value, the value is handled as if it was the return ... | [
"Registers",
"a",
"function",
"to",
"run",
"before",
"each",
"request",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/unchained.py#L346-L358 | train |
briancappello/flask-unchained | flask_unchained/unchained.py | Unchained.before_first_request | def before_first_request(self, fn):
"""
Registers a function to be run before the first request to this
instance of the application.
The function will be called without any arguments and its return
value is ignored.
"""
self._defer(lambda app: app.before_first_re... | python | def before_first_request(self, fn):
"""
Registers a function to be run before the first request to this
instance of the application.
The function will be called without any arguments and its return
value is ignored.
"""
self._defer(lambda app: app.before_first_re... | [
"def",
"before_first_request",
"(",
"self",
",",
"fn",
")",
":",
"self",
".",
"_defer",
"(",
"lambda",
"app",
":",
"app",
".",
"before_first_request",
"(",
"fn",
")",
")",
"return",
"fn"
] | Registers a function to be run before the first request to this
instance of the application.
The function will be called without any arguments and its return
value is ignored. | [
"Registers",
"a",
"function",
"to",
"be",
"run",
"before",
"the",
"first",
"request",
"to",
"this",
"instance",
"of",
"the",
"application",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/unchained.py#L360-L369 | train |
briancappello/flask-unchained | flask_unchained/unchained.py | Unchained.after_request | def after_request(self, fn):
"""
Register a function to be run after each request.
Your function must take one parameter, an instance of
:attr:`response_class` and return a new response object or the
same (see :meth:`process_response`).
As of Flask 0.7 this function mig... | python | def after_request(self, fn):
"""
Register a function to be run after each request.
Your function must take one parameter, an instance of
:attr:`response_class` and return a new response object or the
same (see :meth:`process_response`).
As of Flask 0.7 this function mig... | [
"def",
"after_request",
"(",
"self",
",",
"fn",
")",
":",
"self",
".",
"_defer",
"(",
"lambda",
"app",
":",
"app",
".",
"after_request",
"(",
"fn",
")",
")",
"return",
"fn"
] | Register a function to be run after each request.
Your function must take one parameter, an instance of
:attr:`response_class` and return a new response object or the
same (see :meth:`process_response`).
As of Flask 0.7 this function might not be executed at the end of the
requ... | [
"Register",
"a",
"function",
"to",
"be",
"run",
"after",
"each",
"request",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/unchained.py#L371-L383 | train |
briancappello/flask-unchained | flask_unchained/unchained.py | Unchained.teardown_request | def teardown_request(self, fn):
"""
Register a function to be run at the end of each request,
regardless of whether there was an exception or not. These functions
are executed when the request context is popped, even if not an
actual request was performed.
Example::
... | python | def teardown_request(self, fn):
"""
Register a function to be run at the end of each request,
regardless of whether there was an exception or not. These functions
are executed when the request context is popped, even if not an
actual request was performed.
Example::
... | [
"def",
"teardown_request",
"(",
"self",
",",
"fn",
")",
":",
"self",
".",
"_defer",
"(",
"lambda",
"app",
":",
"app",
".",
"teardown_request",
"(",
"fn",
")",
")",
"return",
"fn"
] | Register a function to be run at the end of each request,
regardless of whether there was an exception or not. These functions
are executed when the request context is popped, even if not an
actual request was performed.
Example::
ctx = app.test_request_context()
... | [
"Register",
"a",
"function",
"to",
"be",
"run",
"at",
"the",
"end",
"of",
"each",
"request",
"regardless",
"of",
"whether",
"there",
"was",
"an",
"exception",
"or",
"not",
".",
"These",
"functions",
"are",
"executed",
"when",
"the",
"request",
"context",
"... | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/unchained.py#L385-L422 | train |
briancappello/flask-unchained | flask_unchained/unchained.py | Unchained.teardown_appcontext | def teardown_appcontext(self, fn):
"""
Registers a function to be called when the application context
ends. These functions are typically also called when the request
context is popped.
Example::
ctx = app.app_context()
ctx.push()
...
... | python | def teardown_appcontext(self, fn):
"""
Registers a function to be called when the application context
ends. These functions are typically also called when the request
context is popped.
Example::
ctx = app.app_context()
ctx.push()
...
... | [
"def",
"teardown_appcontext",
"(",
"self",
",",
"fn",
")",
":",
"self",
".",
"_defer",
"(",
"lambda",
"app",
":",
"app",
".",
"teardown_appcontext",
"(",
"fn",
")",
")",
"return",
"fn"
] | Registers a function to be called when the application context
ends. These functions are typically also called when the request
context is popped.
Example::
ctx = app.app_context()
ctx.push()
...
ctx.pop()
When ``ctx.pop()`` is executed... | [
"Registers",
"a",
"function",
"to",
"be",
"called",
"when",
"the",
"application",
"context",
"ends",
".",
"These",
"functions",
"are",
"typically",
"also",
"called",
"when",
"the",
"request",
"context",
"is",
"popped",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/unchained.py#L424-L453 | train |
briancappello/flask-unchained | flask_unchained/unchained.py | Unchained.context_processor | def context_processor(self, fn):
"""
Registers a template context processor function.
"""
self._defer(lambda app: app.context_processor(fn))
return fn | python | def context_processor(self, fn):
"""
Registers a template context processor function.
"""
self._defer(lambda app: app.context_processor(fn))
return fn | [
"def",
"context_processor",
"(",
"self",
",",
"fn",
")",
":",
"self",
".",
"_defer",
"(",
"lambda",
"app",
":",
"app",
".",
"context_processor",
"(",
"fn",
")",
")",
"return",
"fn"
] | Registers a template context processor function. | [
"Registers",
"a",
"template",
"context",
"processor",
"function",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/unchained.py#L455-L460 | train |
briancappello/flask-unchained | flask_unchained/unchained.py | Unchained.shell_context_processor | def shell_context_processor(self, fn):
"""
Registers a shell context processor function.
"""
self._defer(lambda app: app.shell_context_processor(fn))
return fn | python | def shell_context_processor(self, fn):
"""
Registers a shell context processor function.
"""
self._defer(lambda app: app.shell_context_processor(fn))
return fn | [
"def",
"shell_context_processor",
"(",
"self",
",",
"fn",
")",
":",
"self",
".",
"_defer",
"(",
"lambda",
"app",
":",
"app",
".",
"shell_context_processor",
"(",
"fn",
")",
")",
"return",
"fn"
] | Registers a shell context processor function. | [
"Registers",
"a",
"shell",
"context",
"processor",
"function",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/unchained.py#L462-L467 | train |
briancappello/flask-unchained | flask_unchained/unchained.py | Unchained.url_defaults | def url_defaults(self, fn):
"""
Callback function for URL defaults for all view functions of the
application. It's called with the endpoint and values and should
update the values passed in place.
"""
self._defer(lambda app: app.url_defaults(fn))
return fn | python | def url_defaults(self, fn):
"""
Callback function for URL defaults for all view functions of the
application. It's called with the endpoint and values and should
update the values passed in place.
"""
self._defer(lambda app: app.url_defaults(fn))
return fn | [
"def",
"url_defaults",
"(",
"self",
",",
"fn",
")",
":",
"self",
".",
"_defer",
"(",
"lambda",
"app",
":",
"app",
".",
"url_defaults",
"(",
"fn",
")",
")",
"return",
"fn"
] | Callback function for URL defaults for all view functions of the
application. It's called with the endpoint and values and should
update the values passed in place. | [
"Callback",
"function",
"for",
"URL",
"defaults",
"for",
"all",
"view",
"functions",
"of",
"the",
"application",
".",
"It",
"s",
"called",
"with",
"the",
"endpoint",
"and",
"values",
"and",
"should",
"update",
"the",
"values",
"passed",
"in",
"place",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/unchained.py#L486-L493 | train |
briancappello/flask-unchained | flask_unchained/unchained.py | Unchained.errorhandler | def errorhandler(self, code_or_exception):
"""
Register a function to handle errors by code or exception class.
A decorator that is used to register a function given an
error code. Example::
@app.errorhandler(404)
def page_not_found(error):
retu... | python | def errorhandler(self, code_or_exception):
"""
Register a function to handle errors by code or exception class.
A decorator that is used to register a function given an
error code. Example::
@app.errorhandler(404)
def page_not_found(error):
retu... | [
"def",
"errorhandler",
"(",
"self",
",",
"code_or_exception",
")",
":",
"def",
"decorator",
"(",
"fn",
")",
":",
"self",
".",
"_defer",
"(",
"lambda",
"app",
":",
"app",
".",
"register_error_handler",
"(",
"code_or_exception",
",",
"fn",
")",
")",
"return"... | Register a function to handle errors by code or exception class.
A decorator that is used to register a function given an
error code. Example::
@app.errorhandler(404)
def page_not_found(error):
return 'This page does not exist', 404
You can also regist... | [
"Register",
"a",
"function",
"to",
"handle",
"errors",
"by",
"code",
"or",
"exception",
"class",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/unchained.py#L495-L518 | train |
briancappello/flask-unchained | flask_unchained/unchained.py | Unchained.template_filter | def template_filter(self,
arg: Optional[Callable] = None,
*,
name: Optional[str] = None,
pass_context: bool = False,
inject: Optional[Union[bool, Iterable[str]]] = None,
safe: ... | python | def template_filter(self,
arg: Optional[Callable] = None,
*,
name: Optional[str] = None,
pass_context: bool = False,
inject: Optional[Union[bool, Iterable[str]]] = None,
safe: ... | [
"def",
"template_filter",
"(",
"self",
",",
"arg",
":",
"Optional",
"[",
"Callable",
"]",
"=",
"None",
",",
"*",
",",
"name",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"pass_context",
":",
"bool",
"=",
"False",
",",
"inject",
":",
"Optional... | Decorator to mark a function as a Jinja template filter.
:param name: The name of the filter, if different from the function name.
:param pass_context: Whether or not to pass the template context into the filter.
If ``True``, the first argument must be the context.
:param inject: Wh... | [
"Decorator",
"to",
"mark",
"a",
"function",
"as",
"a",
"Jinja",
"template",
"filter",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/unchained.py#L520-L548 | train |
briancappello/flask-unchained | flask_unchained/unchained.py | Unchained._reset | def _reset(self):
"""
This method is for use by tests only!
"""
self.bundles = AttrDict()
self._bundles = _DeferredBundleFunctionsStore()
self.babel_bundle = None
self.env = None
self.extensions = AttrDict()
self.services = AttrDict()
self... | python | def _reset(self):
"""
This method is for use by tests only!
"""
self.bundles = AttrDict()
self._bundles = _DeferredBundleFunctionsStore()
self.babel_bundle = None
self.env = None
self.extensions = AttrDict()
self.services = AttrDict()
self... | [
"def",
"_reset",
"(",
"self",
")",
":",
"self",
".",
"bundles",
"=",
"AttrDict",
"(",
")",
"self",
".",
"_bundles",
"=",
"_DeferredBundleFunctionsStore",
"(",
")",
"self",
".",
"babel_bundle",
"=",
"None",
"self",
".",
"env",
"=",
"None",
"self",
".",
... | This method is for use by tests only! | [
"This",
"method",
"is",
"for",
"use",
"by",
"tests",
"only!"
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/unchained.py#L625-L641 | train |
briancappello/flask-unchained | flask_unchained/bundles/sqlalchemy/forms.py | model_fields | def model_fields(model, db_session=None, only=None, exclude=None,
field_args=None, converter=None, exclude_pk=False,
exclude_fk=False):
"""
Generate a dictionary of fields for a given SQLAlchemy model.
See `model_form` docstring for description of parameters.
"""
m... | python | def model_fields(model, db_session=None, only=None, exclude=None,
field_args=None, converter=None, exclude_pk=False,
exclude_fk=False):
"""
Generate a dictionary of fields for a given SQLAlchemy model.
See `model_form` docstring for description of parameters.
"""
m... | [
"def",
"model_fields",
"(",
"model",
",",
"db_session",
"=",
"None",
",",
"only",
"=",
"None",
",",
"exclude",
"=",
"None",
",",
"field_args",
"=",
"None",
",",
"converter",
"=",
"None",
",",
"exclude_pk",
"=",
"False",
",",
"exclude_fk",
"=",
"False",
... | Generate a dictionary of fields for a given SQLAlchemy model.
See `model_form` docstring for description of parameters. | [
"Generate",
"a",
"dictionary",
"of",
"fields",
"for",
"a",
"given",
"SQLAlchemy",
"model",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/sqlalchemy/forms.py#L121-L158 | train |
briancappello/flask-unchained | flask_unchained/commands/urls.py | url | def url(url: str, method: str):
"""Show details for a specific URL."""
try:
url_rule, params = (current_app.url_map.bind('localhost')
.match(url, method=method, return_rule=True))
except (NotFound, MethodNotAllowed)\
as e:
click.secho(str(e), fg='white... | python | def url(url: str, method: str):
"""Show details for a specific URL."""
try:
url_rule, params = (current_app.url_map.bind('localhost')
.match(url, method=method, return_rule=True))
except (NotFound, MethodNotAllowed)\
as e:
click.secho(str(e), fg='white... | [
"def",
"url",
"(",
"url",
":",
"str",
",",
"method",
":",
"str",
")",
":",
"try",
":",
"url_rule",
",",
"params",
"=",
"(",
"current_app",
".",
"url_map",
".",
"bind",
"(",
"'localhost'",
")",
".",
"match",
"(",
"url",
",",
"method",
"=",
"method",... | Show details for a specific URL. | [
"Show",
"details",
"for",
"a",
"specific",
"URL",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/commands/urls.py#L18-L37 | train |
briancappello/flask-unchained | flask_unchained/commands/urls.py | urls | def urls(order_by: Optional[str] = None):
"""List all URLs registered with the app."""
url_rules: List[Rule] = current_app.url_map._rules
# sort the rules. by default they're sorted by priority,
# ie in the order they were registered with the app
if order_by == 'view':
url_rules = sorted(ur... | python | def urls(order_by: Optional[str] = None):
"""List all URLs registered with the app."""
url_rules: List[Rule] = current_app.url_map._rules
# sort the rules. by default they're sorted by priority,
# ie in the order they were registered with the app
if order_by == 'view':
url_rules = sorted(ur... | [
"def",
"urls",
"(",
"order_by",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
")",
":",
"url_rules",
":",
"List",
"[",
"Rule",
"]",
"=",
"current_app",
".",
"url_map",
".",
"_rules",
"# sort the rules. by default they're sorted by priority,",
"# ie in the order t... | List all URLs registered with the app. | [
"List",
"all",
"URLs",
"registered",
"with",
"the",
"app",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/commands/urls.py#L45-L66 | train |
briancappello/flask-unchained | flask_unchained/bundles/api/extensions/api.py | Api.register_converter | def register_converter(self, converter, conv_type, conv_format=None, *, name=None):
"""
Register custom path parameter converter.
:param BaseConverter converter: Converter
Subclass of werkzeug's BaseConverter
:param str conv_type: Parameter type
:param str conv_forma... | python | def register_converter(self, converter, conv_type, conv_format=None, *, name=None):
"""
Register custom path parameter converter.
:param BaseConverter converter: Converter
Subclass of werkzeug's BaseConverter
:param str conv_type: Parameter type
:param str conv_forma... | [
"def",
"register_converter",
"(",
"self",
",",
"converter",
",",
"conv_type",
",",
"conv_format",
"=",
"None",
",",
"*",
",",
"name",
"=",
"None",
")",
":",
"if",
"name",
":",
"self",
".",
"app",
".",
"url_map",
".",
"converters",
"[",
"name",
"]",
"... | Register custom path parameter converter.
:param BaseConverter converter: Converter
Subclass of werkzeug's BaseConverter
:param str conv_type: Parameter type
:param str conv_format: Parameter format (optional)
:param str name: Name of the converter. If not None, this name is... | [
"Register",
"custom",
"path",
"parameter",
"converter",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/api/extensions/api.py#L138-L167 | train |
briancappello/flask-unchained | flask_unchained/app_factory_hook.py | AppFactoryHook.run_hook | def run_hook(self, app: FlaskUnchained, bundles: List[Bundle]):
"""
Hook entry point. Override to disable standard behavior of iterating
over bundles to discover objects and processing them.
"""
self.process_objects(app, self.collect_from_bundles(bundles)) | python | def run_hook(self, app: FlaskUnchained, bundles: List[Bundle]):
"""
Hook entry point. Override to disable standard behavior of iterating
over bundles to discover objects and processing them.
"""
self.process_objects(app, self.collect_from_bundles(bundles)) | [
"def",
"run_hook",
"(",
"self",
",",
"app",
":",
"FlaskUnchained",
",",
"bundles",
":",
"List",
"[",
"Bundle",
"]",
")",
":",
"self",
".",
"process_objects",
"(",
"app",
",",
"self",
".",
"collect_from_bundles",
"(",
"bundles",
")",
")"
] | Hook entry point. Override to disable standard behavior of iterating
over bundles to discover objects and processing them. | [
"Hook",
"entry",
"point",
".",
"Override",
"to",
"disable",
"standard",
"behavior",
"of",
"iterating",
"over",
"bundles",
"to",
"discover",
"objects",
"and",
"processing",
"them",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/app_factory_hook.py#L93-L98 | train |
briancappello/flask-unchained | flask_unchained/clips_pattern.py | singularize | def singularize(word, pos=NOUN, custom=None):
""" Returns the singular of a given word.
"""
if custom and word in custom:
return custom[word]
# Recurse compound words (e.g. mothers-in-law).
if "-" in word:
w = word.split("-")
if len(w) > 1 and w[1] in plural_prepositions:
... | python | def singularize(word, pos=NOUN, custom=None):
""" Returns the singular of a given word.
"""
if custom and word in custom:
return custom[word]
# Recurse compound words (e.g. mothers-in-law).
if "-" in word:
w = word.split("-")
if len(w) > 1 and w[1] in plural_prepositions:
... | [
"def",
"singularize",
"(",
"word",
",",
"pos",
"=",
"NOUN",
",",
"custom",
"=",
"None",
")",
":",
"if",
"custom",
"and",
"word",
"in",
"custom",
":",
"return",
"custom",
"[",
"word",
"]",
"# Recurse compound words (e.g. mothers-in-law).",
"if",
"\"-\"",
"in"... | Returns the singular of a given word. | [
"Returns",
"the",
"singular",
"of",
"a",
"given",
"word",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/clips_pattern.py#L539-L573 | train |
briancappello/flask-unchained | flask_unchained/app_factory.py | AppFactory.create_basic_app | def create_basic_app(cls, bundles=None, _config_overrides=None):
"""
Creates a "fake" app for use while developing
"""
bundles = bundles or []
name = bundles[-1].module_name if bundles else 'basic_app'
app = FlaskUnchained(name, template_folder=os.path.join(
o... | python | def create_basic_app(cls, bundles=None, _config_overrides=None):
"""
Creates a "fake" app for use while developing
"""
bundles = bundles or []
name = bundles[-1].module_name if bundles else 'basic_app'
app = FlaskUnchained(name, template_folder=os.path.join(
o... | [
"def",
"create_basic_app",
"(",
"cls",
",",
"bundles",
"=",
"None",
",",
"_config_overrides",
"=",
"None",
")",
":",
"bundles",
"=",
"bundles",
"or",
"[",
"]",
"name",
"=",
"bundles",
"[",
"-",
"1",
"]",
".",
"module_name",
"if",
"bundles",
"else",
"'b... | Creates a "fake" app for use while developing | [
"Creates",
"a",
"fake",
"app",
"for",
"use",
"while",
"developing"
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/app_factory.py#L83-L100 | train |
briancappello/flask-unchained | flask_unchained/bundles/security/commands/roles.py | list_roles | def list_roles():
"""
List roles.
"""
roles = role_manager.all()
if roles:
print_table(['ID', 'Name'], [(role.id, role.name) for role in roles])
else:
click.echo('No roles found.') | python | def list_roles():
"""
List roles.
"""
roles = role_manager.all()
if roles:
print_table(['ID', 'Name'], [(role.id, role.name) for role in roles])
else:
click.echo('No roles found.') | [
"def",
"list_roles",
"(",
")",
":",
"roles",
"=",
"role_manager",
".",
"all",
"(",
")",
"if",
"roles",
":",
"print_table",
"(",
"[",
"'ID'",
",",
"'Name'",
"]",
",",
"[",
"(",
"role",
".",
"id",
",",
"role",
".",
"name",
")",
"for",
"role",
"in",... | List roles. | [
"List",
"roles",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/security/commands/roles.py#L19-L27 | train |
briancappello/flask-unchained | flask_unchained/bundles/security/commands/roles.py | create_role | def create_role(name):
"""
Create a new role.
"""
role = role_manager.create(name=name)
if click.confirm(f'Are you sure you want to create {role!r}?'):
role_manager.save(role, commit=True)
click.echo(f'Successfully created {role!r}')
else:
click.echo('Cancelled.') | python | def create_role(name):
"""
Create a new role.
"""
role = role_manager.create(name=name)
if click.confirm(f'Are you sure you want to create {role!r}?'):
role_manager.save(role, commit=True)
click.echo(f'Successfully created {role!r}')
else:
click.echo('Cancelled.') | [
"def",
"create_role",
"(",
"name",
")",
":",
"role",
"=",
"role_manager",
".",
"create",
"(",
"name",
"=",
"name",
")",
"if",
"click",
".",
"confirm",
"(",
"f'Are you sure you want to create {role!r}?'",
")",
":",
"role_manager",
".",
"save",
"(",
"role",
",... | Create a new role. | [
"Create",
"a",
"new",
"role",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/security/commands/roles.py#L33-L42 | train |
briancappello/flask-unchained | flask_unchained/bundles/security/commands/roles.py | delete_role | def delete_role(query):
"""
Delete a role.
"""
role = _query_to_role(query)
if click.confirm(f'Are you sure you want to delete {role!r}?'):
role_manager.delete(role, commit=True)
click.echo(f'Successfully deleted {role!r}')
else:
click.echo('Cancelled.') | python | def delete_role(query):
"""
Delete a role.
"""
role = _query_to_role(query)
if click.confirm(f'Are you sure you want to delete {role!r}?'):
role_manager.delete(role, commit=True)
click.echo(f'Successfully deleted {role!r}')
else:
click.echo('Cancelled.') | [
"def",
"delete_role",
"(",
"query",
")",
":",
"role",
"=",
"_query_to_role",
"(",
"query",
")",
"if",
"click",
".",
"confirm",
"(",
"f'Are you sure you want to delete {role!r}?'",
")",
":",
"role_manager",
".",
"delete",
"(",
"role",
",",
"commit",
"=",
"True"... | Delete a role. | [
"Delete",
"a",
"role",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/security/commands/roles.py#L48-L57 | train |
briancappello/flask-unchained | flask_unchained/bundles/sqlalchemy/sqla/events.py | slugify | def slugify(field_name, slug_field_name=None, mutable=False):
"""Class decorator to specify a field to slugify. Slugs are immutable by
default unless mutable=True is passed.
Usage::
@slugify('title')
def Post(Model):
title = Column(String(100))
slug = Column(String(... | python | def slugify(field_name, slug_field_name=None, mutable=False):
"""Class decorator to specify a field to slugify. Slugs are immutable by
default unless mutable=True is passed.
Usage::
@slugify('title')
def Post(Model):
title = Column(String(100))
slug = Column(String(... | [
"def",
"slugify",
"(",
"field_name",
",",
"slug_field_name",
"=",
"None",
",",
"mutable",
"=",
"False",
")",
":",
"slug_field_name",
"=",
"slug_field_name",
"or",
"'slug'",
"def",
"_set_slug",
"(",
"target",
",",
"value",
",",
"old_value",
",",
"_",
",",
"... | Class decorator to specify a field to slugify. Slugs are immutable by
default unless mutable=True is passed.
Usage::
@slugify('title')
def Post(Model):
title = Column(String(100))
slug = Column(String(100))
# pass a second argument to specify the slug attribute... | [
"Class",
"decorator",
"to",
"specify",
"a",
"field",
"to",
"slugify",
".",
"Slugs",
"are",
"immutable",
"by",
"default",
"unless",
"mutable",
"=",
"True",
"is",
"passed",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/sqlalchemy/sqla/events.py#L87-L124 | train |
briancappello/flask-unchained | flask_unchained/bundles/mail/utils.py | get_message_plain_text | def get_message_plain_text(msg: Message):
"""
Converts an HTML message to plain text.
:param msg: A :class:`~flask_mail.Message`
:return: The plain text message.
"""
if msg.body:
return msg.body
if BeautifulSoup is None or not msg.html:
return msg.html
plain_text = '\n... | python | def get_message_plain_text(msg: Message):
"""
Converts an HTML message to plain text.
:param msg: A :class:`~flask_mail.Message`
:return: The plain text message.
"""
if msg.body:
return msg.body
if BeautifulSoup is None or not msg.html:
return msg.html
plain_text = '\n... | [
"def",
"get_message_plain_text",
"(",
"msg",
":",
"Message",
")",
":",
"if",
"msg",
".",
"body",
":",
"return",
"msg",
".",
"body",
"if",
"BeautifulSoup",
"is",
"None",
"or",
"not",
"msg",
".",
"html",
":",
"return",
"msg",
".",
"html",
"plain_text",
"... | Converts an HTML message to plain text.
:param msg: A :class:`~flask_mail.Message`
:return: The plain text message. | [
"Converts",
"an",
"HTML",
"message",
"to",
"plain",
"text",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/mail/utils.py#L31-L46 | train |
briancappello/flask-unchained | flask_unchained/bundles/mail/utils.py | _send_mail | def _send_mail(subject_or_message: Optional[Union[str, Message]] = None,
to: Optional[Union[str, List[str]]] = None,
template: Optional[str] = None,
**kwargs):
"""
The default function used for sending emails.
:param subject_or_message: A subject string, or for ... | python | def _send_mail(subject_or_message: Optional[Union[str, Message]] = None,
to: Optional[Union[str, List[str]]] = None,
template: Optional[str] = None,
**kwargs):
"""
The default function used for sending emails.
:param subject_or_message: A subject string, or for ... | [
"def",
"_send_mail",
"(",
"subject_or_message",
":",
"Optional",
"[",
"Union",
"[",
"str",
",",
"Message",
"]",
"]",
"=",
"None",
",",
"to",
":",
"Optional",
"[",
"Union",
"[",
"str",
",",
"List",
"[",
"str",
"]",
"]",
"]",
"=",
"None",
",",
"templ... | The default function used for sending emails.
:param subject_or_message: A subject string, or for backwards compatibility with
stock Flask-Mail, a :class:`~flask_mail.Message` instance
:param to: An email address, or a list of email addresses
:param template: Which template t... | [
"The",
"default",
"function",
"used",
"for",
"sending",
"emails",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/mail/utils.py#L80-L97 | train |
briancappello/flask-unchained | flask_unchained/bundles/babel/commands.py | extract | def extract(domain):
"""
Extract newly added translations keys from source code.
"""
translations_dir = _get_translations_dir()
domain = _get_translations_domain(domain)
babel_cfg = _get_babel_cfg()
pot = os.path.join(translations_dir, f'{domain}.pot')
return _run(f'extract -F {babel_cfg... | python | def extract(domain):
"""
Extract newly added translations keys from source code.
"""
translations_dir = _get_translations_dir()
domain = _get_translations_domain(domain)
babel_cfg = _get_babel_cfg()
pot = os.path.join(translations_dir, f'{domain}.pot')
return _run(f'extract -F {babel_cfg... | [
"def",
"extract",
"(",
"domain",
")",
":",
"translations_dir",
"=",
"_get_translations_dir",
"(",
")",
"domain",
"=",
"_get_translations_domain",
"(",
"domain",
")",
"babel_cfg",
"=",
"_get_babel_cfg",
"(",
")",
"pot",
"=",
"os",
".",
"path",
".",
"join",
"(... | Extract newly added translations keys from source code. | [
"Extract",
"newly",
"added",
"translations",
"keys",
"from",
"source",
"code",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/babel/commands.py#L22-L30 | train |
briancappello/flask-unchained | flask_unchained/bundles/babel/commands.py | init | def init(lang, domain):
"""
Initialize translations for a language code.
"""
translations_dir = _get_translations_dir()
domain = _get_translations_domain(domain)
pot = os.path.join(translations_dir, f'{domain}.pot')
return _run(f'init -i {pot} -d {translations_dir} -l {lang} --domain={domain... | python | def init(lang, domain):
"""
Initialize translations for a language code.
"""
translations_dir = _get_translations_dir()
domain = _get_translations_domain(domain)
pot = os.path.join(translations_dir, f'{domain}.pot')
return _run(f'init -i {pot} -d {translations_dir} -l {lang} --domain={domain... | [
"def",
"init",
"(",
"lang",
",",
"domain",
")",
":",
"translations_dir",
"=",
"_get_translations_dir",
"(",
")",
"domain",
"=",
"_get_translations_domain",
"(",
"domain",
")",
"pot",
"=",
"os",
".",
"path",
".",
"join",
"(",
"translations_dir",
",",
"f'{doma... | Initialize translations for a language code. | [
"Initialize",
"translations",
"for",
"a",
"language",
"code",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/babel/commands.py#L36-L43 | train |
briancappello/flask-unchained | flask_unchained/bundles/babel/commands.py | update | def update(domain):
"""
Update language-specific translations files with new keys discovered by
``flask babel extract``.
"""
translations_dir = _get_translations_dir()
domain = _get_translations_domain(domain)
pot = os.path.join(translations_dir, f'{domain}.pot')
return _run(f'update -i ... | python | def update(domain):
"""
Update language-specific translations files with new keys discovered by
``flask babel extract``.
"""
translations_dir = _get_translations_dir()
domain = _get_translations_domain(domain)
pot = os.path.join(translations_dir, f'{domain}.pot')
return _run(f'update -i ... | [
"def",
"update",
"(",
"domain",
")",
":",
"translations_dir",
"=",
"_get_translations_dir",
"(",
")",
"domain",
"=",
"_get_translations_domain",
"(",
"domain",
")",
"pot",
"=",
"os",
".",
"path",
".",
"join",
"(",
"translations_dir",
",",
"f'{domain}.pot'",
")... | Update language-specific translations files with new keys discovered by
``flask babel extract``. | [
"Update",
"language",
"-",
"specific",
"translations",
"files",
"with",
"new",
"keys",
"discovered",
"by",
"flask",
"babel",
"extract",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/babel/commands.py#L59-L67 | train |
briancappello/flask-unchained | flask_unchained/bundles/sqlalchemy/meta_options.py | RelationshipsMetaOption.get_value | def get_value(self, meta, base_model_meta, mcs_args: McsArgs):
"""overridden to merge with inherited value"""
if mcs_args.Meta.abstract:
return None
value = getattr(base_model_meta, self.name, {}) or {}
value.update(getattr(meta, self.name, {}))
return value | python | def get_value(self, meta, base_model_meta, mcs_args: McsArgs):
"""overridden to merge with inherited value"""
if mcs_args.Meta.abstract:
return None
value = getattr(base_model_meta, self.name, {}) or {}
value.update(getattr(meta, self.name, {}))
return value | [
"def",
"get_value",
"(",
"self",
",",
"meta",
",",
"base_model_meta",
",",
"mcs_args",
":",
"McsArgs",
")",
":",
"if",
"mcs_args",
".",
"Meta",
".",
"abstract",
":",
"return",
"None",
"value",
"=",
"getattr",
"(",
"base_model_meta",
",",
"self",
".",
"na... | overridden to merge with inherited value | [
"overridden",
"to",
"merge",
"with",
"inherited",
"value"
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/sqlalchemy/meta_options.py#L34-L40 | train |
briancappello/flask-unchained | flask_unchained/bundles/controller/controller.py | Controller.flash | def flash(self, msg: str, category: Optional[str] = None):
"""
Convenience method for flashing messages.
:param msg: The message to flash.
:param category: The category of the message.
"""
if not request.is_json and app.config.FLASH_MESSAGES:
flash(msg, categ... | python | def flash(self, msg: str, category: Optional[str] = None):
"""
Convenience method for flashing messages.
:param msg: The message to flash.
:param category: The category of the message.
"""
if not request.is_json and app.config.FLASH_MESSAGES:
flash(msg, categ... | [
"def",
"flash",
"(",
"self",
",",
"msg",
":",
"str",
",",
"category",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
")",
":",
"if",
"not",
"request",
".",
"is_json",
"and",
"app",
".",
"config",
".",
"FLASH_MESSAGES",
":",
"flash",
"(",
"msg",
","... | Convenience method for flashing messages.
:param msg: The message to flash.
:param category: The category of the message. | [
"Convenience",
"method",
"for",
"flashing",
"messages",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/controller/controller.py#L190-L198 | train |
briancappello/flask-unchained | flask_unchained/bundles/controller/controller.py | Controller.render | def render(self, template_name: str, **ctx):
"""
Convenience method for rendering a template.
:param template_name: The template's name. Can either be a full path,
or a filename in the controller's template folder.
:param ctx: Context variables to pass into... | python | def render(self, template_name: str, **ctx):
"""
Convenience method for rendering a template.
:param template_name: The template's name. Can either be a full path,
or a filename in the controller's template folder.
:param ctx: Context variables to pass into... | [
"def",
"render",
"(",
"self",
",",
"template_name",
":",
"str",
",",
"*",
"*",
"ctx",
")",
":",
"if",
"'.'",
"not",
"in",
"template_name",
":",
"template_file_extension",
"=",
"(",
"self",
".",
"Meta",
".",
"template_file_extension",
"or",
"app",
".",
"c... | Convenience method for rendering a template.
:param template_name: The template's name. Can either be a full path,
or a filename in the controller's template folder.
:param ctx: Context variables to pass into the template. | [
"Convenience",
"method",
"for",
"rendering",
"a",
"template",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/controller/controller.py#L200-L215 | train |
briancappello/flask-unchained | flask_unchained/bundles/controller/controller.py | Controller.redirect | def redirect(self,
where: Optional[str] = None,
default: Optional[str] = None,
override: Optional[str] = None,
**url_kwargs):
"""
Convenience method for returning redirect responses.
:param where: A URL, endpoint, or config key... | python | def redirect(self,
where: Optional[str] = None,
default: Optional[str] = None,
override: Optional[str] = None,
**url_kwargs):
"""
Convenience method for returning redirect responses.
:param where: A URL, endpoint, or config key... | [
"def",
"redirect",
"(",
"self",
",",
"where",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"default",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"override",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"*",
"*",
"url_kwargs",... | Convenience method for returning redirect responses.
:param where: A URL, endpoint, or config key name to redirect to.
:param default: A URL, endpoint, or config key name to redirect to if
``where`` is invalid.
:param override: explicitly redirect to a URL, endpoint, or ... | [
"Convenience",
"method",
"for",
"returning",
"redirect",
"responses",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/controller/controller.py#L217-L248 | train |
briancappello/flask-unchained | flask_unchained/bundles/controller/controller.py | Controller.jsonify | def jsonify(self,
data: Any,
code: Union[int, Tuple[int, str, str]] = HTTPStatus.OK,
headers: Optional[Dict[str, str]] = None,
):
"""
Convenience method to return json responses.
:param data: The python data to jsonify.
:pa... | python | def jsonify(self,
data: Any,
code: Union[int, Tuple[int, str, str]] = HTTPStatus.OK,
headers: Optional[Dict[str, str]] = None,
):
"""
Convenience method to return json responses.
:param data: The python data to jsonify.
:pa... | [
"def",
"jsonify",
"(",
"self",
",",
"data",
":",
"Any",
",",
"code",
":",
"Union",
"[",
"int",
",",
"Tuple",
"[",
"int",
",",
"str",
",",
"str",
"]",
"]",
"=",
"HTTPStatus",
".",
"OK",
",",
"headers",
":",
"Optional",
"[",
"Dict",
"[",
"str",
"... | Convenience method to return json responses.
:param data: The python data to jsonify.
:param code: The HTTP status code to return.
:param headers: Any optional headers. | [
"Convenience",
"method",
"to",
"return",
"json",
"responses",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/controller/controller.py#L250-L262 | train |
briancappello/flask-unchained | flask_unchained/bundles/controller/controller.py | Controller.errors | def errors(self,
errors: List[str],
code: Union[int, Tuple[int, str, str]] = HTTPStatus.BAD_REQUEST,
key: str = 'errors',
headers: Optional[Dict[str, str]] = None,
):
"""
Convenience method to return errors as json.
:par... | python | def errors(self,
errors: List[str],
code: Union[int, Tuple[int, str, str]] = HTTPStatus.BAD_REQUEST,
key: str = 'errors',
headers: Optional[Dict[str, str]] = None,
):
"""
Convenience method to return errors as json.
:par... | [
"def",
"errors",
"(",
"self",
",",
"errors",
":",
"List",
"[",
"str",
"]",
",",
"code",
":",
"Union",
"[",
"int",
",",
"Tuple",
"[",
"int",
",",
"str",
",",
"str",
"]",
"]",
"=",
"HTTPStatus",
".",
"BAD_REQUEST",
",",
"key",
":",
"str",
"=",
"'... | Convenience method to return errors as json.
:param errors: The list of errors.
:param code: The HTTP status code.
:param key: The key to return the errors under.
:param headers: Any optional headers. | [
"Convenience",
"method",
"to",
"return",
"errors",
"as",
"json",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/controller/controller.py#L264-L278 | train |
briancappello/flask-unchained | flask_unchained/bundles/security/commands/users.py | set_password | def set_password(query, password, send_email):
"""
Set a user's password.
"""
user = _query_to_user(query)
if click.confirm(f'Are you sure you want to change {user!r}\'s password?'):
security_service.change_password(user, password, send_email=send_email)
user_manager.save(user, commi... | python | def set_password(query, password, send_email):
"""
Set a user's password.
"""
user = _query_to_user(query)
if click.confirm(f'Are you sure you want to change {user!r}\'s password?'):
security_service.change_password(user, password, send_email=send_email)
user_manager.save(user, commi... | [
"def",
"set_password",
"(",
"query",
",",
"password",
",",
"send_email",
")",
":",
"user",
"=",
"_query_to_user",
"(",
"query",
")",
"if",
"click",
".",
"confirm",
"(",
"f'Are you sure you want to change {user!r}\\'s password?'",
")",
":",
"security_service",
".",
... | Set a user's password. | [
"Set",
"a",
"user",
"s",
"password",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/security/commands/users.py#L95-L105 | train |
briancappello/flask-unchained | flask_unchained/bundles/security/commands/users.py | confirm_user | def confirm_user(query):
"""
Confirm a user account.
"""
user = _query_to_user(query)
if click.confirm(f'Are you sure you want to confirm {user!r}?'):
if security_service.confirm_user(user):
click.echo(f'Successfully confirmed {user!r} at '
f'{user.confirme... | python | def confirm_user(query):
"""
Confirm a user account.
"""
user = _query_to_user(query)
if click.confirm(f'Are you sure you want to confirm {user!r}?'):
if security_service.confirm_user(user):
click.echo(f'Successfully confirmed {user!r} at '
f'{user.confirme... | [
"def",
"confirm_user",
"(",
"query",
")",
":",
"user",
"=",
"_query_to_user",
"(",
"query",
")",
"if",
"click",
".",
"confirm",
"(",
"f'Are you sure you want to confirm {user!r}?'",
")",
":",
"if",
"security_service",
".",
"confirm_user",
"(",
"user",
")",
":",
... | Confirm a user account. | [
"Confirm",
"a",
"user",
"account",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/security/commands/users.py#L112-L125 | train |
briancappello/flask-unchained | flask_unchained/bundles/security/commands/users.py | add_role_to_user | def add_role_to_user(user, role):
"""
Add a role to a user.
"""
user = _query_to_user(user)
role = _query_to_role(role)
if click.confirm(f'Are you sure you want to add {role!r} to {user!r}?'):
user.roles.append(role)
user_manager.save(user, commit=True)
click.echo(f'Succe... | python | def add_role_to_user(user, role):
"""
Add a role to a user.
"""
user = _query_to_user(user)
role = _query_to_role(role)
if click.confirm(f'Are you sure you want to add {role!r} to {user!r}?'):
user.roles.append(role)
user_manager.save(user, commit=True)
click.echo(f'Succe... | [
"def",
"add_role_to_user",
"(",
"user",
",",
"role",
")",
":",
"user",
"=",
"_query_to_user",
"(",
"user",
")",
"role",
"=",
"_query_to_role",
"(",
"role",
")",
"if",
"click",
".",
"confirm",
"(",
"f'Are you sure you want to add {role!r} to {user!r}?'",
")",
":"... | Add a role to a user. | [
"Add",
"a",
"role",
"to",
"a",
"user",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/security/commands/users.py#L168-L179 | train |
briancappello/flask-unchained | flask_unchained/bundles/security/commands/users.py | remove_role_from_user | def remove_role_from_user(user, role):
"""
Remove a role from a user.
"""
user = _query_to_user(user)
role = _query_to_role(role)
if click.confirm(f'Are you sure you want to remove {role!r} from {user!r}?'):
user.roles.remove(role)
user_manager.save(user, commit=True)
cli... | python | def remove_role_from_user(user, role):
"""
Remove a role from a user.
"""
user = _query_to_user(user)
role = _query_to_role(role)
if click.confirm(f'Are you sure you want to remove {role!r} from {user!r}?'):
user.roles.remove(role)
user_manager.save(user, commit=True)
cli... | [
"def",
"remove_role_from_user",
"(",
"user",
",",
"role",
")",
":",
"user",
"=",
"_query_to_user",
"(",
"user",
")",
"role",
"=",
"_query_to_role",
"(",
"role",
")",
"if",
"click",
".",
"confirm",
"(",
"f'Are you sure you want to remove {role!r} from {user!r}?'",
... | Remove a role from a user. | [
"Remove",
"a",
"role",
"from",
"a",
"user",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/security/commands/users.py#L188-L199 | train |
briancappello/flask-unchained | flask_unchained/bundles/security/decorators/anonymous_user_required.py | anonymous_user_required | def anonymous_user_required(*decorator_args, msg=None, category=None, redirect_url=None):
"""
Decorator requiring that there is no user currently logged in.
Aborts with ``HTTP 403: Forbidden`` if there is an authenticated user.
"""
def wrapper(fn):
@wraps(fn)
def decorated(*args, **... | python | def anonymous_user_required(*decorator_args, msg=None, category=None, redirect_url=None):
"""
Decorator requiring that there is no user currently logged in.
Aborts with ``HTTP 403: Forbidden`` if there is an authenticated user.
"""
def wrapper(fn):
@wraps(fn)
def decorated(*args, **... | [
"def",
"anonymous_user_required",
"(",
"*",
"decorator_args",
",",
"msg",
"=",
"None",
",",
"category",
"=",
"None",
",",
"redirect_url",
"=",
"None",
")",
":",
"def",
"wrapper",
"(",
"fn",
")",
":",
"@",
"wraps",
"(",
"fn",
")",
"def",
"decorated",
"(... | Decorator requiring that there is no user currently logged in.
Aborts with ``HTTP 403: Forbidden`` if there is an authenticated user. | [
"Decorator",
"requiring",
"that",
"there",
"is",
"no",
"user",
"currently",
"logged",
"in",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/security/decorators/anonymous_user_required.py#L9-L31 | train |
briancappello/flask-unchained | flask_unchained/bundles/security/services/security_service.py | SecurityService.login_user | def login_user(self,
user: User,
remember: Optional[bool] = None,
duration: Optional[timedelta] = None,
force: bool = False,
fresh: bool = True,
) -> bool:
"""
Logs a user in. You should pas... | python | def login_user(self,
user: User,
remember: Optional[bool] = None,
duration: Optional[timedelta] = None,
force: bool = False,
fresh: bool = True,
) -> bool:
"""
Logs a user in. You should pas... | [
"def",
"login_user",
"(",
"self",
",",
"user",
":",
"User",
",",
"remember",
":",
"Optional",
"[",
"bool",
"]",
"=",
"None",
",",
"duration",
":",
"Optional",
"[",
"timedelta",
"]",
"=",
"None",
",",
"force",
":",
"bool",
"=",
"False",
",",
"fresh",
... | Logs a user in. You should pass the actual user object to this. If the
user's `active` property is ``False``, they will not be logged in
unless `force` is ``True``.
This will return ``True`` if the log in attempt succeeds, and ``False`` if
it fails (i.e. because the user is inactive).
... | [
"Logs",
"a",
"user",
"in",
".",
"You",
"should",
"pass",
"the",
"actual",
"user",
"object",
"to",
"this",
".",
"If",
"the",
"user",
"s",
"active",
"property",
"is",
"False",
"they",
"will",
"not",
"be",
"logged",
"in",
"unless",
"force",
"is",
"True",
... | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/security/services/security_service.py#L42-L106 | train |
briancappello/flask-unchained | flask_unchained/bundles/security/services/security_service.py | SecurityService.register_user | def register_user(self, user, allow_login=None, send_email=None,
_force_login_without_confirmation=False):
"""
Service method to register a user.
Sends signal `user_registered`.
Returns True if the user has been logged in, False otherwise.
"""
shou... | python | def register_user(self, user, allow_login=None, send_email=None,
_force_login_without_confirmation=False):
"""
Service method to register a user.
Sends signal `user_registered`.
Returns True if the user has been logged in, False otherwise.
"""
shou... | [
"def",
"register_user",
"(",
"self",
",",
"user",
",",
"allow_login",
"=",
"None",
",",
"send_email",
"=",
"None",
",",
"_force_login_without_confirmation",
"=",
"False",
")",
":",
"should_login_user",
"=",
"(",
"not",
"self",
".",
"security",
".",
"confirmabl... | Service method to register a user.
Sends signal `user_registered`.
Returns True if the user has been logged in, False otherwise. | [
"Service",
"method",
"to",
"register",
"a",
"user",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/security/services/security_service.py#L122-L163 | train |
briancappello/flask-unchained | flask_unchained/bundles/security/services/security_service.py | SecurityService.change_password | def change_password(self, user, password, send_email=None):
"""
Service method to change a user's password.
Sends signal `password_changed`.
:param user: The :class:`User`'s password to change.
:param password: The new password.
:param send_email: Whether or not to over... | python | def change_password(self, user, password, send_email=None):
"""
Service method to change a user's password.
Sends signal `password_changed`.
:param user: The :class:`User`'s password to change.
:param password: The new password.
:param send_email: Whether or not to over... | [
"def",
"change_password",
"(",
"self",
",",
"user",
",",
"password",
",",
"send_email",
"=",
"None",
")",
":",
"user",
".",
"password",
"=",
"password",
"self",
".",
"user_manager",
".",
"save",
"(",
"user",
")",
"if",
"send_email",
"or",
"(",
"app",
"... | Service method to change a user's password.
Sends signal `password_changed`.
:param user: The :class:`User`'s password to change.
:param password: The new password.
:param send_email: Whether or not to override the config option
``SECURITY_SEND_PASSWORD_CHANG... | [
"Service",
"method",
"to",
"change",
"a",
"user",
"s",
"password",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/security/services/security_service.py#L165-L186 | train |
briancappello/flask-unchained | flask_unchained/bundles/security/services/security_service.py | SecurityService.confirm_user | def confirm_user(self, user):
"""
Confirms the specified user. Returns False if the user has already been
confirmed, True otherwise.
:param user: The user to confirm.
"""
if user.confirmed_at is not None:
return False
user.confirmed_at = self.security... | python | def confirm_user(self, user):
"""
Confirms the specified user. Returns False if the user has already been
confirmed, True otherwise.
:param user: The user to confirm.
"""
if user.confirmed_at is not None:
return False
user.confirmed_at = self.security... | [
"def",
"confirm_user",
"(",
"self",
",",
"user",
")",
":",
"if",
"user",
".",
"confirmed_at",
"is",
"not",
"None",
":",
"return",
"False",
"user",
".",
"confirmed_at",
"=",
"self",
".",
"security",
".",
"datetime_factory",
"(",
")",
"user",
".",
"active"... | Confirms the specified user. Returns False if the user has already been
confirmed, True otherwise.
:param user: The user to confirm. | [
"Confirms",
"the",
"specified",
"user",
".",
"Returns",
"False",
"if",
"the",
"user",
"has",
"already",
"been",
"confirmed",
"True",
"otherwise",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/security/services/security_service.py#L249-L263 | train |
briancappello/flask-unchained | flask_unchained/bundles/security/services/security_service.py | SecurityService.send_mail | def send_mail(self, subject, to, template, **template_ctx):
"""
Utility method to send mail with the `mail` template context.
"""
if not self.mail:
from warnings import warn
warn('Attempting to send mail without the mail bundle installed! '
'Pleas... | python | def send_mail(self, subject, to, template, **template_ctx):
"""
Utility method to send mail with the `mail` template context.
"""
if not self.mail:
from warnings import warn
warn('Attempting to send mail without the mail bundle installed! '
'Pleas... | [
"def",
"send_mail",
"(",
"self",
",",
"subject",
",",
"to",
",",
"template",
",",
"*",
"*",
"template_ctx",
")",
":",
"if",
"not",
"self",
".",
"mail",
":",
"from",
"warnings",
"import",
"warn",
"warn",
"(",
"'Attempting to send mail without the mail bundle in... | Utility method to send mail with the `mail` template context. | [
"Utility",
"method",
"to",
"send",
"mail",
"with",
"the",
"mail",
"template",
"context",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/security/services/security_service.py#L265-L277 | train |
briancappello/flask-unchained | flask_unchained/bundles/api/model_serializer.py | _ModelSerializerMetaclass.get_declared_fields | def get_declared_fields(mcs, klass, cls_fields, inherited_fields, dict_cls):
"""
Updates declared fields with fields converted from the SQLAlchemy model
passed as the `model` class Meta option.
"""
opts = klass.opts
converter = opts.model_converter(schema_cls=klass)
... | python | def get_declared_fields(mcs, klass, cls_fields, inherited_fields, dict_cls):
"""
Updates declared fields with fields converted from the SQLAlchemy model
passed as the `model` class Meta option.
"""
opts = klass.opts
converter = opts.model_converter(schema_cls=klass)
... | [
"def",
"get_declared_fields",
"(",
"mcs",
",",
"klass",
",",
"cls_fields",
",",
"inherited_fields",
",",
"dict_cls",
")",
":",
"opts",
"=",
"klass",
".",
"opts",
"converter",
"=",
"opts",
".",
"model_converter",
"(",
"schema_cls",
"=",
"klass",
")",
"base_fi... | Updates declared fields with fields converted from the SQLAlchemy model
passed as the `model` class Meta option. | [
"Updates",
"declared",
"fields",
"with",
"fields",
"converted",
"from",
"the",
"SQLAlchemy",
"model",
"passed",
"as",
"the",
"model",
"class",
"Meta",
"option",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/api/model_serializer.py#L161-L173 | train |
briancappello/flask-unchained | flask_unchained/commands/qtconsole.py | JupyterWidget.reset | def reset(self, clear=False):
"""
Overridden to customize the order that the banners are printed
"""
if self._executing:
self._executing = False
self._request_info['execute'] = {}
self._reading = False
self._highlighter.highlighting_on = False
... | python | def reset(self, clear=False):
"""
Overridden to customize the order that the banners are printed
"""
if self._executing:
self._executing = False
self._request_info['execute'] = {}
self._reading = False
self._highlighter.highlighting_on = False
... | [
"def",
"reset",
"(",
"self",
",",
"clear",
"=",
"False",
")",
":",
"if",
"self",
".",
"_executing",
":",
"self",
".",
"_executing",
"=",
"False",
"self",
".",
"_request_info",
"[",
"'execute'",
"]",
"=",
"{",
"}",
"self",
".",
"_reading",
"=",
"False... | Overridden to customize the order that the banners are printed | [
"Overridden",
"to",
"customize",
"the",
"order",
"that",
"the",
"banners",
"are",
"printed"
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/commands/qtconsole.py#L100-L119 | train |
briancappello/flask-unchained | flask_unchained/commands/qtconsole.py | IPythonKernelApp.log_connection_info | def log_connection_info(self):
"""
Overridden to customize the start-up message printed to the terminal
"""
_ctrl_c_lines = [
'NOTE: Ctrl-C does not work to exit from the command line.',
'To exit, just close the window, type "exit" or "quit" at the '
'... | python | def log_connection_info(self):
"""
Overridden to customize the start-up message printed to the terminal
"""
_ctrl_c_lines = [
'NOTE: Ctrl-C does not work to exit from the command line.',
'To exit, just close the window, type "exit" or "quit" at the '
'... | [
"def",
"log_connection_info",
"(",
"self",
")",
":",
"_ctrl_c_lines",
"=",
"[",
"'NOTE: Ctrl-C does not work to exit from the command line.'",
",",
"'To exit, just close the window, type \"exit\" or \"quit\" at the '",
"'qtconsole prompt, or use Ctrl-\\\\ in UNIX-like environments '",
"'(a... | Overridden to customize the start-up message printed to the terminal | [
"Overridden",
"to",
"customize",
"the",
"start",
"-",
"up",
"message",
"printed",
"to",
"the",
"terminal"
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/commands/qtconsole.py#L135-L151 | train |
briancappello/flask-unchained | flask_unchained/bundles/controller/utils.py | url_for | def url_for(endpoint_or_url_or_config_key: str,
_anchor: Optional[str] = None,
_cls: Optional[Union[object, type]] = None,
_external: Optional[bool] = False,
_external_host: Optional[str] = None,
_method: Optional[str] = None,
_scheme: Optional[str... | python | def url_for(endpoint_or_url_or_config_key: str,
_anchor: Optional[str] = None,
_cls: Optional[Union[object, type]] = None,
_external: Optional[bool] = False,
_external_host: Optional[str] = None,
_method: Optional[str] = None,
_scheme: Optional[str... | [
"def",
"url_for",
"(",
"endpoint_or_url_or_config_key",
":",
"str",
",",
"_anchor",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"_cls",
":",
"Optional",
"[",
"Union",
"[",
"object",
",",
"type",
"]",
"]",
"=",
"None",
",",
"_external",
":",
"Op... | An improved version of flask's url_for function
:param endpoint_or_url_or_config_key: what to lookup. it can be an endpoint
name, an app config key, or an already-formed url. if _cls is specified,
it also accepts a method name.
:param values: the variable arguments of the URL rule
:param _ancho... | [
"An",
"improved",
"version",
"of",
"flask",
"s",
"url_for",
"function"
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/controller/utils.py#L99-L161 | train |
briancappello/flask-unchained | flask_unchained/bundles/controller/utils.py | redirect | def redirect(where: Optional[str] = None,
default: Optional[str] = None,
override: Optional[str] = None,
_anchor: Optional[str] = None,
_cls: Optional[Union[object, type]] = None,
_external: Optional[bool] = False,
_external_host: Optional[st... | python | def redirect(where: Optional[str] = None,
default: Optional[str] = None,
override: Optional[str] = None,
_anchor: Optional[str] = None,
_cls: Optional[Union[object, type]] = None,
_external: Optional[bool] = False,
_external_host: Optional[st... | [
"def",
"redirect",
"(",
"where",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"default",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"override",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"_anchor",
":",
"Optional",
"[",
"st... | An improved version of flask's redirect function
:param where: A URL, endpoint, or config key name to redirect to
:param default: A URL, endpoint, or config key name to redirect to if
``where`` is invalid
:param override: explicitly redirect to a URL, endpoint, or config key name
(takes precede... | [
"An",
"improved",
"version",
"of",
"flask",
"s",
"redirect",
"function"
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/controller/utils.py#L193-L245 | train |
briancappello/flask-unchained | flask_unchained/bundles/controller/utils.py | _url_for | def _url_for(endpoint: str, **values) -> Union[str, None]:
"""
The same as flask's url_for, except this also supports building external
urls for hosts that are different from app.config.SERVER_NAME. One case
where this is especially useful is for single page apps, where the frontend
is not hosted by... | python | def _url_for(endpoint: str, **values) -> Union[str, None]:
"""
The same as flask's url_for, except this also supports building external
urls for hosts that are different from app.config.SERVER_NAME. One case
where this is especially useful is for single page apps, where the frontend
is not hosted by... | [
"def",
"_url_for",
"(",
"endpoint",
":",
"str",
",",
"*",
"*",
"values",
")",
"->",
"Union",
"[",
"str",
",",
"None",
"]",
":",
"_external_host",
"=",
"values",
".",
"pop",
"(",
"'_external_host'",
",",
"None",
")",
"is_external",
"=",
"bool",
"(",
"... | The same as flask's url_for, except this also supports building external
urls for hosts that are different from app.config.SERVER_NAME. One case
where this is especially useful is for single page apps, where the frontend
is not hosted by the same server as the backend, but the backend still needs
to gen... | [
"The",
"same",
"as",
"flask",
"s",
"url_for",
"except",
"this",
"also",
"supports",
"building",
"external",
"urls",
"for",
"hosts",
"that",
"are",
"different",
"from",
"app",
".",
"config",
".",
"SERVER_NAME",
".",
"One",
"case",
"where",
"this",
"is",
"es... | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/controller/utils.py#L263-L284 | train |
briancappello/flask-unchained | flask_unchained/bundles/security/decorators/roles_required.py | roles_required | def roles_required(*roles):
"""
Decorator which specifies that a user must have all the specified roles.
Aborts with HTTP 403: Forbidden if the user doesn't have the required roles.
Example::
@app.route('/dashboard')
@roles_required('ROLE_ADMIN', 'ROLE_EDITOR')
def dashboard()... | python | def roles_required(*roles):
"""
Decorator which specifies that a user must have all the specified roles.
Aborts with HTTP 403: Forbidden if the user doesn't have the required roles.
Example::
@app.route('/dashboard')
@roles_required('ROLE_ADMIN', 'ROLE_EDITOR')
def dashboard()... | [
"def",
"roles_required",
"(",
"*",
"roles",
")",
":",
"def",
"wrapper",
"(",
"fn",
")",
":",
"@",
"wraps",
"(",
"fn",
")",
"def",
"decorated_view",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"perms",
"=",
"[",
"Permission",
"(",
"RoleNeed... | Decorator which specifies that a user must have all the specified roles.
Aborts with HTTP 403: Forbidden if the user doesn't have the required roles.
Example::
@app.route('/dashboard')
@roles_required('ROLE_ADMIN', 'ROLE_EDITOR')
def dashboard():
return 'Dashboard'
Th... | [
"Decorator",
"which",
"specifies",
"that",
"a",
"user",
"must",
"have",
"all",
"the",
"specified",
"roles",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/security/decorators/roles_required.py#L7-L34 | train |
briancappello/flask-unchained | flask_unchained/bundles/security/services/security_utils_service.py | SecurityUtilsService.verify_hash | def verify_hash(self, hashed_data, compare_data):
"""
Verify a hash in the security token hashing context.
"""
return self.security.hashing_context.verify(
encode_string(compare_data), hashed_data) | python | def verify_hash(self, hashed_data, compare_data):
"""
Verify a hash in the security token hashing context.
"""
return self.security.hashing_context.verify(
encode_string(compare_data), hashed_data) | [
"def",
"verify_hash",
"(",
"self",
",",
"hashed_data",
",",
"compare_data",
")",
":",
"return",
"self",
".",
"security",
".",
"hashing_context",
".",
"verify",
"(",
"encode_string",
"(",
"compare_data",
")",
",",
"hashed_data",
")"
] | Verify a hash in the security token hashing context. | [
"Verify",
"a",
"hash",
"in",
"the",
"security",
"token",
"hashing",
"context",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/security/services/security_utils_service.py#L89-L94 | train |
briancappello/flask-unchained | flask_unchained/bundles/security/decorators/auth_required.py | auth_required | def auth_required(decorated_fn=None, **role_rules):
"""
Decorator for requiring an authenticated user, optionally with roles.
Roles are passed as keyword arguments, like so::
@auth_required(role='REQUIRE_THIS_ONE_ROLE')
@auth_required(roles=['REQUIRE', 'ALL', 'OF', 'THESE', 'ROLES'])
... | python | def auth_required(decorated_fn=None, **role_rules):
"""
Decorator for requiring an authenticated user, optionally with roles.
Roles are passed as keyword arguments, like so::
@auth_required(role='REQUIRE_THIS_ONE_ROLE')
@auth_required(roles=['REQUIRE', 'ALL', 'OF', 'THESE', 'ROLES'])
... | [
"def",
"auth_required",
"(",
"decorated_fn",
"=",
"None",
",",
"*",
"*",
"role_rules",
")",
":",
"required_roles",
"=",
"[",
"]",
"one_of_roles",
"=",
"[",
"]",
"if",
"not",
"(",
"decorated_fn",
"and",
"callable",
"(",
"decorated_fn",
")",
")",
":",
"if"... | Decorator for requiring an authenticated user, optionally with roles.
Roles are passed as keyword arguments, like so::
@auth_required(role='REQUIRE_THIS_ONE_ROLE')
@auth_required(roles=['REQUIRE', 'ALL', 'OF', 'THESE', 'ROLES'])
@auth_required(one_of=['EITHER_THIS_ROLE', 'OR_THIS_ONE'])
... | [
"Decorator",
"for",
"requiring",
"an",
"authenticated",
"user",
"optionally",
"with",
"roles",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/security/decorators/auth_required.py#L13-L54 | train |
briancappello/flask-unchained | flask_unchained/bundles/security/decorators/auth_required.py | _auth_required | def _auth_required():
"""
Decorator that protects endpoints through token and session auth mechanisms
"""
login_mechanisms = (
('token', lambda: _check_token()),
('session', lambda: current_user.is_authenticated),
)
def wrapper(fn):
@wraps(fn)
def decorated_view... | python | def _auth_required():
"""
Decorator that protects endpoints through token and session auth mechanisms
"""
login_mechanisms = (
('token', lambda: _check_token()),
('session', lambda: current_user.is_authenticated),
)
def wrapper(fn):
@wraps(fn)
def decorated_view... | [
"def",
"_auth_required",
"(",
")",
":",
"login_mechanisms",
"=",
"(",
"(",
"'token'",
",",
"lambda",
":",
"_check_token",
"(",
")",
")",
",",
"(",
"'session'",
",",
"lambda",
":",
"current_user",
".",
"is_authenticated",
")",
",",
")",
"def",
"wrapper",
... | Decorator that protects endpoints through token and session auth mechanisms | [
"Decorator",
"that",
"protects",
"endpoints",
"through",
"token",
"and",
"session",
"auth",
"mechanisms"
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/security/decorators/auth_required.py#L57-L75 | train |
briancappello/flask-unchained | flask_unchained/bundles/celery/tasks.py | async_mail_task | def async_mail_task(subject_or_message, to=None, template=None, **kwargs):
"""
Celery task to send emails asynchronously using the mail bundle.
"""
to = to or kwargs.pop('recipients', [])
msg = make_message(subject_or_message, to, template, **kwargs)
with mail.connect() as connection:
co... | python | def async_mail_task(subject_or_message, to=None, template=None, **kwargs):
"""
Celery task to send emails asynchronously using the mail bundle.
"""
to = to or kwargs.pop('recipients', [])
msg = make_message(subject_or_message, to, template, **kwargs)
with mail.connect() as connection:
co... | [
"def",
"async_mail_task",
"(",
"subject_or_message",
",",
"to",
"=",
"None",
",",
"template",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"to",
"=",
"to",
"or",
"kwargs",
".",
"pop",
"(",
"'recipients'",
",",
"[",
"]",
")",
"msg",
"=",
"make_mess... | Celery task to send emails asynchronously using the mail bundle. | [
"Celery",
"task",
"to",
"send",
"emails",
"asynchronously",
"using",
"the",
"mail",
"bundle",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/celery/tasks.py#L16-L23 | train |
briancappello/flask-unchained | flask_unchained/bundles/api/__init__.py | ApiBundle.after_init_app | def after_init_app(self, app: FlaskUnchained):
"""
Configure the JSON encoder for Flask to be able to serialize Enums,
LocalProxy objects, and SQLAlchemy models.
"""
self.set_json_encoder(app)
app.before_first_request(self.register_model_resources) | python | def after_init_app(self, app: FlaskUnchained):
"""
Configure the JSON encoder for Flask to be able to serialize Enums,
LocalProxy objects, and SQLAlchemy models.
"""
self.set_json_encoder(app)
app.before_first_request(self.register_model_resources) | [
"def",
"after_init_app",
"(",
"self",
",",
"app",
":",
"FlaskUnchained",
")",
":",
"self",
".",
"set_json_encoder",
"(",
"app",
")",
"app",
".",
"before_first_request",
"(",
"self",
".",
"register_model_resources",
")"
] | Configure the JSON encoder for Flask to be able to serialize Enums,
LocalProxy objects, and SQLAlchemy models. | [
"Configure",
"the",
"JSON",
"encoder",
"for",
"Flask",
"to",
"be",
"able",
"to",
"serialize",
"Enums",
"LocalProxy",
"objects",
"and",
"SQLAlchemy",
"models",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/api/__init__.py#L52-L58 | train |
briancappello/flask-unchained | flask_unchained/bundles/controller/route.py | Route.endpoint | def endpoint(self):
"""
The endpoint for this route.
"""
if self._endpoint:
return self._endpoint
elif self._controller_cls:
endpoint = f'{snake_case(self._controller_cls.__name__)}.{self.method_name}'
return endpoint if not self.bp_name else f... | python | def endpoint(self):
"""
The endpoint for this route.
"""
if self._endpoint:
return self._endpoint
elif self._controller_cls:
endpoint = f'{snake_case(self._controller_cls.__name__)}.{self.method_name}'
return endpoint if not self.bp_name else f... | [
"def",
"endpoint",
"(",
"self",
")",
":",
"if",
"self",
".",
"_endpoint",
":",
"return",
"self",
".",
"_endpoint",
"elif",
"self",
".",
"_controller_cls",
":",
"endpoint",
"=",
"f'{snake_case(self._controller_cls.__name__)}.{self.method_name}'",
"return",
"endpoint",
... | The endpoint for this route. | [
"The",
"endpoint",
"for",
"this",
"route",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/controller/route.py#L102-L113 | train |
briancappello/flask-unchained | flask_unchained/bundles/controller/route.py | Route.method_name | def method_name(self):
"""
The string name of this route's view function.
"""
if isinstance(self.view_func, str):
return self.view_func
return self.view_func.__name__ | python | def method_name(self):
"""
The string name of this route's view function.
"""
if isinstance(self.view_func, str):
return self.view_func
return self.view_func.__name__ | [
"def",
"method_name",
"(",
"self",
")",
":",
"if",
"isinstance",
"(",
"self",
".",
"view_func",
",",
"str",
")",
":",
"return",
"self",
".",
"view_func",
"return",
"self",
".",
"view_func",
".",
"__name__"
] | The string name of this route's view function. | [
"The",
"string",
"name",
"of",
"this",
"route",
"s",
"view",
"function",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/controller/route.py#L133-L139 | train |
briancappello/flask-unchained | flask_unchained/bundles/controller/route.py | Route.module_name | def module_name(self):
"""
The module where this route's view function was defined.
"""
if not self.view_func:
return None
elif self._controller_cls:
rv = inspect.getmodule(self._controller_cls).__name__
return rv
return inspect.getmodu... | python | def module_name(self):
"""
The module where this route's view function was defined.
"""
if not self.view_func:
return None
elif self._controller_cls:
rv = inspect.getmodule(self._controller_cls).__name__
return rv
return inspect.getmodu... | [
"def",
"module_name",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"view_func",
":",
"return",
"None",
"elif",
"self",
".",
"_controller_cls",
":",
"rv",
"=",
"inspect",
".",
"getmodule",
"(",
"self",
".",
"_controller_cls",
")",
".",
"__name__",
"re... | The module where this route's view function was defined. | [
"The",
"module",
"where",
"this",
"route",
"s",
"view",
"function",
"was",
"defined",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/controller/route.py#L153-L162 | train |
briancappello/flask-unchained | flask_unchained/bundles/controller/route.py | Route.full_rule | def full_rule(self):
"""
The full url rule for this route, including any blueprint prefix.
"""
return join(self.bp_prefix, self.rule, trailing_slash=self.rule.endswith('/')) | python | def full_rule(self):
"""
The full url rule for this route, including any blueprint prefix.
"""
return join(self.bp_prefix, self.rule, trailing_slash=self.rule.endswith('/')) | [
"def",
"full_rule",
"(",
"self",
")",
":",
"return",
"join",
"(",
"self",
".",
"bp_prefix",
",",
"self",
".",
"rule",
",",
"trailing_slash",
"=",
"self",
".",
"rule",
".",
"endswith",
"(",
"'/'",
")",
")"
] | The full url rule for this route, including any blueprint prefix. | [
"The",
"full",
"url",
"rule",
"for",
"this",
"route",
"including",
"any",
"blueprint",
"prefix",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/controller/route.py#L195-L199 | train |
briancappello/flask-unchained | flask_unchained/bundles/controller/route.py | Route.full_name | def full_name(self):
"""
The full name of this route's view function, including the module path
and controller name, if any.
"""
if not self.view_func:
return None
prefix = self.view_func.__module__
if self._controller_cls:
prefix = f'{pre... | python | def full_name(self):
"""
The full name of this route's view function, including the module path
and controller name, if any.
"""
if not self.view_func:
return None
prefix = self.view_func.__module__
if self._controller_cls:
prefix = f'{pre... | [
"def",
"full_name",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"view_func",
":",
"return",
"None",
"prefix",
"=",
"self",
".",
"view_func",
".",
"__module__",
"if",
"self",
".",
"_controller_cls",
":",
"prefix",
"=",
"f'{prefix}.{self._controller_cls.__n... | The full name of this route's view function, including the module path
and controller name, if any. | [
"The",
"full",
"name",
"of",
"this",
"route",
"s",
"view",
"function",
"including",
"the",
"module",
"path",
"and",
"controller",
"name",
"if",
"any",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/bundles/controller/route.py#L235-L246 | train |
briancappello/flask-unchained | flask_unchained/commands/new.py | project | def project(dest, app_bundle, force, dev,
admin, api, celery, graphene, mail, oauth,
security, session, sqlalchemy, webpack):
"""
Create a new Flask Unchained project.
"""
if os.path.exists(dest) and os.listdir(dest) and not force:
if not click.confirm(f'WARNING: Project ... | python | def project(dest, app_bundle, force, dev,
admin, api, celery, graphene, mail, oauth,
security, session, sqlalchemy, webpack):
"""
Create a new Flask Unchained project.
"""
if os.path.exists(dest) and os.listdir(dest) and not force:
if not click.confirm(f'WARNING: Project ... | [
"def",
"project",
"(",
"dest",
",",
"app_bundle",
",",
"force",
",",
"dev",
",",
"admin",
",",
"api",
",",
"celery",
",",
"graphene",
",",
"mail",
",",
"oauth",
",",
"security",
",",
"session",
",",
"sqlalchemy",
",",
"webpack",
")",
":",
"if",
"os",... | Create a new Flask Unchained project. | [
"Create",
"a",
"new",
"Flask",
"Unchained",
"project",
"."
] | 4d536cb90e2cc4829c1c05f2c74d3e22901a1399 | https://github.com/briancappello/flask-unchained/blob/4d536cb90e2cc4829c1c05f2c74d3e22901a1399/flask_unchained/commands/new.py#L182-L224 | train |
ironfroggy/straight.plugin | straight/plugin/manager.py | PluginManager.produce | def produce(self, *args, **kwargs):
"""Produce a new set of plugins, treating the current set as plugin
factories.
"""
new_plugins = []
for p in self._plugins:
r = p(*args, **kwargs)
new_plugins.append(r)
return PluginManager(new_plugins) | python | def produce(self, *args, **kwargs):
"""Produce a new set of plugins, treating the current set as plugin
factories.
"""
new_plugins = []
for p in self._plugins:
r = p(*args, **kwargs)
new_plugins.append(r)
return PluginManager(new_plugins) | [
"def",
"produce",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"new_plugins",
"=",
"[",
"]",
"for",
"p",
"in",
"self",
".",
"_plugins",
":",
"r",
"=",
"p",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"new_plugins",
".",... | Produce a new set of plugins, treating the current set as plugin
factories. | [
"Produce",
"a",
"new",
"set",
"of",
"plugins",
"treating",
"the",
"current",
"set",
"as",
"plugin",
"factories",
"."
] | aaaf68db51b823d164cf714b1be2262a75ee2a79 | https://github.com/ironfroggy/straight.plugin/blob/aaaf68db51b823d164cf714b1be2262a75ee2a79/straight/plugin/manager.py#L15-L24 | train |
ironfroggy/straight.plugin | straight/plugin/manager.py | PluginManager.call | def call(self, methodname, *args, **kwargs):
"""Call a common method on all the plugins, if it exists."""
for plugin in self._plugins:
method = getattr(plugin, methodname, None)
if method is None:
continue
yield method(*args, **kwargs) | python | def call(self, methodname, *args, **kwargs):
"""Call a common method on all the plugins, if it exists."""
for plugin in self._plugins:
method = getattr(plugin, methodname, None)
if method is None:
continue
yield method(*args, **kwargs) | [
"def",
"call",
"(",
"self",
",",
"methodname",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"for",
"plugin",
"in",
"self",
".",
"_plugins",
":",
"method",
"=",
"getattr",
"(",
"plugin",
",",
"methodname",
",",
"None",
")",
"if",
"method",
"... | Call a common method on all the plugins, if it exists. | [
"Call",
"a",
"common",
"method",
"on",
"all",
"the",
"plugins",
"if",
"it",
"exists",
"."
] | aaaf68db51b823d164cf714b1be2262a75ee2a79 | https://github.com/ironfroggy/straight.plugin/blob/aaaf68db51b823d164cf714b1be2262a75ee2a79/straight/plugin/manager.py#L26-L33 | train |
ironfroggy/straight.plugin | straight/plugin/manager.py | PluginManager.pipe | def pipe(self, methodname, first_arg, *args, **kwargs):
"""Call a common method on all the plugins, if it exists. The return
value of each call becomes the replaces the first argument in the given
argument list to pass to the next.
Useful to utilize plugins as sets of filters.
"... | python | def pipe(self, methodname, first_arg, *args, **kwargs):
"""Call a common method on all the plugins, if it exists. The return
value of each call becomes the replaces the first argument in the given
argument list to pass to the next.
Useful to utilize plugins as sets of filters.
"... | [
"def",
"pipe",
"(",
"self",
",",
"methodname",
",",
"first_arg",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"for",
"plugin",
"in",
"self",
".",
"_plugins",
":",
"method",
"=",
"getattr",
"(",
"plugin",
",",
"methodname",
",",
"None",
")",
... | Call a common method on all the plugins, if it exists. The return
value of each call becomes the replaces the first argument in the given
argument list to pass to the next.
Useful to utilize plugins as sets of filters. | [
"Call",
"a",
"common",
"method",
"on",
"all",
"the",
"plugins",
"if",
"it",
"exists",
".",
"The",
"return",
"value",
"of",
"each",
"call",
"becomes",
"the",
"replaces",
"the",
"first",
"argument",
"in",
"the",
"given",
"argument",
"list",
"to",
"pass",
"... | aaaf68db51b823d164cf714b1be2262a75ee2a79 | https://github.com/ironfroggy/straight.plugin/blob/aaaf68db51b823d164cf714b1be2262a75ee2a79/straight/plugin/manager.py#L46-L61 | train |
ironfroggy/straight.plugin | straight/plugin/loaders.py | unified_load | def unified_load(namespace, subclasses=None, recurse=False):
"""Provides a unified interface to both the module and class loaders,
finding modules by default or classes if given a ``subclasses`` parameter.
"""
if subclasses is not None:
return ClassLoader(recurse=recurse).load(namespace, subcla... | python | def unified_load(namespace, subclasses=None, recurse=False):
"""Provides a unified interface to both the module and class loaders,
finding modules by default or classes if given a ``subclasses`` parameter.
"""
if subclasses is not None:
return ClassLoader(recurse=recurse).load(namespace, subcla... | [
"def",
"unified_load",
"(",
"namespace",
",",
"subclasses",
"=",
"None",
",",
"recurse",
"=",
"False",
")",
":",
"if",
"subclasses",
"is",
"not",
"None",
":",
"return",
"ClassLoader",
"(",
"recurse",
"=",
"recurse",
")",
".",
"load",
"(",
"namespace",
",... | Provides a unified interface to both the module and class loaders,
finding modules by default or classes if given a ``subclasses`` parameter. | [
"Provides",
"a",
"unified",
"interface",
"to",
"both",
"the",
"module",
"and",
"class",
"loaders",
"finding",
"modules",
"by",
"default",
"or",
"classes",
"if",
"given",
"a",
"subclasses",
"parameter",
"."
] | aaaf68db51b823d164cf714b1be2262a75ee2a79 | https://github.com/ironfroggy/straight.plugin/blob/aaaf68db51b823d164cf714b1be2262a75ee2a79/straight/plugin/loaders.py#L161-L169 | train |
ironfroggy/straight.plugin | straight/plugin/loaders.py | ModuleLoader._fill_cache | def _fill_cache(self, namespace):
"""Load all modules found in a namespace"""
modules = self._findPluginModules(namespace)
self._cache = list(modules) | python | def _fill_cache(self, namespace):
"""Load all modules found in a namespace"""
modules = self._findPluginModules(namespace)
self._cache = list(modules) | [
"def",
"_fill_cache",
"(",
"self",
",",
"namespace",
")",
":",
"modules",
"=",
"self",
".",
"_findPluginModules",
"(",
"namespace",
")",
"self",
".",
"_cache",
"=",
"list",
"(",
"modules",
")"
] | Load all modules found in a namespace | [
"Load",
"all",
"modules",
"found",
"in",
"a",
"namespace"
] | aaaf68db51b823d164cf714b1be2262a75ee2a79 | https://github.com/ironfroggy/straight.plugin/blob/aaaf68db51b823d164cf714b1be2262a75ee2a79/straight/plugin/loaders.py#L111-L116 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.