cyjs 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.
cyjs-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Vizonex
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.
cyjs-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,141 @@
1
+ Metadata-Version: 2.4
2
+ Name: cyjs
3
+ Version: 0.1.0
4
+ Summary: A Next Generation QuickJS Intrepreter for cython & python
5
+ Author-email: Vizonex <VizonexBusiness@gmail.com>
6
+ Requires-Python: >=3.10
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Dynamic: license-file
10
+
11
+ <img src="cyjs-logo.png" style="width: 30%;"/>
12
+
13
+ ------
14
+ # CYJS
15
+
16
+ ECMAScript interpreter for Cython & Python built for
17
+ - Solving & Decrypting Annoying Puzzles and Captchas at immense speeds.
18
+ - Calling upon different Javascript libraries Examples might include:
19
+ - llparse (Even though I maintain a python version but you could easily call upon llparse from javascript using this extension)
20
+ - yt-dlp-ejs (Decrypting challenges might take a while but that was why I wrote this library so we could start optimizing these things
21
+ )
22
+ - Being tiny and easy to use
23
+ - Having ECMA6 Support
24
+ - Having a maintained backend (QuickJS-NG)
25
+ - Being a good companion alongside [selectolax](https://github.com/rushter/selectolax) or beautiful-soup the choice is yours...
26
+ - License friendly, after abandoning pyduktape due to the backend no longer being maintained but also having a pretty poor license all together, It inspired me to try something new for a change that could run newer HTML5 Javascript for any puzzle that is thrown your way.
27
+
28
+ ## Quick Example
29
+
30
+
31
+ ```python
32
+ from cyjs import Context, Runtime
33
+
34
+
35
+ def main():
36
+ # You can also provide a runtime if needed it's usage before making multiple contexts however
37
+ # is completely optional
38
+ rt = Runtime()
39
+
40
+ ctx = Context(rt)
41
+
42
+ ctx.eval("function add(a, b){ return a + b; }; globalThis.add = add;")
43
+ add_func = ctx.get_global().get("add")
44
+
45
+ # 3
46
+ print(add_func(1, 2))
47
+
48
+ if __name__ == "__main__":
49
+ main()
50
+ ```
51
+
52
+ Example of use with external html parser tools.
53
+
54
+ ```python
55
+ from cyjs import Context
56
+ from selectolax.lexbor import LexborHTMLParser
57
+
58
+ # This example demonstates ways of cracking javascript out of webpages
59
+ # with an expernal HTML Parser and cyjs to handle the javascript logic.
60
+
61
+ # Know that A True HTML5 Dom-API Might require you to make your own
62
+ # functions and imagination but also reverse engineering the target page.
63
+
64
+ HTML_PAGE = b"""
65
+ <!DOCTYPE html>
66
+ <html lang="en">
67
+ <head>
68
+ <meta charset="UTF-8">
69
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
70
+ <title>Document</title>
71
+ </head>
72
+ <body>
73
+ <div class="captcha">
74
+ <script>
75
+ function fake_captcha(name) {
76
+ return name + "-key";
77
+ }
78
+ </script>
79
+ <!-- Use your imagination a little... -->
80
+ </div>
81
+ <div>
82
+ <script>
83
+ this.captcha = fake_captcha('123')
84
+ </script>
85
+ </div>
86
+ </body>
87
+ </html>
88
+ """
89
+
90
+ def main():
91
+ html = LexborHTMLParser(HTML_PAGE)
92
+ captcha = html.css_first("div.captcha > script").text(strip=True)
93
+
94
+ fake_solver = Context()
95
+ fake_solver.eval(captcha + "\nglobalThis.fake_captcha = fake_captcha;")
96
+ result = fake_solver.get_global().invoke("fake_captcha", "123")
97
+ # should print
98
+ # "123-key"
99
+ print(result)
100
+
101
+ if __name__ == "__main__":
102
+ main()
103
+
104
+ ```
105
+
106
+ There will be more examples in a future update.
107
+
108
+
109
+
110
+
111
+
112
+ ## Alternative Python Javascript Interpreters
113
+
114
+ | Library | ECMA-6 Support | Size | Performance | Typestubs And Readability | Cython cimportable |
115
+ |---------|-----------------------------------|------|-------------|-----------|----|
116
+ | [js2py](https://github.com/PiotrDabkowski/Js2Py) | has to translate ECMA6 to 5 | Medium | Decent at ECMA5 and html5 scripts that use Emca-5 but starts suffering when trying to do ECMA-6 | Lacks proper typehinting making everything into an unwanted guessing game | No and it's pure python
117
+ | [quickjs (python library)](https://github.com/PetterS/quickjs) | Yes | Small | Has to convert some objects back and forth but lacks typestubs and documentation | Lacks typestubs | CPython Extension that could've used a C-API Capsule to help it gain a bit of lubricant with other projects.
118
+ | pyduktape | No | Small | somewhat fast but the backend is unmaintained and lacks proper type-hinting | None | Impossible
119
+ | pyduktape2 | No | Small | somewhat fast but the backend is unmaintained and lacks proper type-hinting | Because this one didn't have that and my pull requests kept being laid dormant I wrote __pyduktape3__ | can't be done
120
+ | [pyduktape3](https://github.com/Vizonex/pyduktape3) | No | Small | Very fast but the backend made by me but the C backend is unmaintained which is why the project was soon abandoned in favor of __cyjs__ | I did add typestubs to this library. | The Last cherry on top this was cimporting pyducktape3
121
+ | strv8 | I haven't tried this one yet (Might be due to lack of windows support but I don't remeber) | Large due to V8 | Probably very fast becuase v8 is built by google. | I don't know, I sure hope a project like this has that. | I haven't seen the sourcecode yet...
122
+
123
+
124
+
125
+ ## How to Contribute
126
+ There's a few things I didn't get to becuase they are more or less puzzles to implement than they need to be
127
+ but if anybody can figure these out feel free to fork and send a pull request along with a test added to pytest
128
+ for eatch to ensure it works correctly. I may be uploading this library to pypi after the other things are implemented but these seem more of a chore for me to solve than really anything else.
129
+
130
+ - [ ] If anybody finds a smarter approch to anything that has already been written throw me an issue or pull request.
131
+
132
+ - [ ] Reporting and fixing bugs.
133
+
134
+ - [ ] JSCFunction I haven't figured out a good solution for this one just yet since I'm trying to limit the number of cdef classes to keep the code small and easy to compile. We need a way to bind an opaque Python Object and trying the old quickjs method seems to trigger crashes (believe me when I say I tried doing that already).
135
+
136
+ - [ ] JSClass cdef class extension that can be subclassed in python and cython along with the hooks for all the JSClassExoticMethods (we need an approch to passing off a cdef class as an opaque value which I have not figured out how to do yet)
137
+ - [ ] JSClassFinalizer Hook
138
+ - [ ] JSClassGCMark Hook
139
+ - [ ] A safe approch for handling JSClass to python object conversion and vice versa (if possible)
140
+
141
+
cyjs-0.1.0/README.md ADDED
@@ -0,0 +1,131 @@
1
+ <img src="cyjs-logo.png" style="width: 30%;"/>
2
+
3
+ ------
4
+ # CYJS
5
+
6
+ ECMAScript interpreter for Cython & Python built for
7
+ - Solving & Decrypting Annoying Puzzles and Captchas at immense speeds.
8
+ - Calling upon different Javascript libraries Examples might include:
9
+ - llparse (Even though I maintain a python version but you could easily call upon llparse from javascript using this extension)
10
+ - yt-dlp-ejs (Decrypting challenges might take a while but that was why I wrote this library so we could start optimizing these things
11
+ )
12
+ - Being tiny and easy to use
13
+ - Having ECMA6 Support
14
+ - Having a maintained backend (QuickJS-NG)
15
+ - Being a good companion alongside [selectolax](https://github.com/rushter/selectolax) or beautiful-soup the choice is yours...
16
+ - License friendly, after abandoning pyduktape due to the backend no longer being maintained but also having a pretty poor license all together, It inspired me to try something new for a change that could run newer HTML5 Javascript for any puzzle that is thrown your way.
17
+
18
+ ## Quick Example
19
+
20
+
21
+ ```python
22
+ from cyjs import Context, Runtime
23
+
24
+
25
+ def main():
26
+ # You can also provide a runtime if needed it's usage before making multiple contexts however
27
+ # is completely optional
28
+ rt = Runtime()
29
+
30
+ ctx = Context(rt)
31
+
32
+ ctx.eval("function add(a, b){ return a + b; }; globalThis.add = add;")
33
+ add_func = ctx.get_global().get("add")
34
+
35
+ # 3
36
+ print(add_func(1, 2))
37
+
38
+ if __name__ == "__main__":
39
+ main()
40
+ ```
41
+
42
+ Example of use with external html parser tools.
43
+
44
+ ```python
45
+ from cyjs import Context
46
+ from selectolax.lexbor import LexborHTMLParser
47
+
48
+ # This example demonstates ways of cracking javascript out of webpages
49
+ # with an expernal HTML Parser and cyjs to handle the javascript logic.
50
+
51
+ # Know that A True HTML5 Dom-API Might require you to make your own
52
+ # functions and imagination but also reverse engineering the target page.
53
+
54
+ HTML_PAGE = b"""
55
+ <!DOCTYPE html>
56
+ <html lang="en">
57
+ <head>
58
+ <meta charset="UTF-8">
59
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
60
+ <title>Document</title>
61
+ </head>
62
+ <body>
63
+ <div class="captcha">
64
+ <script>
65
+ function fake_captcha(name) {
66
+ return name + "-key";
67
+ }
68
+ </script>
69
+ <!-- Use your imagination a little... -->
70
+ </div>
71
+ <div>
72
+ <script>
73
+ this.captcha = fake_captcha('123')
74
+ </script>
75
+ </div>
76
+ </body>
77
+ </html>
78
+ """
79
+
80
+ def main():
81
+ html = LexborHTMLParser(HTML_PAGE)
82
+ captcha = html.css_first("div.captcha > script").text(strip=True)
83
+
84
+ fake_solver = Context()
85
+ fake_solver.eval(captcha + "\nglobalThis.fake_captcha = fake_captcha;")
86
+ result = fake_solver.get_global().invoke("fake_captcha", "123")
87
+ # should print
88
+ # "123-key"
89
+ print(result)
90
+
91
+ if __name__ == "__main__":
92
+ main()
93
+
94
+ ```
95
+
96
+ There will be more examples in a future update.
97
+
98
+
99
+
100
+
101
+
102
+ ## Alternative Python Javascript Interpreters
103
+
104
+ | Library | ECMA-6 Support | Size | Performance | Typestubs And Readability | Cython cimportable |
105
+ |---------|-----------------------------------|------|-------------|-----------|----|
106
+ | [js2py](https://github.com/PiotrDabkowski/Js2Py) | has to translate ECMA6 to 5 | Medium | Decent at ECMA5 and html5 scripts that use Emca-5 but starts suffering when trying to do ECMA-6 | Lacks proper typehinting making everything into an unwanted guessing game | No and it's pure python
107
+ | [quickjs (python library)](https://github.com/PetterS/quickjs) | Yes | Small | Has to convert some objects back and forth but lacks typestubs and documentation | Lacks typestubs | CPython Extension that could've used a C-API Capsule to help it gain a bit of lubricant with other projects.
108
+ | pyduktape | No | Small | somewhat fast but the backend is unmaintained and lacks proper type-hinting | None | Impossible
109
+ | pyduktape2 | No | Small | somewhat fast but the backend is unmaintained and lacks proper type-hinting | Because this one didn't have that and my pull requests kept being laid dormant I wrote __pyduktape3__ | can't be done
110
+ | [pyduktape3](https://github.com/Vizonex/pyduktape3) | No | Small | Very fast but the backend made by me but the C backend is unmaintained which is why the project was soon abandoned in favor of __cyjs__ | I did add typestubs to this library. | The Last cherry on top this was cimporting pyducktape3
111
+ | strv8 | I haven't tried this one yet (Might be due to lack of windows support but I don't remeber) | Large due to V8 | Probably very fast becuase v8 is built by google. | I don't know, I sure hope a project like this has that. | I haven't seen the sourcecode yet...
112
+
113
+
114
+
115
+ ## How to Contribute
116
+ There's a few things I didn't get to becuase they are more or less puzzles to implement than they need to be
117
+ but if anybody can figure these out feel free to fork and send a pull request along with a test added to pytest
118
+ for eatch to ensure it works correctly. I may be uploading this library to pypi after the other things are implemented but these seem more of a chore for me to solve than really anything else.
119
+
120
+ - [ ] If anybody finds a smarter approch to anything that has already been written throw me an issue or pull request.
121
+
122
+ - [ ] Reporting and fixing bugs.
123
+
124
+ - [ ] JSCFunction I haven't figured out a good solution for this one just yet since I'm trying to limit the number of cdef classes to keep the code small and easy to compile. We need a way to bind an opaque Python Object and trying the old quickjs method seems to trigger crashes (believe me when I say I tried doing that already).
125
+
126
+ - [ ] JSClass cdef class extension that can be subclassed in python and cython along with the hooks for all the JSClassExoticMethods (we need an approch to passing off a cdef class as an opaque value which I have not figured out how to do yet)
127
+ - [ ] JSClassFinalizer Hook
128
+ - [ ] JSClassGCMark Hook
129
+ - [ ] A safe approch for handling JSClass to python object conversion and vice versa (if possible)
130
+
131
+
@@ -0,0 +1,24 @@
1
+ from ._cyjs import (
2
+ CancelledError,
3
+ Context,
4
+ JSError,
5
+ JSFunction,
6
+ Object,
7
+ Promise,
8
+ PromiseHookType,
9
+ Runtime,
10
+ )
11
+
12
+ __author__ = "Vizonex"
13
+ __version__ = "0.1.0"
14
+
15
+ __all__ = (
16
+ "CancelledError",
17
+ "Context",
18
+ "JSError",
19
+ "JSFunction",
20
+ "Object",
21
+ "Promise",
22
+ "PromiseHookType",
23
+ "Runtime",
24
+ )