123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- """Test states for upload-related tests."""
- from pathlib import Path
- from typing import ClassVar, List
- import reflex as rx
- from reflex.state import BaseState, State
- class UploadState(BaseState):
- """The base state for uploading a file."""
- async def handle_upload1(self, files: List[rx.UploadFile]):
- """Handle the upload of a file.
- Args:
- files: The uploaded files.
- """
- pass
- class BaseState(BaseState):
- """The test base state."""
- pass
- class SubUploadState(BaseState):
- """The test substate."""
- img: str
- async def handle_upload(self, files: List[rx.UploadFile]):
- """Handle the upload of a file.
- Args:
- files: The uploaded files.
- """
- pass
- class FileUploadState(State):
- """The base state for uploading a file."""
- img_list: List[str]
- _tmp_path: ClassVar[Path]
- async def handle_upload2(self, files):
- """Handle the upload of a file.
- Args:
- files: The uploaded files.
- """
- pass
- async def multi_handle_upload(self, files: List[rx.UploadFile]):
- """Handle the upload of a file.
- Args:
- files: The uploaded files.
- """
- for file in files:
- upload_data = await file.read()
- assert file.filename is not None
- outfile = self._tmp_path / file.filename
- # Save the file.
- outfile.write_bytes(upload_data)
- # Update the img var.
- self.img_list.append(file.filename)
- @rx.event(background=True)
- async def bg_upload(self, files: List[rx.UploadFile]):
- """Background task cannot be upload handler.
- Args:
- files: The uploaded files.
- """
- pass
- class FileStateBase1(State):
- """The base state for a child FileUploadState."""
- pass
- class ChildFileUploadState(FileStateBase1):
- """The child state for uploading a file."""
- img_list: List[str]
- _tmp_path: ClassVar[Path]
- async def handle_upload2(self, files):
- """Handle the upload of a file.
- Args:
- files: The uploaded files.
- """
- pass
- async def multi_handle_upload(self, files: List[rx.UploadFile]):
- """Handle the upload of a file.
- Args:
- files: The uploaded files.
- """
- for file in files:
- upload_data = await file.read()
- assert file.filename is not None
- outfile = self._tmp_path / file.filename
- # Save the file.
- outfile.write_bytes(upload_data)
- # Update the img var.
- self.img_list.append(file.filename)
- @rx.event(background=True)
- async def bg_upload(self, files: List[rx.UploadFile]):
- """Background task cannot be upload handler.
- Args:
- files: The uploaded files.
- """
- pass
- class FileStateBase2(FileStateBase1):
- """The parent state for a grandchild FileUploadState."""
- pass
- class GrandChildFileUploadState(FileStateBase2):
- """The child state for uploading a file."""
- img_list: List[str]
- _tmp_path: ClassVar[Path]
- async def handle_upload2(self, files):
- """Handle the upload of a file.
- Args:
- files: The uploaded files.
- """
- pass
- async def multi_handle_upload(self, files: List[rx.UploadFile]):
- """Handle the upload of a file.
- Args:
- files: The uploaded files.
- """
- for file in files:
- upload_data = await file.read()
- assert file.filename is not None
- outfile = self._tmp_path / file.filename
- # Save the file.
- outfile.write_bytes(upload_data)
- # Update the img var.
- self.img_list.append(file.filename)
- @rx.event(background=True)
- async def bg_upload(self, files: List[rx.UploadFile]):
- """Background task cannot be upload handler.
- Args:
- files: The uploaded files.
- """
- pass
|