yhttp 8.3.0__tar.gz → 8.4.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {yhttp-8.3.0 → yhttp-8.4.2}/PKG-INFO +1 -1
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_locale.py +3 -3
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_middleware.py +3 -3
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_request.py +5 -1
- {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/application.py +4 -2
- {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/request.py +7 -0
- yhttp-8.4.2/yhttp/core/version.py +1 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/yhttp.egg-info/PKG-INFO +1 -1
- yhttp-8.3.0/yhttp/core/version.py +0 -1
- {yhttp-8.3.0 → yhttp-8.4.2}/LICENSE +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/README.md +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/setup.cfg +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/setup.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_application.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_applicationcli.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_builtincli_serve.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_builtincli_version.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_builtincli_yhttp_version.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_cookie.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_cookieset.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_extension.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_form.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_form_json.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_form_multipart.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_form_urlencoded.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_fswatcher.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_guard.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_guard_body.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_guard_contenttypes.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_guard_query.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_headerset.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_jsonencoding.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_multidict.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_multipart.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_querystring.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_responseheaders.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_rewrite.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_rewritecli.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_routing.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_static.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_statuses.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_statushandler.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/__init__.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/cli.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/contenttypes.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/cookieset.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/fswatcher.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/guard.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/headerset.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/main.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/multidict.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/multipart.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/response.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/rewrite.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/static.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/statuses.py +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/yhttp.egg-info/SOURCES.txt +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/yhttp.egg-info/dependency_links.txt +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/yhttp.egg-info/entry_points.txt +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/yhttp.egg-info/requires.txt +0 -0
- {yhttp-8.3.0 → yhttp-8.4.2}/yhttp.egg-info/top_level.txt +0 -0
|
@@ -7,15 +7,15 @@ def test_locales(app, httpreq):
|
|
|
7
7
|
@app.route()
|
|
8
8
|
@json
|
|
9
9
|
def get(req):
|
|
10
|
-
return req.locales
|
|
10
|
+
return [req.locales, req.language]
|
|
11
11
|
|
|
12
12
|
with httpreq(headers={'Accept-Languages': 'en-US,*;q=0.5,fa;q=0.7'}):
|
|
13
13
|
assert status == 200
|
|
14
|
-
assert response.json == ['en-US', 'fa', '*']
|
|
14
|
+
assert response.json == [['en-US', 'fa', '*'], 'en']
|
|
15
15
|
|
|
16
16
|
when(headers={})
|
|
17
17
|
assert status == 200
|
|
18
|
-
assert response.json == ['*']
|
|
18
|
+
assert response.json == [['*'], None]
|
|
19
19
|
|
|
20
20
|
when(headers={'Accept-Languages': ';;'})
|
|
21
21
|
assert status == 400
|
|
@@ -7,7 +7,7 @@ def test_middleware_returnnone(app, httpreq):
|
|
|
7
7
|
def middleware(request):
|
|
8
8
|
request.query['baz'] = 'qux'
|
|
9
9
|
|
|
10
|
-
app.
|
|
10
|
+
app.request_middlewares.append(middleware)
|
|
11
11
|
|
|
12
12
|
@app.route()
|
|
13
13
|
def get(req):
|
|
@@ -22,7 +22,7 @@ def test_middleware_returnbody(app, httpreq):
|
|
|
22
22
|
def middleware(request):
|
|
23
23
|
return 'something else'
|
|
24
24
|
|
|
25
|
-
app.
|
|
25
|
+
app.request_middlewares.append(middleware)
|
|
26
26
|
|
|
27
27
|
@app.route()
|
|
28
28
|
def get(req):
|
|
@@ -37,7 +37,7 @@ def test_middleware_raise(app, httpreq):
|
|
|
37
37
|
def middleware(request):
|
|
38
38
|
raise statuses.found('/foo')
|
|
39
39
|
|
|
40
|
-
app.
|
|
40
|
+
app.request_middlewares.append(middleware)
|
|
41
41
|
|
|
42
42
|
@app.route()
|
|
43
43
|
def get(req):
|
|
@@ -8,6 +8,10 @@ def test_request(app, httpreq):
|
|
|
8
8
|
assert req.scheme == 'http'
|
|
9
9
|
assert req.headers.get('foo-bar') == 'baz'
|
|
10
10
|
assert req.contenttype is None
|
|
11
|
+
assert req.language == 'fa'
|
|
11
12
|
|
|
12
|
-
with httpreq('/foo?bar=baz', headers={
|
|
13
|
+
with httpreq('/foo?bar=baz', headers={
|
|
14
|
+
'Foo-Bar': 'baz',
|
|
15
|
+
'Accept-Languages': 'fa-IR'
|
|
16
|
+
}):
|
|
13
17
|
assert status == 200
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import inspect
|
|
2
|
+
import traceback
|
|
2
3
|
import functools
|
|
3
4
|
import re
|
|
4
5
|
import types
|
|
@@ -62,7 +63,7 @@ class BaseApplication:
|
|
|
62
63
|
self.events = {}
|
|
63
64
|
self.cliarguments = []
|
|
64
65
|
self.settings = pymlconf.Root(self._builtinsettings)
|
|
65
|
-
self.
|
|
66
|
+
self.request_middlewares = []
|
|
66
67
|
|
|
67
68
|
def when(self, func):
|
|
68
69
|
"""Return decorator to registers the ``func`` into :attr:`events` by
|
|
@@ -302,7 +303,7 @@ class Application(BaseApplication):
|
|
|
302
303
|
try:
|
|
303
304
|
|
|
304
305
|
# execute middlewares if any
|
|
305
|
-
for middleware in self.
|
|
306
|
+
for middleware in self.request_middlewares:
|
|
306
307
|
body = middleware(request)
|
|
307
308
|
if body:
|
|
308
309
|
break
|
|
@@ -322,6 +323,7 @@ class Application(BaseApplication):
|
|
|
322
323
|
except statuses.HTTPStatus as exc:
|
|
323
324
|
self.handlestatus(request, exc)
|
|
324
325
|
except Exception as exc:
|
|
326
|
+
traceback.print_exc()
|
|
325
327
|
self.handlestatus(request, statuses.internalservererror(
|
|
326
328
|
error=exc if self.settings.debug else None
|
|
327
329
|
))
|
|
@@ -68,6 +68,13 @@ class Request:
|
|
|
68
68
|
|
|
69
69
|
return [i[0] for i in sorted(langs, key=lambda x: x[1], reverse=True)]
|
|
70
70
|
|
|
71
|
+
@property
|
|
72
|
+
def language(self):
|
|
73
|
+
if self.locales == ['*']:
|
|
74
|
+
return None
|
|
75
|
+
|
|
76
|
+
return self.locales[0].split('-', 1)[0]
|
|
77
|
+
|
|
71
78
|
@cached_property
|
|
72
79
|
def verb(self):
|
|
73
80
|
"""HTTP method."""
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = '8.4.2'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = '8.3.0'
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|