Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Remove redundant request_handler decorator
Browse files Browse the repository at this point in the history
This is needless complexity; we might as well use the wrapper directly.

Also rename wrap_request_handler->wrap_json_request_handler.
  • Loading branch information
richvdh committed May 10, 2018
1 parent 3589df2 commit 9d01771
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 38 deletions.
4 changes: 2 additions & 2 deletions synapse/http/additional_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from synapse.http.server import wrap_request_handler
from synapse.http.server import wrap_json_request_handler
from twisted.web.resource import Resource
from twisted.web.server import NOT_DONE_YET

Expand Down Expand Up @@ -50,6 +50,6 @@ def render(self, request):
self._async_render(request)
return NOT_DONE_YET

@wrap_request_handler
@wrap_json_request_handler
def _async_render(self, request):
return self._handler(request)
9 changes: 2 additions & 7 deletions synapse/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@
logger = logging.getLogger(__name__)


def request_handler():
"""Decorator for ``wrap_request_handler``"""
return wrap_request_handler


def wrap_request_handler(h):
def wrap_json_request_handler(h):
"""Wraps a request handler method with exception handling.
Also adds logging as per wrap_request_handler_with_logging.
Expand Down Expand Up @@ -213,7 +208,7 @@ def render(self, request):
self._async_render(request)
return server.NOT_DONE_YET

@request_handler()
@wrap_json_request_handler
@defer.inlineCallbacks
def _async_render(self, request):
""" This gets called from render() every time someone sends us a request.
Expand Down
8 changes: 5 additions & 3 deletions synapse/rest/key/v2/remote_key_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from synapse.http.server import request_handler, respond_with_json_bytes
from synapse.http.server import (
respond_with_json_bytes, wrap_json_request_handler,
)
from synapse.http.servlet import parse_integer, parse_json_object_from_request
from synapse.api.errors import SynapseError, Codes
from synapse.crypto.keyring import KeyLookupError
Expand Down Expand Up @@ -99,7 +101,7 @@ def render_GET(self, request):
self.async_render_GET(request)
return NOT_DONE_YET

@request_handler()
@wrap_json_request_handler
@defer.inlineCallbacks
def async_render_GET(self, request):
if len(request.postpath) == 1:
Expand All @@ -124,7 +126,7 @@ def render_POST(self, request):
self.async_render_POST(request)
return NOT_DONE_YET

@request_handler()
@wrap_json_request_handler
@defer.inlineCallbacks
def async_render_POST(self, request):
content = parse_json_object_from_request(request)
Expand Down
16 changes: 9 additions & 7 deletions synapse/rest/media/v1/download_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import synapse.http.servlet
import logging

from ._base import parse_media_id, respond_404
from twisted.internet import defer
from twisted.web.resource import Resource
from synapse.http.server import request_handler, set_cors_headers

from twisted.web.server import NOT_DONE_YET
from twisted.internet import defer

import logging
from synapse.http.server import (
set_cors_headers,
wrap_json_request_handler,
)
import synapse.http.servlet
from ._base import parse_media_id, respond_404

logger = logging.getLogger(__name__)

Expand All @@ -43,7 +45,7 @@ def render_GET(self, request):
self._async_render_GET(request)
return NOT_DONE_YET

@request_handler()
@wrap_json_request_handler
@defer.inlineCallbacks
def _async_render_GET(self, request):
set_cors_headers(request)
Expand Down
5 changes: 3 additions & 2 deletions synapse/rest/media/v1/preview_url_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@
from synapse.util.caches.expiringcache import ExpiringCache
from synapse.http.client import SpiderHttpClient
from synapse.http.server import (
request_handler, respond_with_json_bytes,
respond_with_json_bytes,
respond_with_json,
wrap_json_request_handler,
)
from synapse.util.async import ObservableDeferred
from synapse.util.stringutils import is_ascii
Expand Down Expand Up @@ -90,7 +91,7 @@ def render_GET(self, request):
self._async_render_GET(request)
return NOT_DONE_YET

@request_handler()
@wrap_json_request_handler
@defer.inlineCallbacks
def _async_render_GET(self, request):

Expand Down
23 changes: 13 additions & 10 deletions synapse/rest/media/v1/thumbnail_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@
# limitations under the License.


from ._base import (
parse_media_id, respond_404, respond_with_file, FileInfo,
respond_with_responder,
)
from twisted.web.resource import Resource
from synapse.http.servlet import parse_string, parse_integer
from synapse.http.server import request_handler, set_cors_headers
import logging

from twisted.web.server import NOT_DONE_YET
from twisted.internet import defer
from twisted.web.resource import Resource
from twisted.web.server import NOT_DONE_YET

import logging
from synapse.http.server import (
set_cors_headers,
wrap_json_request_handler,
)
from synapse.http.servlet import parse_integer, parse_string
from ._base import (
FileInfo, parse_media_id, respond_404, respond_with_file,
respond_with_responder,
)

logger = logging.getLogger(__name__)

Expand All @@ -48,7 +51,7 @@ def render_GET(self, request):
self._async_render_GET(request)
return NOT_DONE_YET

@request_handler()
@wrap_json_request_handler
@defer.inlineCallbacks
def _async_render_GET(self, request):
set_cors_headers(request)
Expand Down
15 changes: 8 additions & 7 deletions synapse/rest/media/v1/upload_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from synapse.http.server import respond_with_json, request_handler

from synapse.api.errors import SynapseError
import logging

from twisted.web.server import NOT_DONE_YET
from twisted.internet import defer

from twisted.web.resource import Resource
from twisted.web.server import NOT_DONE_YET

import logging
from synapse.api.errors import SynapseError
from synapse.http.server import (
respond_with_json,
wrap_json_request_handler,
)

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -51,7 +52,7 @@ def render_OPTIONS(self, request):
respond_with_json(request, 200, {}, send_cors=True)
return NOT_DONE_YET

@request_handler()
@wrap_json_request_handler
@defer.inlineCallbacks
def _async_render_POST(self, request):
requester = yield self.auth.get_user_by_req(request)
Expand Down

0 comments on commit 9d01771

Please sign in to comment.