local

class trame.assets.local.LocalFileManager(base_path)

Bases: object

LocalFileManager provide convenient methods for handling local files

base64(key, file_path=None)

Store a base64 file content under the provided key name

Parameters:
  • key (str) – name for that content which can then be accessed by the [] or . notation

  • file_path (str) – A file or directory path

Returns:

Return the stored content

Return type:

str

url(key, file_path)

Store a url encoded file content under the provided key name

Parameters:
  • key (str) – name for that content which can then be accessed by the [] or . notation

  • file_path (str) – A file or directory path

Returns:

Return the stored content

Return type:

str

txt(key, file_path)

Store a file content (text) under the provided key name

Parameters:
  • key (str) – name for that content which can then be accessed by the [] or . notation

  • file_path (str) – A file or directory path

Returns:

Return the stored content

Return type:

str

property assets

Return the full set of assets as a dict

get_assets(*keys)

Return a filtered out dict using the provided set of keys

trame.assets.local.to_mime(file_path)

Return the mime type from a given path

Parameters:

file_path (str) – Path to analyse

Returns:

Mime type

Return type:

str

trame.assets.local.to_txt(full_path)

Return the text content of the file path

Parameters:

file_path (str) – Path to the file to read

Returns:

File content

Return type:

str

trame.assets.local.to_base64(full_path)

Return the base64 content of the file path

Parameters:

file_path (str) – Path to the file to read

Returns:

File content encoded in base64

Return type:

str

trame.assets.local.to_url(full_path)

Return the base64 encoded URL of the file path

Parameters:

file_path (str) – Path to the file to read

Returns:

Inlined bas64 encoded url (data:{mime};base64,{content})

Return type:

str