mangledotdev 0.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.
- mangledotdev-0.1.0/LICENSE +201 -0
- mangledotdev-0.1.0/PKG-INFO +61 -0
- mangledotdev-0.1.0/README.md +49 -0
- mangledotdev-0.1.0/pyproject.toml +20 -0
- mangledotdev-0.1.0/setup.cfg +4 -0
- mangledotdev-0.1.0/src/mangledotdev/__init__.py +0 -0
- mangledotdev-0.1.0/src/mangledotdev/mangledotdev.py +431 -0
- mangledotdev-0.1.0/src/mangledotdev.egg-info/PKG-INFO +61 -0
- mangledotdev-0.1.0/src/mangledotdev.egg-info/SOURCES.txt +9 -0
- mangledotdev-0.1.0/src/mangledotdev.egg-info/dependency_links.txt +1 -0
- mangledotdev-0.1.0/src/mangledotdev.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Wass B.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mangledotdev
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: The universal programming language communication system
|
|
5
|
+
Author-email: "Wass B." <wass.be@proton.me>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/WassBe/mangle.dev
|
|
8
|
+
Requires-Python: >=3.8
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
# Installation
|
|
14
|
+
|
|
15
|
+
Mangle.dev for Python can be installed in multiple ways depending on your preference.
|
|
16
|
+
|
|
17
|
+
## Option 1: Using pip (Recommended)
|
|
18
|
+
|
|
19
|
+
Install Mangle.dev directly from PyPI:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install mangledotdev
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Or with pip3:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip3 install mangledotdev
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Option 2: Manual Installation
|
|
32
|
+
|
|
33
|
+
Download the `mangledotdev.py` file and place it in your project directory or Python path.
|
|
34
|
+
|
|
35
|
+
### Project Structure Example
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
project/
|
|
39
|
+
├── mangledotdev.py
|
|
40
|
+
├── main.py
|
|
41
|
+
└── process.py
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Verifying Installation
|
|
45
|
+
|
|
46
|
+
After installation, verify that Mangle.dev is working correctly:
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
# test_mangledotdev.py
|
|
50
|
+
try:
|
|
51
|
+
from mangledotdev import InputManager, OutputManager
|
|
52
|
+
print("Mangle imported successfully!")
|
|
53
|
+
except ImportError as e:
|
|
54
|
+
print(f"Import error: {e}")
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Run the test:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
python test_mangledotdev.py
|
|
61
|
+
```
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Installation
|
|
2
|
+
|
|
3
|
+
Mangle.dev for Python can be installed in multiple ways depending on your preference.
|
|
4
|
+
|
|
5
|
+
## Option 1: Using pip (Recommended)
|
|
6
|
+
|
|
7
|
+
Install Mangle.dev directly from PyPI:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install mangledotdev
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or with pip3:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip3 install mangledotdev
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Option 2: Manual Installation
|
|
20
|
+
|
|
21
|
+
Download the `mangledotdev.py` file and place it in your project directory or Python path.
|
|
22
|
+
|
|
23
|
+
### Project Structure Example
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
project/
|
|
27
|
+
├── mangledotdev.py
|
|
28
|
+
├── main.py
|
|
29
|
+
└── process.py
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Verifying Installation
|
|
33
|
+
|
|
34
|
+
After installation, verify that Mangle.dev is working correctly:
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
# test_mangledotdev.py
|
|
38
|
+
try:
|
|
39
|
+
from mangledotdev import InputManager, OutputManager
|
|
40
|
+
print("Mangle imported successfully!")
|
|
41
|
+
except ImportError as e:
|
|
42
|
+
print(f"Import error: {e}")
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Run the test:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
python test_mangledotdev.py
|
|
49
|
+
```
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "mangledotdev"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "The universal programming language communication system"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "Apache-2.0"}
|
|
11
|
+
authors = [
|
|
12
|
+
{ name="Wass B.", email="wass.be@proton.me" }
|
|
13
|
+
]
|
|
14
|
+
dependencies = [
|
|
15
|
+
# "requests>=2.28"
|
|
16
|
+
]
|
|
17
|
+
requires-python = ">=3.8"
|
|
18
|
+
|
|
19
|
+
[project.urls]
|
|
20
|
+
Homepage = "https://github.com/WassBe/mangle.dev"
|
|
File without changes
|
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
import subprocess
|
|
2
|
+
import json
|
|
3
|
+
import time
|
|
4
|
+
import random
|
|
5
|
+
import os
|
|
6
|
+
import sys
|
|
7
|
+
import io
|
|
8
|
+
import uuid
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class InputManager:
|
|
12
|
+
"""
|
|
13
|
+
Manages sending requests to other processes and handling responses.
|
|
14
|
+
|
|
15
|
+
This is an instance-based class - create one instance per request.
|
|
16
|
+
|
|
17
|
+
Attributes:
|
|
18
|
+
response (dict): Complete response with status, data, errors, warnings
|
|
19
|
+
|
|
20
|
+
Methods:
|
|
21
|
+
request(): Send a request to another process
|
|
22
|
+
get_response(): Get the full response object
|
|
23
|
+
get_data(): Get the response data (returns None on error)
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
@staticmethod
|
|
27
|
+
def __genKey():
|
|
28
|
+
"""Generate a unique key for request/response matching."""
|
|
29
|
+
return uuid.uuid4().hex
|
|
30
|
+
|
|
31
|
+
def __init__(self):
|
|
32
|
+
"""Initialize a new InputManager instance."""
|
|
33
|
+
self.__process = None
|
|
34
|
+
self.__raw_request = None
|
|
35
|
+
self.__request = None
|
|
36
|
+
self.__response = None
|
|
37
|
+
self.response = None
|
|
38
|
+
self.__data = None
|
|
39
|
+
self.__key = None
|
|
40
|
+
|
|
41
|
+
def __get_command(self, language, file):
|
|
42
|
+
"""
|
|
43
|
+
Validate file and build command to execute.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
language (str): Programming language/runtime
|
|
47
|
+
file (str): Path to file to execute
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
list: Command array for subprocess
|
|
51
|
+
|
|
52
|
+
Raises:
|
|
53
|
+
ValueError: Invalid file extension for language
|
|
54
|
+
FileNotFoundError: File does not exist
|
|
55
|
+
PermissionError: File not readable/executable
|
|
56
|
+
"""
|
|
57
|
+
lang_upper = str(language).upper()
|
|
58
|
+
|
|
59
|
+
# On Windows, convert forward slashes to backslashes for file system operations
|
|
60
|
+
if os.name == 'nt':
|
|
61
|
+
file = file.replace('/', '\\')
|
|
62
|
+
|
|
63
|
+
file_ext = os.path.splitext(file)[1].lower()
|
|
64
|
+
|
|
65
|
+
# Extension validation - FIRST before file existence check
|
|
66
|
+
extension_map = {
|
|
67
|
+
'PYTHON': ['.py'],
|
|
68
|
+
'PY': ['.py'],
|
|
69
|
+
'JAVASCRIPT': ['.js'],
|
|
70
|
+
'JS': ['.js'],
|
|
71
|
+
'NODE': ['.js'],
|
|
72
|
+
'NODEJS': ['.js'],
|
|
73
|
+
'RUBY': ['.rb'],
|
|
74
|
+
'RB': ['.rb'],
|
|
75
|
+
'C': ['.c', '.out', '.exe', ''],
|
|
76
|
+
'CS': ['.exe', '.dll', ''],
|
|
77
|
+
'CPP': ['.cpp', '.cc', '.cxx', '.out', '.exe', ''],
|
|
78
|
+
'C#': ['.exe', '.dll', ''],
|
|
79
|
+
'C++': ['.cpp', '.cc', '.cxx', '.out', '.exe', ''],
|
|
80
|
+
'CSHARP': ['.exe', '.dll', ''],
|
|
81
|
+
'CPLUSPLUS': ['.cpp', '.cc', '.cxx', '.out', '.exe', ''],
|
|
82
|
+
'EXE': ['.cpp', '.cc', '.cxx', '.out', '.exe', ''],
|
|
83
|
+
'JAR': ['.jar'],
|
|
84
|
+
'JAVA': ['.jar'],
|
|
85
|
+
'RUST': ['.rs', '.exe', '.out', ''],
|
|
86
|
+
'RS': ['.rs', '.exe', '.out', ''],
|
|
87
|
+
'GO': ['.go', '.exe', '.out', ''],
|
|
88
|
+
'GOLANG': ['.go', '.exe', '.out', '']
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if lang_upper in extension_map:
|
|
92
|
+
valid_extensions = extension_map[lang_upper]
|
|
93
|
+
if file_ext not in valid_extensions:
|
|
94
|
+
expected = ', '.join([ext if ext else '(no extension)' for ext in valid_extensions])
|
|
95
|
+
raise ValueError(f"Invalid file '{file}' for language '{language}'. Expected: e.g. 'file{expected}'")
|
|
96
|
+
|
|
97
|
+
# File existence check
|
|
98
|
+
if not os.path.exists(file):
|
|
99
|
+
raise FileNotFoundError(f"File not found: {file}")
|
|
100
|
+
|
|
101
|
+
if not os.path.isfile(file):
|
|
102
|
+
raise ValueError(f"Path is not a file: {file}")
|
|
103
|
+
|
|
104
|
+
# Permission checks
|
|
105
|
+
compiled_langs = ['C', 'CS', 'CPP', 'C#', 'C++', 'CSHARP', 'CPLUSPLUS', 'EXE', 'RUST', 'RS', 'GO', 'GOLANG']
|
|
106
|
+
if lang_upper in compiled_langs:
|
|
107
|
+
if not os.access(file, os.X_OK):
|
|
108
|
+
raise PermissionError(f"File is not executable: {file}")
|
|
109
|
+
else:
|
|
110
|
+
if not os.access(file, os.R_OK):
|
|
111
|
+
raise PermissionError(f"File is not readable: {file}")
|
|
112
|
+
|
|
113
|
+
# Auto-add ./ for compiled executables if not present and not absolute path
|
|
114
|
+
if lang_upper in compiled_langs and not os.path.isabs(file) and not file.startswith('./'):
|
|
115
|
+
file = './' + file
|
|
116
|
+
|
|
117
|
+
# Build command
|
|
118
|
+
lang_map = {
|
|
119
|
+
'PYTHON': ['python', file],
|
|
120
|
+
'PY': ['python', file],
|
|
121
|
+
'JAVASCRIPT': ['node', file],
|
|
122
|
+
'JS': ['node', file],
|
|
123
|
+
'NODE': ['node', file],
|
|
124
|
+
'NODEJS': ['node', file],
|
|
125
|
+
'RUBY': ['ruby', file],
|
|
126
|
+
'RB': ['ruby', file],
|
|
127
|
+
'C': [file],
|
|
128
|
+
'CS': ['dotnet', file] if file_ext == '.dll' else [file],
|
|
129
|
+
'CPP': [file],
|
|
130
|
+
'C#': ['dotnet', file] if file_ext == '.dll' else [file],
|
|
131
|
+
'C++': [file],
|
|
132
|
+
'CSHARP': ['dotnet', file] if file_ext == '.dll' else [file],
|
|
133
|
+
'CPLUSPLUS': [file],
|
|
134
|
+
'EXE': [file],
|
|
135
|
+
'JAR': ['java', '-jar', file],
|
|
136
|
+
'JAVA': ['java', '-jar', file],
|
|
137
|
+
'RUST': [file],
|
|
138
|
+
'RS': [file],
|
|
139
|
+
'GO': ['go', 'run', file] if file_ext == '.go' else [file],
|
|
140
|
+
'GOLANG': ['go', 'run', file] if file_ext == '.go' else [file]
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if lang_upper not in lang_map:
|
|
144
|
+
raise ValueError(f"Unsupported language: {language}")
|
|
145
|
+
|
|
146
|
+
return lang_map[lang_upper]
|
|
147
|
+
|
|
148
|
+
def request(self, isUnique=True, optionalOutput=True, data: any=None, language: any=str, file: any=str):
|
|
149
|
+
"""
|
|
150
|
+
Send a request to another process.
|
|
151
|
+
|
|
152
|
+
Args:
|
|
153
|
+
isUnique (bool): Expect single output (True) or multiple (False)
|
|
154
|
+
optionalOutput (bool): Output is optional (True) or required (False)
|
|
155
|
+
data: Data to send (any JSON-serializable type)
|
|
156
|
+
language (str): Target language/runtime
|
|
157
|
+
file (str): Path to target file
|
|
158
|
+
|
|
159
|
+
Sets:
|
|
160
|
+
self.response (dict): Complete response with keys:
|
|
161
|
+
- request_status (bool|None): Success status
|
|
162
|
+
- data: Response data
|
|
163
|
+
- optionalOutput (bool): Echo of parameter
|
|
164
|
+
- isUnique (bool): Echo of parameter
|
|
165
|
+
- warnings (list): Warning messages
|
|
166
|
+
- errors (list): Error messages
|
|
167
|
+
"""
|
|
168
|
+
try:
|
|
169
|
+
self.__key = InputManager._InputManager__genKey()
|
|
170
|
+
command = self.__get_command(language, file)
|
|
171
|
+
|
|
172
|
+
self.__process = subprocess.Popen(
|
|
173
|
+
command,
|
|
174
|
+
stdin=subprocess.PIPE,
|
|
175
|
+
stdout=subprocess.PIPE,
|
|
176
|
+
stderr=subprocess.PIPE,
|
|
177
|
+
text=True
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
self.__raw_request = {
|
|
181
|
+
"key": self.__key,
|
|
182
|
+
"optionalOutput": optionalOutput,
|
|
183
|
+
"isUnique": isUnique,
|
|
184
|
+
"data": data
|
|
185
|
+
}
|
|
186
|
+
self.__request = json.dumps(self.__raw_request)
|
|
187
|
+
|
|
188
|
+
response = {
|
|
189
|
+
"request_status": None,
|
|
190
|
+
"data": None,
|
|
191
|
+
"optionalOutput": optionalOutput,
|
|
192
|
+
"isUnique": isUnique,
|
|
193
|
+
"warnings": [],
|
|
194
|
+
"errors": []
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
output, errors = self.__process.communicate(input=self.__request)
|
|
198
|
+
|
|
199
|
+
if self.__process.returncode != 0:
|
|
200
|
+
response["request_status"] = False
|
|
201
|
+
response["errors"].append(f"Process exited with code {self.__process.returncode}")
|
|
202
|
+
if errors.strip():
|
|
203
|
+
response["errors"].append(f"stderr: {errors.strip()}")
|
|
204
|
+
response["warnings"].append("Warning: these kind of errors result from an error in the targeted script.")
|
|
205
|
+
self.response = response
|
|
206
|
+
return
|
|
207
|
+
|
|
208
|
+
self.__response = []
|
|
209
|
+
for line in output.strip().split('\n'):
|
|
210
|
+
if not line.strip():
|
|
211
|
+
continue
|
|
212
|
+
|
|
213
|
+
try:
|
|
214
|
+
__data = json.loads(line)
|
|
215
|
+
|
|
216
|
+
# Validate response has matching key or null key (for init errors)
|
|
217
|
+
# This ensures we only process responses meant for this request
|
|
218
|
+
if isinstance(__data, dict) and (__data.get('key') == self.__key or __data.get('key') is None):
|
|
219
|
+
self.__response.append(__data)
|
|
220
|
+
except json.JSONDecodeError:
|
|
221
|
+
# Ignore lines that aren't valid JSON (e.g., debug prints)
|
|
222
|
+
pass
|
|
223
|
+
|
|
224
|
+
if len(self.__response) != 0:
|
|
225
|
+
failure = False
|
|
226
|
+
for i in self.__response:
|
|
227
|
+
if not i["request_status"]:
|
|
228
|
+
failure = True
|
|
229
|
+
|
|
230
|
+
if not failure:
|
|
231
|
+
response["request_status"] = True
|
|
232
|
+
else:
|
|
233
|
+
response["request_status"] = False
|
|
234
|
+
|
|
235
|
+
response["isUnique"] = self.__response[0]["isUnique"]
|
|
236
|
+
|
|
237
|
+
for i in self.__response:
|
|
238
|
+
for index, e in enumerate(i["errors"]):
|
|
239
|
+
response["errors"].append(i["errors"][index])
|
|
240
|
+
|
|
241
|
+
data_list = []
|
|
242
|
+
for i in self.__response:
|
|
243
|
+
data_list.append(i["data"])
|
|
244
|
+
|
|
245
|
+
if response["isUnique"]:
|
|
246
|
+
if len(data_list) == 1:
|
|
247
|
+
response["data"] = data_list[0]
|
|
248
|
+
else:
|
|
249
|
+
response["request_status"] = False
|
|
250
|
+
response["data"] = None
|
|
251
|
+
response["errors"].append(f"Error: Expected 1 output (isUnique=True) but received {len(data_list)}.")
|
|
252
|
+
else:
|
|
253
|
+
response["data"] = data_list
|
|
254
|
+
|
|
255
|
+
elif optionalOutput:
|
|
256
|
+
response["request_status"] = None
|
|
257
|
+
response["data"] = None
|
|
258
|
+
response["warnings"].append("Warning: the output setting is set to optional, and the targeted program didn't gave any output.")
|
|
259
|
+
else:
|
|
260
|
+
response["request_status"] = False
|
|
261
|
+
response["data"] = None
|
|
262
|
+
response["errors"].append("Error: OutputManager might not be used or not correctly.")
|
|
263
|
+
|
|
264
|
+
self.response = response
|
|
265
|
+
|
|
266
|
+
except (FileNotFoundError, PermissionError, ValueError) as e:
|
|
267
|
+
self.response = {
|
|
268
|
+
"request_status": False,
|
|
269
|
+
"data": None,
|
|
270
|
+
"optionalOutput": optionalOutput,
|
|
271
|
+
"isUnique": isUnique,
|
|
272
|
+
"warnings": ["Warning: targeted file not found or can't be executed, consider checking file informations and language dependencies."],
|
|
273
|
+
"errors": [f"Error: {str(e)}"]
|
|
274
|
+
}
|
|
275
|
+
except Exception as e:
|
|
276
|
+
self.response = {
|
|
277
|
+
"request_status": False,
|
|
278
|
+
"data": None,
|
|
279
|
+
"optionalOutput": optionalOutput,
|
|
280
|
+
"isUnique": isUnique,
|
|
281
|
+
"warnings": [],
|
|
282
|
+
"errors": [f"Unexpected error: {str(e)}"]
|
|
283
|
+
}
|
|
284
|
+
return
|
|
285
|
+
|
|
286
|
+
def get_response(self):
|
|
287
|
+
"""
|
|
288
|
+
Get the full response object.
|
|
289
|
+
|
|
290
|
+
Returns:
|
|
291
|
+
dict: The complete response with status, data, errors, warnings.
|
|
292
|
+
Keys: request_status, data, optionalOutput, isUnique, warnings, errors
|
|
293
|
+
"""
|
|
294
|
+
return self.response
|
|
295
|
+
|
|
296
|
+
def get_data(self):
|
|
297
|
+
"""
|
|
298
|
+
Get the response data if request was successful.
|
|
299
|
+
|
|
300
|
+
Returns:
|
|
301
|
+
The data from the response (any type), or None if request failed.
|
|
302
|
+
The return type matches the type sent by the target process.
|
|
303
|
+
"""
|
|
304
|
+
if self.response:
|
|
305
|
+
if self.response["request_status"]:
|
|
306
|
+
return self.response["data"]
|
|
307
|
+
return None
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
class OutputManager:
|
|
311
|
+
"""
|
|
312
|
+
Manages receiving requests from other processes and sending responses.
|
|
313
|
+
|
|
314
|
+
This is a class-based/static manager - all methods are class methods.
|
|
315
|
+
Must call init() before using.
|
|
316
|
+
|
|
317
|
+
Class Attributes:
|
|
318
|
+
data: The request data (accessible after init())
|
|
319
|
+
|
|
320
|
+
Class Methods:
|
|
321
|
+
init(): Initialize and read request from stdin
|
|
322
|
+
output(val): Send response back via stdout
|
|
323
|
+
"""
|
|
324
|
+
|
|
325
|
+
__original_stdout = None
|
|
326
|
+
__request = None
|
|
327
|
+
__data = None
|
|
328
|
+
data = None
|
|
329
|
+
__request_status = None
|
|
330
|
+
__optional = None
|
|
331
|
+
__unique_state = None
|
|
332
|
+
__init_error = None
|
|
333
|
+
__errors = []
|
|
334
|
+
__warnings = []
|
|
335
|
+
|
|
336
|
+
@classmethod
|
|
337
|
+
def init(cls):
|
|
338
|
+
"""
|
|
339
|
+
Initialize OutputManager and read request from stdin.
|
|
340
|
+
|
|
341
|
+
Must be called before using output() or accessing data.
|
|
342
|
+
Suppresses stdout to prevent pollution of JSON protocol.
|
|
343
|
+
"""
|
|
344
|
+
# Save original stdout so we can restore it later
|
|
345
|
+
cls.__original_stdout = sys.stdout
|
|
346
|
+
# Redirect stdout to StringIO to suppress all print statements
|
|
347
|
+
sys.stdout = io.StringIO()
|
|
348
|
+
# Read the entire stdin (the JSON request from InputManager)
|
|
349
|
+
cls.__request = sys.stdin.read()
|
|
350
|
+
cls.__data = json.loads(cls.__request)
|
|
351
|
+
cls.data = cls.__data["data"]
|
|
352
|
+
cls.__optional = cls.__data["optionalOutput"]
|
|
353
|
+
|
|
354
|
+
# Reset state for new request
|
|
355
|
+
cls.__errors = []
|
|
356
|
+
cls.__warnings = []
|
|
357
|
+
cls.__init_error = None
|
|
358
|
+
cls.__request_status = None
|
|
359
|
+
cls.__unique_state = None
|
|
360
|
+
|
|
361
|
+
@classmethod
|
|
362
|
+
def __write(cls, args, _data):
|
|
363
|
+
"""
|
|
364
|
+
Internal method to write JSON response to stdout.
|
|
365
|
+
|
|
366
|
+
Args:
|
|
367
|
+
args: Data to send in response
|
|
368
|
+
_data: Request data for key/metadata
|
|
369
|
+
"""
|
|
370
|
+
# Restore original stdout to actually write the response
|
|
371
|
+
if cls.__original_stdout:
|
|
372
|
+
sys.stdout = cls.__original_stdout
|
|
373
|
+
else:
|
|
374
|
+
sys.stdout = sys.__stdout__
|
|
375
|
+
|
|
376
|
+
# Build and write JSON response
|
|
377
|
+
response = json.dumps({
|
|
378
|
+
"key": _data["key"] if _data else None,
|
|
379
|
+
"request_status": cls.__request_status,
|
|
380
|
+
"data": args,
|
|
381
|
+
"optionalOutput": cls.__optional,
|
|
382
|
+
"isUnique": _data["isUnique"] if _data else None,
|
|
383
|
+
"errors": cls.__errors,
|
|
384
|
+
"warnings": cls.__warnings
|
|
385
|
+
})
|
|
386
|
+
|
|
387
|
+
sys.stdout.write(response)
|
|
388
|
+
sys.stdout.write("\n")
|
|
389
|
+
sys.stdout.flush()
|
|
390
|
+
|
|
391
|
+
@classmethod
|
|
392
|
+
def output(cls, val):
|
|
393
|
+
"""
|
|
394
|
+
Send response back to the calling process.
|
|
395
|
+
|
|
396
|
+
Args:
|
|
397
|
+
val: Data to send (any JSON-serializable type)
|
|
398
|
+
|
|
399
|
+
Note:
|
|
400
|
+
Can be called multiple times if isUnique=False in request.
|
|
401
|
+
Will error if called multiple times when isUnique=True.
|
|
402
|
+
"""
|
|
403
|
+
# Check if OutputManager was initialized
|
|
404
|
+
if not cls.__data:
|
|
405
|
+
if not cls.__init_error:
|
|
406
|
+
if cls.__original_stdout:
|
|
407
|
+
sys.stdout = cls.__original_stdout
|
|
408
|
+
else:
|
|
409
|
+
sys.stdout = sys.__stdout__
|
|
410
|
+
|
|
411
|
+
cls.__request_status = False
|
|
412
|
+
cls.__errors.append("Error: OutputManager isn't initialized.")
|
|
413
|
+
cls._OutputManager__write(args=None, _data=cls.__data)
|
|
414
|
+
cls.__init_error = True
|
|
415
|
+
|
|
416
|
+
else:
|
|
417
|
+
# Check if we can output based on isUnique setting
|
|
418
|
+
# unique_state tracks if we've already output once
|
|
419
|
+
if not cls.__unique_state or not cls.__data["isUnique"]:
|
|
420
|
+
cls.__request_status = True
|
|
421
|
+
cls._OutputManager__write(args=val, _data=cls.__data)
|
|
422
|
+
else:
|
|
423
|
+
# Multiple outputs when isUnique=True is an error
|
|
424
|
+
cls.__request_status = False
|
|
425
|
+
cls.__errors.append(f"Error: outputs out of bound (isUnique: {cls.__unique_state}).")
|
|
426
|
+
cls._OutputManager__write(args=val, _data=cls.__data)
|
|
427
|
+
|
|
428
|
+
# Mark that we've output once
|
|
429
|
+
cls.__unique_state = cls.__data["isUnique"]
|
|
430
|
+
# Re-suppress stdout after writing response
|
|
431
|
+
sys.stdout = io.StringIO()
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mangledotdev
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: The universal programming language communication system
|
|
5
|
+
Author-email: "Wass B." <wass.be@proton.me>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/WassBe/mangle.dev
|
|
8
|
+
Requires-Python: >=3.8
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Dynamic: license-file
|
|
12
|
+
|
|
13
|
+
# Installation
|
|
14
|
+
|
|
15
|
+
Mangle.dev for Python can be installed in multiple ways depending on your preference.
|
|
16
|
+
|
|
17
|
+
## Option 1: Using pip (Recommended)
|
|
18
|
+
|
|
19
|
+
Install Mangle.dev directly from PyPI:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install mangledotdev
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Or with pip3:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip3 install mangledotdev
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Option 2: Manual Installation
|
|
32
|
+
|
|
33
|
+
Download the `mangledotdev.py` file and place it in your project directory or Python path.
|
|
34
|
+
|
|
35
|
+
### Project Structure Example
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
project/
|
|
39
|
+
├── mangledotdev.py
|
|
40
|
+
├── main.py
|
|
41
|
+
└── process.py
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Verifying Installation
|
|
45
|
+
|
|
46
|
+
After installation, verify that Mangle.dev is working correctly:
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
# test_mangledotdev.py
|
|
50
|
+
try:
|
|
51
|
+
from mangledotdev import InputManager, OutputManager
|
|
52
|
+
print("Mangle imported successfully!")
|
|
53
|
+
except ImportError as e:
|
|
54
|
+
print(f"Import error: {e}")
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Run the test:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
python test_mangledotdev.py
|
|
61
|
+
```
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/mangledotdev/__init__.py
|
|
5
|
+
src/mangledotdev/mangledotdev.py
|
|
6
|
+
src/mangledotdev.egg-info/PKG-INFO
|
|
7
|
+
src/mangledotdev.egg-info/SOURCES.txt
|
|
8
|
+
src/mangledotdev.egg-info/dependency_links.txt
|
|
9
|
+
src/mangledotdev.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mangledotdev
|