autoinput 1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
autoinput-1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 makssem13
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
autoinput-1.0/PKG-INFO ADDED
@@ -0,0 +1,55 @@
1
+ Metadata-Version: 2.4
2
+ Name: autoinput
3
+ Version: 1.0
4
+ Summary: Easier input for Python
5
+ Author-email: Semenii Maksym <maks20sem@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/makssem13/Autoinput
8
+ Project-URL: Issues, https://github.com/makssem13/Autoinput/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.9
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Dynamic: license-file
15
+
16
+ # Autoinput
17
+ This library is for easier input in Python. It is 100% that you don't want to do this:
18
+
19
+ ```Python
20
+ while 1:
21
+ try:
22
+ x = int(input())
23
+ break
24
+ except:
25
+ print("Please input a number")
26
+ ```
27
+
28
+ because it is 6 lines when you can have 1 line:
29
+
30
+ ```Python
31
+ x = autoinput("", autoinput_type.INTEGER)
32
+ ```
33
+
34
+ and everything is inside the function. No work by hands.
35
+
36
+ ## how to use
37
+ Here is the definition
38
+
39
+ ```Python
40
+ def autoinput(outstring: str, typeel, pipe_in: Callable[[str], str]=input, pipe_out: Callable[[str], None]=print, pipe_out_end_name: str="end", parser=None) -> Any:
41
+ ```
42
+
43
+ First argument - `outstring`, string to show.
44
+
45
+ Second argument - `typeel`, use autoinput_type enum to form this (example: `autoinput_type.INTEGER | autoinput_type.ARRAY`)
46
+
47
+ kwargs:
48
+
49
+ `pipe_in` - for custom input function (for example if you use GUI)
50
+
51
+ `pipe_out` - for custom output function
52
+
53
+ `parser` - for custom parser (don't use with `autoinput_type` except of `autoinput_type.ARRAY`)
54
+
55
+ `pipe_out_end_name` - if your custom output function doesn't have parameter like `print`'s `end` use `None`, if has but called not `end` use the parameter to specify the name.
@@ -0,0 +1,40 @@
1
+ # Autoinput
2
+ This library is for easier input in Python. It is 100% that you don't want to do this:
3
+
4
+ ```Python
5
+ while 1:
6
+ try:
7
+ x = int(input())
8
+ break
9
+ except:
10
+ print("Please input a number")
11
+ ```
12
+
13
+ because it is 6 lines when you can have 1 line:
14
+
15
+ ```Python
16
+ x = autoinput("", autoinput_type.INTEGER)
17
+ ```
18
+
19
+ and everything is inside the function. No work by hands.
20
+
21
+ ## how to use
22
+ Here is the definition
23
+
24
+ ```Python
25
+ def autoinput(outstring: str, typeel, pipe_in: Callable[[str], str]=input, pipe_out: Callable[[str], None]=print, pipe_out_end_name: str="end", parser=None) -> Any:
26
+ ```
27
+
28
+ First argument - `outstring`, string to show.
29
+
30
+ Second argument - `typeel`, use autoinput_type enum to form this (example: `autoinput_type.INTEGER | autoinput_type.ARRAY`)
31
+
32
+ kwargs:
33
+
34
+ `pipe_in` - for custom input function (for example if you use GUI)
35
+
36
+ `pipe_out` - for custom output function
37
+
38
+ `parser` - for custom parser (don't use with `autoinput_type` except of `autoinput_type.ARRAY`)
39
+
40
+ `pipe_out_end_name` - if your custom output function doesn't have parameter like `print`'s `end` use `None`, if has but called not `end` use the parameter to specify the name.
@@ -0,0 +1,23 @@
1
+ [build-system]
2
+ requires = ["setuptools >= 77.0.3"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "autoinput"
7
+ version = "1.0"
8
+ authors = [
9
+ { name="Semenii Maksym", email="maks20sem@gmail.com" },
10
+ ]
11
+ description = "Easier input for Python"
12
+ readme = "README.md"
13
+ requires-python = ">=3.9"
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "Operating System :: OS Independent",
17
+ ]
18
+ license = "MIT"
19
+ license-files = ["LICEN[CS]E*"]
20
+
21
+ [project.urls]
22
+ Homepage = "https://github.com/makssem13/Autoinput"
23
+ Issues = "https://github.com/makssem13/Autoinput/issues"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,55 @@
1
+ Metadata-Version: 2.4
2
+ Name: autoinput
3
+ Version: 1.0
4
+ Summary: Easier input for Python
5
+ Author-email: Semenii Maksym <maks20sem@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/makssem13/Autoinput
8
+ Project-URL: Issues, https://github.com/makssem13/Autoinput/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.9
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Dynamic: license-file
15
+
16
+ # Autoinput
17
+ This library is for easier input in Python. It is 100% that you don't want to do this:
18
+
19
+ ```Python
20
+ while 1:
21
+ try:
22
+ x = int(input())
23
+ break
24
+ except:
25
+ print("Please input a number")
26
+ ```
27
+
28
+ because it is 6 lines when you can have 1 line:
29
+
30
+ ```Python
31
+ x = autoinput("", autoinput_type.INTEGER)
32
+ ```
33
+
34
+ and everything is inside the function. No work by hands.
35
+
36
+ ## how to use
37
+ Here is the definition
38
+
39
+ ```Python
40
+ def autoinput(outstring: str, typeel, pipe_in: Callable[[str], str]=input, pipe_out: Callable[[str], None]=print, pipe_out_end_name: str="end", parser=None) -> Any:
41
+ ```
42
+
43
+ First argument - `outstring`, string to show.
44
+
45
+ Second argument - `typeel`, use autoinput_type enum to form this (example: `autoinput_type.INTEGER | autoinput_type.ARRAY`)
46
+
47
+ kwargs:
48
+
49
+ `pipe_in` - for custom input function (for example if you use GUI)
50
+
51
+ `pipe_out` - for custom output function
52
+
53
+ `parser` - for custom parser (don't use with `autoinput_type` except of `autoinput_type.ARRAY`)
54
+
55
+ `pipe_out_end_name` - if your custom output function doesn't have parameter like `print`'s `end` use `None`, if has but called not `end` use the parameter to specify the name.
@@ -0,0 +1,9 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/autoinput.egg-info/PKG-INFO
5
+ src/autoinput.egg-info/SOURCES.txt
6
+ src/autoinput.egg-info/dependency_links.txt
7
+ src/autoinput.egg-info/top_level.txt
8
+ src/autoinput_makssem13/__init__.py
9
+ src/autoinput_makssem13/autoinput.py
@@ -0,0 +1 @@
1
+ autoinput_makssem13
@@ -0,0 +1 @@
1
+ from .autoinput import autoinput, autoinput_type
@@ -0,0 +1,113 @@
1
+ from enum import IntFlag
2
+ from typing import Callable, Any
3
+ import traceback as tracebk
4
+ import sys
5
+
6
+ class autoinput_type(IntFlag):
7
+ STRING = 0x00
8
+ INTEGER = 0x01
9
+ FLOAT = 0x02
10
+ BOOLYN = 0x04
11
+ BOOLTF = 0x08
12
+ ARRAY = 0x10
13
+
14
+ class InputError(Exception):
15
+ def __init__(self, ostr):
16
+ super().__init__(ostr)
17
+
18
+ class ProgramError(Exception):
19
+ def __init__(self, ostr):
20
+ super().__init__(f"{ostr} This error is not your fault, it's a program's error (bug)")
21
+
22
+
23
+ def string_yes_no_to_bool(string: str) -> bool:
24
+ if not string.lower() in set(["yes", "no", "y", "n"]):
25
+ raise ValueError("Not a parsable input.")
26
+ return string.lower() in set(["yes", "y"])
27
+
28
+ def string_true_false_to_bool(string: str) -> bool:
29
+ if not string.lower() in set(["true", "false", "t", "f"]):
30
+ raise ValueError("Not a parsable input.")
31
+ return string.lower() in set(["true", "t"])
32
+
33
+
34
+ def one_space(string: str) -> str:
35
+ res = ""
36
+ prevspace = False
37
+ for sym in string:
38
+ if sym == " ":
39
+ if not prevspace:
40
+ res += sym
41
+ prevspace = True
42
+ else:
43
+ res += sym
44
+ prevspace = False
45
+ return res
46
+
47
+
48
+ def autoinput(outstring: str, typeel, pipe_in: Callable[[str], str]=input, pipe_out: Callable[[str], None]=print, pipe_out_end_name: str="end", parser=None) -> Any:
49
+ """
50
+ autoinput - input with automatic parsing and error handling.
51
+ """
52
+ array: bool = False
53
+ def check_parser():
54
+ nonlocal parser
55
+ if not parser is None:
56
+ raise ProgramError(f"Tried to load two parsers at the same time.")
57
+ if typeel & autoinput_type.INTEGER:
58
+ check_parser()
59
+ parser = int
60
+ if typeel & autoinput_type.FLOAT:
61
+ check_parser()
62
+ parser = float
63
+ if typeel & autoinput_type.BOOLYN:
64
+ check_parser()
65
+ parser = string_yes_no_to_bool
66
+ if typeel & autoinput_type.BOOLTF:
67
+ check_parser()
68
+ parser = string_true_false_to_bool
69
+ if typeel & autoinput_type.ARRAY:
70
+ array = True
71
+ while 1:
72
+ # block 1: print
73
+ try:
74
+ if pipe_out_end_name is None:
75
+ pipe_out(outstring)
76
+ else:
77
+ pipe_out(outstring, **{pipe_out_end_name: ""})
78
+ except Exception as e:
79
+ print("Error while printing! Traceback:", file=sys.stderr)
80
+ tracebk.print_exc()
81
+ raise ProgramError("Error while printing.")
82
+ # block 2: get input without parsing to types (excluding arrays) and return
83
+ instr: str = pipe_in()
84
+ if array:
85
+ inobj = instr.split()
86
+ else:
87
+ inobj: str = instr
88
+ # block 3: parse input and process errors
89
+ try:
90
+ try:
91
+ if not parser is None:
92
+ if type(inobj) is str:
93
+ res = parser(inobj)
94
+ else:
95
+ res = []
96
+ for el in inobj:
97
+ res.append(parser(el))
98
+ else:
99
+ res = inobj
100
+ return res
101
+ except (KeyboardInterrupt, EOFError):
102
+ exit()
103
+ except ValueError:
104
+ raise InputError(one_space(f"Not {'an array of' if array else 'an' if typeel & autoinput_type.INTEGER else 'a'}\
105
+ {'integer' if typeel & autoinput_type.INTEGER\
106
+ else 'float' if typeel & autoinput_type.FLOAT\
107
+ else 'bool (yes/no)' if typeel & autoinput_type.BOOLYN\
108
+ else 'bool (true/false)' if typeel & autoinput_type.BOOLTF\
109
+ else 'string or custom type'}."))
110
+ except TypeError:
111
+ raise ProgramError("Error while parsing input.")
112
+ except InputError:
113
+ tracebk.print_exc()