chapisha/create/create.py
def _get_validated_bytes(self, 
                             source: [Path, bytes], 
                             base_type: Optional[List[Literal["cover", "work"]]] = None) -> bytes:
        """
        Validate a source file, and return a bytes version.

        Parameters
        ----------
        source: Path, bytes or base64 string
            Filename to open, base64 string, or bytes from an opened file
        base_type: Optional, str
            Must be one of "cover" or "work" for interpreting base64 mime type

        Raises
        ------
        PermissionError: if metadata not yet validated.
        FileNotFoundError: if the source is not valid.

        Returns
        -------
        bytes
        """
        if not self.metadata:
            e = "`set_metadata` before setting source document."
            raise PermissionError(e)
        if isinstance(source, Path):
            try:
                _c.check_source(source)
                with open(source, "rb") as f:
                    source = f.read()
            except FileNotFoundError:
                e = F"`{source}` is not a valid file source."
                raise FileNotFoundError(e)
        if isinstance(source, str) and base_type:
            # Base64 string, remove any provided mime type
            source_type = re.search(_c.DEFAULT_BASE64_TYPES[base_type], source)
            if source_type:
                source = source.replace(source_type.group(0), "")
            source = base64.b64decode(source)
        if not isinstance(source, bytes):
            e = F"File is not valid."
            raise FileNotFoundError(e)
        return source

        Validate a source file, and return a bytes version.

        Parameters
        ----------
        source: Path, bytes or base64 string
            Filename to open, base64 string, or bytes from an opened file
        base_type: Optional, str
            Must be one of "cover" or "work" for interpreting base64 mime type

        Raises
        ------
        PermissionError: if metadata not yet validated.
        FileNotFoundError: if the source is not valid.

        Returns
        -------
        bytes
        
Validate a source file, and return a bytes version.
Parameters

Path, bytes or base64 string
Filename to open, base64 string, or bytes from an opened file
base_type: Optional, str
Must be one of "cover" or "work" for interpreting base64 mime type

Raises

if metadata not yet validated.
FileNotFoundError: if the source is not valid.

Returns

bytes
Validate a source file and return a bytes version . Parameters Path bytes or base64 string Filename to open base64 string or bytes from an opened file base_type : Optional str Must be one of " cover " or " work " for interpreting base64 mime type Raises if metadata not yet validated . FileNotFoundError : if the source is not valid . Returns bytes
def _get_validated_bytes(self, 
                             source: [Path, bytes], 
                             base_type: Optional[List[Literal["cover", "work"]]] = None) -> bytes:
        if not self.metadata:
            e = "`set_metadata` before setting source document."
            raise PermissionError(e)
        if isinstance(source, Path):
            try:
                _c.check_source(source)
                with open(source, "rb") as f:
                    source = f.read()
            except FileNotFoundError:
                e = F"`{source}` is not a valid file source."
                raise FileNotFoundError(e)
        if isinstance(source, str) and base_type:
            source_type = re.search(_c.DEFAULT_BASE64_TYPES[base_type], source)
            if source_type:
                source = source.replace(source_type.group(0), "")
            source = base64.b64decode(source)
        if not isinstance(source, bytes):
            e = F"File is not valid."
            raise FileNotFoundError(e)
        return source
def _get_validated_bytes ( self , source : [ Path , bytes ] , base_type : Optional [ List [ Literal [ "cover" , "work" ] ] ] = None ) -> bytes : if not self . metadata : e = "`set_metadata` before setting source document." raise PermissionError ( e ) if isinstance ( source , Path ) : try : _c . check_source ( source ) with open ( source , "rb" ) as f : source = f . read ( ) except FileNotFoundError : e = F"`{source}` is not a valid file source." raise FileNotFoundError ( e ) if isinstance ( source , str ) and base_type : source_type = re . search ( _c . DEFAULT_BASE64_TYPES [ base_type ] , source ) if source_type : source = source . replace ( source_type . group ( 0 ) , "" ) source = base64 . b64decode ( source ) if not isinstance ( source , bytes ) : e = F"File is not valid." raise FileNotFoundError ( e ) return source
Validate a source file, and return a bytes version.
Validate a source file and return a bytes version .
"""
        Validate a source file, and return a bytes version.

        Parameters
        ----------
        source: Path, bytes or base64 string
            Filename to open, base64 string, or bytes from an opened file
        base_type: Optional, str
            Must be one of "cover" or "work" for interpreting base64 mime type

        Raises
        ------
        PermissionError: if metadata not yet validated.
        FileNotFoundError: if the source is not valid.

        Returns
        -------
        bytes
        """ # Base64 string, remove any provided mime type
self
source
[Path, bytes]
base_type
Optional[List[Literal["cover", "work"]]]