Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
gi0baro committed Mar 6, 2022
2 parents 8c4e07a + febe268 commit cd37084
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 30 deletions.
2 changes: 1 addition & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ You should now be using your virtualenv (notice how the prompt of your shell has
Now you can just enter the following command to get Emmett activated in your virtualenv:

```bash
$ pip install emmett
$ pip install emmett[crypto]
```

And now you are good to go.
Expand Down
23 changes: 12 additions & 11 deletions docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ Tutorial
========

So, you want to develop an application with Python and Emmett, huh? We should
start with an example.
start with an example.

We will create a simple microblog application, using Emmett and a database.
SQLite comes out of the box with Python, so you won't need to download anything
other than Emmett.

If you want the full source code in advance, check out the
[example source](https://github.com/emmett-framework/emmett/tree/master/examples/bloggy).
If you want the full source code in advance, check out the [example source](https://github.com/emmett-framework/emmett/tree/master/examples/bloggy).

Bloggy: a micro blog
--------------------
Expand Down Expand Up @@ -238,7 +237,7 @@ Moreover, to use the authorization module, we need to add a **session manager**
```python
from emmett.sessions import SessionManager
app.pipeline = [
SessionManager.cookies('GreatScott'),
SessionManager.cookies('GreatScott', encryption_mode='modern'),
db.pipe,
auth.pipe
]
Expand Down Expand Up @@ -269,12 +268,14 @@ async def one(pid):
post = Post.get(pid)
if not post:
abort(404)
# get comments and create a form
# get comments
comments = post.comments(orderby=~Comment.date)
form = await Comment.form(onvalidation=_validate_comment)
if form.accepted:
redirect(url('one', pid))
return {'post': post, 'comments': comments, 'form': form}
# and create a form for commenting if the user is logged in
if session.auth:
form = await Comment.form(onvalidation=_validate_comment)
if form.accepted:
redirect(url('one', pid))
return locals()
```

As you can see, the `one` function will show the post text, the comments users
Expand Down Expand Up @@ -312,7 +313,7 @@ The templates
-------------

We should create a template for every function we exposed. However, since the
Renoir templating system supports blocks and nesting, and we don't really want
Renoir templating system supports blocks and nesting, and we don't really want
to repeat ourselves when writing code, we will start with a main layout file
under *templates/layout.html*, and we will extend it with the functions' templates:

Expand Down Expand Up @@ -422,7 +423,7 @@ As you can see, the only difference from the template we wrote before to create
Some styling
------------

Now that everything works, it's time to add some style to bloggy.
Now that everything works, it's time to add some style to bloggy.
We just create a *style.css* file inside *static* folder and write down
something like this:

Expand Down
2 changes: 1 addition & 1 deletion emmett/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.4.3"
__version__ = "2.4.4"
10 changes: 10 additions & 0 deletions emmett/orm/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from __future__ import annotations

import copyreg
import operator
import re
import time
Expand Down Expand Up @@ -570,3 +571,12 @@ def typed_row_reference_from_record(record: Any, model: Any):
rv = refcls(id, model.table)
rv._refrecord = record
return rv


def _rowref_pickler(obj):
return obj._refmeta.caster, (obj.__pure__(), )


copyreg.pickle(RowReferenceInt, _rowref_pickler)
copyreg.pickle(RowReferenceStr, _rowref_pickler)
copyreg.pickle(RowReferenceMulti, _rowref_pickler)
18 changes: 7 additions & 11 deletions emmett/wrappers/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,13 @@ async def _load_params(self):
@cachedprop
def client(self) -> str:
g = _regex_client.search(self.headers.get('x-forwarded-for', ''))
client = (g.group() or '').split(',')[0] if g else None
if client in (None, '', 'unknown'):
g = _regex_client.search(self.headers.get('remote-addr', ''))
if g:
client = g.group()
elif self.host.startswith('['):
# IPv6
client = '::1'
else:
# IPv4
client = '127.0.0.1'
client = (
(g.group() or '').split(',')[0] if g else (
self._scope['client'][0] if self._scope['client'] else None
)
)
if client in (None, '', 'unknown', 'localhost'):
client = '::1' if self.host.startswith('[') else '127.0.0.1'
return client # type: ignore

async def push_promise(self, path: str):
Expand Down
14 changes: 9 additions & 5 deletions examples/bloggy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ def setup():

#: pipeline
app.pipeline = [
SessionManager.cookies('GreatScott'), db.pipe, auth.pipe
SessionManager.cookies('GreatScott', encryption_mode='modern'),
db.pipe,
auth.pipe
]


Expand All @@ -111,11 +113,13 @@ def _validate_comment(form):
post = Post.get(pid)
if not post:
abort(404)
# get comments and create a form for commenting
# get comments
comments = post.comments(orderby=~Comment.date)
form = await Comment.form(onvalidation=_validate_comment)
if form.accepted:
redirect(url('one', pid))
# and create a form for commenting if the user is logged in
if session.auth:
form = await Comment.form(onvalidation=_validate_comment)
if form.accepted:
redirect(url('one', pid))
return locals()


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "Emmett"
version = "2.4.3"
version = "2.4.4"
description = "The web framework for inventors"
authors = ["Giovanni Barillari <[email protected]>"]
license = "BSD-3-Clause"
Expand Down

0 comments on commit cd37084

Please sign in to comment.