booklet.utils package#

Submodules#

booklet.utils.color module#

booklet.utils.conversion module#

booklet.utils.fonts module#

booklet.utils.images module#

booklet.utils.matrix module#

booklet.utils.matrix.concatenate(matrix: list[list]) list#
booklet.utils.matrix.flip(matrix: list) list#
booklet.utils.matrix.reshape(list1d: list, shape) list[list]#
booklet.utils.matrix.split_list(list1d: list, n: int, mode='l') list#
booklet.utils.matrix.transpose(list2d: list) list#

booklet.utils.misc module#

class booklet.utils.misc.NamedTempFile(tempfile, mode=None, delete: bool = False)#

Bases: object

NamedTemporary file IO warpper for reading and writing

close()#
property closed#
fileno()#
flush()#
classmethod from_temp_setting(*args, **kwargs)#
isatty()#
read(*args, **kwargs)#
readable()#
readline(*args, **kwargs)#
readlines(*args, **kwargs)#
seek(*args, **kwargs)#
tell()#
truncate()#
write(*args, **kwargs)#
writeable()#
writeline(*args, **kwargs)#
writelines(*args, **kwargs)#
booklet.utils.misc.get_page_range(page_range_string: str) list#

Calculate exact range of pages for given formatted string.

  • All pages connected with comma, ‘,’.

  • Each pages can be a single page number.

  • Multiple consequence pages can be represented with start page, hypen, and end page.

Example:

input: 1-5, 15, 19, 40-46 return: 1,2,3,4,5,15,19,40,41,42,43,44,45,46

Parameters

page_range_string (str) – Formatted string represent page range.

booklet.utils.misc.open_url(url: str) NoReturn#

Open the website of the given url with system default browser.

Parameters

url (str) – URL

Returns

Nothing

Return type

NoReturn

booklet.utils.misc.resources_path(rel_path: str, dir: str) str#

Get absolute resource path to use temper directory.

Parameters
  • rel_path (str) – Relative path that used inside of codes

  • dir (str) – Subdirectory in project directory

Returns

Absolute path in execution environment for resource

Return type

str

booklet.utils.permutation module#

class booklet.utils.permutation.Permutation(n: int, plist: list)#

Bases: object

Permutation implementation

classmethod from_lists(lists: Union[list[int], list[list[int]]]) Permutation#

Generate booklet.permutation.Permutation from lists

Parameters

lists (Union[list[int], list[list[int]]]) – list of integers or list of integer lists. In other words, 1-dim and 2-dim integer arrays are supported

Returns

Permutation defined from all element of the given list. Order is preserved and for 2-dim array, it follows row-major order.

Return type

Permutation

classmethod get_permutations(n: int, per=False) Union[list[booklet.utils.permutation.Permutation], list[list[int]]]#

Return all permuation of length \(n\). Based on standard permutation routine in itertools.

Parameters
  • n (int) – Length of permuatation. Bigger than 0

  • per (bool, optional) – Return type determinator. True, booklet.permutation.Permutation , False, list. Default = False.

Returns

list of length \(n\) permutations.

Return type

Union[list[Permutation], list[list[int]]]

index_mul(other: Permutation, oper=False) Union[list, Permutation]#
index_mul_partial(sub_permutation: Permutation, oper: bool = False) Union[list, Permutation]#
inverse() Permutation#
notation_cauchy() str#
notation_cyclic(canonical: bool = False, string: bool = False, sep: str = '') Union[str, list]#
permute_to_list_index(li: list) list#
classmethod reverse_permutation(n: int) Permutation#

Do not confuse with inverse permutation. It only reverses order of 1 step increasing permutation. For example, reverse_permutation(3) == Permutation(3,[3, 2, 1]).

Parameters

n (int) – length of permutation

Returns

Reverse permutation of length \(n\).

Return type

Permutation

classmethod subpermutation_to_list_index(per: Permutation, li: list) list#

Applying permutation to larger length list literally.

Parameters
  • per (Permutation) – _description_

  • li (list) – _description_

Raises
  • ValueError – _description_

  • ValueError – _description_

Returns

_description_

Return type

list

booklet.utils.validation module#

booklet.utils.validation.check_integer(i: int, positive: bool = False) bool#

_summary_

Parameters
  • i (int) – _description_

  • positive (bool, optional) – _description_, defaults to False

Returns

True or False

Return type

bool

booklet.utils.validation.check_number(i: Union[str, Number], positive=False) bool#

Validate the type of the given value and its sign whether positive or negative. Return boolean value.

Parameters
  • i (Union[str, Number]) – Unknown value

  • positive (bool, optional) – Additional check, whether the given value is positive or not, defaults to False

Returns

True or False

Return type

bool

booklet.utils.validation.check_path(_path: Union[str, Path], mode: str) bool#

_summary_

Parameters
  • _path (Union[str, Path]) – _description_

  • mode (str) – _description_

Returns

True or False

Return type

bool

booklet.utils.validation.integer(i: Union[str, Number], positive: bool = False) NoReturn#

_summary_

Parameters
  • i (int) – Unknown value

  • positive (bool, optional) – Additional check, whether the given value is positive or not, defaults to False

Raises
  • TypeError – Not an integer object or integer string.

  • ValueError – Not a positive value.

Returns

None

Return type

NoReturn

booklet.utils.validation.number(i: Union[str, Number], positive=False) NoReturn#

Validate the type of the given value and its sign whether positive or negative. Raise error.

Parameters
  • i (Union[str, Number]) – Unknown value

  • positive (bool, optional) – Additional check, whether the given value is positive or not, defaults to False

Raises
  • ValueError – Invaild string, not even a float number

  • ValueError – Invaild string, not an integer

  • TypeError – Invaild type

  • ValueError – Not a positive value.

Returns

None

Return type

NoReturn

booklet.utils.validation.path(_path: Union[str, Path], mode: str = 'f') NoReturn#

_summary_

Parameters
  • _path (Union[str, Path]) – _description_

  • mode (str, optional) – _description_, defaults to “f”

Raises
  • TypeError – The given argument is not a string and path object

  • ValueError – No such file or directory exists.

  • ValueError – Invaild file path, not a file.

  • ValueError – Invaild directory path, not a directory.

Returns

_description_

Return type

NoReturn

Module contents#