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.
Files changed (61) hide show
  1. {yhttp-8.3.0 → yhttp-8.4.2}/PKG-INFO +1 -1
  2. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_locale.py +3 -3
  3. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_middleware.py +3 -3
  4. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_request.py +5 -1
  5. {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/application.py +4 -2
  6. {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/request.py +7 -0
  7. yhttp-8.4.2/yhttp/core/version.py +1 -0
  8. {yhttp-8.3.0 → yhttp-8.4.2}/yhttp.egg-info/PKG-INFO +1 -1
  9. yhttp-8.3.0/yhttp/core/version.py +0 -1
  10. {yhttp-8.3.0 → yhttp-8.4.2}/LICENSE +0 -0
  11. {yhttp-8.3.0 → yhttp-8.4.2}/README.md +0 -0
  12. {yhttp-8.3.0 → yhttp-8.4.2}/setup.cfg +0 -0
  13. {yhttp-8.3.0 → yhttp-8.4.2}/setup.py +0 -0
  14. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_application.py +0 -0
  15. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_applicationcli.py +0 -0
  16. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_builtincli_serve.py +0 -0
  17. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_builtincli_version.py +0 -0
  18. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_builtincli_yhttp_version.py +0 -0
  19. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_cookie.py +0 -0
  20. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_cookieset.py +0 -0
  21. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_extension.py +0 -0
  22. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_form.py +0 -0
  23. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_form_json.py +0 -0
  24. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_form_multipart.py +0 -0
  25. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_form_urlencoded.py +0 -0
  26. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_fswatcher.py +0 -0
  27. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_guard.py +0 -0
  28. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_guard_body.py +0 -0
  29. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_guard_contenttypes.py +0 -0
  30. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_guard_query.py +0 -0
  31. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_headerset.py +0 -0
  32. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_jsonencoding.py +0 -0
  33. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_multidict.py +0 -0
  34. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_multipart.py +0 -0
  35. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_querystring.py +0 -0
  36. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_responseheaders.py +0 -0
  37. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_rewrite.py +0 -0
  38. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_rewritecli.py +0 -0
  39. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_routing.py +0 -0
  40. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_static.py +0 -0
  41. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_statuses.py +0 -0
  42. {yhttp-8.3.0 → yhttp-8.4.2}/tests/test_statushandler.py +0 -0
  43. {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/__init__.py +0 -0
  44. {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/cli.py +0 -0
  45. {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/contenttypes.py +0 -0
  46. {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/cookieset.py +0 -0
  47. {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/fswatcher.py +0 -0
  48. {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/guard.py +0 -0
  49. {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/headerset.py +0 -0
  50. {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/main.py +0 -0
  51. {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/multidict.py +0 -0
  52. {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/multipart.py +0 -0
  53. {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/response.py +0 -0
  54. {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/rewrite.py +0 -0
  55. {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/static.py +0 -0
  56. {yhttp-8.3.0 → yhttp-8.4.2}/yhttp/core/statuses.py +0 -0
  57. {yhttp-8.3.0 → yhttp-8.4.2}/yhttp.egg-info/SOURCES.txt +0 -0
  58. {yhttp-8.3.0 → yhttp-8.4.2}/yhttp.egg-info/dependency_links.txt +0 -0
  59. {yhttp-8.3.0 → yhttp-8.4.2}/yhttp.egg-info/entry_points.txt +0 -0
  60. {yhttp-8.3.0 → yhttp-8.4.2}/yhttp.egg-info/requires.txt +0 -0
  61. {yhttp-8.3.0 → yhttp-8.4.2}/yhttp.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: yhttp
3
- Version: 8.3.0
3
+ Version: 8.4.2
4
4
  Summary: A very micro http framework.
5
5
  Home-page: http://github.com/yhttp/yhttp
6
6
  Author: Vahid Mardani
@@ -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.middlewares.append(middleware)
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.middlewares.append(middleware)
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.middlewares.append(middleware)
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={'Foo-Bar': 'baz'}):
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.middlewares = []
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.middlewares:
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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: yhttp
3
- Version: 8.3.0
3
+ Version: 8.4.2
4
4
  Summary: A very micro http framework.
5
5
  Home-page: http://github.com/yhttp/yhttp
6
6
  Author: Vahid Mardani
@@ -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