Commit Graph

386 Commits

Author SHA1 Message Date
Raphael Deem
0e1bb6ab04 add loop property 2017-02-11 16:28:35 -08:00
Angus Hollands
8b08a370c5 Remove todo 2017-02-11 14:39:32 +00:00
Angus Hollands
b5e50ecb75 Use app decorator instead of run arguments for before_start
Mirror listener of blueprints
2017-02-11 14:30:17 +00:00
Angus Hollands
e00c9d0ee0 Fix line length 2017-02-11 12:39:04 +00:00
Angus Hollands
be9c9f045a Cleanup middleware decorator 2017-02-11 12:27:25 +00:00
lixxu
fb419eaa36 fix bug: netloc always in url if SERVER_NAME defined in config even _external not true 2017-02-09 18:26:17 +08:00
lixxu
cf2a363e5e improve url_for to support multi values for one arg, add _anchor/_external/_scheme options 2017-02-09 16:44:23 +08:00
Eli Uriegas
579afe012b Fixes errors related to #378 2017-02-08 19:59:34 -06:00
Eli Uriegas
eb059183f7 Merge branch 'master' into master 2017-02-08 19:37:32 -06:00
Eli Uriegas
419156f7cc Merge pull request #397 from seemethere/increment_031
Increment to v0.3.1
2017-02-08 19:23:20 -06:00
Eli Uriegas
b7f7883fb7 Increment to v0.3.1 2017-02-08 19:22:51 -06:00
Eli Uriegas
a5a7490bca Merge pull request #379 from youknowone/exception
Let exception handler handle inherited exceptions
2017-02-08 19:20:42 -06:00
Eli Uriegas
6724d8131c Merge pull request #387 from subyraman/url-for-v3
Add `url_for` method for simple routes, blueprints, HTTPMethodView
2017-02-08 19:20:09 -06:00
Raphael Deem
a19bb15070 Merge pull request #389 from chenfengyuan/fix_run_async_demo
fix run_async demo
2017-02-07 14:58:48 -08:00
Eli Uriegas
2ee0147848 Merge pull request #386 from youknowone/sanic_endpoint_test
Fix sanic_endpoint_test working with redirects
2017-02-07 10:57:05 -06:00
Jeong YunWon
413c92c631 Let exception handler handle inherited exceptions
Original sanic exception handler only could handle exact matching
exceptions. New `lookup` method will provide ability to looking up
their ancestors without additional cost of performance.
2017-02-07 21:08:31 +09:00
Suby Raman
36d519026f reject unnamed handlers 2017-02-06 11:11:00 -05:00
Fengyuan Chen
aa54785918 fix always warning loop is passed issue 2017-02-06 11:11:00 -05:00
Jeong YunWon
a15ee3ad06 Fix sanic_endpoint_test working with redirects
Before fix, it raises error like:

```
tests/test_utils.py F

================================= FAILURES =================================
______________________________ test_redirect _______________________________

app = <sanic.sanic.Sanic object at 0x1045fda20>, method = 'get', uri = '/1', gather_request = True, debug = False
server_kwargs = {}, request_args = (), request_kwargs = {}
_collect_request = <function sanic_endpoint_test.<locals>._collect_request at 0x1045ec950>
_collect_response = <function sanic_endpoint_test.<locals>._collect_response at 0x1045ec7b8>

    def sanic_endpoint_test(app, method='get', uri='/', gather_request=True,
                            debug=False, server_kwargs={},
                            *request_args, **request_kwargs):
        results = []
        exceptions = []

        if gather_request:
            def _collect_request(request):
                results.append(request)
            app.request_middleware.appendleft(_collect_request)

        async def _collect_response(sanic, loop):
            try:
                response = await local_request(method, uri, *request_args,
                                               **request_kwargs)
                results.append(response)
            except Exception as e:
                exceptions.append(e)
            app.stop()

        app.run(host=HOST, debug=debug, port=PORT,
                after_start=_collect_response, **server_kwargs)

        if exceptions:
            raise ValueError("Exception during request: {}".format(exceptions))

        if gather_request:
            try:
>               request, response = results
E               ValueError: too many values to unpack (expected 2)

sanic/utils.py:47: ValueError

During handling of the above exception, another exception occurred:

utils_app = <sanic.sanic.Sanic object at 0x1045fda20>

    def test_redirect(utils_app):
        """Test sanic_endpoint_test is working for redirection"""
>       request, response = sanic_endpoint_test(utils_app, uri='/1')

tests/test_utils.py:33:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

app = <sanic.sanic.Sanic object at 0x1045fda20>, method = 'get', uri = '/1', gather_request = True, debug = False
server_kwargs = {}, request_args = (), request_kwargs = {}
_collect_request = <function sanic_endpoint_test.<locals>._collect_request at 0x1045ec950>
_collect_response = <function sanic_endpoint_test.<locals>._collect_response at 0x1045ec7b8>

    def sanic_endpoint_test(app, method='get', uri='/', gather_request=True,
                            debug=False, server_kwargs={},
                            *request_args, **request_kwargs):
        results = []
        exceptions = []

        if gather_request:
            def _collect_request(request):
                results.append(request)
            app.request_middleware.appendleft(_collect_request)

        async def _collect_response(sanic, loop):
            try:
                response = await local_request(method, uri, *request_args,
                                               **request_kwargs)
                results.append(response)
            except Exception as e:
                exceptions.append(e)
            app.stop()

        app.run(host=HOST, debug=debug, port=PORT,
                after_start=_collect_response, **server_kwargs)

        if exceptions:
            raise ValueError("Exception during request: {}".format(exceptions))

        if gather_request:
            try:
                request, response = results
                return request, response
            except:
                raise ValueError(
                    "Request and response object expected, got ({})".format(
>                       results))
E               ValueError: Request and response object expected, got ([{}, {}, {}, <ClientResponse(http://127.0.0.1:42101/3) [200 OK]>
E               <CIMultiDictProxy('Content-Type': 'text/plain; charset=utf-8', 'Content-Length': '2', 'Connection': 'keep-alive', 'Keep-Alive': 'timeout=1')>
E               ])

sanic/utils.py:52: ValueError
```
2017-02-05 13:57:04 +09:00
Fengyuan Chen
29680cb515 fix always warning loop is passed issue 2017-02-04 16:09:09 +08:00
Fengyuan Chen
884749f345 fix run_async demo 2017-02-04 15:27:46 +08:00
Suby Raman
5632d073be update docs 2017-02-02 13:00:15 -05:00
Suby Raman
f9056099f9 all works 2017-02-02 12:52:48 -05:00
Suby Raman
7c09ec29f7 rebase 2017-02-02 12:21:14 -05:00
Eli Uriegas
6f0b09509e Merge pull request #213 from sfstpala/master
Make it possible to disable the logo by subclassing Config
2017-02-01 23:07:52 -06:00
Raphael Deem
b29f648148 typo: async_run -> run_async 2017-01-31 12:46:02 -08:00
Eli Uriegas
487e3352e4 Revert "fix async run, add tests"
This reverts commit 41da793b5a.
2017-01-31 07:30:17 -06:00
Eli Uriegas
17a92a58b2 Merge pull request #369 from r0fls/fix-async-run
fix async run, add tests
2017-01-30 22:21:25 -06:00
Kyle Blöm
d193a1eb70 Added the tests, code formatting changes, and the Range Request feature. 2017-01-30 17:04:51 -08:00
Eli Uriegas
6d18fb6bae Merge pull request #363 from r0fls/run-helper
Run helper
2017-01-30 05:51:50 -06:00
Raphael Deem
41da793b5a fix async run, add tests 2017-01-29 23:47:47 -08:00
Channel Cat
0ef39f35ae Added route shorthands to blueprints 2017-01-29 23:20:38 -08:00
Channel Cat
4c80cd185f Fix flake8 2017-01-29 17:44:46 -08:00
Channel Cat
629524af04 Restructured blueprint class
Blueprints currently queue functions to be called, which are simple, yet
hard to inspect.  These changes allow tools to be built that analyze
blueprints more easily.
2017-01-29 17:39:55 -08:00
Raphael Deem
82d1d30a41 review updates 2017-01-29 14:01:00 -08:00
Raphael Deem
10dbb9186d combine logic from create_server() and run() 2017-01-29 13:36:13 -08:00
Eli Uriegas
a547798b08 Merge pull request #360 from seemethere/fix_route_overloading_for_dynamic_routes
Fixes route overloading for dynamic routes
2017-01-29 15:35:13 -06:00
Eli Uriegas
f56c5e3a45 Merge pull request #199 from Tim-Erwin/improved_config
added methods to load config from a file
2017-01-29 15:27:34 -06:00
Eli Uriegas
0a5fa72099 Add logic to make dynamic route merging work
This is by no means the final solution but it's a start in the right
direction. Eventually what needs to happen is we need to reduce the
complexity of the routing. CompsitionView can probably be removed later
on in favor of better Route objects. Also in the next version of sanic
we need to move merge_route and add_parameter out of the add_route logic
and just have them as standalone methods.

The tests should cover everything that we need so that if any changes
are made we can identify regression.
2017-01-29 15:16:07 -06:00
Raphael Deem
753d2da6db fix async run 2017-01-28 15:47:29 -08:00
Eli Uriegas
d3344da9c5 Add a pesky newline 2017-01-27 22:15:34 -06:00
Eli Uriegas
dea8e16f49 Force method to lower 2017-01-27 22:07:31 -06:00
Eli Uriegas
13803bdb30 Update for HTTPMethodView compatibility 2017-01-27 22:05:46 -06:00
Eli Uriegas
41c52487ee Fixes route overloading for dynamic routes
Addresses #353, now dynamic routes work alongside our newly minted
overloaded routes! Also fixed an unintended side effect where methods
were still being passed in as None for `Sanic.add_route`.
2017-01-27 21:00:33 -06:00
Raphael Deem
0eb779185d fix deprecation warnings 2017-01-27 18:09:19 -08:00
Eli Uriegas
cfc32d940a Increment version to 0.3.0 2017-01-27 19:36:03 -06:00
Eli Uriegas
59242df7d6 Move serve_multiple, fix tests (#357)
* Move serve_multiple, remove stop_events, fix tests

Moves serve_multiple out of the app, removes stop_event (adds a
deprecation warning, but it also wasn't doing anything) fixes
multiprocessing tests so that they don't freeze pytest's runner.

Other notes:

Also moves around some imports so that they are better optimized as
well.

* Re-add in stop_event, maybe it wasn't so bad!

* Get rid of unused warnings import
2017-01-27 19:34:21 -06:00
Eli Uriegas
fad9fbca6f Merge pull request #335 from r0fls/remove-loop
remove loop as argument and update examples
2017-01-27 19:25:09 -06:00
Jordan Pittier
fa36dcbe09 Use `isinstance( instead of issubclass(type(`
When we already have an `instance` it's less typing and faster to
use `isinstance`.
2017-01-27 11:11:29 +01:00
Raphael Deem
c72bcc136c add semaphore concurrency limit example 2017-01-26 17:43:54 -08:00
Raphael Deem
d52f5f0b09 remove loop as argument and update examples 2017-01-26 17:38:46 -08:00
Raphael Deem
2774414f9e Merge pull request #350 from r0fls/deprecate-loop
add deprecate loop message
2017-01-26 15:24:43 -08:00
Raphael Deem
965fbc917d use string formatting in start message 2017-01-26 15:11:53 -08:00
Raphael Deem
2a1b63c93c add deprecate loop message 2017-01-26 15:07:42 -08:00
Eli Uriegas
d1c4f3172f Merge pull request #348 from r0fls/275
add async run
2017-01-26 10:37:52 -06:00
Raphael Deem
14697c7ea9 review changes 2017-01-26 08:36:00 -08:00
Raphael Deem
54ca8c787b add async run 2017-01-25 22:47:18 -08:00
Channel Cat
88c3bffe20 Merge pull request #342 from channelcat/fix-slow-upload
Fix slow upload
2017-01-25 22:04:48 -08:00
Channel Cat
fd118a41fd Only use request.body 2017-01-25 21:56:49 -08:00
Raphael Deem
a162f2ce34 Merge branch 'master' into cookie-usability 2017-01-25 21:24:30 -08:00
Raphael Deem
3c355f19eb false cookie attributes should not be set 2017-01-25 16:47:14 -08:00
Raphael Deem
4efcb6d5ad fix before/after event docstrings 2017-01-25 16:25:16 -08:00
Channel Cat
d0a121ad06 Added del cookie and default path 2017-01-25 01:53:39 -08:00
Channel Cat
85a28d3c30 Fix slow upload 2017-01-25 01:19:21 -08:00
Tim Mundt
5bba3388a0 Merge branch 'master' into improved_config 2017-01-25 09:36:21 +01:00
Raphael Deem
28f7abd1f8 set error handler debug from run debug arg 2017-01-24 17:24:06 -08:00
Raphael Deem
afe390d407 Merge pull request #253 from dutradda/add_register_sys_signals_flag
add a flag to skip SIGINT and SIGTERM signals registration
2017-01-21 23:09:12 -08:00
ctlaltdefeat
592ee5f839 fixed line length to satisfy travis 2017-01-21 23:02:02 +02:00
ctlaltdefeat
a811c84e99 allowed passing arguments to json response encoder 2017-01-21 22:40:34 +02:00
Eli Uriegas
214162adf0 Merge branch 'master' into add_register_sys_signals_flag 2017-01-21 10:25:57 -06:00
Raphael Deem
28396c8620 Merge pull request #327 from awiddersheim/logging-override
Make it easier to override logging
2017-01-20 16:23:03 -08:00
Andrew Widdersheim
72fba62e09 Make it easier to override logging
Take influence from how Werkzeug configures logging by only configuring
a handler if no root handlers were previously configured by the end
user.
2017-01-20 18:26:55 -05:00
Eli Uriegas
e5cbf25cbd Merge pull request #325 from seemethere/add_key_error
Simplify RequestParameters
2017-01-20 15:27:00 -06:00
Eli Uriegas
7780a8c187 Merge pull request #320 from r0fls/method-decorators
add method shorthands
2017-01-20 14:38:34 -06:00
Eli Uriegas
a7cd4ccd09 Simplify RequestParameters
Simplifies request parameters, it defined a bit more than it had too,
added some docstrings and made the code simpler as well. Should now
raise a KeyError on __getitem__ as @amsb had noted on commit 9dd954b
2017-01-20 14:31:24 -06:00
Raphael Deem
96424b6b0a add method shorthands 2017-01-20 00:07:22 -08:00
Eli Uriegas
bef34d66f5 Merge pull request #314 from seemethere/make_closed_transport_handling_more_robust
Add exception handling for closed transports
2017-01-19 21:31:30 -06:00
Eli Uriegas
c6049be688 Merge pull request #316 from youknowone/route-get
For function decorators, ['GET'] is the default methods
2017-01-19 21:31:06 -06:00
Eli Uriegas
ed4752bbc0 Move transport close to finally statment 2017-01-19 16:35:48 -06:00
Cadel Watson
7c4ffa8866 Merge branch 'master' into sphinx-docs 2017-01-20 09:30:42 +11:00
Eli Uriegas
a79f073077 Merge pull request #228 from seanpar203/issue_41
Adding more docstrings
2017-01-19 16:18:28 -06:00
Raphael Deem
d2217b5c5f Merge branch 'master' into ssl 2017-01-19 11:23:21 -08:00
Jeong YunWon
0a160c4a0b For function decorators, ['GET'] is the default methods 2017-01-19 23:56:51 +09:00
James Michael DuPont
ba60659894 untie 2017-01-19 04:04:16 -05:00
zkanda
cc43ee3b3d Always log of there's an exception occured. 2017-01-19 16:03:12 +08:00
Eli Uriegas
5a7b70c054 Merge pull request #313 from r0fls/logging-var
remove logger from run
2017-01-18 23:50:07 -06:00
Eli Uriegas
e9bfa30c1d Add exception handling for closed transports
Adds handling for closed transports in the server for `write_response`
as well as `write_error`, letting it all flow to `bail_out` seemed to be
a little light handed in terms of telling the logs where the
error actually occured.

Handling to fix the infinite `write_error` loop is still there and those
exceptions will get reported on in the debug logs.
2017-01-18 23:46:22 -06:00
Raphael Deem
bb83a25a52 remove logger from run 2017-01-18 21:45:30 -08:00
Raphael Deem
2c1ff5bf5d allow using a list of hosts on a route 2017-01-18 19:41:32 -08:00
Jeong YunWon
11f3c79a77 Feature: Routing overload
When user specifies HTTP methods to function handlers, it automatically
will be overloaded unless they duplicate.

Example:

    # This is a new route. It works as before.
    @app.route('/overload', methods=['GET'])
    async def handler1(request):
        return text('OK1')

    # This is the exiting route but a new method. They are merged and
    # work as combined. The route will serve all of GET, POST and PUT.
    @app.route('/overload', methods=['POST', 'PUT'])
    async def handler2(request):
        return text('OK2')

    # This is the existing route and PUT method is the duplicated method.
    # It raises RouteExists.
    @app.route('/overload', methods=['PUT', 'DELETE'])
    async def handler3(request):
	return text('Duplicated')
2017-01-19 07:12:45 +09:00
Cadel Watson
9d4b104d2d Merge branch 'master' into sphinx-docs 2017-01-19 08:48:54 +11:00
Raphael Deem
9102a9cd6e Merge branch 'master' into ssl 2017-01-17 18:09:33 -08:00
Eli Uriegas
573d1da0ef Fixes write_error loop from bail_out function
Fixes stack-overflow found in #307
2017-01-17 18:28:22 -06:00
Raphael Deem
ba1e006585 update logging placement 2017-01-17 15:49:17 -08:00
Eli Uriegas
9108a4c69f Merge pull request #291 from subyraman/master
Add rich HTML traceback in debug mode, add HTML 500 page in prod
2017-01-17 15:47:37 -06:00
Guilherme Polo
5903dd2939 cannot use the new .ip without updating __slots__ 2017-01-17 02:58:45 -02:00
Eli Uriegas
55b39a3f15 Merge pull request #301 from r0fls/cache-remote-ip
cache the remote IP property
2017-01-16 20:07:53 -06:00
Raphael Deem
9bc69f7de9 use hasattr 2017-01-16 17:35:08 -08:00
Channel Cat
2aa380c5a3 Merge pull request #302 from channelcat/request-headers-ci
Trimmed down features of CIMultiDict
2017-01-16 17:08:12 -08:00
Channel Cat
638fbcb619 Encoding needs a default 2017-01-16 17:03:55 -08:00