pyechonext.utils package

Submodules

pyechonext.utils.exceptions module

exception pyechonext.utils.exceptions.InternationalizationNotFound(message: str, *args)[source]

Bases: pyEchoNextException

exception pyechonext.utils.exceptions.LocalizationNotFound(message: str, *args)[source]

Bases: pyEchoNextException

exception pyechonext.utils.exceptions.MethodNotAllow(message: str, *args)[source]

Bases: WebError

code = 405
exception pyechonext.utils.exceptions.RoutePathExistsError(message: str, *args)[source]

Bases: pyEchoNextException

exception pyechonext.utils.exceptions.StaticFileNotFoundError(message: str, *args)[source]

Bases: pyEchoNextException

exception pyechonext.utils.exceptions.TeapotError(message: str, *args)[source]

Bases: WebError

code = 418
exception pyechonext.utils.exceptions.TemplateNotFileError(message: str, *args)[source]

Bases: pyEchoNextException

exception pyechonext.utils.exceptions.URLNotFound(message: str, *args)[source]

Bases: WebError

code = 404
exception pyechonext.utils.exceptions.WebError(message: str, *args)[source]

Bases: pyEchoNextException

code = 400
get_explanation() str[source]

Gets the explanation.

Returns:

The explanation.

Return type:

str

exception pyechonext.utils.exceptions.pyEchoNextException(message: str, *args)[source]

Bases: Exception

Exception for signaling pyechonext errors.

__init__(message: str, *args)[source]
get_explanation() str[source]

Gets the explanation.

Returns:

The explanation.

Return type:

str

pyechonext.utils.patterns module

class pyechonext.utils.patterns.Singleton[source]

Bases: type

A metaclass that implements the Singleton pattern.

This metaclass ensures that a class has only one instance, and provides a global point of access to it.

pyechonext.utils.performance module

class pyechonext.utils.performance.InMemoryPerformanceCache(max_size: int = 1000, ttl: int = 60)[source]

Bases: PerformanceCacheBase

An in-memory PerformanceCache implementation.

This class stores PerformanceCached values in a dictionary, with a separate dictionary to track the access times of each entry. Entries are evicted from the PerformanceCache when the maximum size is reached or when the time-to-live (TTL) has expired.

__init__(max_size: int = 1000, ttl: int = 60) None[source]

Constructs a new instance.

Parameters:
  • max_size (int) – The maximum size

  • ttl (int) – The ttl

clear() None[source]

Clears the PerformanceCache

get(key: str) Any[source]

Gets the specified key.

Parameters:

key (str) – The key

Returns:

Any value

Return type:

Any

set(key: str, value: Any, timestamp: float) None[source]

Set new PerformanceCache element

Parameters:
  • key (str) – The new value

  • value (Any) – The value

  • timestamp (float) – The timestamp

class pyechonext.utils.performance.PerformanceCacheBase[source]

Bases: object

An abstract base class for implementing a PerformanceCache.

This class defines the basic interface for a PerformanceCache, including methods for getting, setting, and clearing PerformanceCache entries.

clear() None[source]

Clear all entries from the PerformanceCache.

get(key: str) Any[source]

Retrieve a value from the PerformanceCache.

Args: key (str): The key to retrieve.

Returns: Any: The PerformanceCached value, or None if the key is not found.

Parameters:

key (str) – The key

Returns:

value from PerformanceCache

Return type:

Any

set(key: str, value: Any, timestamp: float) None[source]

Store a value in the PerformanceCache.

Args: key (str): The key to store the value under. value (Any): The value to store. timestamp (float): The timestamp when the value was generated.

Parameters:
  • key (str) – The new value

  • value (Any) – The value

  • timestamp (float) – The timestamp

Returns:

{ description_of_the_return_value }

Return type:

None

class pyechonext.utils.performance.PerformanceCacheFactory[source]

Bases: object

A factory for creating different types of PerformanceCaches.

This class follows the Factory pattern to provide a consistent interface for creating PerformanceCache instances, without exposing the specific implementation details.

static create_performance_cache(performance_cache_type: Type[PerformanceCacheBase], *args, **kwargs) PerformanceCacheBase[source]

Create a new PerformanceCache instance of the specified type.

Args: performance_cache_type (Type[PerformanceCacheBase]): The type of PerformanceCache to create. *args: Positional arguments to pass to the PerformanceCache constructor. **kwargs: Keyword arguments to pass to the PerformanceCache constructor.

Returns: PerformanceCacheBase: A new instance of the specified PerformanceCache type.

Parameters:
  • performance_cache_type (Type[PerformanceCacheBase]) – The PerformanceCache type

  • args (list) – The arguments

  • kwargs (dictionary) – The keywords arguments

Returns:

The PerformanceCache base.

Return type:

PerformanceCacheBase

class pyechonext.utils.performance.SingletonPerformanceCache(*args, **kwargs)[source]

Bases: PerformanceCacheBase

A Singleton PerformanceCache that delegates to a specific PerformanceCache implementation.

This class follows the Singleton pattern to ensure that there is only one instance of the PerformanceCache in the application. It also uses the Factory pattern to create the underlying PerformanceCache implementation.

__init__(performance_cache_type: Type[PerformanceCacheBase], *args, **kwargs) None[source]

Constructs a new instance.

Parameters:
  • performance_cache_type (Type[PerformanceCacheBase]) – The PerformanceCache type

  • args (list) – The arguments

  • kwargs (dictionary) – The keywords arguments

clear() None[source]

Clear PerformanceCache

get(key: str) Any[source]

Gets the specified key.

Parameters:

key (str) – The key

Returns:

Any value

Return type:

Any

set(key: str, value: Any, timestamp: float) None[source]

Set new PerformanceCache element

Parameters:
  • key (str) – The new value

  • value (Any) – The value

  • timestamp (float) – The timestamp

pyechonext.utils.performance.performance_cached(performance_cache: ~pyechonext.utils.performance.SingletonPerformanceCache, key_func: ~typing.Callable[[~typing.Any, ~typing.Any], str] = <function <lambda>>) Callable[source]

A decorator that PerformanceCaches the results of a function or method.

This decorator uses the provided PerformanceCache instance to store and retrieve the results of the decorated function or method. The key_func argument allows you to customize how the PerformanceCache key is generated from the function/method arguments.

Args: PerformanceCache (SingletonPerformanceCache): The PerformanceCache instance to use for caching. key_func (Callable[[Any, Any], str]): A function that generates the PerformanceCache key from the function/method arguments.

Returns: Callable: A new function or method that PerformanceCaches the results.

Parameters:
  • performance_cache (SingletonPerformanceCache) – The PerformanceCache

  • key_func ((Callable[[Any, Any], str])) – The key function

Returns:

decorator

Return type:

Callable

pyechonext.utils.slugger module

class pyechonext.utils.slugger.SlugGenerator[source]

Bases: object

This class describes a slug generator.

generate_slug(phrase: str) str[source]

Generate slug

Parameters:

phrase (str) – phrase

Returns:

slug

Return type:

str

pyechonext.utils.stack module

class pyechonext.utils.stack.LIFOStack[source]

Bases: object

This class describes a LIFO-stack.

__init__()[source]

Constructs a new instance.

is_empty() bool[source]

Determines is empty

Returns:

true is empty, false otherwise

Return type:

bool

property items: Any

Get reversed stack items

Returns:

reversed stack items

Return type:

Any

peek() Any[source]

Peek the last item

Raises:

IndexError – stack is empty

Returns:

stack item

Return type:

Any

pop() Any[source]

Pop the object

Raises:

IndexError – stack if empty

Returns:

stack items with popped item

Return type:

Any

push(*args)[source]

Push item to stack items

property size: int

Get stack length

Returns:

length of stack items

Return type:

int

Module contents

class pyechonext.utils.CommandManager[source]

Bases: object

This class describes an command manager.

static change_directory(path: str)[source]

Change current directory

Parameters:

path (str) – The path

static run_command(command: str) int[source]

Run a command in the shell

Parameters:

command (str) – The command

Returns:

return code

Return type:

int

Raises:

RuntimeError – command failed

pyechonext.utils.create_directory(path: Path)[source]

Creates a directory if not exist.

Parameters:

path (Path) – The path

pyechonext.utils.get_current_datetime() str[source]

Gets the current datetime.

Returns:

The current datetime.

Return type:

str

pyechonext.utils.prepare_url(url: str) str[source]

Prepare URL (remove ending /)

Parameters:

url (str) – The url

Returns:

prepared url

Return type:

str

pyechonext.utils.print_header(msg_type: str, text: str)[source]

Prints a header.

Parameters:
  • msg_type (str) – The message type

  • text (str) – The text

pyechonext.utils.print_message(msg_type: str, text: str)[source]

Prints a message.

Parameters:
  • msg_type (str) – The message type

  • text (str) – The text

pyechonext.utils.print_step(msg_type: str, text: str)[source]

Prints a step.

Parameters:
  • msg_type (str) – The message type

  • text (str) – The text

pyechonext.utils.print_substep(msg_type: str, text: str)[source]

Prints a substep.

Parameters:
  • msg_type (str) – The message type

  • text (str) – The text

pyechonext.utils.validate_project_name(project_name: str)[source]

Validate project name

Parameters:

project_name (str) – The project name

Raises:

ValueError – invalid project name