Skip to content

Commit

Permalink
Merge pull request sanic-org#175 from Derrreks/master
Browse files Browse the repository at this point in the history
Improving comments
  • Loading branch information
seemethere authored Dec 3, 2016
2 parents 98b0867 + 70c56b7 commit d8a974b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
4 changes: 2 additions & 2 deletions sanic/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def json(self):
try:
self.parsed_json = json_loads(self.body)
except Exception:
log.exception("failed when parsing body as json")
log.exception("Failed when parsing body as json")

return self.parsed_json

Expand All @@ -89,7 +89,7 @@ def form(self):
self.parsed_form, self.parsed_files = (
parse_multipart_form(self.body, boundary))
except Exception:
log.exception("failed when parsing form")
log.exception("Failed when parsing form")

return self.parsed_form

Expand Down
12 changes: 9 additions & 3 deletions sanic/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ class Router:
@sanic.route('/my/url/<my_parameter>', methods=['GET', 'POST', ...])
def my_route(request, my_parameter):
do stuff...
or
@sanic.route('/my/url/<my_paramter>:type', methods['GET', 'POST', ...])
def my_route_with_type(request, my_parameter):
do stuff...
Parameters will be passed as keyword arguments to the request handling
function provided Parameters can also have a type by appending :type to
the <parameter>. If no type is provided, a string is expected. A regular
expression can also be passed in as the type
function. Provided parameters can also have a type by appending :type to
the <parameter>. Given parameter must be able to be type-casted to this.
If no type is provided, a string is expected. A regular expression can
also be passed in as the type. The argument given to the function will
always be a string, independent of the type.
"""
routes_static = None
routes_dynamic = None
Expand Down
4 changes: 2 additions & 2 deletions sanic/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ async def _collect_response(sanic, loop):
return request, response
except:
raise ValueError(
"request and response object expected, got ({})".format(
"Request and response object expected, got ({})".format(
results))
else:
try:
return results[0]
except:
raise ValueError(
"request object expected, got ({})".format(results))
"Request object expected, got ({})".format(results))
9 changes: 6 additions & 3 deletions sanic/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

class HTTPMethodView:
""" Simple class based implementation of view for the sanic.
You should implement methods(get, post, put, patch, delete) for the class
You should implement methods (get, post, put, patch, delete) for the class
to every HTTP method you want to support.
For example:
class DummyView(View):
Expand All @@ -14,9 +15,11 @@ def get(self, request, *args, **kwargs):
def put(self, request, *args, **kwargs):
return text('I am put method')
etc.
If someone try use not implemented method, there will be 405 response
If you need any url params just mention them in method definition like:
If someone tries to use a non-implemented method, there will be a
405 response.
If you need any url params just mention them in method definition:
class DummyView(View):
def get(self, request, my_param_here, *args, **kwargs):
Expand Down

0 comments on commit d8a974b

Please sign in to comment.