mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-08-09 02:12:12 -04:00
Use the proper Request in type hints. (#9515)
This also pins the Twisted version in the mypy job for CI until proper type hints are fixed throughout Synapse.
This commit is contained in:
parent
e12077a78a
commit
a0bc9d387e
18 changed files with 38 additions and 31 deletions
|
@ -15,9 +15,9 @@
|
|||
# limitations under the License.
|
||||
|
||||
import logging
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import IO, TYPE_CHECKING
|
||||
|
||||
from twisted.web.http import Request
|
||||
from twisted.web.server import Request
|
||||
|
||||
from synapse.api.errors import Codes, SynapseError
|
||||
from synapse.http.server import DirectServeJsonResource, respond_with_json
|
||||
|
@ -79,7 +79,9 @@ class UploadResource(DirectServeJsonResource):
|
|||
headers = request.requestHeaders
|
||||
|
||||
if headers.hasHeader(b"Content-Type"):
|
||||
media_type = headers.getRawHeaders(b"Content-Type")[0].decode("ascii")
|
||||
content_type_headers = headers.getRawHeaders(b"Content-Type")
|
||||
assert content_type_headers # for mypy
|
||||
media_type = content_type_headers[0].decode("ascii")
|
||||
else:
|
||||
raise SynapseError(msg="Upload request missing 'Content-Type'", code=400)
|
||||
|
||||
|
@ -88,8 +90,9 @@ class UploadResource(DirectServeJsonResource):
|
|||
# TODO(markjh): parse content-dispostion
|
||||
|
||||
try:
|
||||
content = request.content # type: IO # type: ignore
|
||||
content_uri = await self.media_repo.create_content(
|
||||
media_type, upload_name, request.content, content_length, requester.user
|
||||
media_type, upload_name, content, content_length, requester.user
|
||||
)
|
||||
except SpamMediaException:
|
||||
# For uploading of media we want to respond with a 400, instead of
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue