Skip to content

Commit

Permalink
refactor: bytesio .seek(0) & .read() methods with .getvalue() (#1001)
Browse files Browse the repository at this point in the history
* refactor: replace bytesio .seek(0) with .getvalue()

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
spwoodcock and pre-commit-ci[bot] authored Nov 22, 2023
1 parent 0d9581a commit 496dcbc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
1 change: 0 additions & 1 deletion src/backend/app/central/central_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#
from enum import Enum

from loguru import logger as log
from pydantic import BaseModel


Expand Down
2 changes: 1 addition & 1 deletion src/backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import logging
import sys
from typing import Optional
from contextlib import asynccontextmanager
from typing import Optional

import sentry_sdk
from fastapi import FastAPI, Request
Expand Down
33 changes: 11 additions & 22 deletions src/backend/app/projects/project_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,7 @@ async def upload_multi_project_boundary(
"Uploading project boundary multipolygon for " f"project ID: {project_id}"
)
# read entire file
await project_geojson.seek(0)
content = await project_geojson.read()
content = await project_geojson.getvalue()
boundary = json.loads(content)

# Validatiing Coordinate Reference System
Expand Down Expand Up @@ -414,8 +413,7 @@ async def task_split(
"""
# read entire file
await project_geojson.seek(0)
content = await project_geojson.read()
content = await project_geojson.getvalue()
boundary = json.loads(content)

# Validatiing Coordinate Reference System
Expand Down Expand Up @@ -454,8 +452,7 @@ async def upload_project_boundary(
raise HTTPException(status_code=400, detail="Provide a valid .geojson file")

# read entire file
await upload.seek(0)
content = await upload.read()
content = await upload.getvalue()
boundary = json.loads(content)

# Validatiing Coordinate Reference System
Expand Down Expand Up @@ -493,8 +490,7 @@ async def edit_project_boundary(
raise HTTPException(status_code=400, detail="Provide a valid .geojson file")

# read entire file
await upload.seek(0)
content = await upload.read()
content = await upload.getvalue()
boundary = json.loads(content)

# Validatiing Coordinate Reference System
Expand Down Expand Up @@ -532,8 +528,7 @@ async def validate_form(
if file_ext not in allowed_extensions:
raise HTTPException(status_code=400, detail="Provide a valid .xls file")

await form.seek(0)
contents = await form.read()
contents = await form.getvalue()
return await central_crud.test_form_validity(contents, file_ext[1:])


Expand All @@ -547,8 +542,7 @@ async def generate_files(
data_extracts: Optional[UploadFile] = File(None),
db: Session = Depends(database.get_db),
):
"""
Generate additional content for the project to function.
"""Generate additional content for the project to function.
QR codes,
Expand Down Expand Up @@ -590,8 +584,7 @@ async def generate_files(
if file_ext not in allowed_extensions:
raise HTTPException(status_code=400, detail="Provide a valid .xls file")
xform_title = file_name[0]
await xls_form_upload.seek(0)
custom_xls_form = await xls_form_upload.read()
custom_xls_form = await xls_form_upload.getvalue()

project.form_xls = custom_xls_form

Expand All @@ -602,8 +595,7 @@ async def generate_files(
raise HTTPException(
status_code=400, detail="Provide a valid .yaml config file"
)
await xls_form_config_file.seek(0)
config_file_contents = await xls_form_config_file.read()
config_file_contents = await xls_form_config_file.getvalue()
project.form_config_file = config_file_contents

db.commit()
Expand Down Expand Up @@ -655,8 +647,7 @@ async def get_data_extracts(
):
try:
# read entire file
await aoi.seek(0)
aoi_content = await aoi.read()
aoi_content = await aoi.getvalue()
boundary = json.loads(aoi_content)

# Validatiing Coordinate Reference System
Expand Down Expand Up @@ -819,8 +810,7 @@ async def preview_tasks(
raise HTTPException(status_code=400, detail="Provide a valid .geojson file")

# read entire file
await project_geojson.seek(0)
content = await project_geojson.read()
content = await project_geojson.getvalue()
boundary = json.loads(content)

# Validatiing Coordinate Reference System
Expand Down Expand Up @@ -1187,8 +1177,7 @@ async def generate_files_janakpur(
if file_ext not in allowed_extensions:
raise HTTPException(status_code=400, detail="Provide a valid .xls file")
xform_title = file_name[0]
await form.seek(0)
contents = await form.read()
contents = await form.getvalue()
project.form_xls = contents
db.commit()

Expand Down

0 comments on commit 496dcbc

Please sign in to comment.