Enable Ruff RSE (#113695)
This commit is contained in:
parent
685553d17d
commit
82a60fe8ad
155 changed files with 325 additions and 324 deletions
|
@ -219,21 +219,21 @@ class LocalMediaView(http.HomeAssistantView):
|
|||
try:
|
||||
raise_if_invalid_path(location)
|
||||
except ValueError as err:
|
||||
raise web.HTTPBadRequest() from err
|
||||
raise web.HTTPBadRequest from err
|
||||
|
||||
if source_dir_id not in self.hass.config.media_dirs:
|
||||
raise web.HTTPNotFound()
|
||||
raise web.HTTPNotFound
|
||||
|
||||
media_path = self.source.async_full_path(source_dir_id, location)
|
||||
|
||||
# Check that the file exists
|
||||
if not media_path.is_file():
|
||||
raise web.HTTPNotFound()
|
||||
raise web.HTTPNotFound
|
||||
|
||||
# Check that it's a media file
|
||||
mime_type, _ = mimetypes.guess_type(str(media_path))
|
||||
if not mime_type or mime_type.split("/")[0] not in MEDIA_MIME_TYPES:
|
||||
raise web.HTTPNotFound()
|
||||
raise web.HTTPNotFound
|
||||
|
||||
return web.FileResponse(media_path)
|
||||
|
||||
|
@ -265,19 +265,19 @@ class UploadMediaView(http.HomeAssistantView):
|
|||
data = self.schema(dict(await request.post()))
|
||||
except vol.Invalid as err:
|
||||
LOGGER.error("Received invalid upload data: %s", err)
|
||||
raise web.HTTPBadRequest() from err
|
||||
raise web.HTTPBadRequest from err
|
||||
|
||||
try:
|
||||
item = MediaSourceItem.from_uri(self.hass, data["media_content_id"], None)
|
||||
except ValueError as err:
|
||||
LOGGER.error("Received invalid upload data: %s", err)
|
||||
raise web.HTTPBadRequest() from err
|
||||
raise web.HTTPBadRequest from err
|
||||
|
||||
try:
|
||||
source_dir_id, location = self.source.async_parse_identifier(item)
|
||||
except Unresolvable as err:
|
||||
LOGGER.error("Invalid local source ID")
|
||||
raise web.HTTPBadRequest() from err
|
||||
raise web.HTTPBadRequest from err
|
||||
|
||||
uploaded_file: FileField = data["file"]
|
||||
|
||||
|
@ -289,7 +289,7 @@ class UploadMediaView(http.HomeAssistantView):
|
|||
raise_if_invalid_filename(uploaded_file.filename)
|
||||
except ValueError as err:
|
||||
LOGGER.error("Invalid filename")
|
||||
raise web.HTTPBadRequest() from err
|
||||
raise web.HTTPBadRequest from err
|
||||
|
||||
try:
|
||||
await self.hass.async_add_executor_job(
|
||||
|
@ -299,7 +299,7 @@ class UploadMediaView(http.HomeAssistantView):
|
|||
)
|
||||
except ValueError as err:
|
||||
LOGGER.error("Moving upload failed: %s", err)
|
||||
raise web.HTTPBadRequest() from err
|
||||
raise web.HTTPBadRequest from err
|
||||
|
||||
return self.json(
|
||||
{"media_content_id": f"{data['media_content_id']}/{uploaded_file.filename}"}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue