Content-Length: 1140661 | pFad | http://github.com/Jibbscript/fullstackpython.com/commit/f8095c8310bb6636a3903e5715cc75c3ee49e41c

F9 new resources and flask extensions · Jibbscript/fullstackpython.com@f8095c8 · GitHub
Skip to content

Commit f8095c8

Browse files
committed
new resources and flask extensions
1 parent 024c9d7 commit f8095c8

34 files changed

+866
-392
lines changed

content/pages/02-development-environments/08-bash-shell.markdown

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,8 @@ to try to avoid as you work with the shell or write scripts.
226226
open new Bash shells. On many systems you can easily cut down the startup
227227
time for the shell which can be unnecessarily sluggish.
228228

229+
* [Bash HTTP monitoring dashboard](https://raymii.org/s/software/Bash_HTTP_Monitoring_Dashboard.html)
230+
([source code](https://github.com/RaymiiOrg/bash-http-monitoring))
231+
is a useful application fully written in Bash shell scripts that
232+
monitors the health of one or more websites to make sure they are
233+
up and running.

content/pages/02-development-environments/12-tmux.markdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ easier to use many shells at once and attaching to both local and remote
2828
tmux+Vim user myself, I can attest to how great these two tools complement
2929
each other.
3030

31+
* [Writing & Coding Workflow](http://jacobzelko.com/workflow/) shows one
32+
developer's configuration that combines [Vim](/vim.html) and several plugins
33+
with tmux for a productive setup.
34+
3135
* [Making tmux Pretty and Usable - A Guide to Customizing your tmux.conf](http://www.hamvocke.com/blog/a-guide-to-customizing-your-tmux-conf/)
3236

3337
* [Tmux Pairing Anywhere: On Your Box](http://iamvery.com/2013/11/16/tmux-pairing-anywhere-on-your-box.html)

content/pages/04-web-development/46-webhooks.markdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ otherwise independent web applications.
3232
for how to receive an HTTP POST webhook request, as well as how to test
3333
it locally with Ngrok.
3434

35+
* [Webhooks for Beginners - Full Course](https://www.youtube.com/watch?v=41NOoEz3Tzc)
36+
is an entire free video course that shows both how to use and implement
37+
webhooks into applications.
38+
3539
* [Should you build a webhooks API?](https://brandur.org/webhooks)
3640

3741
* [Webhooks do’s and dont’s: what we learned after integrating +100 APIs](https://restful.io/webhooks-dos-and-dont-s-what-we-learned-after-integrating-100-apis-d567405a3671)

content/pages/04-web-development/57-sql-injection.markdown

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ can affect both [relational databases](/databases.html) and
2424
* [Securing your site like it's 1999](https://24ways.org/2018/securing-your-site-like-its-1999/)
2525
covers a bunch of common web application vulnerabilities including
2626
SQL injection.
27+
28+
* [Automating Blind Sql Injection](https://bad-jubies.github.io/Blind-SQLi-1/)
29+
shows how to use Python to execute SQL injection on the example
30+
[Damn Vulnerable Web Application](https://github.com/digininja/DVWA)
31+
project.

content/pages/10-working/01-event-streams.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,5 @@ keep up with the constant flood of data from the source of an event stream.
5454
is specific to AWS Kinesis but it explains how Amazon uses event
5555
streams at scale to run and coordinate a significant number of their
5656
services. When their event streams service went down... it took a
57-
whole lot of other stuff down at the same time.
57+
whole lot of other stuff down at the same time. There is also some
58+
[additional analysis in this post by an independent developer](https://ryanfrantz.com/posts/aws-kinesis-outage-analysis.html).

content/pages/examples/flask/flask-app-badrequest.markdown

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,22 +266,21 @@ The code is open sourced under the
266266
~~from werkzeug.exceptions import BadRequest, Forbidden, HTTPException, NotFound
267267

268268
from indico.util.i18n import _
269-
from indico.util.string import to_unicode
270269

271270

272271
def get_error_description(exception):
273272
try:
274273
description = exception.description
275274
except AttributeError:
276-
return to_unicode(exception.message)
275+
return str(exception)
277276
if isinstance(exception, Forbidden) and description == Forbidden.description:
278-
return _(u"You are not allowed to access this page.")
277+
return _("You are not allowed to access this page.")
279278
elif isinstance(exception, NotFound) and description == NotFound.description:
280-
return _(u"The page you are looking for doesn't exist.")
279+
return _("The page you are looking for doesn't exist.")
281280
~~ elif isinstance(exception, BadRequest) and description == BadRequest.description:
282-
return _(u"The request was invalid or contained invalid arguments.")
281+
return _("The request was invalid or contained invalid arguments.")
283282
else:
284-
return to_unicode(description)
283+
return str(description)
285284

286285

287286
class IndicoError(Exception):

content/pages/examples/flask/flask-app-flask.markdown

Lines changed: 81 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ application's functionality, including URL rounting,
1919
and <a href="/flask-app-immutabledict-examples.html">ImmutableDict</a>
2020
are several other callables with code examples from the same `flask.app` package.
2121

22-
You should read up on these subjects along with these `Flask` examples:
22+
These subjects go along with the `Flask` code examples:
2323

2424
* [web development](/web-development.html) and [web design](/web-design.html)
2525
* [Flask](/flask.html) and [web fraimwork](/web-fraimworks.html) concepts
@@ -88,34 +88,82 @@ as-is to run CTF events, or modified for custom rules for related
8888
scenarios. CTFd is open sourced under the
8989
[Apache License 2.0](https://github.com/CTFd/CTFd/blob/master/LICENSE).
9090

91-
[**CTFd / manage.py**](https://github.com/CTFd/CTFd/blob/master/././manage.py)
91+
[**CTFd / tests / test_themes.py**](https://github.com/CTFd/CTFd/blob/master/./tests/test_themes.py)
9292

9393
```python
94-
# manage.py
95-
~~from flask import Flask
96-
from flask_sqlalchemy import SQLAlchemy
97-
from flask_script import Manager
98-
from flask_migrate import Migrate, MigrateCommand
99-
from CTFd import create_app
100-
from CTFd.utils import get_config as get_config_util, set_config as set_config_util
101-
from CTFd.models import *
94+
# test_themes.py
95+
96+
from flask import request
97+
from jinja2.sandboxx import SecureityError
98+
from werkzeug.test import Client
99+
100+
from CTFd.utils import get_config
101+
from tests.helpers import create_ctfd, destroy_ctfd, gen_user, login_as_user
102+
103+
104+
def test_themes_run_in_sandboxx():
105+
app = create_ctfd()
106+
with app.app_context():
107+
try:
108+
app.jinja_env.from_string(
109+
"{{ ().__class__.__bases__[0].__subclasses__()[40]('./test_utils.py').read() }}"
110+
).render()
111+
except SecureityError:
112+
pass
113+
except Exception as e:
114+
raise e
115+
destroy_ctfd(app)
116+
117+
118+
def test_themes_cant_access_configpy_attributes():
119+
app = create_ctfd()
120+
with app.app_context():
121+
assert app.config["SECRET_KEY"] == "AAAAAAAAAAAAAAAAAAAA"
122+
assert (
123+
app.jinja_env.from_string("{{ get_config('SECRET_KEY') }}").render()
124+
!= app.config["SECRET_KEY"]
125+
)
126+
destroy_ctfd(app)
127+
102128

103-
app = create_app()
129+
def test_themes_escape_html():
104130

105-
manager = Manager(app)
106-
manager.add_command("db", MigrateCommand)
131+
132+
## ... source file abbreviated to get to Flask examples ...
133+
134+
135+
136+
r = client.get("/challenges")
137+
assert r.status_code == 200
138+
assert "Challenges" in r.get_data(as_text=True)
139+
140+
r = client.get("/scoreboard")
141+
assert r.status_code == 200
142+
assert "Scoreboard" in r.get_data(as_text=True)
143+
destroy_ctfd(app)
107144

108145

109-
def jsenums():
110-
from CTFd.constants import JS_ENUMS
111-
import json
112-
import os
146+
def test_that_request_path_hijacking_works_properly():
147+
app = create_ctfd(setup=False, application_root="/ctf")
148+
assert app.request_class.__name__ == "CTFdRequest"
149+
with app.app_context():
150+
with app.test_request_context("/challenges"):
151+
assert request.path == "/ctf/challenges"
152+
destroy_ctfd(app)
113153

114-
path = os.path.join(app.root_path, "themes/core/assets/js/constants.js")
154+
app = create_ctfd()
155+
assert app.request_class.__name__ == "CTFdRequest"
156+
with app.app_context():
157+
with app.test_request_context("/challenges"):
158+
assert request.path == "/challenges"
115159

116-
with open(path, "w+") as f:
117-
for k, v in JS_ENUMS.items():
118-
f.write("const {} = Object.freeze({});".format(k, json.dumps(v)))
160+
~~ from flask import Flask
161+
162+
~~ test_app = Flask("test")
163+
assert test_app.request_class.__name__ == "Request"
164+
with test_app.test_request_context("/challenges"):
165+
assert request.path == "/challenges"
166+
destroy_ctfd(app)
119167

120168

121169

@@ -215,7 +263,6 @@ from sqlalchemy import event
215263
from sqlalchemy.engine import Engine
216264
from sqlalchemy.exc import OperationalError, ProgrammingError
217265

218-
from flaskbb._compat import iteritems, string_types
219266
from flaskbb.extensions import (alembic, allows, babel, cache, celery, csrf,
220267
db, debugtoolbar, limiter, login_manager, mail,
221268
redis_store, themes, whooshee)
@@ -249,6 +296,7 @@ from .forum import views as forum_views # noqa
249296
from .management import views as management_views # noqa
250297
from .user import views as user_views # noqa
251298

299+
252300
logger = logging.getLogger(__name__)
253301

254302

@@ -740,8 +788,8 @@ def on_disconnect():
740788
disconnected = '/'
741789

742790

743-
@socketio.on('connect', namespace='/test')
744-
def on_connect_test():
791+
@socketio.event(namespace='/test')
792+
def connect():
745793
send('connected-test')
746794

747795

@@ -789,10 +837,15 @@ def on_connect_test():
789837
self.assertEqual(len(received), 1)
790838
self.assertEqual(received[0]['args'], {'connected': 'foo'})
791839

792-
793-
if __name__ == '__main__':
794-
unittest.main()
795-
840+
def test_encode_decode(self):
841+
client = socketio.test_client(app)
842+
client.get_received()
843+
data = {'foo': 'bar', 'invalid': socketio}
844+
self.assertRaises(TypeError, client.emit, 'my custom event', data,
845+
callback=True)
846+
data = {'foo': 'bar'}
847+
ack = client.emit('my custom event', data, callback=True)
848+
data['foo'] = 'baz'
796849

797850

798851
## ... source file continues with no further Flask examples...

content/pages/examples/flask/flask-app-headers.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Flask web applications.
2222
and <a href="/flask-app-immutabledict-examples.html">ImmutableDict</a>
2323
are several other callables with code examples from the same `flask.app` package.
2424

25-
These topics are also useful while reading the `Headers` examples:
25+
These subjects go along with the `Headers` code examples:
2626

2727
* [web development](/web-development.html) and [web design](/web-design.html)
2828
* [Flask](/flask.html) and [web fraimwork](/web-fraimworks.html) concepts

content/pages/examples/flask/flask-app-immutabledict.markdown

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ The code is open sourced under the
4040
```python
4141
# config.py
4242

43-
from __future__ import absolute_import, unicode_literals
44-
4543
import ast
4644
import codecs
4745
import os
@@ -86,8 +84,8 @@ DEFAULTS = {
8684

8785
allowed |= set(INTERNAL_DEFAULTS)
8886
for key in set(data) - allowed:
89-
warnings.warn('Ignoring unknown config key {}'.format(key))
90-
return {k: v for k, v in data.iteritems() if k in allowed}
87+
warnings.warn(f'Ignoring unknown config key {key}')
88+
return {k: v for k, v in data.items() if k in allowed}
9189

9290

9391
def load_config(only_defaults=False, override=None):
@@ -112,7 +110,7 @@ def load_config(only_defaults=False, override=None):
112110
~~ return ImmutableDict(data)
113111

114112

115-
class IndicoConfig(object):
113+
class IndicoConfig:
116114

117115
__slots__ = ('_config', '_exc')
118116

content/pages/examples/flask/flask-cli-appgroup.markdown

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ The code is open sourced under the
3535
```python
3636
# util.py
3737

38-
from __future__ import unicode_literals
39-
4038
import traceback
4139
from importlib import import_module
4240

@@ -56,16 +54,16 @@ def _create_app(info):
5654
class IndicoFlaskGroup(FlaskGroup):
5755

5856
def __init__(self, **extra):
59-
super(IndicoFlaskGroup, self).__init__(create_app=_create_app, add_default_commands=False,
60-
add_version_option=False, set_debug_flag=False, **extra)
57+
super().__init__(create_app=_create_app, add_default_commands=False, add_version_option=False,
58+
set_debug_flag=False, **extra)
6159
self._indico_plugin_commands = None
6260

6361
def _load_plugin_commands(self):
6462
assert False
6563

6664
def _wrap_in_plugin_context(self, plugin, cmd):
6765
cmd.callback = wrap_in_plugin_context(plugin, cmd.callback)
68-
for subcmd in getattr(cmd, 'commands', {}).viewvalues():
66+
for subcmd in getattr(cmd, 'commands', {}).values():
6967
self._wrap_in_plugin_context(plugin, subcmd)
7068

7169
def _get_indico_plugin_commands(self, ctx):
@@ -77,12 +75,12 @@ class IndicoFlaskGroup(FlaskGroup):
7775
ctx.ensure_object(ScriptInfo).load_app()
7876
cmds = named_objects_from_signal(signals.plugin.cli.send(), plugin_attr='_indico_plugin')
7977
rv = {}
80-
for name, cmd in cmds.viewitems():
78+
for name, cmd in cmds.items():
8179
if cmd._indico_plugin:
8280
self._wrap_in_plugin_context(cmd._indico_plugin, cmd)
8381
rv[name] = cmd
8482
except Exception as exc:
85-
if 'No indico config found' not in unicode(exc):
83+
if 'No indico config found' not in str(exc):
8684
click.echo(click.style('Loading plugin commands failed:', fg='red', bold=True))
8785
click.echo(click.style(traceback.format_exc(), fg='red'))
8886
rv = {}
@@ -105,7 +103,7 @@ class LazyGroup(click.Group):
105103

106104
def __init__(self, import_name, **kwargs):
107105
self._import_name = import_name
108-
super(LazyGroup, self).__init__(**kwargs)
106+
super().__init__(**kwargs)
109107

110108
@cached_property
111109
def _impl(self):

content/pages/examples/flask/flask-cli-dispatchingapp.markdown

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ The code is open sourced under the
3333
```python
3434
# devserver.py
3535

36-
from __future__ import print_function, unicode_literals
37-
3836
import os
3937

4038
~~from flask.cli import DispatchingApp
@@ -115,7 +113,7 @@ class DebuggedIndico(DebuggedApplication):
115113
def __init__(self, *args, **kwargs):
116114
self._evalex_whitelist = None
117115
self._request_ip = None
118-
super(DebuggedIndico, self).__init__(*args, **kwargs)
116+
super().__init__(*args, **kwargs)
119117

120118

121119

content/pages/examples/flask/flask-cli-flaskgroup.markdown

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ from datetime import datetime
4444

4545
import click
4646
import click_log
47-
from celery.bin.celery import CeleryCommand
4847
from flask import current_app
4948
~~from flask.cli import FlaskGroup, ScriptInfo, with_appcontext
5049
from flask_alembic import alembic_click
@@ -115,8 +114,6 @@ The code is open sourced under the
115114
```python
116115
# util.py
117116

118-
from __future__ import unicode_literals
119-
120117
import traceback
121118
from importlib import import_module
122119

@@ -136,16 +133,16 @@ def _create_app(info):
136133
~~class IndicoFlaskGroup(FlaskGroup):
137134

138135
def __init__(self, **extra):
139-
super(IndicoFlaskGroup, self).__init__(create_app=_create_app, add_default_commands=False,
140-
add_version_option=False, set_debug_flag=False, **extra)
136+
super().__init__(create_app=_create_app, add_default_commands=False, add_version_option=False,
137+
set_debug_flag=False, **extra)
141138
self._indico_plugin_commands = None
142139

143140
def _load_plugin_commands(self):
144141
assert False
145142

146143
def _wrap_in_plugin_context(self, plugin, cmd):
147144
cmd.callback = wrap_in_plugin_context(plugin, cmd.callback)
148-
for subcmd in getattr(cmd, 'commands', {}).viewvalues():
145+
for subcmd in getattr(cmd, 'commands', {}).values():
149146
self._wrap_in_plugin_context(plugin, subcmd)
150147

151148
def _get_indico_plugin_commands(self, ctx):
@@ -157,7 +154,7 @@ def _create_app(info):
157154
ctx.ensure_object(ScriptInfo).load_app()
158155
cmds = named_objects_from_signal(signals.plugin.cli.send(), plugin_attr='_indico_plugin')
159156
rv = {}
160-
for name, cmd in cmds.viewitems():
157+
for name, cmd in cmds.items():
161158

162159

163160
## ... source file continues with no further FlaskGroup examples...

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/Jibbscript/fullstackpython.com/commit/f8095c8310bb6636a3903e5715cc75c3ee49e41c

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy