UpgradedInput 0.0.1__py3-none-any.whl
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.
|
File without changes
|
UpgradedInput/main.py
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
from typing import Callable
|
|
2
|
+
|
|
3
|
+
class UpgradedInput:
|
|
4
|
+
"""Main class for the 'Upgraded input' module.
|
|
5
|
+
|
|
6
|
+
By default, all callbacks are initialized to None.
|
|
7
|
+
|
|
8
|
+
If an EOFError, KeyboardInterrupt, or RuntimeError is encountered
|
|
9
|
+
in this state the program will exit with status code 1.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
def __init__(self) -> None:
|
|
13
|
+
self.before_input_function: Callable | None = None
|
|
14
|
+
"""
|
|
15
|
+
This variable takes any function or None
|
|
16
|
+
|
|
17
|
+
If the function is valid it gets called before python's default input gets called
|
|
18
|
+
|
|
19
|
+
So it works like this:
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
your_function()
|
|
23
|
+
return input()
|
|
24
|
+
```
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
self.exception_close_input_function: Callable | None = None
|
|
28
|
+
"""
|
|
29
|
+
This variable takes any function or None
|
|
30
|
+
|
|
31
|
+
If the function is valid it gets called when the input function returns either EOFError or KeyboardInterrupt
|
|
32
|
+
|
|
33
|
+
So it works like this:
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
try:
|
|
37
|
+
return input()
|
|
38
|
+
except EOFError, KeyboardInterrupt
|
|
39
|
+
your_function()
|
|
40
|
+
```
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
self.after_input_function: Callable | None = None
|
|
45
|
+
"""
|
|
46
|
+
This variable takes any function or None
|
|
47
|
+
|
|
48
|
+
If the function is valid it gets called when the input ends getting called
|
|
49
|
+
|
|
50
|
+
So it works like this:
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
text = input()
|
|
54
|
+
your_function()
|
|
55
|
+
return text
|
|
56
|
+
```
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
self.runtime_error_function: Callable | None = None
|
|
60
|
+
"""
|
|
61
|
+
This variable takes any function or None
|
|
62
|
+
|
|
63
|
+
If the function is valid it gets called when input gets called in case sys.stdin gets lost
|
|
64
|
+
|
|
65
|
+
(as in you so sys.stdin = None)
|
|
66
|
+
|
|
67
|
+
So it works like this:
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
try:
|
|
71
|
+
return input()
|
|
72
|
+
except RuntimeError:
|
|
73
|
+
runtime_error_function()
|
|
74
|
+
```
|
|
75
|
+
"""
|
|
76
|
+
|
|
77
|
+
def input(self, prompt: object = "") -> str:
|
|
78
|
+
"""Original documentation for input:
|
|
79
|
+
|
|
80
|
+
Read a string from standard input. The trailing newline is stripped.
|
|
81
|
+
|
|
82
|
+
The prompt string, if given, is printed to standard output without a
|
|
83
|
+
trailing newline before reading input.
|
|
84
|
+
|
|
85
|
+
If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.
|
|
86
|
+
On *nix systems, readline is used if available.
|
|
87
|
+
"""
|
|
88
|
+
|
|
89
|
+
before_input_func:Callable | None = self.before_input_function
|
|
90
|
+
exception_func:Callable | None = self.exception_close_input_function
|
|
91
|
+
after_input_func:Callable | None = self.after_input_function
|
|
92
|
+
runtime_error_func:Callable | None = self.runtime_error_function
|
|
93
|
+
|
|
94
|
+
def default_exit():
|
|
95
|
+
print("Exiting...")
|
|
96
|
+
exit(1)
|
|
97
|
+
|
|
98
|
+
try:
|
|
99
|
+
if callable(before_input_func):
|
|
100
|
+
before_input_func()
|
|
101
|
+
|
|
102
|
+
text = input(prompt)
|
|
103
|
+
|
|
104
|
+
if callable(after_input_func):
|
|
105
|
+
after_input_func()
|
|
106
|
+
|
|
107
|
+
return text
|
|
108
|
+
|
|
109
|
+
except (EOFError, KeyboardInterrupt):
|
|
110
|
+
if callable(exception_func):
|
|
111
|
+
exception_func()
|
|
112
|
+
else:
|
|
113
|
+
default_exit()
|
|
114
|
+
|
|
115
|
+
except RuntimeError: # lost sys.stdin
|
|
116
|
+
if callable(runtime_error_func):
|
|
117
|
+
runtime_error_func()
|
|
118
|
+
else:
|
|
119
|
+
default_exit()
|
|
120
|
+
|
|
121
|
+
return ""
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: UpgradedInput
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A better input() for python
|
|
5
|
+
Author: riccy10210
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Ricca665/UpgradedInput
|
|
8
|
+
Project-URL: Issues, https://github.com/Ricca665/UpgradedInput/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
|
+
# UpgradedInput
|
|
17
|
+
A better input() for python
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
UpgradedInput/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
UpgradedInput/main.py,sha256=rDa1WCA4_MrxxPQEOtSy6Zm4DVl2bD4dLkpnVZsEvyg,3469
|
|
3
|
+
upgradedinput-0.0.1.dist-info/licenses/LICENSE,sha256=unlS3FU2mT6OWz1KWka-TmMCRcozvIQtJJo5YP90ET0,1065
|
|
4
|
+
upgradedinput-0.0.1.dist-info/METADATA,sha256=ewXxFQ0YvXmKUPAYnWVkr7zPnRu1e5sqWywYxa9upnM,536
|
|
5
|
+
upgradedinput-0.0.1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
6
|
+
upgradedinput-0.0.1.dist-info/top_level.txt,sha256=A46FUH92D3WKbTWfWFzVFcL9pkcRIkoi3ZkvPydQnXY,14
|
|
7
|
+
upgradedinput-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ricca665
|
|
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.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
UpgradedInput
|