├── .editorconfig
├── .gitignore
├── AUTHORS
├── AndroidManifest.xml
├── CONTRIBUTING.md
├── LICENSE
├── MANIFEST.in
├── README.rst
├── beekeeper.yml
├── build-android.xml
├── build-java.xml
├── build.xml
├── checkstyle.xml
├── docs
├── Makefile
├── background
│ ├── community.rst
│ ├── faq.rst
│ ├── index.rst
│ ├── install.rst
│ ├── releases.rst
│ └── roadmap.rst
├── conf.py
├── how-to
│ ├── contribute-code.rst
│ ├── contribute-docs.rst
│ ├── development-env.rst
│ ├── index.rst
│ └── release_process.rst
├── index.rst
├── make.bat
├── reference
│ ├── differences.rst
│ ├── index.rst
│ ├── signatures.rst
│ └── typesystem.rst
├── requirements_rtd.txt
├── spelling_wordlist
└── tutorial
│ ├── index.rst
│ ├── tutorial-0.rst
│ └── tutorial-1.rst
├── lib
└── checkstyle-6.19-all.jar
├── python
├── android
│ └── python
│ │ └── _platform
│ │ ├── AndroidPlatform.java
│ │ └── LogStream.java
├── common
│ ├── org
│ │ ├── Python.java
│ │ └── python
│ │ │ ├── Attribute.java
│ │ │ ├── Callable.java
│ │ │ ├── Class.java
│ │ │ ├── ImportLib.java
│ │ │ ├── Method.java
│ │ │ ├── Module.java
│ │ │ ├── Object.java
│ │ │ ├── exceptions
│ │ │ ├── ArithmeticError.java
│ │ │ ├── AssertionError.java
│ │ │ ├── AttributeError.java
│ │ │ ├── BaseException.java
│ │ │ ├── BlockingIOError.java
│ │ │ ├── BrokenPipeError.java
│ │ │ ├── BufferError.java
│ │ │ ├── BytesWarning.java
│ │ │ ├── ChildProcessError.java
│ │ │ ├── ConnectionAbortedError.java
│ │ │ ├── ConnectionError.java
│ │ │ ├── ConnectionRefusedError.java
│ │ │ ├── ConnectionResetError.java
│ │ │ ├── DeprecationWarning.java
│ │ │ ├── EOFError.java
│ │ │ ├── Exception.java
│ │ │ ├── FileExistsError.java
│ │ │ ├── FileNotFoundError.java
│ │ │ ├── FloatingPointError.java
│ │ │ ├── FutureWarning.java
│ │ │ ├── GeneratorExit.java
│ │ │ ├── ImportError.java
│ │ │ ├── ImportWarning.java
│ │ │ ├── IndentationError.java
│ │ │ ├── IndexError.java
│ │ │ ├── InterruptedError.java
│ │ │ ├── IsADirectoryError.java
│ │ │ ├── KeyError.java
│ │ │ ├── KeyboardInterrupt.java
│ │ │ ├── LookupError.java
│ │ │ ├── MemoryError.java
│ │ │ ├── NameError.java
│ │ │ ├── NotADirectoryError.java
│ │ │ ├── NotImplementedError.java
│ │ │ ├── OSError.java
│ │ │ ├── OverflowError.java
│ │ │ ├── PendingDeprecationWarning.java
│ │ │ ├── PermissionError.java
│ │ │ ├── ProcessLookupError.java
│ │ │ ├── ReferenceError.java
│ │ │ ├── ResourceWarning.java
│ │ │ ├── RuntimeError.java
│ │ │ ├── RuntimeWarning.java
│ │ │ ├── StandardError.java
│ │ │ ├── StopIteration.java
│ │ │ ├── SyntaxError.java
│ │ │ ├── SyntaxWarning.java
│ │ │ ├── SystemError.java
│ │ │ ├── SystemExit.java
│ │ │ ├── TabError.java
│ │ │ ├── TimeoutError.java
│ │ │ ├── TypeError.java
│ │ │ ├── UnboundLocalError.java
│ │ │ ├── UnicodeDecodeError.java
│ │ │ ├── UnicodeEncodeError.java
│ │ │ ├── UnicodeError.java
│ │ │ ├── UnicodeTranslateError.java
│ │ │ ├── UnicodeWarning.java
│ │ │ ├── UserWarning.java
│ │ │ ├── ValueError.java
│ │ │ ├── Warning.java
│ │ │ └── ZeroDivisionError.java
│ │ │ ├── internals
│ │ │ └── Scope.java
│ │ │ ├── java
│ │ │ ├── Field.java
│ │ │ ├── Function.java
│ │ │ ├── Method.java
│ │ │ ├── Module.java
│ │ │ ├── Object.java
│ │ │ └── Type.java
│ │ │ ├── stdlib
│ │ │ ├── _io
│ │ │ │ └── TextIOWrapper.java
│ │ │ ├── collections
│ │ │ │ ├── DefaultDict.java
│ │ │ │ ├── OrderedDict.java
│ │ │ │ ├── OrderedDictItems.java
│ │ │ │ ├── OrderedDictKeys.java
│ │ │ │ ├── OrderedDictValues.java
│ │ │ │ └── OrderedDict_Iterator.java
│ │ │ ├── sys
│ │ │ │ └── VersionInfo.java
│ │ │ └── time
│ │ │ │ └── Namespace.java
│ │ │ └── types
│ │ │ ├── Bool.java
│ │ │ ├── ByteArray.java
│ │ │ ├── Bytes.java
│ │ │ ├── Closure.java
│ │ │ ├── Code.java
│ │ │ ├── Complex.java
│ │ │ ├── ContextManager.java
│ │ │ ├── Dict.java
│ │ │ ├── DictItems.java
│ │ │ ├── DictKeys.java
│ │ │ ├── DictValues.java
│ │ │ ├── DictValues_Iterator.java
│ │ │ ├── DictView.java
│ │ │ ├── Dict_KeyIterator.java
│ │ │ ├── Ellipsis.java
│ │ │ ├── Filter.java
│ │ │ ├── Float.java
│ │ │ ├── FrozenSet.java
│ │ │ ├── Function.java
│ │ │ ├── Generator.java
│ │ │ ├── Int.java
│ │ │ ├── Iterator.java
│ │ │ ├── List.java
│ │ │ ├── List_Iterator.java
│ │ │ ├── List_ReverseIterator.java
│ │ │ ├── Map.java
│ │ │ ├── MemoryView.java
│ │ │ ├── Method.java
│ │ │ ├── Module.java
│ │ │ ├── NoneType.java
│ │ │ ├── NotImplementedType.java
│ │ │ ├── Object.java
│ │ │ ├── PlaceholderType.java
│ │ │ ├── Property.java
│ │ │ ├── Range.java
│ │ │ ├── ReverseIterator.java
│ │ │ ├── Reversed.java
│ │ │ ├── Set.java
│ │ │ ├── Set_Iterator.java
│ │ │ ├── SimpleNamespace.java
│ │ │ ├── Slice.java
│ │ │ ├── Str.java
│ │ │ ├── Super.java
│ │ │ ├── Tuple.java
│ │ │ ├── Tuple_Iterator.java
│ │ │ └── Type.java
│ └── python
│ │ ├── PlatformInterface.java
│ │ ├── _io.java
│ │ ├── collections.java
│ │ ├── importlib.java
│ │ ├── os.java
│ │ ├── platform.java
│ │ ├── sys.java
│ │ ├── time.java
│ │ └── types.java
├── java
│ └── python
│ │ └── _platform
│ │ └── JavaPlatform.java
├── testdaemon
│ └── python
│ │ └── testdaemon
│ │ ├── JoinClassLoader.java
│ │ └── TestDaemon.java
└── testfile.class
├── requirements
├── docs.txt
└── tests.txt
├── setup.cfg
├── setup.py
├── stdlib_tests
├── test_argparse.py
├── test_base64.py
├── test_bisect.py
├── test_calendar.py
├── test_chunk.py
├── test_colorsys.py
├── test_datetime.py
├── test_decimal.py
├── test_ipaddress.py
├── test_itertools.py
├── test_json.py
├── test_keyword.py
├── test_operator.py
├── test_textwrap.py
├── test_this.py
├── test_types.py
├── test_urllib.py
└── test_warnings.py
├── tests
├── __init__.py
├── benchmarks
│ ├── binary-trees.py
│ ├── call_simple.py
│ ├── pystone.py
│ └── unpack_sequence.py
├── builtins
│ ├── __init__.py
│ ├── test_abs.py
│ ├── test_all.py
│ ├── test_any.py
│ ├── test_ascii.py
│ ├── test_bin.py
│ ├── test_bool.py
│ ├── test_bytearray.py
│ ├── test_bytes.py
│ ├── test_callable.py
│ ├── test_chr.py
│ ├── test_classmethod.py
│ ├── test_compile.py
│ ├── test_complex.py
│ ├── test_delattr.py
│ ├── test_dict.py
│ ├── test_dir.py
│ ├── test_divmod.py
│ ├── test_enumerate.py
│ ├── test_eval.py
│ ├── test_exec.py
│ ├── test_filter.py
│ ├── test_float.py
│ ├── test_format.py
│ ├── test_frozenset.py
│ ├── test_getattr.py
│ ├── test_globals.py
│ ├── test_hasattr.py
│ ├── test_hash.py
│ ├── test_help.py
│ ├── test_hex.py
│ ├── test_id.py
│ ├── test_import.py
│ ├── test_input.py
│ ├── test_int.py
│ ├── test_isinstance.py
│ ├── test_issubclass.py
│ ├── test_iter.py
│ ├── test_len.py
│ ├── test_list.py
│ ├── test_locals.py
│ ├── test_map.py
│ ├── test_max.py
│ ├── test_memoryview.py
│ ├── test_min.py
│ ├── test_next.py
│ ├── test_object.py
│ ├── test_oct.py
│ ├── test_open.py
│ ├── test_ord.py
│ ├── test_pow.py
│ ├── test_print.py
│ ├── test_property.py
│ ├── test_range.py
│ ├── test_repr.py
│ ├── test_reversed.py
│ ├── test_round.py
│ ├── test_set.py
│ ├── test_setattr.py
│ ├── test_slice.py
│ ├── test_sorted.py
│ ├── test_staticmethod.py
│ ├── test_str.py
│ ├── test_sum.py
│ ├── test_super.py
│ ├── test_tuple.py
│ ├── test_type.py
│ ├── test_vars.py
│ └── test_zip.py
├── datatypes
│ ├── __init__.py
│ ├── test_NoneType.py
│ ├── test_NotImplemented.py
│ ├── test_bool.py
│ ├── test_bytearray.py
│ ├── test_bytes.py
│ ├── test_complex.py
│ ├── test_dict.py
│ ├── test_float.py
│ ├── test_frozenset.py
│ ├── test_int.py
│ ├── test_list.py
│ ├── test_object.py
│ ├── test_range.py
│ ├── test_set.py
│ ├── test_slice.py
│ ├── test_str.py
│ └── test_tuple.py
├── microbenchmarks.py
├── stdlib
│ ├── __init__.py
│ ├── test_collections.py
│ ├── test_os.py
│ ├── test_sys.py
│ └── test_time.py
├── structures
│ ├── __init__.py
│ ├── test_SimpleNamespace.py
│ ├── test_assert.py
│ ├── test_assignment.py
│ ├── test_class.py
│ ├── test_closure.py
│ ├── test_comparisons.py
│ ├── test_decorators.py
│ ├── test_delete.py
│ ├── test_descriptor.py
│ ├── test_dict_comprehension.py
│ ├── test_docstrings.py
│ ├── test_exception.py
│ ├── test_extends.py
│ ├── test_for.py
│ ├── test_function.py
│ ├── test_generator.py
│ ├── test_if_elif_else.py
│ ├── test_import.py
│ ├── test_interface.py
│ ├── test_iterator.py
│ ├── test_java.py
│ ├── test_list_comprehension.py
│ ├── test_methods.py
│ ├── test_nonlocal.py
│ ├── test_return.py
│ ├── test_scope.py
│ ├── test_sequences.py
│ ├── test_set_comprehension.py
│ ├── test_try_catch.py
│ ├── test_while.py
│ └── test_with.py
├── test_benchmarks.py
├── test_codecs.py
├── test_large_code.py
├── test_utils.py
└── utils.py
├── tools
├── build_stdlib_report.py
├── compile_stdlib.py
└── upload.py
└── voc
├── __init__.py
├── __main__.py
├── java
├── __init__.py
├── __main__.py
├── attributes.py
├── constants.py
├── fields.py
├── klass.py
├── methods.py
├── mutf_8.py
├── opcodes.py
└── signatures.py
├── python
├── __init__.py
├── ast.py
├── blocks.py
├── debug.py
├── klass.py
├── methods.py
├── modules.py
├── structures.py
└── types
│ ├── __init__.py
│ ├── java.py
│ ├── primitives.py
│ └── python.py
└── transpiler.py
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig is awesome: http://EditorConfig.org
2 |
3 | # top-most EditorConfig file
4 | root = true
5 |
6 | # Unix-style newlines with a newline ending every file,
7 | # with 4 space indentation
8 | [*]
9 | end_of_line = lf
10 | insert_final_newline = true
11 | indent_style = space
12 | indent_size = 4
13 |
14 | # Set default charset
15 | [*.py]
16 | charset = utf-8
17 |
18 | # Override for tab indentation in Makefiles
19 | [Makefile]
20 | indent_style = tab
21 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.pyc
2 | *~
3 | .*.sw[op]
4 | *.egg-info
5 | dist
6 | build
7 | local
8 | local.properties
9 | distribute-*
10 | tests/temp
11 | /org
12 | /docs/_build
13 | .project
14 | .pydevproject
15 | tests/tmp*
16 | .cache/
17 | .env
18 | /stdlib_tests/*.class
19 | /stdlib_tests/python
20 | /python/*.class
21 |
22 | .DS_Store
23 | .idea/
24 | .vscode
--------------------------------------------------------------------------------
/AUTHORS:
--------------------------------------------------------------------------------
1 | VOC was originally created in August 2015.
2 |
3 | The PRIMARY AUTHORS are (and/or have been):
4 | Russell Keith-Magee
5 |
6 | And here is an inevitably incomplete list of MUCH-APPRECIATED CONTRIBUTORS --
7 | people who have submitted patches, reported bugs, added translations, helped
8 | answer newbie questions, and generally made VOC that much better:
9 |
10 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | BeeWare <3's contributions!
4 |
5 | Please be aware, BeeWare operates under a Code of Conduct.
6 |
7 | See [CONTRIBUTING to BeeWare](https://beeware.org/contributing) for details.
8 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2015 Russell Keith-Magee.
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without modification,
5 | are permitted provided that the following conditions are met:
6 |
7 | 1. Redistributions of source code must retain the above copyright notice,
8 | this list of conditions and the following disclaimer.
9 |
10 | 2. Redistributions in binary form must reproduce the above copyright
11 | notice, this list of conditions and the following disclaimer in the
12 | documentation and/or other materials provided with the distribution.
13 |
14 | 3. Neither the name of VOC nor the names of its contributors may
15 | be used to endorse or promote products derived from this software without
16 | specific prior written permission.
17 |
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/MANIFEST.in:
--------------------------------------------------------------------------------
1 | include README.rst
2 | include AUTHORS
3 | include LICENSE
4 | include Makefile
5 | include requirements*.txt
6 | include *.properties
7 | include *.xml
8 | recursive-include voc *.py
9 | recursive-include docs *.bat
10 | recursive-include docs *.png
11 | recursive-include docs *.py
12 | recursive-include docs *.rst
13 | recursive-include docs Makefile
14 | recursive-include tests *.py
15 | recursive-include python *.java
16 |
17 |
--------------------------------------------------------------------------------
/beekeeper.yml:
--------------------------------------------------------------------------------
1 | pull_request:
2 | - beefore:
3 | name: Prebuild checks
4 | subtasks:
5 | - pycodestyle:
6 | name: Python lint checks
7 | image: pybee/beefore
8 | - javacheckstyle:
9 | name: Java lint checks
10 | image: pybee/beefore-java
11 | - smoke-test:
12 | image: pybee/voc-py34
13 | name: Smoke build (Python 3.4)
14 | profile: hi-cpu
15 | - full-test:
16 | subtasks:
17 | - py3.5:
18 | name: Python 3.5 tests
19 | image: pybee/voc-py35
20 | - py3.6:
21 | name: Python 3.6 tests
22 | image: pybee/voc-py36
23 | - py3.7:
24 | name: Python 3.7 tests
25 | image: pybee/voc-py37
26 | profile: hi-cpu
27 | push:
28 | - smoke-test:
29 | image: pybee/voc-py34
30 | name: Smoke build (Python 3.4)
31 | profile: hi-cpu
32 |
--------------------------------------------------------------------------------
/build-android.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
19 |
20 |
21 |
22 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
45 |
46 |
49 |
50 | Python version: ${python-version}
51 | Build: ${release}
52 |
53 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/build-java.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Build Python support libraries for voc
4 |
5 |
6 |
7 |
8 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
43 |
44 |
47 |
48 |
49 |
50 |
51 |
52 |
54 |
55 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Build Python support libraries for voc
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/docs/background/community.rst:
--------------------------------------------------------------------------------
1 | The VOC Developer and User community
2 | ====================================
3 |
4 | .. note::
5 | If you're a newcomer to the project looking for how to start contributing,
6 | check out the `First Timers Guide`_.
7 |
8 | VOC is part of the `BeeWare suite`_. You can talk to the community through:
9 |
10 | * `@pybeeware on Twitter`_
11 |
12 | * `Our Gitter channel`_ for discussion about development and general help around this project or anything under the BeeWare suite of projects.
13 |
14 | Code of Conduct
15 | ---------------
16 |
17 | The BeeWare community has a strict `Code of Conduct`_. All users and developers are expected to adhere to this code.
18 |
19 | If you have any concerns about this code of conduct, or you wish to report a violation of this code, please contact the project founder `Russell Keith-Magee`.
20 |
21 | Contributing
22 | ------------
23 |
24 | If you experience problems with VOC, `log them on GitHub`_. If you
25 | want to contribute code, please `fork the code`_ and `submit a pull request`_.
26 |
27 | .. _BeeWare suite: https://beeware.org
28 | .. _Read The Docs: https://voc.readthedocs.io
29 | .. _@pybeeware on Twitter: https://twitter.com/pybeeware
30 | .. _Our Gitter channel: https://gitter.im/beeware/general
31 | .. _log them on Github: https://github.com/beeware/voc/issues
32 | .. _fork the code: https://github.com/beeware/voc
33 | .. _submit a pull request: https://github.com/beeware/voc/pulls
34 |
35 | .. _Code of Conduct: https://beeware.org/community/behavior/code-of-conduct/
36 | .. _Russell Keith-Magee: mailto:russell@keith-magee.com
37 | .. _First Timers Guide: https://voc.readthedocs.io/en/latest/how-to/contribute-code.html
38 |
--------------------------------------------------------------------------------
/docs/background/index.rst:
--------------------------------------------------------------------------------
1 | .. _background:
2 |
3 | =========
4 | About VOC
5 | =========
6 |
7 | VOC is a transpiler that takes Python 3.4+ source code, and compiles it into a
8 | Java class file that can then be executed on a JVM.
9 |
10 | It honors Python 3.4+ syntax and conventions, but also provides the ability to
11 | reference objects and classes defined in Java code, and implement interfaces
12 | defined in Java code.
13 |
14 | .. toctree::
15 | :maxdepth: 1
16 | :glob:
17 |
18 | community
19 | faq
20 | install
21 | releases
22 | roadmap
23 |
--------------------------------------------------------------------------------
/docs/background/install.rst:
--------------------------------------------------------------------------------
1 | ============
2 | Installation
3 | ============
4 |
5 | In this guide we will walk you through setting up your VOC environment for
6 | development and testing. We will assume that you have Python 3.4 or 3.5, Java 7 or Java 8 JDK,
7 | and Apache ANT installed.
8 |
9 | Checking Dependencies
10 | ---------------------
11 |
12 | To check if you have Python installed, run ``python --version`` at the command line
13 |
14 | .. code-block:: bash
15 |
16 | $ python3 --version
17 | Python 3.4.4
18 |
19 | If you do not have Python 3.4 or newer `install Python `_ and check again.
20 |
21 | To check if you have the JDK installed, run ``javac -version``
22 |
23 | .. code-block:: bash
24 |
25 | $ javac -version
26 | javac 1.7.0_101
27 |
28 | If you do not have at least Java 7 `install Java `_ and check again.
29 |
30 | To check if Apache ANT is installed, run ``ant -version``
31 |
32 | .. code-block:: bash
33 |
34 | $ ant -version
35 | Apache Ant(TM) version 1.9.7 compiled on April 24 2016
36 |
37 | If Apache Ant is not installed, look for the binary file from `Apache `_ to download the latest version.
38 |
39 | Get a copy of VOC
40 | -----------------
41 |
42 | The first step is to create a project directory, and clone VOC:
43 |
44 | .. code-block:: bash
45 |
46 | $ mkdir tutorial
47 | $ cd tutorial
48 | $ git clone https://github.com/beeware/voc.git
49 |
50 | Then create a virtual environment and install VOC into it:
51 |
52 | .. code-block:: bash
53 |
54 | $ python3 -m venv env
55 | $ . env/bin/activate
56 | $ cd voc
57 | $ pip install -e .
58 |
59 | For Windows the use of cmd under Administrator permission is suggested instead of PowerShell.
60 |
61 | .. code-block:: bash
62 |
63 | > py -3 -m venv env
64 | > env\Scripts\activate.bat
65 | > cd voc
66 | > pip install -e .
67 |
68 |
69 |
70 | Building the support JAR file
71 | -----------------------------
72 |
73 | Next, you need to build the Python support file:
74 |
75 | .. code-block:: bash
76 |
77 | $ ant java
78 |
79 | This should create a ``dist/python-java-support.jar`` file. This JAR
80 | file is a support library that implements Python-like behavior and
81 | provides the Python standard library for the Java environment. This
82 | JAR file must be included on the classpath for any VOC-generated
83 | project.
84 |
85 | Next Steps
86 | ----------
87 |
88 | You now have a working VOC environment, so you can :doc:`start the first
89 | tutorial `.
90 |
--------------------------------------------------------------------------------
/docs/background/releases.rst:
--------------------------------------------------------------------------------
1 | Release History
2 | ===============
3 |
4 | 0.1.6
5 | -----
6 |
7 | * Major speed improvements in generated code
8 | * Improvements to generator handling
9 | * Improvements to exception handling
10 | * Added support for `yield from`
11 |
12 | 0.1.5
13 | -----
14 |
15 | * Added support for if conditions in list comprehensions
16 | * Added support for printf-style formatting
17 | * Several fixes for arguments handling and operations with numbers
18 | * Many bugfixes and improvements to docs, tests and error messages
19 | * Added implementations for many builtin functions and type methods
20 | * VOC jar library now ships with the stdlib modules that it already compiles
21 |
22 |
23 | 0.1.4
24 | -----
25 |
26 | * Added support for self-assignment for attributes and subscript
27 | * Added support for multiple comparison
28 | * Improved support for slices
29 | * Many bugfixes and improvements to docs and tests
30 | * Added implementations for many builtin functions and type methods
31 | * VOC is now tested in Python 3.6, and uses BeeKeeper for CI
32 |
33 | 0.1.3
34 | -----
35 |
36 | Progress release. VOC is able to run Toga tutorials on Android.
37 |
38 | 0.1.2
39 | -----
40 |
41 | Progress release. VOC is able to compile the Toga and Colosseum libraries.
42 |
43 | 0.1.1
44 | -----
45 |
46 | Switched approach to parse Python code with ``ast`` instead of transpiling
47 | CPython bytecode.
48 |
49 | Many bugs fixed.
50 |
51 | 0.1.0
52 | -----
53 |
54 | Progress release. VOC is currently able to compile a simple working Android
55 | application.
56 |
57 | 0.0.1
58 | -----
59 |
60 | Initial public release.
61 |
--------------------------------------------------------------------------------
/docs/background/roadmap.rst:
--------------------------------------------------------------------------------
1 | VOC Roadmap
2 | ===========
3 |
4 | VOC is a new project - we have lots of things that we'd like to do. If
5 | you'd like to contribute, providing a patch for one of these features:
6 |
7 | * Port a set of basic type operations
8 |
9 | * Implement a Python standard library module for
10 |
11 | * Implement StackMapFrames for the generated Java class files.
12 |
13 | * Work out how to run the CPython test suite with VOC
14 |
--------------------------------------------------------------------------------
/docs/how-to/contribute-docs.rst:
--------------------------------------------------------------------------------
1 | Contributing to VOC's documentation
2 | ===================================
3 |
4 | Here are some tips for working on this documentation. You're welcome to add
5 | more and help us out!
6 |
7 | First of all, you should check the `Restructured Text (reST) and Sphinx
8 | CheatSheet `_ to
9 | learn how to write your .rst file.
10 |
11 | To create a .rst file
12 | ---------------------
13 |
14 | Look at the structure and choose the best category to put your .rst file. Make
15 | sure that it is referenced in the index of the corresponding category, so it
16 | will show on in the documentation. If you have no idea how to do this, study
17 | the other index files for clues.
18 |
19 |
20 | To build locally on GNU/Linux and open it on the browser:
21 | ---------------------------------------------------------
22 |
23 | Go to the documentation folder: ::
24 |
25 | $ cd docs
26 |
27 | Install Sphinx with the helpers and extensions we use: ::
28 |
29 | $ pip install -r requirements_rtd.txt
30 |
31 | Create the static files: ::
32 |
33 | $ make html
34 |
35 | Check for any errors and,if possible, fix them. The output of the file should
36 | be in the ``_build/html`` folder. Open the file you changed in the browser.
37 |
--------------------------------------------------------------------------------
/docs/how-to/index.rst:
--------------------------------------------------------------------------------
1 | .. _how-to:
2 |
3 | =============
4 | How-to guides
5 | =============
6 |
7 | How-to guides are recipes that take the user through steps in key subjects.
8 | They are more advanced than tutorials and assume a lot more about what the user
9 | already knows than tutorials do, and unlike documents in the tutorial they can
10 | stand alone.
11 |
12 | .. toctree::
13 | :maxdepth: 1
14 | :glob:
15 |
16 | development-env
17 | contribute-code
18 | contribute-docs
19 | Release a new version of VOC
20 |
--------------------------------------------------------------------------------
/docs/how-to/release_process.rst:
--------------------------------------------------------------------------------
1 | Release Process
2 | ===============
3 |
4 | .. note:: For Developers Only!
5 |
6 | This guide is provided for the benefit of the VOC team. As an end user,
7 | you shouldn't ever need to use these instructions.
8 |
9 | So, it's time for a new VOC release! Here's how to publish a new version so
10 | others can benefit from the changes that have been made recently.
11 |
12 | 1. Update local checkout
13 |
14 | Make sure your developer checkout of VOC is up to date with a::
15 |
16 | $ git pull
17 |
18 | 2. Confirm that the trunk currently builds for JDK and Android on each version
19 | of Python you're planning to support::
20 |
21 | $ ant clean
22 | $ ant
23 |
24 | Fix any problems that are identified
25 |
26 | 3. Make release related changes
27 |
28 | * **Release history** in ``docs/background/releases.rst``
29 | * **Build number** in ``build.xml``
30 | * **Version number** in ``voc/__init__.py``
31 |
32 | 4. Push to Github to get confirmation of a clean CI build.
33 |
34 | 5. When CI passes, merge.
35 |
36 | 6. Update your checkout of the main ``beeware/voc`` repository
37 |
38 | 7. Tag the release. There is a version tag for VOC, plus tags for each
39 | of the support libraries that will be released::
40 |
41 | $ git tag v0.1.2
42 | $ git tag 3.4-b3
43 | $ git tag 3.5-b3
44 | $ git tag 3.6-b3
45 | $ git push —tags
46 |
47 | 8. Build the PyPI packages::
48 |
49 | $ python setup.py sdist bdist_wheel
50 |
51 | 9. Upload the PyPI packages::
52 |
53 | $ twine upload dist/voc-0.1.2*
54 |
55 | 10. Check that you have AWS credentials in a file named ``.env`` file in the
56 | root directory of your project checkout::
57 |
58 | AWS_ACCESS_KEY_ID=...
59 | AWS_SECRET_ACCESS_KEY=...
60 | AWS_REGION=us-west-2
61 |
62 | 11. Upload the support zipfile to S3::
63 |
64 | $ python tools/upload b3
65 |
66 | 11. Check that Read The Docs has updated.
67 |
--------------------------------------------------------------------------------
/docs/index.rst:
--------------------------------------------------------------------------------
1 | .. raw:: html
2 |
3 |
26 |
27 |
28 | ===
29 | VOC
30 | ===
31 |
32 | VOC is a transpiler that takes Python 3.4+ source code, and compiles it into a Java
33 | class file that can then be executed on a JVM, or run through a DEX tool to
34 | run on Android. It does this *at the bytecode level*, rather than the source code level.
35 |
36 | It honors Python 3.4+ syntax and conventions, but also provides the ability to
37 | reference objects and classes defined in Java code, and implement interfaces
38 | defined in Java code.
39 |
40 | .. rst-class:: row
41 |
42 | Table of contents
43 | =================
44 |
45 | .. rst-class:: clearfix row
46 |
47 | .. rst-class:: column column2
48 |
49 |
50 | :ref:`Tutorial `
51 | --------------------------
52 |
53 | Get started with a hands-on introduction for beginners
54 |
55 |
56 | .. rst-class:: column column2
57 |
58 | :ref:`How-to guides `
59 | -----------------------------
60 |
61 | Guides and recipes for common problems and tasks, including how to contribute
62 |
63 |
64 | .. rst-class:: column column2
65 |
66 | :ref:`Background `
67 | ------------------------------
68 |
69 | Explanation and discussion of key topics and concepts
70 |
71 |
72 | .. rst-class:: column column2
73 |
74 | :ref:`Reference `
75 | ----------------------------
76 |
77 | Technical reference - commands, modules, classes, methods
78 |
79 |
80 | .. rst-class:: clearfix row
81 |
82 | Community
83 | =========
84 |
85 | VOC is part of the `BeeWare suite`_. You can talk to the community through:
86 |
87 | * `@pybeeware on Twitter`_
88 |
89 | * `beeware/general on Gitter`_
90 |
91 | .. _BeeWare suite: https://beeware.org
92 | .. _Read The Docs: https://voc.readthedocs.io
93 | .. _@pybeeware on Twitter: https://twitter.com/pybeeware
94 | .. _beeware/general on Gitter: https://gitter.im/beeware/general
95 |
96 |
97 | .. toctree::
98 | :maxdepth: 2
99 | :hidden:
100 | :titlesonly:
101 |
102 | tutorial/index
103 | how-to/index
104 | background/index
105 | reference/index
106 |
--------------------------------------------------------------------------------
/docs/reference/differences.rst:
--------------------------------------------------------------------------------
1 | Differences between VOC and CPython
2 | ===================================
3 |
4 | StopIteration
5 | -------------
6 |
7 | A ``StopIteration`` is a signal raised by an iterator to tell whomever is
8 | iterating that there are no more items to be produced. This is used in ``for``
9 | loops, generator functions, etc. The ``org.python.exception.StopIteration``
10 | exception differs from the CPython ``StopIteration`` exception in that it is a
11 | singleton. This was introduced in `PR #811`_
12 | as part of a performance effort as it yields a non-trivial performance improvement
13 | for nested ``for`` loops. However, it also means that an equality comparison
14 | between two ``StopIteration`` exceptions will always be ``True``, which is not
15 | the case in CPython.
16 |
--------------------------------------------------------------------------------
/docs/reference/index.rst:
--------------------------------------------------------------------------------
1 | .. _reference:
2 |
3 | =========
4 | Reference
5 | =========
6 |
7 | This is the technical reference for public APIs provided by VOC.
8 |
9 | .. toctree::
10 | :maxdepth: 1
11 |
12 | Python signatures for Java-defined methods
13 | The VOC type system
14 | Differences between VOC and CPython
15 |
--------------------------------------------------------------------------------
/docs/requirements_rtd.txt:
--------------------------------------------------------------------------------
1 | sphinx
2 | sphinxcontrib-spelling
3 | pyenchant
4 | sphinx-autobuild
5 | sphinx_rtd_theme
6 | sphinx_tabs==1.1.8
7 |
--------------------------------------------------------------------------------
/docs/spelling_wordlist:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beeware/voc/dd9f15a7d56d00d8c9e501a57194694e601ea401/docs/spelling_wordlist
--------------------------------------------------------------------------------
/docs/tutorial/index.rst:
--------------------------------------------------------------------------------
1 | .. _tutorial:
2 |
3 | =========
4 | Tutorials
5 | =========
6 |
7 | These tutorials are step-by step guides for using VOC. They all assume that
8 | you've set up your development environment as described in :doc:`/background/install`.
9 |
10 | .. toctree::
11 | :maxdepth: 1
12 | :glob:
13 |
14 | tutorial-0
15 | tutorial-1
16 |
--------------------------------------------------------------------------------
/docs/tutorial/tutorial-0.rst:
--------------------------------------------------------------------------------
1 | Tutorial 0 - Hello, world!
2 | ==========================
3 |
4 | In this tutorial, you'll take a really simple "Hello, world!" program written in
5 | Python, convert it into a classfile, and run it on the Java Virtual Machine.
6 |
7 | Setup
8 | -----
9 |
10 | This tutorial assumes you've read and followed the instructions in
11 | :doc:`/background/install`. If you've done this, you should have:
12 |
13 | * Java 7 (or higher) installed and available on your path,
14 | * An ``env`` directory for your virtualenv
15 | * A ``tutorial`` directory with a VOC checkout,
16 | * An activated Python 3.4+ virtual environment,
17 | * VOC installed in that virtual environment,
18 | * A compiled VOC support library.
19 |
20 | Start a new project
21 | -------------------
22 |
23 | Let's start by creating a ``tutorial0`` directory in the tutorial directory alongside the ``voc`` directory you just cloned into:
24 |
25 | .. code-block:: bash
26 |
27 | $ mkdir tutorial0
28 | $ cd tutorial0
29 |
30 | So that your directory structure looks like::
31 |
32 | tutorial
33 | ├── env
34 | ├── ouroboros
35 | ├── tutorial0
36 | └── voc
37 |
38 | Then create a file called ``example.py`` in this ``tutorial0`` directory.
39 | Add the following Python code to ``example.py``:
40 |
41 | .. code-block:: python
42 |
43 | print("Hello World!")
44 |
45 | Save the file. Run VOC over this file, compiling the Python code into a Java
46 | class file:
47 |
48 | .. code-block:: bash
49 |
50 | $ voc -v example.py
51 |
52 | This runs the VOC compiler over the ``example.py`` source file. The ``-v`` flag
53 | asks VOC to use verbose output so you can see what is going on.
54 | You will see output like the following:
55 |
56 | .. code-block:: bash
57 |
58 | Compiling example.py ...
59 | Writing python/example.class ...
60 |
61 | This will produce an ``example.class`` in the ``python`` namespace.
62 | This classfile can run on any Java 6 (or higher) VM. To run the project, type:
63 |
64 | * On Linux / OS X
65 |
66 | .. code-block:: bash
67 |
68 | $ java -classpath ../voc/dist/python-java-support.jar:. python.example
69 | Hello World!
70 |
71 | * On Windows
72 |
73 | .. code-block:: bash
74 |
75 | > java -classpath ../voc/dist/python-java-support.jar;. python.example
76 | Hello World!
77 |
78 |
79 | Congratulations! You've just run your first Python program under Java using
80 | VOC! Now you're ready to get a little more adventurous.
81 |
--------------------------------------------------------------------------------
/lib/checkstyle-6.19-all.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beeware/voc/dd9f15a7d56d00d8c9e501a57194694e601ea401/lib/checkstyle-6.19-all.jar
--------------------------------------------------------------------------------
/python/android/python/_platform/AndroidPlatform.java:
--------------------------------------------------------------------------------
1 | package python._platform;
2 |
3 | import android.os.Debug;
4 |
5 | public class AndroidPlatform implements python.PlatformInterface {
6 | private org.python.stdlib._io.TextIOWrapper _stderr;
7 | private org.python.stdlib._io.TextIOWrapper _stdout;
8 | private org.python.stdlib._io.TextIOWrapper _stdin;
9 |
10 | public AndroidPlatform() {
11 | _stderr = new org.python.stdlib._io.TextIOWrapper(new LogStream(android.util.Log.ERROR, "Python", 1024));
12 | _stdout = new org.python.stdlib._io.TextIOWrapper(new LogStream(android.util.Log.INFO, "Python", 1024));
13 | // _stdin = new org.python.stdlib._io.TextIOWrapper(System.in);
14 | }
15 |
16 | public long clock() {
17 | return Debug.threadCpuTimeNanos();
18 | }
19 |
20 | public void debug(java.lang.String msg) {
21 | android.util.Log.i("Python", msg);
22 | }
23 |
24 | public void debug(java.lang.String msg, java.lang.Object obj) {
25 | android.util.Log.i("Python", msg + " " + obj);
26 | }
27 |
28 | public org.python.Object getPlatform() {
29 | return new org.python.types.Str("android");
30 | }
31 |
32 | public org.python.Object stderr() {
33 | return _stderr;
34 | }
35 |
36 | public org.python.Object stdout() {
37 | return _stdout;
38 | }
39 |
40 | public org.python.Object stdin() {
41 | return _stdin;
42 | }
43 |
44 | public org.python.Object args() {
45 | return new org.python.types.List();
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/python/android/python/_platform/LogStream.java:
--------------------------------------------------------------------------------
1 | package python._platform;
2 |
3 | public class LogStream extends java.io.OutputStream {
4 | protected java.lang.String tag;
5 | protected byte[] buf;
6 | protected int size;
7 | protected int count;
8 | protected int priority;
9 |
10 | public LogStream(int priority, java.lang.String tag, int size) {
11 | this.tag = tag;
12 | this.priority = priority;
13 | this.size = size;
14 |
15 | buf = new byte[size];
16 | }
17 |
18 | public void write(int b) {
19 | if (b != '\n') {
20 | buf[count] = (byte) b;
21 | count++;
22 | }
23 |
24 | if (b == '\n' || count == size) {
25 | android.util.Log.println(priority, tag, new java.lang.String(buf, 0, count));
26 | count = 0;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/python/common/org/python/Attribute.java:
--------------------------------------------------------------------------------
1 | package org.python;
2 |
3 | @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
4 | public @interface Attribute {
5 | }
6 |
--------------------------------------------------------------------------------
/python/common/org/python/Callable.java:
--------------------------------------------------------------------------------
1 | package org.python;
2 |
3 | public interface Callable {
4 | public org.python.Object invoke(org.python.Object[] args, java.util.Map kwargs);
5 | }
6 |
--------------------------------------------------------------------------------
/python/common/org/python/Class.java:
--------------------------------------------------------------------------------
1 | package org.python;
2 |
3 | @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
4 | public @interface Class {
5 | java.lang.String __doc__() default "";
6 | }
7 |
--------------------------------------------------------------------------------
/python/common/org/python/Method.java:
--------------------------------------------------------------------------------
1 | package org.python;
2 |
3 | @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
4 | public @interface Method {
5 | java.lang.String name() default "";
6 | java.lang.String __doc__() default "";
7 | java.lang.String[] args() default {};
8 | java.lang.String varargs() default "";
9 | java.lang.String[] default_args() default {};
10 | java.lang.String[] kwonlyargs() default {};
11 | java.lang.String kwargs() default "";
12 | }
13 |
--------------------------------------------------------------------------------
/python/common/org/python/Module.java:
--------------------------------------------------------------------------------
1 | package org.python;
2 |
3 | @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
4 | public @interface Module {
5 | java.lang.String __doc__() default "[undocumented]";
6 | }
7 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/ArithmeticError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class ArithmeticError extends org.python.exceptions.Exception {
4 | public ArithmeticError() {
5 | super();
6 | }
7 |
8 | public ArithmeticError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public ArithmeticError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/AssertionError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class AssertionError extends org.python.exceptions.Exception {
4 | public AssertionError() {
5 | super("");
6 | }
7 |
8 | public AssertionError(java.lang.String msg) {
9 | super(msg);
10 | }
11 |
12 | public AssertionError(org.python.Object msg) {
13 | super(msg.toString());
14 | }
15 |
16 | public AssertionError(org.python.Object[] args, java.util.Map kwargs) {
17 | super(args, kwargs);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/AttributeError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class AttributeError extends org.python.exceptions.Exception {
4 | public AttributeError(java.lang.String msg) {
5 | super(msg);
6 | }
7 |
8 | public AttributeError(org.python.Object obj, java.lang.String attr) {
9 | super("'" + obj.typeName() + "' object has no attribute '" + attr + "'");
10 | }
11 |
12 | public AttributeError(java.lang.Class klass, java.lang.String attr) {
13 | super("'" + org.python.types.Type.pythonType(klass).typeName() + "' object has no attribute '" + attr + "'");
14 | }
15 |
16 | public AttributeError(org.python.Object[] args, java.util.Map kwargs) {
17 | super("'" + args[0] + "' object has no attribute '" + args[1] + "'");
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/BaseException.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | @org.python.Class(
4 | __doc__ = "Common base class for all exceptions"
5 | )
6 | public class BaseException extends org.python.types.Object {
7 | @org.python.Attribute()
8 | public org.python.types.Tuple args = new org.python.types.Tuple();
9 |
10 | public BaseException() {
11 | super();
12 | }
13 |
14 | public BaseException(String msg) {
15 | super(msg);
16 | this.args.value.add(new org.python.types.Str(msg));
17 | }
18 |
19 | public BaseException(org.python.Object[] args, java.util.Map kwargs) {
20 | super();
21 | this.args = buildTuple(args);
22 | }
23 |
24 | private static org.python.types.Tuple buildTuple(org.python.Object[] args) {
25 | return new org.python.types.Tuple(java.util.Arrays.asList(args));
26 | }
27 |
28 | @org.python.Method(
29 | __doc__ = "Return repr(self)."
30 | )
31 | public org.python.Object __repr__() {
32 | if (org.Python.VERSION < 0x03070000 || this.args.value.size() != 1) {
33 | return new org.python.types.Str(this.getClass().getSimpleName() + this.args.toString());
34 | } else {
35 | return new org.python.types.Str(this.getClass().getSimpleName() + "(" + this.args.value.get(0).__repr__() + ")");
36 | }
37 | }
38 |
39 | @org.python.Method(
40 | __doc__ = "Return str(self)."
41 | )
42 | public org.python.Object __str__() {
43 | if (this.args.value.size() == 0) {
44 | return new org.python.types.Str("");
45 | } else if (this.args.value.size() == 1) {
46 | return this.args.value.get(0).__str__();
47 | }
48 | return this.args.__str__();
49 | }
50 |
51 | public java.lang.String toString() {
52 | return this.getClass().getSimpleName() + ": " + this.getMessage();
53 | }
54 |
55 | public java.lang.String getMessage() {
56 | return this.__str__().toString();
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/BlockingIOError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class BlockingIOError extends org.python.exceptions.OSError {
4 | public BlockingIOError() {
5 | super();
6 | }
7 |
8 | public BlockingIOError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public BlockingIOError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/BrokenPipeError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class BrokenPipeError extends org.python.exceptions.ConnectionError {
4 | public BrokenPipeError() {
5 | super();
6 | }
7 |
8 | public BrokenPipeError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public BrokenPipeError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/BufferError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class BufferError extends org.python.exceptions.Exception {
4 | public BufferError() {
5 | super();
6 | }
7 |
8 | public BufferError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public BufferError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/BytesWarning.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class BytesWarning extends org.python.exceptions.Warning {
4 | public BytesWarning() {
5 | super();
6 | }
7 |
8 | public BytesWarning(String msg) {
9 | super(msg);
10 | }
11 |
12 | public BytesWarning(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/ChildProcessError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class ChildProcessError extends org.python.exceptions.OSError {
4 | public ChildProcessError() {
5 | super();
6 | }
7 |
8 | public ChildProcessError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public ChildProcessError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/ConnectionAbortedError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class ConnectionAbortedError extends org.python.exceptions.ConnectionError {
4 | public ConnectionAbortedError() {
5 | super();
6 | }
7 |
8 | public ConnectionAbortedError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public ConnectionAbortedError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/ConnectionError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class ConnectionError extends org.python.exceptions.OSError {
4 | public ConnectionError() {
5 | super();
6 | }
7 |
8 | public ConnectionError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public ConnectionError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/ConnectionRefusedError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class ConnectionRefusedError extends org.python.exceptions.ConnectionError {
4 | public ConnectionRefusedError() {
5 | super();
6 | }
7 |
8 | public ConnectionRefusedError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public ConnectionRefusedError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/ConnectionResetError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class ConnectionResetError extends org.python.exceptions.ConnectionError {
4 | public ConnectionResetError() {
5 | super();
6 | }
7 |
8 | public ConnectionResetError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public ConnectionResetError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/DeprecationWarning.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class DeprecationWarning extends org.python.exceptions.Warning {
4 | public DeprecationWarning() {
5 | super();
6 | }
7 |
8 | public DeprecationWarning(String msg) {
9 | super(msg);
10 | }
11 |
12 | public DeprecationWarning(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/EOFError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class EOFError extends org.python.exceptions.Exception {
4 | public EOFError() {
5 | super();
6 | }
7 |
8 | public EOFError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public EOFError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/Exception.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class Exception extends org.python.exceptions.BaseException {
4 | public Exception() {
5 | super();
6 | }
7 |
8 | public Exception(java.lang.String msg) {
9 | super(msg);
10 | }
11 |
12 | @org.python.Method(__doc__ = "", varargs = "args")
13 | public Exception(org.python.Object[] args, java.util.Map kwargs) {
14 | super(args, kwargs);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/FileExistsError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class FileExistsError extends org.python.exceptions.OSError {
4 | public FileExistsError() {
5 | super();
6 | }
7 |
8 | public FileExistsError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public FileExistsError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/FileNotFoundError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class FileNotFoundError extends org.python.exceptions.OSError {
4 | public FileNotFoundError() {
5 | super();
6 | }
7 |
8 | public FileNotFoundError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public FileNotFoundError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/FloatingPointError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class FloatingPointError extends org.python.exceptions.ArithmeticError {
4 | public FloatingPointError() {
5 | super();
6 | }
7 |
8 | public FloatingPointError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public FloatingPointError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/FutureWarning.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class FutureWarning extends org.python.exceptions.Warning {
4 | public FutureWarning() {
5 | super();
6 | }
7 |
8 | public FutureWarning(String msg) {
9 | super(msg);
10 | }
11 |
12 | public FutureWarning(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/GeneratorExit.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class GeneratorExit extends org.python.exceptions.BaseException {
4 | public GeneratorExit() {
5 | super();
6 | }
7 |
8 | public GeneratorExit(String msg) {
9 | super(msg);
10 | }
11 |
12 | public GeneratorExit(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/ImportError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class ImportError extends org.python.exceptions.Exception {
4 | public ImportError() {
5 | super();
6 | }
7 |
8 | public ImportError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public ImportError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/ImportWarning.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class ImportWarning extends org.python.exceptions.Warning {
4 | public ImportWarning() {
5 | super();
6 | }
7 |
8 | public ImportWarning(String msg) {
9 | super(msg);
10 | }
11 |
12 | public ImportWarning(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/IndentationError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class IndentationError extends org.python.exceptions.SyntaxError {
4 | public IndentationError() {
5 | super();
6 | }
7 |
8 | public IndentationError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public IndentationError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/IndexError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class IndexError extends org.python.exceptions.LookupError {
4 | public IndexError() {
5 | super();
6 | }
7 |
8 | public IndexError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public IndexError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/InterruptedError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class InterruptedError extends org.python.exceptions.OSError {
4 | public InterruptedError() {
5 | super();
6 | }
7 |
8 | public InterruptedError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public InterruptedError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/IsADirectoryError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class IsADirectoryError extends org.python.exceptions.OSError {
4 | public IsADirectoryError() {
5 | super();
6 | }
7 |
8 | public IsADirectoryError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public IsADirectoryError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/KeyError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class KeyError extends org.python.exceptions.LookupError {
4 | public KeyError(org.python.Object[] args, java.util.Map kwargs) {
5 | super(args, kwargs);
6 | }
7 |
8 | @org.python.Method(
9 | __doc__ = "Return str(self)."
10 | )
11 | public org.python.Object __str__() {
12 | if (this.args.value.size() == 1) {
13 | return this.args.value.get(0).__repr__();
14 | }
15 | return this.args.__str__();
16 | }
17 |
18 | public KeyError(org.python.Object key) {
19 | super(new org.python.Object[] {key}, null);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/KeyboardInterrupt.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class KeyboardInterrupt extends org.python.exceptions.BaseException {
4 | public KeyboardInterrupt() {
5 | super();
6 | }
7 |
8 | public KeyboardInterrupt(String msg) {
9 | super(msg);
10 | }
11 |
12 | public KeyboardInterrupt(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/LookupError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class LookupError extends org.python.exceptions.Exception {
4 | public LookupError() {
5 | super();
6 | }
7 |
8 | public LookupError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public LookupError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/MemoryError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class MemoryError extends org.python.exceptions.Exception {
4 | public MemoryError() {
5 | super();
6 | }
7 |
8 | public MemoryError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public MemoryError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/NameError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class NameError extends org.python.exceptions.Exception {
4 | public NameError(org.python.Object var_name) {
5 | super("name '" + var_name + "' is not defined");
6 | }
7 |
8 | public NameError(java.lang.String var_name) {
9 | super("name '" + var_name + "' is not defined");
10 | }
11 |
12 | NameError(java.lang.String msg_or_var, boolean raw_msg) {
13 | super(msg_or_var);
14 | }
15 |
16 | public NameError(org.python.Object[] args, java.util.Map kwargs) {
17 | super("name '" + args[0] + "' is not defined");
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/NotADirectoryError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class NotADirectoryError extends org.python.exceptions.OSError {
4 | public NotADirectoryError() {
5 | super();
6 | }
7 |
8 | public NotADirectoryError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public NotADirectoryError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/NotImplementedError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class NotImplementedError extends org.python.exceptions.RuntimeError {
4 | public NotImplementedError() {
5 | super();
6 | }
7 |
8 | public NotImplementedError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public NotImplementedError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/OSError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class OSError extends org.python.exceptions.Exception {
4 | public OSError() {
5 | super();
6 | }
7 |
8 | public OSError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public OSError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/OverflowError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class OverflowError extends org.python.exceptions.ArithmeticError {
4 | public OverflowError() {
5 | super();
6 | }
7 |
8 | public OverflowError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public OverflowError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/PendingDeprecationWarning.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class PendingDeprecationWarning extends org.python.exceptions.Warning {
4 | public PendingDeprecationWarning() {
5 | super();
6 | }
7 |
8 | public PendingDeprecationWarning(String msg) {
9 | super(msg);
10 | }
11 |
12 | public PendingDeprecationWarning(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/PermissionError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class PermissionError extends org.python.exceptions.OSError {
4 | public PermissionError() {
5 | super();
6 | }
7 |
8 | public PermissionError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public PermissionError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/ProcessLookupError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class ProcessLookupError extends org.python.exceptions.OSError {
4 | public ProcessLookupError() {
5 | super();
6 | }
7 |
8 | public ProcessLookupError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public ProcessLookupError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/ReferenceError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class ReferenceError extends org.python.exceptions.Exception {
4 | public ReferenceError() {
5 | super();
6 | }
7 |
8 | public ReferenceError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public ReferenceError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/ResourceWarning.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class ResourceWarning extends org.python.exceptions.Warning {
4 | public ResourceWarning() {
5 | super();
6 | }
7 |
8 | public ResourceWarning(String msg) {
9 | super(msg);
10 | }
11 |
12 | public ResourceWarning(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/RuntimeError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class RuntimeError extends org.python.exceptions.Exception {
4 | public RuntimeError() {
5 | super();
6 | }
7 |
8 | public RuntimeError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public RuntimeError(org.python.Object msg) {
13 | this(msg.toString());
14 | }
15 |
16 | public RuntimeError(org.python.Object[] args, java.util.Map kwargs) {
17 | super(args, kwargs);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/RuntimeWarning.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class RuntimeWarning extends org.python.exceptions.Warning {
4 | public RuntimeWarning() {
5 | super();
6 | }
7 |
8 | public RuntimeWarning(String msg) {
9 | super(msg);
10 | }
11 |
12 | public RuntimeWarning(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/StandardError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class StandardError extends org.python.exceptions.Exception {
4 | public StandardError() {
5 | super();
6 | }
7 |
8 | public StandardError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public StandardError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/StopIteration.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class StopIteration extends org.python.exceptions.Exception {
4 | @org.python.Attribute()
5 | public org.python.Object value;
6 |
7 | /**
8 | * StopIteration is a singleton instance for performance reasons, introduced in
9 | * PR #881 (https://github.com/beeware/voc/pull/881/). This results in a non-trivial
10 | * performance improvement for nested loops. However, this also means that the equality
11 | * comparison between StopIteration instances will always be true.
12 | */
13 | public static final org.python.exceptions.StopIteration STOPITERATION = new org.python.exceptions.StopIteration();
14 |
15 | private StopIteration() {
16 | super("");
17 | this.value = org.python.types.NoneType.NONE;
18 | }
19 |
20 | public StopIteration(org.python.Object value) {
21 | super();
22 | this.value = value;
23 | }
24 |
25 | public StopIteration(org.python.Object[] args, java.util.Map kwargs) {
26 | super(args, kwargs);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/SyntaxError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class SyntaxError extends org.python.exceptions.Exception {
4 | public SyntaxError() {
5 | super();
6 | }
7 |
8 | public SyntaxError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public SyntaxError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/SyntaxWarning.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class SyntaxWarning extends org.python.exceptions.Warning {
4 | public SyntaxWarning() {
5 | super();
6 | }
7 |
8 | public SyntaxWarning(String msg) {
9 | super(msg);
10 | }
11 |
12 | public SyntaxWarning(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/SystemError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class SystemError extends org.python.exceptions.Exception {
4 | public SystemError() {
5 | super();
6 | }
7 |
8 | public SystemError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public SystemError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/SystemExit.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class SystemExit extends org.python.exceptions.BaseException {
4 | public int return_code;
5 |
6 | public SystemExit() {
7 | super("0");
8 | return_code = 0;
9 | }
10 |
11 | public SystemExit(org.python.Object val) {
12 | super(java.lang.String.format("%s", ((org.python.types.Int) val.__int__()).value));
13 | this.return_code = (int) ((org.python.types.Int) val.__int__()).value;
14 | }
15 |
16 | public SystemExit(org.python.Object[] args, java.util.Map kwargs) {
17 | this(args[0]);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/TabError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class TabError extends org.python.exceptions.IndentationError {
4 | public TabError() {
5 | super();
6 | }
7 |
8 | public TabError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public TabError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/TimeoutError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class TimeoutError extends org.python.exceptions.OSError {
4 | public TimeoutError() {
5 | super();
6 | }
7 |
8 | public TimeoutError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public TimeoutError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/TypeError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class TypeError extends org.python.exceptions.Exception {
4 | public TypeError() {
5 | super();
6 | }
7 |
8 | public TypeError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public TypeError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/UnboundLocalError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class UnboundLocalError extends org.python.exceptions.NameError {
4 | public UnboundLocalError(String var) {
5 | super("local variable '" + var + "' referenced before assignment", true);
6 | }
7 |
8 | public UnboundLocalError(org.python.Object[] args, java.util.Map kwargs) {
9 | this(args[0].toString());
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/UnicodeDecodeError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class UnicodeDecodeError extends org.python.exceptions.UnicodeError {
4 | public UnicodeDecodeError() {
5 | super();
6 | }
7 |
8 | public UnicodeDecodeError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public UnicodeDecodeError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/UnicodeEncodeError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class UnicodeEncodeError extends org.python.exceptions.UnicodeError {
4 | public UnicodeEncodeError() {
5 | super();
6 | }
7 |
8 | public UnicodeEncodeError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public UnicodeEncodeError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/UnicodeError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class UnicodeError extends org.python.exceptions.ValueError {
4 | public UnicodeError() {
5 | super();
6 | }
7 |
8 | public UnicodeError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public UnicodeError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/UnicodeTranslateError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class UnicodeTranslateError extends org.python.exceptions.UnicodeError {
4 | public UnicodeTranslateError() {
5 | super();
6 | }
7 |
8 | public UnicodeTranslateError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public UnicodeTranslateError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/UnicodeWarning.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class UnicodeWarning extends org.python.exceptions.Warning {
4 | public UnicodeWarning() {
5 | super();
6 | }
7 |
8 | public UnicodeWarning(String msg) {
9 | super(msg);
10 | }
11 |
12 | public UnicodeWarning(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/UserWarning.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class UserWarning extends org.python.exceptions.Warning {
4 | public UserWarning() {
5 | super();
6 | }
7 |
8 | public UserWarning(String msg) {
9 | super(msg);
10 | }
11 |
12 | public UserWarning(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/ValueError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class ValueError extends org.python.exceptions.Exception {
4 | public ValueError() {
5 | super();
6 | }
7 |
8 | public ValueError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public ValueError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/Warning.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class Warning extends org.python.exceptions.Exception {
4 | public Warning() {
5 | super();
6 | }
7 |
8 | public Warning(String msg) {
9 | super(msg);
10 | }
11 |
12 | public Warning(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/exceptions/ZeroDivisionError.java:
--------------------------------------------------------------------------------
1 | package org.python.exceptions;
2 |
3 | public class ZeroDivisionError extends org.python.exceptions.ArithmeticError {
4 | public ZeroDivisionError() {
5 | super();
6 | }
7 |
8 | public ZeroDivisionError(String msg) {
9 | super(msg);
10 | }
11 |
12 | public ZeroDivisionError(org.python.Object[] args, java.util.Map kwargs) {
13 | super(args, kwargs);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/python/common/org/python/java/Field.java:
--------------------------------------------------------------------------------
1 | package org.python.java;
2 |
3 | public class Field extends org.python.types.Object {
4 | java.lang.reflect.Field field;
5 |
6 | public Field(java.lang.reflect.Field field) {
7 | super();
8 | this.field = field;
9 | }
10 |
11 | public org.python.types.Str __repr__() {
12 | return new org.python.types.Str(
13 | String.format("",
14 | this.field
15 | )
16 | );
17 | }
18 |
19 | public org.python.Object __get__(org.python.Object instance, org.python.Object klass) {
20 | if (instance == klass) {
21 | if (java.lang.reflect.Modifier.isStatic(this.field.getModifiers())) {
22 | try {
23 | return org.python.types.Type.toPython(this.field.get(null));
24 | } catch (IllegalAccessException iae) {
25 | throw new org.python.exceptions.RuntimeError("Illegal access to native field " + this.field.getName());
26 | }
27 | } else {
28 | return this;
29 | }
30 | } else {
31 | try {
32 | return org.python.types.Type.toPython(this.field.get(instance.toJava()));
33 | } catch (IllegalAccessException iae) {
34 | throw new org.python.exceptions.RuntimeError("Illegal access to native field " + this.field.getName());
35 | }
36 | }
37 | }
38 |
39 | public void __set__(org.python.Object instance, org.python.Object value) {
40 | try {
41 | this.field.set(instance.toJava(), org.python.types.Type.toJava(this.field.getType(), value));
42 | } catch (IllegalAccessException iae) {
43 | throw new org.python.exceptions.RuntimeError("Illegal access to native field " + this.field.getName());
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/python/common/org/python/java/Method.java:
--------------------------------------------------------------------------------
1 | package org.python.java;
2 |
3 | public class Method extends org.python.types.Object implements org.python.Callable {
4 | org.python.Object instance;
5 | org.python.java.Function function;
6 |
7 | public Method(org.python.Object instance, org.python.java.Function function) {
8 | super();
9 | this.instance = instance;
10 | this.function = function;
11 | // System.out.println("Create method " + function.name);
12 | }
13 |
14 | public org.python.types.Str __repr__() {
15 | if (this.instance == null) {
16 | return this.function.__repr__();
17 | } else {
18 | return new org.python.types.Str(
19 | String.format("",
20 | this.function.klass.getName(),
21 | this.function.name,
22 | this.instance.__repr__()
23 | )
24 | );
25 | }
26 | }
27 |
28 | public org.python.Object invoke(org.python.Object[] args, java.util.Map kwargs) {
29 | return this.function.invoke(this.instance, args, kwargs);
30 | }
31 |
32 | public org.python.Object __get__(org.python.Object instance, org.python.types.Type klass) {
33 | return this;
34 | }
35 |
36 | @org.python.Method(
37 | __doc__ = ""
38 | )
39 | public org.python.Object __bool__() {
40 | return org.python.types.Bool.TRUE;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/python/common/org/python/java/Module.java:
--------------------------------------------------------------------------------
1 | package org.python.java;
2 |
3 | public class Module extends org.python.types.Module {
4 | public java.lang.String java_namespace;
5 |
6 | public int hashCode() {
7 | return this.java_namespace.hashCode();
8 | }
9 |
10 | public Module(java.lang.String java_namespace) {
11 | super();
12 | this.java_namespace = java_namespace;
13 | }
14 |
15 | public org.python.types.Str __repr__() {
16 | return new org.python.types.Str(String.format("", this.java_namespace));
17 | }
18 |
19 | public org.python.Object __getattribute__(java.lang.String name) {
20 | // System.out.println("GETATTRIBUTE NATIVE MODULE " + this + " " + name);
21 | org.python.types.Type cls = org.python.types.Type.pythonType(this.klass);
22 | // System.out.println("instance __dict__ = " + this.__dict__);
23 | // System.out.println("class __dict__ = " + cls.__dict__);
24 | org.python.Object value;
25 |
26 | value = cls.__dict__.get(name);
27 | if (value == null) {
28 | try {
29 | java.lang.Class java_class = java.lang.Thread.currentThread().getContextClassLoader().loadClass(java_namespace + "." + name);
30 | value = new org.python.java.Type(org.python.types.Type.Origin.JAVA, java_class);
31 | cls.__dict__.put(name, value);
32 | } catch (java.lang.ClassNotFoundException e) {
33 | throw new org.python.exceptions.NameError(name);
34 | }
35 | }
36 | return value;
37 | }
38 |
39 | public void __setattr__(java.lang.String name, org.python.Object value) {
40 | // The base object can't have attribute set on it unless the attribute already exists.
41 | // System.out.println("SETATTRIBUTE NATIVE MODULE " + this + " " + name + " = " + value);
42 | org.python.types.Type cls = org.python.types.Type.pythonType(this.klass);
43 | // System.out.println("instance __dict__ = " + this.__dict__);
44 | // System.out.println("class __dict__ = " + cls.__dict__);
45 |
46 | cls.__dict__.put(name, value);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/python/common/org/python/java/Object.java:
--------------------------------------------------------------------------------
1 | package org.python.java;
2 |
3 | public class Object extends org.python.types.Object {
4 | public java.lang.Object object;
5 |
6 | public int hashCode() {
7 | return this.object.hashCode();
8 | }
9 |
10 | public java.lang.Object toJava() {
11 | return this.object;
12 | }
13 |
14 | public java.lang.Object toObject() {
15 | return this.object;
16 | }
17 |
18 | public Object(java.lang.Object object) {
19 | this(org.python.types.Type.Origin.JAVA, object);
20 | }
21 |
22 | public Object(org.python.types.Type.Origin origin, java.lang.Object object) {
23 | super(origin, object.getClass());
24 | // System.out.println("JAVA WRAPPER FOR " + object.getClass());
25 | this.object = object;
26 | try {
27 | java.lang.reflect.Field voc_field = this.object.getClass().getField("__VOC__");
28 | voc_field.set(this.object, this);
29 | } catch (NoSuchFieldException e) {
30 | // System.out.println("NO __VOC__ FIELD");
31 | } catch (java.lang.IllegalAccessException e) {
32 | throw new org.python.exceptions.RuntimeError("Illegal access to __VOC__ field for " + this.object.getClass());
33 | }
34 | }
35 |
36 | @org.python.Method(
37 | __doc__ = ""
38 | )
39 | public org.python.types.Str __repr__() {
40 | return new org.python.types.Str(String.format("", this.object.getClass().getName(), this.object.hashCode()));
41 | }
42 |
43 | @org.python.Method(
44 | __doc__ = ""
45 | )
46 | public org.python.types.Str __str__() {
47 | return new org.python.types.Str(this.object.toString());
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/python/common/org/python/stdlib/collections/OrderedDictItems.java:
--------------------------------------------------------------------------------
1 | package org.python.stdlib.collections;
2 |
3 | public class OrderedDictItems extends org.python.types.DictItems {
4 | static {
5 | org.python.types.Type.declarePythonType(OrderedDictItems.class, "odict_items", null, null);
6 | }
7 |
8 | OrderedDictItems(org.python.stdlib.collections.OrderedDict odict) {
9 | super(odict);
10 | }
11 |
12 | @org.python.Method(
13 | __doc__ = ""
14 | )
15 | public org.python.Object __reversed__() {
16 | if (org.Python.VERSION < 0x03050000) {
17 | throw new org.python.exceptions.TypeError("argument to reversed() must be a sequence");
18 | }
19 |
20 | return org.python.stdlib.collections.OrderedDict_Iterator.get_reverse_itemIterator(this.value);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/python/common/org/python/stdlib/collections/OrderedDictKeys.java:
--------------------------------------------------------------------------------
1 | package org.python.stdlib.collections;
2 |
3 | public class OrderedDictKeys extends org.python.types.DictKeys {
4 | static {
5 | org.python.types.Type.declarePythonType(OrderedDictKeys.class, "odict_keys", null, null);
6 | }
7 |
8 | OrderedDictKeys(org.python.stdlib.collections.OrderedDict odict) {
9 | super(odict);
10 | }
11 |
12 | @org.python.Method(
13 | __doc__ = ""
14 | )
15 | public org.python.Object __reversed__() {
16 | if (org.Python.VERSION < 0x03050000) {
17 | throw new org.python.exceptions.TypeError("argument to reversed() must be a sequence");
18 | }
19 |
20 | return org.python.stdlib.collections.OrderedDict_Iterator.get_reverse_keyIterator(this.value);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/python/common/org/python/stdlib/collections/OrderedDictValues.java:
--------------------------------------------------------------------------------
1 | package org.python.stdlib.collections;
2 |
3 | public class OrderedDictValues extends org.python.types.DictValues {
4 | static {
5 | org.python.types.Type.declarePythonType(OrderedDictValues.class, "odict_values", null, null);
6 | }
7 |
8 | OrderedDictValues(org.python.stdlib.collections.OrderedDict odict) {
9 | super(odict);
10 | }
11 |
12 | @org.python.Method(
13 | __doc__ = ""
14 | )
15 | public org.python.Object __reversed__() {
16 | if (org.Python.VERSION < 0x03050000) {
17 | throw new org.python.exceptions.TypeError("argument to reversed() must be a sequence");
18 | }
19 |
20 | return org.python.stdlib.collections.OrderedDict_Iterator.get_reverse_valueIterator(this.value);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/python/common/org/python/stdlib/collections/OrderedDict_Iterator.java:
--------------------------------------------------------------------------------
1 | package org.python.stdlib.collections;
2 |
3 | class OrderedDict_Iterator extends org.python.types.Iterator {
4 | static {
5 | org.python.types.Type.declarePythonType(OrderedDict_Iterator.class, "odict_iterator", null, null);
6 | }
7 |
8 | OrderedDict_Iterator(org.python.stdlib.collections.OrderedDict odict) {
9 | this.iterator = odict.value.keySet().iterator();
10 | }
11 |
12 | private OrderedDict_Iterator() {
13 | this.iterator = null;
14 | }
15 |
16 | static OrderedDict_Iterator get_reverse_keyIterator(java.util.Set keySet) {
17 | org.python.stdlib.collections.OrderedDict_Iterator keyIterator =
18 | new org.python.stdlib.collections.OrderedDict_Iterator();
19 | java.util.LinkedList keyLinkedList = new java.util.LinkedList<>();
20 | keyLinkedList.addAll(keySet);
21 | keyIterator.iterator = keyLinkedList.descendingIterator();
22 |
23 | return keyIterator;
24 | }
25 |
26 | static OrderedDict_Iterator get_reverse_itemIterator(
27 | java.util.Set> entrySet) {
28 | org.python.stdlib.collections.OrderedDict_Iterator itemIterator =
29 | new org.python.stdlib.collections.OrderedDict_Iterator();
30 | java.util.LinkedList itemLinkedList = new java.util.LinkedList<>();
31 | for (java.util.Map.Entry entry : entrySet) {
32 | java.util.List tmp = new java.util.ArrayList();
33 | tmp.add(entry.getKey());
34 | tmp.add(entry.getValue());
35 | itemLinkedList.add(new org.python.types.Tuple(tmp));
36 | }
37 | itemIterator.iterator = itemLinkedList.descendingIterator();
38 |
39 | return itemIterator;
40 | }
41 |
42 | static OrderedDict_Iterator get_reverse_valueIterator(java.util.Collection values) {
43 | org.python.stdlib.collections.OrderedDict_Iterator valueIterator =
44 | new org.python.stdlib.collections.OrderedDict_Iterator();
45 | java.util.LinkedList valueLinkedList = new java.util.LinkedList<>();
46 | valueLinkedList.addAll(values);
47 | valueIterator.iterator = valueLinkedList.descendingIterator();
48 |
49 | return valueIterator;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/python/common/org/python/stdlib/time/Namespace.java:
--------------------------------------------------------------------------------
1 | package org.python.stdlib.time;
2 |
3 | /**
4 | * Data structure for the return value of time.get_clock_info
5 | */
6 | public class Namespace extends org.python.types.Object {
7 | @org.python.Attribute
8 | public org.python.types.Bool adjustable;
9 | @org.python.Attribute
10 | public org.python.types.Str implementation;
11 | @org.python.Attribute
12 | public org.python.types.Bool monotonic;
13 | @org.python.Attribute
14 | public org.python.types.Float resolution;
15 |
16 | public Namespace(boolean adjustable, String implementation, boolean monotonic, double resolution) {
17 | this.adjustable = org.python.types.Bool.getBool(adjustable);
18 | this.implementation = new org.python.types.Str(implementation);
19 | this.monotonic = org.python.types.Bool.getBool(monotonic);
20 | this.resolution = new org.python.types.Float(resolution);
21 | }
22 |
23 | @org.python.Method(
24 | __doc__ = "Return repr(self)."
25 | )
26 | public org.python.types.Str __repr__() {
27 | java.lang.StringBuilder buffer = new java.lang.StringBuilder("namespace(");
28 | buffer.append("adjustable=");
29 | buffer.append(this.adjustable.__repr__());
30 | buffer.append(", implementation=");
31 | buffer.append(this.implementation.__repr__());
32 | buffer.append(", monotonic=");
33 | buffer.append(this.monotonic.__repr__());
34 | buffer.append(", resolution=");
35 | buffer.append(this.resolution.__repr__());
36 | buffer.append(")");
37 |
38 | return new org.python.types.Str(buffer.toString());
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/python/common/org/python/types/Closure.java:
--------------------------------------------------------------------------------
1 | package org.python.types;
2 |
3 | public class Closure extends org.python.types.Object {
4 | public java.util.List> locals_list;
5 |
6 | public Closure(java.util.List> locals_list) {
7 | super();
8 | this.locals_list = locals_list;
9 | }
10 |
11 | @org.python.Method(
12 | __doc__ = "Return repr(self)."
13 | )
14 | public org.python.Object __repr__() {
15 | return new org.python.types.Str(String.format("", this.typeName(), this.hashCode()));
16 | }
17 |
18 | public java.util.Map get_locals(int level) {
19 | return this.locals_list.get(level - 1);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/python/common/org/python/types/ContextManager.java:
--------------------------------------------------------------------------------
1 | package org.python.types;
2 |
3 | public class ContextManager extends org.python.types.Object {
4 | }
5 |
--------------------------------------------------------------------------------
/python/common/org/python/types/DictValues_Iterator.java:
--------------------------------------------------------------------------------
1 | package org.python.types;
2 |
3 | class DictValues_Iterator extends org.python.types.Iterator {
4 | public DictValues_Iterator(org.python.types.DictValues dict_values) {
5 | this.iterator = dict_values.value.iterator();
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/python/common/org/python/types/DictView.java:
--------------------------------------------------------------------------------
1 | package org.python.types;
2 |
3 | public class DictView extends org.python.types.Object {
4 | }
5 |
--------------------------------------------------------------------------------
/python/common/org/python/types/Dict_KeyIterator.java:
--------------------------------------------------------------------------------
1 | package org.python.types;
2 |
3 | public class Dict_KeyIterator extends org.python.types.Iterator {
4 | public Dict_KeyIterator(org.python.types.Dict dict) {
5 | this.iterator = dict.value.keySet().iterator();
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/python/common/org/python/types/Ellipsis.java:
--------------------------------------------------------------------------------
1 | package org.python.types;
2 |
3 | public class Ellipsis extends org.python.types.Object {
4 | public static org.python.Object ELLIPSIS = new org.python.types.Ellipsis();
5 | }
6 |
--------------------------------------------------------------------------------
/python/common/org/python/types/Filter.java:
--------------------------------------------------------------------------------
1 | package org.python.types;
2 |
3 | public class Filter extends org.python.types.Object implements org.python.Object {
4 | private org.python.Callable callable;
5 | private org.python.Object iterator;
6 |
7 | public Filter(org.python.Object callable, org.python.Object iterator) {
8 | if (org.python.types.NoneType.NONE == callable) {
9 | this.callable = null;
10 | } else {
11 | this.callable = (org.python.Callable) callable;
12 | }
13 | this.iterator = iterator;
14 | }
15 |
16 | @org.python.Method(
17 | __doc__ = "Implement iter(self)."
18 | )
19 | public org.python.Object __iter__() {
20 | return this;
21 | }
22 |
23 | @org.python.Method(
24 | __doc__ = "Implement next(self)."
25 | )
26 | public org.python.Object __next__() {
27 | while (true) { // loop until we find first true
28 | org.python.Object current = iterator.__next__();
29 | org.python.Object value = current;
30 | if (callable != null) {
31 | org.python.Object[] args = new org.python.Object[] {current};
32 | value = callable.invoke(args, new java.util.HashMap());
33 | }
34 | if (value.toBoolean()) {
35 | return current;
36 | }
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/python/common/org/python/types/Iterator.java:
--------------------------------------------------------------------------------
1 | package org.python.types;
2 |
3 | public class Iterator extends org.python.types.Object implements org.python.Object {
4 | protected java.util.Iterator iterator;
5 |
6 | public int hashCode() {
7 | return this.iterator.hashCode();
8 | }
9 |
10 | @org.python.Method(
11 | __doc__ = "Implement iter(self)."
12 | )
13 | public org.python.Object __iter__(java.util.List args, java.util.Map kwargs, java.util.List default_args, java.util.Map default_kwargs) {
14 | if (kwargs != null && kwargs.size() != 0) {
15 | throw new org.python.exceptions.TypeError("__iter__ doesn't take keyword arguments");
16 | }
17 | if (args != null && args.size() != 0) {
18 | throw new org.python.exceptions.TypeError("Expected 0 arguments, got " + args.size());
19 | }
20 | return this;
21 | }
22 |
23 | public org.python.Object __iter__() {
24 | return this.__iter__(null, null, null, null);
25 | }
26 |
27 | @org.python.Method(
28 | __doc__ = "Implement next(self)."
29 | )
30 | public org.python.Object __next__(java.util.List args, java.util.Map kwargs, java.util.List default_args, java.util.Map default_kwargs) {
31 | if (kwargs != null && kwargs.size() != 0) {
32 | throw new org.python.exceptions.TypeError("__next__ doesn't take keyword arguments");
33 | }
34 | if (args != null && args.size() != 0) {
35 | throw new org.python.exceptions.TypeError("Expected 0 arguments, got " + args.size());
36 | }
37 |
38 | try {
39 | return this.iterator.next();
40 | } catch (java.util.NoSuchElementException e) {
41 | // StopIteration is a singleton by design, see org/python/exceptions/StopIteration
42 | throw org.python.exceptions.StopIteration.STOPITERATION;
43 | }
44 | }
45 |
46 | public org.python.Object __next__() {
47 | return this.__next__(null, null, null, null);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/python/common/org/python/types/List_Iterator.java:
--------------------------------------------------------------------------------
1 | package org.python.types;
2 |
3 | class List_Iterator extends org.python.types.Iterator {
4 | public List_Iterator(org.python.types.List list) {
5 | this.iterator = list.value.iterator();
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/python/common/org/python/types/List_ReverseIterator.java:
--------------------------------------------------------------------------------
1 | package org.python.types;
2 |
3 | class List_ReverseIterator extends ReverseIterator {
4 | public List_ReverseIterator(org.python.types.List list) {
5 | this.iterator = list.value.listIterator(list.value.size());
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/python/common/org/python/types/Map.java:
--------------------------------------------------------------------------------
1 | package org.python.types;
2 |
3 | public class Map extends org.python.types.Object implements org.python.Object {
4 | private org.python.Object callable;
5 | private org.python.Object[] iterators;
6 |
7 | public Map(org.python.Object callable, org.python.types.Tuple iterables) {
8 | this.callable = callable;
9 | this.iterators = new org.python.Object[iterables.value.size()];
10 | for (int i = 0; i < iterables.value.size(); i++) {
11 | this.iterators[i] = org.Python.iter(iterables.value.get(i));
12 | }
13 | }
14 |
15 | @org.python.Method(
16 | __doc__ = "Implement iter(self)."
17 | )
18 | public org.python.Object __iter__() {
19 | return this;
20 | }
21 |
22 | @org.python.Method(
23 | __doc__ = "Implement next(self)."
24 | )
25 | public org.python.Object __next__() {
26 | org.python.Object[] args = new org.python.Object[iterators.length];
27 | for (int i = 0; i < iterators.length; i++) {
28 | args[i] = iterators[i].__next__();
29 | }
30 | return ((org.python.Callable) callable).invoke(args, new java.util.HashMap());
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/python/common/org/python/types/MemoryView.java:
--------------------------------------------------------------------------------
1 | package org.python.types;
2 |
3 | public class MemoryView extends org.python.types.Object {
4 | @org.python.Method(
5 | __doc__ = "memoryview(object)" +
6 | "\n" +
7 | "Create a new memoryview object which references the given object.\n"
8 | )
9 | public MemoryView(org.python.Object[] args, java.util.Map kwargs) {
10 | throw new org.python.exceptions.NotImplementedError("Builtin function 'memoryview' not implemented");
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/python/common/org/python/types/Method.java:
--------------------------------------------------------------------------------
1 | package org.python.types;
2 |
3 | public class Method extends org.python.types.Object implements org.python.Callable {
4 | org.python.Object im_self;
5 | org.python.types.Type im_class;
6 | org.python.types.Function im_func;
7 |
8 | public Method(org.python.Object instance, org.python.types.Type klass, org.python.types.Function function) {
9 | super();
10 | this.im_self = instance;
11 | this.im_class = klass;
12 | this.im_func = function;
13 | // System.out.println("Create method " + function.name + " on " + instance);
14 | }
15 |
16 | @org.python.Method(
17 | __doc__ = ""
18 | )
19 | public org.python.types.Str __repr__() {
20 | if (this.im_self == null) {
21 | return new org.python.types.Str(
22 | String.format("",
23 | this.im_class.__dict__.get("__name__"),
24 | this.im_func.__dict__.get("__name__")
25 | )
26 | );
27 | } else {
28 | return new org.python.types.Str(
29 | String.format("",
30 | this.im_class,
31 | this.im_func.__dict__.get("__name__"),
32 | this.im_self
33 | )
34 | );
35 | }
36 | }
37 |
38 | @org.python.Method(
39 | __doc__ = ""
40 | )
41 | public org.python.Object __bool__() {
42 | return org.python.types.Bool.TRUE;
43 | }
44 |
45 | public org.python.Object invoke(org.python.Object[] args, java.util.Map kwargs) {
46 | // System.out.println("METHOD Invocation: " + this.im_self);
47 | return this.im_func.invoke(this.im_self, args, kwargs);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/python/common/org/python/types/Module.java:
--------------------------------------------------------------------------------
1 | package org.python.types;
2 |
3 | public class Module extends org.python.types.Object {
4 | public java.lang.Class klass;
5 |
6 | public int hashCode() {
7 | return this.klass.hashCode();
8 | }
9 |
10 | public void module$import() {
11 | org.Python.initializeModule(this.getClass(), this.__dict__);
12 | }
13 |
14 | protected Module() {
15 | this.klass = this.getClass();
16 | }
17 |
18 | public Module(java.lang.Class klass) {
19 | this.klass = klass;
20 | }
21 |
22 | @org.python.Method(
23 | __doc__ = ""
24 | )
25 | public org.python.types.Str __repr__() {
26 | return new org.python.types.Str(
27 | String.format(
28 | "",
29 | this.getClass().getPackage().getName(),
30 | this.getClass()
31 | )
32 | );
33 | }
34 |
35 | public org.python.Object __getattribute__(java.lang.String name) {
36 | org.python.Object value = this.__getattribute_null(name);
37 | if (value == null) {
38 | throw new org.python.exceptions.NameError(name);
39 | }
40 | return value;
41 | }
42 |
43 | public org.python.Object __getattribute_null(java.lang.String name) {
44 | // System.out.println("GETATTRIBUTE MODULE " + this + " " + name);
45 | // // System.out.println("MODULE ATTRS " + this.__dict__);
46 | // org.python.types.Type cls = org.python.types.Type.pythonType(this.klass);
47 | // // System.out.println("MODULE CLS = " + cls);
48 | // // System.out.println("MODULE CLS ATTRS = " + cls.__dict__);
49 |
50 | org.python.Object value = super.__getattribute_null(name);
51 |
52 | // If we don't have a module attribute, look for a builtin.
53 | if (value == null) {
54 | value = org.Python.builtins.get(name);
55 | }
56 |
57 | // System.out.println("GETATTR Module value " + name + " = " + value);
58 | return value;
59 | }
60 |
61 | public void __setattr__(java.lang.String name, org.python.Object value) {
62 | if (!this.__setattr_null(name, value)) {
63 | throw new org.python.exceptions.TypeError("can't set attributes of built-in/extension type '" + org.Python.typeName(this.klass) + "'");
64 | }
65 | }
66 |
67 | public void __delattr__(java.lang.String name) {
68 | if (!this.__delattr_null(name)) {
69 | throw new org.python.exceptions.NameError(name);
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/python/common/org/python/types/PlaceholderType.java:
--------------------------------------------------------------------------------
1 | package org.python.types;
2 |
3 | class PlaceholderType extends org.python.types.Type {
4 | private java.util.ArrayList instances = new java.util.ArrayList();
5 |
6 | PlaceholderType(java.lang.Class klass) {
7 | super(org.python.types.Type.Origin.PLACEHOLDER, klass);
8 | }
9 |
10 | public void add_reference(org.python.Object instance) {
11 | instances.add(instance);
12 | }
13 |
14 | public void resolve(org.python.types.Type python_type) {
15 | for (org.python.Object obj : this.instances) {
16 | obj.__new__(python_type);
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/python/common/org/python/types/ReverseIterator.java:
--------------------------------------------------------------------------------
1 | package org.python.types;
2 |
3 |
4 | class ReverseIterator extends org.python.types.Object implements org.python.Object {
5 | java.util.ListIterator iterator;
6 |
7 | public int hashCode() {
8 | return this.iterator.hashCode();
9 | }
10 |
11 | @org.python.Method(
12 | __doc__ = "Implement iter(self)."
13 | )
14 | public org.python.Object __iter__(java.util.List args, java.util.Map kwargs, java.util.List default_args, java.util.Map default_kwargs) {
15 | if (kwargs != null && kwargs.size() != 0) {
16 | throw new org.python.exceptions.TypeError("__iter__ doesn't take keyword arguments");
17 | }
18 | if (args != null && args.size() != 0) {
19 | throw new org.python.exceptions.TypeError("Expected 0 arguments, got " + args.size());
20 | }
21 | return this;
22 | }
23 |
24 | public org.python.Object __iter__() {
25 | return this.__iter__(null, null, null, null);
26 | }
27 |
28 | @org.python.Method(
29 | __doc__ = "Implement next(self)."
30 | )
31 | public org.python.Object __next__(java.util.List args, java.util.Map kwargs, java.util.List default_args, java.util.Map default_kwargs) {
32 | if (kwargs != null && kwargs.size() != 0) {
33 | throw new org.python.exceptions.TypeError("__next__ doesn't take keyword arguments");
34 | }
35 | if (args != null && args.size() != 0) {
36 | throw new org.python.exceptions.TypeError("Expected 0 arguments, got " + args.size());
37 | }
38 |
39 | try {
40 | return this.iterator.previous();
41 | } catch (java.util.NoSuchElementException e) {
42 | // StopIteration is a singleton by design, see org/python/exceptions/StopIteration
43 | throw org.python.exceptions.StopIteration.STOPITERATION;
44 | }
45 | }
46 |
47 | public org.python.Object __next__() {
48 | return this.__next__(null, null, null, null);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/python/common/org/python/types/Reversed.java:
--------------------------------------------------------------------------------
1 | package org.python.types;
2 |
3 |
4 | public class Reversed extends Object implements org.python.Object {
5 | org.python.Object sequence;
6 | long index;
7 |
8 | public Reversed(org.python.Object sequence) {
9 | this.sequence = sequence;
10 | this.index = ((Int) sequence.__len__()).value - 1;
11 | }
12 |
13 | @org.python.Method(
14 | __doc__ = "Implement iter(self)."
15 | )
16 | public org.python.Object __iter__() {
17 | return this;
18 | }
19 |
20 | @org.python.Method(
21 | __doc__ = "Implement next(self)."
22 | )
23 | public org.python.Object __next__() {
24 | if (this.index < 0) {
25 | // StopIteration is a singleton by design, see org/python/exceptions/StopIteration
26 | throw org.python.exceptions.StopIteration.STOPITERATION;
27 | }
28 | org.python.Object item = this.sequence.__getitem__(org.python.types.Int.getInt(this.index));
29 | this.index--;
30 | return item;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/python/common/org/python/types/Set_Iterator.java:
--------------------------------------------------------------------------------
1 | package org.python.types;
2 |
3 | class Set_Iterator extends org.python.types.Iterator {
4 | public Set_Iterator(org.python.types.Set set) {
5 | this.iterator = set.value.iterator();
6 | }
7 |
8 | public Set_Iterator(org.python.types.FrozenSet set) {
9 | this.iterator = set.value.iterator();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/python/common/org/python/types/SimpleNamespace.java:
--------------------------------------------------------------------------------
1 | package org.python.types;
2 |
3 | public class SimpleNamespace extends org.python.types.Object {
4 | @org.python.Method(
5 | __doc__ = "A simple attribute-based namespace.\n" +
6 | "\n" +
7 | "SimpleNamespace(**kwargs)"
8 | )
9 | public SimpleNamespace(org.python.Object[] args, java.util.Map kwargs) {
10 | if (args.length > 0) {
11 | throw new org.python.exceptions.TypeError("no positional arguments expected");
12 | }
13 |
14 | for (java.util.Map.Entry entry : kwargs.entrySet()) {
15 | this.__setattr__(entry.getKey(), entry.getValue());
16 | }
17 | }
18 |
19 | @org.python.Method(
20 | __doc__ = "Return repr(self)."
21 | )
22 | public org.python.types.Str __repr__() {
23 | java.lang.StringBuilder buffer = new java.lang.StringBuilder("namespace(");
24 | java.lang.Object[] sorted_keys = this.__dict__.keySet().toArray();
25 | java.util.Arrays.sort(sorted_keys);
26 | boolean first = true;
27 | for (java.lang.Object key : sorted_keys) {
28 | if (!first) {
29 | buffer.append(", ");
30 | }
31 | first = false;
32 | buffer.append(key);
33 | buffer.append("=");
34 | buffer.append(this.__dict__.get((java.lang.String) key).__repr__());
35 | }
36 | buffer.append(")");
37 |
38 | return new org.python.types.Str(buffer.toString());
39 | }
40 |
41 | @org.python.Method(
42 | __doc__ = "Return self==value.",
43 | args = {"other"}
44 | )
45 | public org.python.Object __eq__(org.python.Object other) {
46 | if (this.__dict__.equals(((org.python.types.Object) other).__dict__)) {
47 | return org.python.types.Bool.TRUE;
48 | } else {
49 | return org.python.types.NotImplementedType.NOT_IMPLEMENTED;
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/python/common/org/python/types/Tuple_Iterator.java:
--------------------------------------------------------------------------------
1 | package org.python.types;
2 |
3 | class Tuple_Iterator extends org.python.types.Iterator {
4 | public Tuple_Iterator(org.python.types.Tuple tuple) {
5 | this.iterator = tuple.value.iterator();
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/python/common/python/PlatformInterface.java:
--------------------------------------------------------------------------------
1 | package python;
2 |
3 | public interface PlatformInterface {
4 | /**
5 | * Return the number of CPU nanoseconds that this thread has consumed.
6 | */
7 | public long clock();
8 |
9 | public void debug(java.lang.String msg);
10 |
11 | public void debug(java.lang.String msg, java.lang.Object obj);
12 |
13 | public org.python.Object getPlatform();
14 |
15 | public org.python.Object stderr();
16 |
17 | public org.python.Object stdout();
18 |
19 | public org.python.Object stdin();
20 |
21 | public org.python.Object args();
22 | }
23 |
--------------------------------------------------------------------------------
/python/java/python/_platform/JavaPlatform.java:
--------------------------------------------------------------------------------
1 | package python._platform;
2 |
3 | import java.lang.management.ManagementFactory;
4 | import java.lang.management.ThreadMXBean;
5 |
6 | public class JavaPlatform implements python.PlatformInterface {
7 | private org.python.stdlib._io.TextIOWrapper _stderr;
8 | private org.python.stdlib._io.TextIOWrapper _stdout;
9 | private org.python.stdlib._io.TextIOWrapper _stdin;
10 |
11 | public JavaPlatform() {
12 | _stderr = new org.python.stdlib._io.TextIOWrapper(System.err);
13 | _stdout = new org.python.stdlib._io.TextIOWrapper(System.out);
14 | _stdin = new org.python.stdlib._io.TextIOWrapper(System.in);
15 | }
16 |
17 | public long clock() {
18 | ThreadMXBean tmxb = ManagementFactory.getThreadMXBean();
19 | return tmxb.getCurrentThreadCpuTime();
20 | }
21 |
22 | public void debug(java.lang.String msg) {
23 | System.out.println("DEBUG " + msg);
24 | }
25 |
26 | public void debug(java.lang.String msg, java.lang.Object obj) {
27 | System.out.println("DEBUG " + msg + ": " + obj);
28 | }
29 |
30 | public org.python.Object getPlatform() {
31 | java.lang.String os_name = System.getProperty("os.name");
32 | java.lang.String py_name;
33 | if (os_name.startsWith("Windows")) {
34 | py_name = "win32";
35 | } else if (os_name.equals("Mac OS X")) {
36 | py_name = "darwin";
37 | } else if (os_name.equals("Linux")) {
38 | py_name = "linux";
39 | } else {
40 | System.out.println(os_name);
41 | py_name = "unknown";
42 | }
43 |
44 | return new org.python.types.Str(py_name);
45 | }
46 |
47 | public org.python.Object stderr() {
48 | return _stderr;
49 | }
50 |
51 | public org.python.Object stdout() {
52 | return _stdout;
53 | }
54 |
55 | public org.python.Object stdin() {
56 | return _stdin;
57 | }
58 |
59 | public org.python.Object args() {
60 | // java.util.regex.Pattern cmdline_pattern = java.util.regex.Pattern.compile("(\"[^\"]*\"|[^\"]+)(\\s+|$)");
61 | java.util.regex.Pattern cmdline_pattern = java.util.regex.Pattern.compile("\\s+");
62 | java.lang.String[] cmdline_args = cmdline_pattern.split(System.getProperty("sun.java.command"));
63 | java.util.List arg_list = new java.util.ArrayList();
64 | for (String arg : cmdline_args) {
65 | arg_list.add(new org.python.types.Str(arg));
66 | }
67 |
68 | return new org.python.types.List(arg_list);
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/python/testfile.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beeware/voc/dd9f15a7d56d00d8c9e501a57194694e601ea401/python/testfile.class
--------------------------------------------------------------------------------
/requirements/docs.txt:
--------------------------------------------------------------------------------
1 | # Support for docs generation
2 | sphinx
3 | sphinx_rtd_theme
4 |
--------------------------------------------------------------------------------
/requirements/tests.txt:
--------------------------------------------------------------------------------
1 | # execnet dependency
2 | apipkg==1.4
3 |
4 | # pytest dependency
5 | py==1.4.31
6 |
7 | # pytest-xdist dependencies
8 | execnet==1.4.1
9 | pytest==2.9.2
10 |
11 | # Support for parallel test execution
12 | pytest-xdist==1.14
13 |
14 | # Install cricket for GUI testsuite
15 | cricket
16 |
--------------------------------------------------------------------------------
/setup.cfg:
--------------------------------------------------------------------------------
1 | [flake8]
2 | # https://flake8.readthedocs.org/en/latest/
3 | exclude=local/*,docs/*,settings.py,*/migrations/*,tools/*
4 | max-complexity = 10
5 | max-line-length = 119
6 | ignore = E121,E123,E126,E226,E24,E704,W503,W504,C901
7 | [metadata]
8 | description-file = README.md
9 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | import io
3 | import re
4 | from setuptools import setup, find_packages
5 |
6 | with io.open('./voc/__init__.py', encoding='utf8') as version_file:
7 | version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_file.read(), re.M)
8 | if version_match:
9 | version = version_match.group(1)
10 | else:
11 | raise RuntimeError("Unable to find version string.")
12 |
13 |
14 | with io.open('README.rst', encoding='utf8') as readme:
15 | long_description = readme.read()
16 |
17 |
18 | setup(
19 | name='voc',
20 | version=version,
21 | description='Tools to convert Python code into Java bytecode.',
22 | long_description=long_description,
23 | author='Russell Keith-Magee',
24 | author_email='russell@keith-magee.com',
25 | url='https://beeware.org/voc',
26 | packages=find_packages(exclude=['docs', 'tests']),
27 | python_requires='>=3.4',
28 | entry_points={
29 | 'console_scripts': [
30 | 'voc = voc.__main__:main',
31 | 'vod = voc.java.__main__:main',
32 | ]
33 | },
34 | license='New BSD',
35 | classifiers=[
36 | 'Development Status :: 4 - Beta',
37 | 'Intended Audience :: Developers',
38 | 'License :: OSI Approved :: BSD License',
39 | 'Operating System :: OS Independent',
40 | 'Programming Language :: Python :: 3',
41 | 'Programming Language :: Python :: 3.4',
42 | 'Programming Language :: Python :: 3.5',
43 | 'Programming Language :: Python :: 3.6',
44 | 'Programming Language :: Python :: 3.7',
45 | 'Programming Language :: Python :: 3 :: Only',
46 | 'Topic :: Software Development',
47 | 'Topic :: Utilities',
48 | ],
49 | test_suite='tests',
50 | project_urls={
51 | 'Funding': 'https://beeware.org/contributing/membership/',
52 | 'Documentation': 'https://voc.readthedocs.io/en/latest/',
53 | 'Tracker': 'https://github.com/beeware/voc/issues',
54 | 'Source': 'https://github.com/beeware/voc',
55 | },
56 | )
57 |
--------------------------------------------------------------------------------
/stdlib_tests/test_argparse.py:
--------------------------------------------------------------------------------
1 | import argparse
2 |
3 | parser = argparse.ArgumentParser()
4 | parser.add_argument('--foo', help='Getting foo help')
5 | args = parser.print_help()
6 |
--------------------------------------------------------------------------------
/stdlib_tests/test_base64.py:
--------------------------------------------------------------------------------
1 | import base64
2 |
3 | encoded_data = base64.b64encode(b'Here is the string to be encoded')
4 | print("Base 64 Encoded data: ", encoded_data)
5 | decoded_data = base64.b64decode(encoded_data)
6 | print("Base 64 Decoded data: ", decoded_data)
7 |
--------------------------------------------------------------------------------
/stdlib_tests/test_bisect.py:
--------------------------------------------------------------------------------
1 | import bisect
2 |
3 | print(bisect.bisect([1, 5, 9, 10], 7))
4 | print(bisect.bisect([1, 5, 9, 10], 10))
5 |
--------------------------------------------------------------------------------
/stdlib_tests/test_calendar.py:
--------------------------------------------------------------------------------
1 | import calendar
2 |
3 | print(calendar.isleap(2020))
4 | print(calendar.isleap(2018))
5 | print(calendar.isleap(2008))
6 |
--------------------------------------------------------------------------------
/stdlib_tests/test_chunk.py:
--------------------------------------------------------------------------------
1 | import chunk
2 |
3 |
4 | class fake_file():
5 | def read(self, n=0):
6 | return b"some initial binary data:"
7 |
8 |
9 | testChunk = chunk.Chunk(fake_file())
10 |
11 | print("Name = ", testChunk.getname())
12 | print("Size = ", testChunk.getsize())
13 | print("IsAtty = ", testChunk.isatty())
14 | print("Read0 = ", testChunk.read(5))
15 | print("Tell = ", testChunk.tell())
16 |
--------------------------------------------------------------------------------
/stdlib_tests/test_colorsys.py:
--------------------------------------------------------------------------------
1 | import colorsys
2 |
3 |
4 | print(colorsys.rgb_to_hls(256, 0, 0))
5 | print(colorsys.hls_to_rgb(*colorsys.rgb_to_hls(256, 0, 0)))
6 |
--------------------------------------------------------------------------------
/stdlib_tests/test_datetime.py:
--------------------------------------------------------------------------------
1 | from datetime import datetime
2 |
3 | print(datetime.now())
4 |
--------------------------------------------------------------------------------
/stdlib_tests/test_decimal.py:
--------------------------------------------------------------------------------
1 | from decimal import Decimal
2 |
3 | print(Decimal(10))
4 |
--------------------------------------------------------------------------------
/stdlib_tests/test_ipaddress.py:
--------------------------------------------------------------------------------
1 | import ipaddress
2 |
3 | print(ipaddress.IPv4Address('192.168.0.1'))
4 | print(ipaddress.IPv4Address(323223552))
5 | print(ipaddress.IPv4Address(b'\xC0\xA8\x00\x01'))
6 | print(ipaddress.IPv6Address('2001:db8::'))
7 | print(ipaddress.ip_network('192.168.0.0/28'))
8 | print(ipaddress.IPv4Address('127.0.0.2') > ipaddress.IPv4Address('127.0.0.1'))
9 | print(ipaddress.IPv4Address('127.0.0.2') == ipaddress.IPv4Address('127.0.0.1'))
10 | print(ipaddress.IPv4Address('127.0.0.2') != ipaddress.IPv4Address('127.0.0.1'))
11 | print(ipaddress.IPv4Address('127.0.0.2') + 3)
12 | print(ipaddress.IPv4Address('127.0.0.2') - 3)
13 | print(list(ipaddress.ip_network('192.0.2.0/29').hosts()))
14 | print(list(ipaddress.ip_network('192.0.2.0/24').subnets()))
15 | print(ipaddress.ip_network('192.0.2.1/32').compare_networks(ipaddress.ip_network('192.0.2.0/32')))
16 | for addr in ipaddress.IPv4Network('192.0.2.0/28'):
17 | print(addr)
18 | print(ipaddress.IPv4Address('192.0.2.6') in ipaddress.IPv4Network('192.0.2.0/28'))
19 |
20 |
--------------------------------------------------------------------------------
/stdlib_tests/test_itertools.py:
--------------------------------------------------------------------------------
1 | import itertools
2 |
3 | print(list(itertools.repeat(4, 5)))
4 |
--------------------------------------------------------------------------------
/stdlib_tests/test_json.py:
--------------------------------------------------------------------------------
1 | import json
2 | print(json.dumps(['1', {'2': ('3', 4)}]))
3 |
--------------------------------------------------------------------------------
/stdlib_tests/test_keyword.py:
--------------------------------------------------------------------------------
1 | from keyword import iskeyword
2 |
3 | print(iskeyword('def'))
4 | print(iskeyword('raise'))
5 | print(iskeyword('elif'))
6 | print(iskeyword('not_keyword'))
7 |
--------------------------------------------------------------------------------
/stdlib_tests/test_operator.py:
--------------------------------------------------------------------------------
1 | import operator
2 |
3 | print(operator.itemgetter(1)(['a', 'b', 'c']))
4 |
--------------------------------------------------------------------------------
/stdlib_tests/test_textwrap.py:
--------------------------------------------------------------------------------
1 | import textwrap
2 |
3 |
4 | print(textwrap.fill('one two three four five six seven', width=10))
5 |
--------------------------------------------------------------------------------
/stdlib_tests/test_this.py:
--------------------------------------------------------------------------------
1 | import this
2 |
--------------------------------------------------------------------------------
/stdlib_tests/test_types.py:
--------------------------------------------------------------------------------
1 | import types
2 |
3 | print(types.new_class('SomeClass'))
4 |
--------------------------------------------------------------------------------
/stdlib_tests/test_urllib.py:
--------------------------------------------------------------------------------
1 | from urllib.parse import urlparse
2 |
3 | o = urlparse('http://127.0.0.1:8000')
4 | print(o.port)
5 |
--------------------------------------------------------------------------------
/stdlib_tests/test_warnings.py:
--------------------------------------------------------------------------------
1 | import warnings
2 |
3 | warnings.showwarning("Show warning", category=Warning, filename="test_warnings", lineno=3)
4 |
--------------------------------------------------------------------------------
/tests/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beeware/voc/dd9f15a7d56d00d8c9e501a57194694e601ea401/tests/__init__.py
--------------------------------------------------------------------------------
/tests/benchmarks/binary-trees.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | # The Computer Language Benchmarks Game
3 | # http://shootout.alioth.debian.org/
4 | #
5 | # contributed by Antoine Pitrou
6 | # modified by Dominique Wahli and Daniel Nanz
7 |
8 | import sys
9 |
10 |
11 | def make_tree(i, d):
12 |
13 | if d > 0:
14 | i2 = i + i
15 | d -= 1
16 | return (i, make_tree(i2 - 1, d), make_tree(i2, d))
17 | return (i, None, None)
18 |
19 |
20 | def check_tree(node):
21 |
22 | (i, l, r) = node
23 | if l is None:
24 | return i
25 | else:
26 | return i + check_tree(l) - check_tree(r)
27 |
28 |
29 | def make_check(itde, make=make_tree, check=check_tree):
30 |
31 | i, d = itde
32 | return check(make(i, d))
33 |
34 |
35 | def get_argchunks(i, d, chunksize=5000):
36 |
37 | assert chunksize % 2 == 0
38 | chunk = []
39 | for k in range(1, i + 1):
40 | chunk.extend([(k, d), (-k, d)])
41 | if len(chunk) == chunksize:
42 | yield chunk
43 | chunk = []
44 | if len(chunk) > 0:
45 | yield chunk
46 |
47 |
48 | def main(n, min_depth=4):
49 |
50 | max_depth = max(min_depth + 2, n)
51 | stretch_depth = max_depth + 1
52 |
53 | print('stretch tree of depth %d\t check: %d' % (
54 | stretch_depth, make_check((0, stretch_depth))))
55 |
56 | long_lived_tree = make_tree(0, max_depth)
57 |
58 | mmd = max_depth + min_depth
59 | for d in range(min_depth, stretch_depth, 2):
60 | i = 2 ** (mmd - d)
61 | cs = 0
62 | for argchunk in get_argchunks(i, d):
63 | cs += sum(map(make_check, argchunk))
64 | print('%d\t trees of depth %d\t check: %d' % (i * 2, d, cs))
65 |
66 | print('long lived tree of depth %d\t check: %d' % (
67 | max_depth, check_tree(long_lived_tree)))
68 |
69 |
70 | if __name__ == '__main__':
71 | for i in range(int(sys.argv[1])):
72 | main(int(sys.argv[1]))
73 |
--------------------------------------------------------------------------------
/tests/builtins/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beeware/voc/dd9f15a7d56d00d8c9e501a57194694e601ea401/tests/builtins/__init__.py
--------------------------------------------------------------------------------
/tests/builtins/test_abs.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 | from unittest import expectedFailure
4 |
5 |
6 | class AbsTests(TranspileTestCase):
7 | def test_abs_not_implemented(self):
8 | self.assertCodeExecution("""
9 | class NotAbsLike:
10 | pass
11 | x = NotAbsLike()
12 | try:
13 | print(abs(x))
14 | except TypeError as err:
15 | print(err)
16 | """)
17 |
18 | @expectedFailure
19 | def test_incorrect_abs_call(self):
20 | self.assertCodeExecution("""
21 | x = 1
22 | print(x.abs())
23 | """)
24 |
25 |
26 | class BuiltinAbsFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
27 | functions = ["abs"]
28 |
29 | not_implemented = [
30 | ]
31 |
--------------------------------------------------------------------------------
/tests/builtins/test_all.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class AllTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinAllFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["all"]
10 |
--------------------------------------------------------------------------------
/tests/builtins/test_any.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class AnyTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinAnyFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["any"]
10 |
--------------------------------------------------------------------------------
/tests/builtins/test_ascii.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class AsciiTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinAsciiFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["ascii"]
10 |
11 | not_implemented = [
12 | 'test_bool',
13 | 'test_bytearray',
14 | 'test_bytes',
15 | 'test_class',
16 | 'test_complex',
17 | 'test_dict',
18 | 'test_float',
19 | 'test_frozenset',
20 | 'test_int',
21 | 'test_list',
22 | 'test_None',
23 | 'test_NotImplemented',
24 | 'test_range',
25 | 'test_set',
26 | 'test_slice',
27 | 'test_str',
28 | 'test_tuple',
29 | 'test_obj',
30 | ]
31 |
--------------------------------------------------------------------------------
/tests/builtins/test_bin.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class BinTests(TranspileTestCase):
5 | def test_int_but_no_index(self):
6 | self.assertCodeExecution("""
7 | class IntLike:
8 | def __init__(self, val):
9 | self.val = val
10 | def __int__(self):
11 | return self.val
12 |
13 | x = IntLike(5)
14 | try:
15 | print(bin(x))
16 | except TypeError as err:
17 | print(err)
18 | """)
19 |
20 |
21 | class BuiltinBinFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
22 | functions = ["bin"]
23 |
24 | not_implemented = [
25 | ]
26 |
--------------------------------------------------------------------------------
/tests/builtins/test_bool.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class BoolTests(TranspileTestCase):
5 | def test_bool_omitted(self):
6 | self.assertCodeExecution("""
7 | print(bool())
8 | """)
9 |
10 | def test_bool_like(self):
11 | self.assertCodeExecution("""
12 | class BoolLike:
13 | def __init__(self, val):
14 | self.val = val
15 |
16 | def __bool__(self):
17 | return self.val == 1
18 |
19 | print(bool(BoolLike(0)))
20 | print(bool(BoolLike(1)))
21 | """)
22 |
23 | def test_len_only(self):
24 | self.assertCodeExecution("""
25 | class LenButNoBool:
26 | def __init__(self, val):
27 | self.val = val
28 |
29 | def __len__(self):
30 | return self.val
31 |
32 | print(bool(LenButNoBool(0)))
33 | print(bool(LenButNoBool(1)))
34 | """)
35 |
36 | def test_no_bool_no_len(self):
37 | self.assertCodeExecution("""
38 | class NoLenNoBool:
39 | def __init__(self, val):
40 | self.val = val
41 |
42 | print(bool(NoLenNoBool(0)))
43 | print(bool(NoLenNoBool(1)))
44 | print(bool(NoLenNoBool(42)))
45 | print(bool(NoLenNoBool(-2)))
46 | """)
47 |
48 |
49 | class BuiltinBoolFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
50 | functions = ["bool"]
51 |
52 | not_implemented = [
53 | ]
54 |
--------------------------------------------------------------------------------
/tests/builtins/test_bytearray.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class BytearrayTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinBytearrayFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["bytearray"]
10 |
--------------------------------------------------------------------------------
/tests/builtins/test_bytes.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class BytesTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinBytesFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["bytes"]
10 |
--------------------------------------------------------------------------------
/tests/builtins/test_callable.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class CallableTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinCallableFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["callable"]
10 |
11 | not_implemented = [
12 | ]
13 |
--------------------------------------------------------------------------------
/tests/builtins/test_chr.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class ChrTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinChrFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["chr"]
10 |
11 | not_implemented = [
12 | 'test_complex',
13 | ]
14 |
--------------------------------------------------------------------------------
/tests/builtins/test_classmethod.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class ClassmethodTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinClassmethodFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["classmethod"]
10 |
11 | not_implemented = [
12 | 'test_bool',
13 | 'test_bytearray',
14 | 'test_bytes',
15 | 'test_class',
16 | 'test_complex',
17 | 'test_dict',
18 | 'test_float',
19 | 'test_frozenset',
20 | 'test_int',
21 | 'test_list',
22 | 'test_None',
23 | 'test_NotImplemented',
24 | 'test_range',
25 | 'test_set',
26 | 'test_slice',
27 | 'test_str',
28 | 'test_tuple',
29 | 'test_obj',
30 | ]
31 |
--------------------------------------------------------------------------------
/tests/builtins/test_compile.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class CompileTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinCompileFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["compile"]
10 |
11 | not_implemented = [
12 | 'test_bool',
13 | 'test_bytearray',
14 | 'test_bytes',
15 | 'test_class',
16 | 'test_complex',
17 | 'test_dict',
18 | 'test_float',
19 | 'test_frozenset',
20 | 'test_int',
21 | 'test_list',
22 | 'test_None',
23 | 'test_NotImplemented',
24 | 'test_range',
25 | 'test_set',
26 | 'test_slice',
27 | 'test_str',
28 | 'test_tuple',
29 | 'test_obj',
30 | ]
31 |
--------------------------------------------------------------------------------
/tests/builtins/test_complex.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class ComplexTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinComplexFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["complex"]
10 |
11 | not_implemented = [
12 | 'test_complex',
13 | ]
14 |
--------------------------------------------------------------------------------
/tests/builtins/test_delattr.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinTwoargFunctionTestCase
2 |
3 |
4 | class DelattrTests(TranspileTestCase):
5 | def test_minimal(self):
6 | self.assertCodeExecution("""
7 | class MyClass(object):
8 | class_value = 42
9 |
10 | def __init__(self, val):
11 | self.value = val
12 |
13 | print("On class: ")
14 | delattr(MyClass, 'class_value')
15 | try:
16 | print(' class_value =', MyClass.class_value)
17 | print(" Shouldn't be able to get attribute class_value")
18 | except AttributeError:
19 | print(" Can't get attribute class_value")
20 |
21 | try:
22 | delattr(MyClass, 'class_value')
23 | print(" Shouldn't be able to delete attribute class_value")
24 | except AttributeError:
25 | print(" Can't delete attribute class_value")
26 |
27 | try:
28 | delattr(MyClass, 'other_class_value')
29 | print(" Shouldn't be able to delete attribute other_class_value")
30 | except AttributeError:
31 | print(" Can't delete attribute other_class_value")
32 |
33 | obj = MyClass(37)
34 |
35 | print("On instance:")
36 | delattr(obj, 'value')
37 | try:
38 | print(' value =', MyClass.value)
39 | print(" Shouldn't be able to get attribute value")
40 | except AttributeError:
41 | print(" Can't get attribute value")
42 |
43 | try:
44 | delattr(obj, 'value')
45 | print(" Shouldn't be able to delete attribute value")
46 | except AttributeError:
47 | print(" Can't delete attribute value")
48 |
49 | try:
50 | delattr(obj, 'other_value')
51 | print(" Shouldn't be able to delete attribute other_value")
52 | except AttributeError:
53 | print(" Can't delete attribute other_value")
54 | """, run_in_function=False)
55 |
56 |
57 | class BuiltinDelattrFunctionTests(BuiltinTwoargFunctionTestCase, TranspileTestCase):
58 | functions = ["delattr"]
59 |
60 | not_implemented = [
61 | 'test_class_str',
62 | 'test_obj_str',
63 | 'test_class_obj'
64 | ]
65 |
--------------------------------------------------------------------------------
/tests/builtins/test_dict.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class DictTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinDictFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["dict"]
10 |
--------------------------------------------------------------------------------
/tests/builtins/test_dir.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class DirTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinDirFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["dir"]
10 |
11 | not_implemented = [
12 | 'test_bool',
13 | 'test_bytearray',
14 | 'test_bytes',
15 | 'test_class',
16 | 'test_complex',
17 | 'test_dict',
18 | 'test_float',
19 | 'test_frozenset',
20 | 'test_int',
21 | 'test_list',
22 | 'test_None',
23 | 'test_NotImplemented',
24 | 'test_range',
25 | 'test_set',
26 | 'test_slice',
27 | 'test_str',
28 | 'test_tuple',
29 | 'test_obj',
30 | ]
31 |
--------------------------------------------------------------------------------
/tests/builtins/test_divmod.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase, BuiltinTwoargFunctionTestCase
2 |
3 |
4 | class DivmodTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinDivmodFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["divmod"]
10 |
11 | not_implemented = [
12 | 'test_bool',
13 | 'test_bytearray',
14 | 'test_bytes',
15 | 'test_class',
16 | 'test_complex',
17 | 'test_dict',
18 | 'test_float',
19 | 'test_frozenset',
20 | 'test_int',
21 | 'test_list',
22 | 'test_None',
23 | 'test_NotImplemented',
24 | 'test_range',
25 | 'test_set',
26 | 'test_slice',
27 | 'test_str',
28 | 'test_tuple',
29 | 'test_obj',
30 | ]
31 |
32 |
33 | class BuiltinTwoargDivmodFunctionTests(BuiltinTwoargFunctionTestCase, TranspileTestCase):
34 | functions = ["divmod"]
35 |
36 | not_implemented = [
37 | 'test_obj_class',
38 | 'test_class_obj'
39 | ]
40 |
--------------------------------------------------------------------------------
/tests/builtins/test_enumerate.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class EnumerateTests(TranspileTestCase):
5 | def test_enumerate(self):
6 | self.assertCodeExecution("""
7 | lst=['a','b','c','d','e']
8 | print(list(enumerate(lst)))
9 | lst=['a','b','c','d','e']
10 | print(list(enumerate(lst,start=-40)))
11 | lst=['a','b','c','d','e']
12 | print(list(enumerate(lst,start=46)))
13 | lst=[('a',4),'b','c',10,'e']
14 | print(list(enumerate(lst)))
15 | print(list(enumerate([])))
16 | print(list(enumerate([], start=10)))
17 | """)
18 |
19 | def test_enumerate_invalid_start_args(self):
20 | self.assertCodeExecution("""
21 | try:
22 | print(list(enumerate(['a','b','c'], start=None)))
23 | except TypeError as err:
24 | print(err)
25 | try:
26 | print(list(enumerate(['a','b','c'], start=1.5)))
27 | except TypeError as err:
28 | print(err)
29 | try:
30 | print(list(enumerate(['a','b','c'], start="start_string")))
31 | except TypeError as err:
32 | print(err)
33 | """)
34 |
35 | def test_enumerate_invalid_iterable(self):
36 | self.assertCodeExecution("""
37 | try:
38 | num=10
39 | print(list(enumerate(num, start=10)))
40 | except TypeError as err:
41 | print(err)
42 | try:
43 | print(list(enumerate()))
44 | except TypeError as err:
45 | print(err)
46 | """)
47 |
48 |
49 | class BuiltinEnumerateFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
50 | functions = ["enumerate"]
51 |
52 | not_implemented = [
53 | 'test_bytearray',
54 | 'test_bytes',
55 | 'test_dict',
56 | 'test_frozenset',
57 | 'test_list',
58 | 'test_range',
59 | 'test_set',
60 | 'test_str',
61 | 'test_tuple',
62 | ]
63 |
--------------------------------------------------------------------------------
/tests/builtins/test_eval.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class EvalTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinEvalFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["eval"]
10 |
11 | not_implemented = [
12 | 'test_bool',
13 | 'test_bytearray',
14 | 'test_bytes',
15 | 'test_class',
16 | 'test_complex',
17 | 'test_dict',
18 | 'test_float',
19 | 'test_frozenset',
20 | 'test_int',
21 | 'test_list',
22 | 'test_None',
23 | 'test_NotImplemented',
24 | 'test_range',
25 | 'test_set',
26 | 'test_slice',
27 | 'test_str',
28 | 'test_tuple',
29 | 'test_obj',
30 | ]
31 |
--------------------------------------------------------------------------------
/tests/builtins/test_exec.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class ExecTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinExecFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["exec"]
10 |
11 | not_implemented = [
12 | 'test_bool',
13 | 'test_bytearray',
14 | 'test_bytes',
15 | 'test_class',
16 | 'test_complex',
17 | 'test_dict',
18 | 'test_float',
19 | 'test_frozenset',
20 | 'test_int',
21 | 'test_list',
22 | 'test_None',
23 | 'test_NotImplemented',
24 | 'test_range',
25 | 'test_set',
26 | 'test_slice',
27 | 'test_str',
28 | 'test_tuple',
29 | 'test_obj'
30 | ]
31 |
--------------------------------------------------------------------------------
/tests/builtins/test_float.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class FloatTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinFloatFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["float"]
10 |
11 | not_implemented = [
12 | 'test_bytearray',
13 | 'test_bytes',
14 | 'test_complex',
15 | ]
16 |
--------------------------------------------------------------------------------
/tests/builtins/test_format.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class FormatTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinFormatFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["format"]
10 |
11 | not_implemented = [
12 | 'test_class',
13 | ]
14 |
--------------------------------------------------------------------------------
/tests/builtins/test_frozenset.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class FrozensetTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinFrozensetFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["frozenset"]
10 |
11 | not_implemented = [
12 | 'test_bytes',
13 | 'test_str',
14 | ]
15 |
16 | is_flakey = [
17 | 'test_dict',
18 | 'test_tuple',
19 | ]
20 |
--------------------------------------------------------------------------------
/tests/builtins/test_getattr.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinTwoargFunctionTestCase
2 |
3 |
4 | class GetattrTests(TranspileTestCase):
5 | def test_minimal(self):
6 | self.assertCodeExecution("""
7 | class MyClass(object):
8 | class_value = 42
9 |
10 | def __init__(self, val):
11 | self.value = val
12 |
13 | def stuff(self, delta):
14 | print("DELTA: ", delta)
15 | return self.value + delta
16 |
17 | print("On class: ")
18 | print(' class_value =', getattr(MyClass, 'class_value'))
19 | # print(' stuff =', getattr(MyClass, 'stuff')) # FIXME
20 | try:
21 | getattr(MyClass, 'foo')
22 | print(" Shouldn't be able to get attribute foo")
23 | except AttributeError:
24 | print(" Can't get attribute foo")
25 | print(' foo (default) =', getattr(MyClass, 'foo', 42))
26 |
27 | obj = MyClass(37)
28 |
29 | print("On instance:")
30 | print(' class_value =', getattr(obj, 'class_value'))
31 | print(' value =', getattr(obj, 'value'))
32 | # print(' stuff =', getattr(obj, 'stuff')) # FIXME
33 | try:
34 | getattr(MyClass, 'foo')
35 | print(" Shouldn't be able to get attribute foo")
36 | except AttributeError:
37 | print(" Can't get attribute foo")
38 | print(' foo (default) =', getattr(obj, 'foo', 42))
39 | """, run_in_function=False)
40 |
41 |
42 | class BuiltinGetattrFunctionTests(BuiltinTwoargFunctionTestCase, TranspileTestCase):
43 | functions = ["getattr"]
44 |
45 | not_implemented = [
46 | 'test_class_str',
47 | 'test_obj_str',
48 | ]
49 |
--------------------------------------------------------------------------------
/tests/builtins/test_globals.py:
--------------------------------------------------------------------------------
1 | from unittest import expectedFailure
2 |
3 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
4 |
5 |
6 | class GlobalsTests(TranspileTestCase):
7 | def test_simple(self):
8 | self.assertCodeExecution("""
9 | print("There are %s globals" % len(globals()))
10 | x = 1
11 | y = 'z'
12 | print("There are %s globals" % len(globals()))
13 |
14 | def method():
15 | print("In method: there are %s globals" % len(globals()))
16 |
17 | print("globals()['x'] =", globals()['x'])
18 | print("globals()['y'] =", globals()['y'])
19 | try:
20 | print("globals()['z'] =", globals()['z'])
21 | except KeyError:
22 | print("Variable z not defined")
23 |
24 | globals()[y] = 2
25 |
26 | print("In method: there are %s globals" % len(globals()))
27 |
28 | method()
29 |
30 | print("There are %s globals" % len(globals()))
31 | print("globals()['x'] =", globals()['x'])
32 | print("globals()['y'] =", globals()['y'])
33 | print("globals()['z'] =", globals()['z'])
34 | print('x', x)
35 | print('y', y)
36 | print('z', z)
37 |
38 | print('Done')
39 | """, run_in_function=False)
40 |
41 | @expectedFailure
42 | def test_preloaded_globals(self):
43 | self.assertCodeExecution("""
44 | glbs = globals
45 | x = 1
46 | y = 2
47 |
48 | for i in range(10):
49 | print(glbs())
50 | """)
51 |
52 | class BuiltinGlobalsFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
53 | functions = ["globals"]
54 |
55 | not_implemented = [
56 | 'test_bool',
57 | 'test_bytearray',
58 | 'test_bytes',
59 | 'test_class',
60 | 'test_complex',
61 | 'test_dict',
62 | 'test_float',
63 | 'test_frozenset',
64 | 'test_int',
65 | 'test_list',
66 | 'test_None',
67 | 'test_NotImplemented',
68 | 'test_range',
69 | 'test_set',
70 | 'test_slice',
71 | 'test_str',
72 | 'test_tuple',
73 | 'test_obj',
74 | ]
75 |
--------------------------------------------------------------------------------
/tests/builtins/test_hasattr.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinTwoargFunctionTestCase
2 |
3 |
4 | class HasattrTests(TranspileTestCase):
5 | def test_minimal(self):
6 | self.assertCodeExecution("""
7 | class MyClass(object):
8 | class_value = 42
9 |
10 | def __init__(self, val):
11 | self.value = val
12 |
13 | def stuff(self, delta):
14 | print("DELTA: ", delta)
15 | return self.value + delta
16 |
17 | print("On class: ")
18 | print('MyClass.foo', hasattr(MyClass, 'foo'))
19 | print('MyClass.value', hasattr(MyClass, 'value'))
20 | print('MyClass.class_value', hasattr(MyClass, 'class_value'))
21 | print('MyClass.stuff', hasattr(MyClass, 'stuff'))
22 |
23 | obj = MyClass(37)
24 |
25 | print("On instance:")
26 | print('obj.foo', hasattr(obj, 'foo'))
27 | print('obj.value', hasattr(obj, 'value'))
28 | print('obj.class_value', hasattr(obj, 'class_value'))
29 | print('obj.stuff', hasattr(obj, 'stuff'))
30 | """, run_in_function=False)
31 |
32 |
33 | class BuiltinHasattrFunctionTests(BuiltinTwoargFunctionTestCase, TranspileTestCase):
34 | functions = ["hasattr"]
35 |
36 | not_implemented = [
37 | ]
38 |
--------------------------------------------------------------------------------
/tests/builtins/test_hash.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class HashTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinHashFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["hash"]
10 |
11 | not_implemented = [
12 | 'test_bool',
13 | 'test_bytearray',
14 | 'test_bytes',
15 | 'test_class',
16 | 'test_complex',
17 | 'test_dict',
18 | 'test_float',
19 | 'test_frozenset',
20 | 'test_int',
21 | 'test_list',
22 | 'test_None',
23 | 'test_NotImplemented',
24 | 'test_range',
25 | 'test_set',
26 | 'test_slice',
27 | 'test_str',
28 | 'test_tuple',
29 | 'test_obj',
30 | ]
31 |
--------------------------------------------------------------------------------
/tests/builtins/test_help.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class HelpTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinHelpFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["help"]
10 |
11 | not_implemented = [
12 | 'test_bool',
13 | 'test_bytearray',
14 | 'test_bytes',
15 | 'test_class',
16 | 'test_complex',
17 | 'test_dict',
18 | 'test_float',
19 | 'test_frozenset',
20 | 'test_int',
21 | 'test_list',
22 | 'test_None',
23 | 'test_NotImplemented',
24 | 'test_range',
25 | 'test_set',
26 | 'test_slice',
27 | 'test_str',
28 | 'test_tuple',
29 | 'test_obj',
30 | ]
31 |
--------------------------------------------------------------------------------
/tests/builtins/test_hex.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class HexTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinHexFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["hex"]
10 |
11 | not_implemented = [
12 | ]
13 |
--------------------------------------------------------------------------------
/tests/builtins/test_id.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class IdTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinIdFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["id"]
10 |
11 | not_implemented = [
12 | 'test_bool',
13 | 'test_bytearray',
14 | 'test_bytes',
15 | 'test_class',
16 | 'test_complex',
17 | 'test_dict',
18 | 'test_float',
19 | 'test_frozenset',
20 | 'test_int',
21 | 'test_list',
22 | 'test_None',
23 | 'test_NotImplemented',
24 | 'test_range',
25 | 'test_set',
26 | 'test_slice',
27 | 'test_str',
28 | 'test_tuple',
29 | 'test_obj',
30 | ]
31 |
--------------------------------------------------------------------------------
/tests/builtins/test_import.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class ImportTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinImportFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["__import__"]
10 |
11 | not_implemented = [
12 | 'test_bool',
13 | 'test_bytearray',
14 | 'test_bytes',
15 | 'test_class',
16 | 'test_complex',
17 | 'test_dict',
18 | 'test_float',
19 | 'test_frozenset',
20 | 'test_int',
21 | 'test_list',
22 | 'test_None',
23 | 'test_NotImplemented',
24 | 'test_range',
25 | 'test_set',
26 | 'test_slice',
27 | 'test_str',
28 | 'test_tuple',
29 | 'test_obj',
30 | ]
31 |
--------------------------------------------------------------------------------
/tests/builtins/test_input.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase # , BuiltinFunctionTestCase
2 |
3 |
4 | class InputTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | # FIXME: This test can't run without a redirection for stdin.
9 | # class BuiltinInputFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
10 | # functions = ["input"]
11 |
12 | # not_implemented = [
13 | # 'test_bool',
14 | # 'test_bytearray',
15 | # 'test_bytes',
16 | # 'test_class',
17 | # 'test_complex',
18 | # 'test_dict',
19 | # 'test_float',
20 | # 'test_frozenset',
21 | # 'test_int',
22 | # 'test_list',
23 | # 'test_None',
24 | # 'test_NotImplemented',
25 | # 'test_range',
26 | # 'test_set',
27 | # 'test_slice',
28 | # 'test_str',
29 | # 'test_tuple',
30 | # ]
31 |
--------------------------------------------------------------------------------
/tests/builtins/test_int.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class IntTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinIntFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["int"]
10 |
11 | not_implemented = [
12 | 'test_bytearray',
13 | 'test_bytes',
14 | ]
15 |
--------------------------------------------------------------------------------
/tests/builtins/test_iter.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class IterTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinIterFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["iter"]
10 |
11 | not_implemented = [
12 | 'test_bytearray',
13 | 'test_bytes',
14 | 'test_str',
15 | ]
16 |
--------------------------------------------------------------------------------
/tests/builtins/test_len.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class LenTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinLenFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["len"]
10 |
11 | not_implemented = []
12 |
--------------------------------------------------------------------------------
/tests/builtins/test_list.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase, SAMPLE_SUBSTITUTIONS
2 |
3 |
4 | class ListTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinListFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["list"]
10 |
11 | substitutions = dict(SAMPLE_SUBSTITUTIONS)
12 | substitutions.update({
13 | "[1, 2.3456, 'another']": [
14 | "[1, 'another', 2.3456]",
15 | "[2.3456, 1, 'another']",
16 | "[2.3456, 'another', 1]",
17 | "['another', 1, 2.3456]",
18 | "['another', 2.3456, 1]",
19 | ],
20 | "['a', 'c', 'd']": [
21 | "['a', 'd', 'c']",
22 | "['c', 'a', 'd']",
23 | "['c', 'd', 'a']",
24 | "['d', 'a', 'c']",
25 | "['d', 'c', 'a']",
26 | ]
27 | })
28 |
--------------------------------------------------------------------------------
/tests/builtins/test_map.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinTwoargFunctionTestCase
2 |
3 |
4 | class MapTests(TranspileTestCase):
5 | base_code = """
6 | iterable = %s
7 | def testish(x):
8 | return %s
9 | it = map(testish, iterable)
10 | print(it)
11 | print(next(it))
12 | print(next(it))
13 | print(next(it))
14 | try:
15 | print(next(it))
16 | except StopIteration:
17 | pass
18 | """
19 |
20 | def test_bool(self):
21 | self.assertCodeExecution(self.base_code % ("[True, False, True]", "bool(x)"))
22 |
23 | def test_bytearray(self):
24 | self.assertCodeExecution(self.base_code % ("b'123'", "x"))
25 |
26 | def test_float(self):
27 | self.assertCodeExecution(self.base_code % ("[3.14, 2.17, 1.0]", "x > 1"))
28 |
29 | def test_int(self):
30 | self.assertCodeExecution(self.base_code % ("[1, 2, 3]", "x * 2"))
31 |
32 |
33 | class BuiltinMapFunctionTests(BuiltinTwoargFunctionTestCase, TranspileTestCase):
34 | functions = ["map"]
35 |
36 | not_implemented = [
37 | 'test_class_obj'
38 | ]
39 |
--------------------------------------------------------------------------------
/tests/builtins/test_max.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class MaxTests(TranspileTestCase):
5 | def test_args(self):
6 | self.assertCodeExecution("""
7 | try:
8 | max()
9 | except TypeError:
10 | print("Threw an error as expected")
11 |
12 | # Single integer
13 | try:
14 | max(4)
15 | except TypeError:
16 | print("Threw an error as expected")
17 |
18 | # Multiple integers
19 | print(max(1, 5, 2, 4))
20 |
21 | # Mixed types
22 | print(max(2, 5.0, True))
23 | print(max(5.0, 2, True))
24 | print(max(True, 5.0, 2))
25 |
26 | # String (an iterable)
27 | print(max("Hello World"))
28 |
29 | # Multiple strings
30 | print(max("Hello World", "Goodbye World"))
31 | """)
32 |
33 | def test_iterable(self):
34 | self.assertCodeExecution("""
35 | # Empty iterable
36 | try:
37 | max([])
38 | except ValueError:
39 | print("Threw an error as expected")
40 |
41 | # Single iterable argument
42 | print(max([1, 5, 2, 4]))
43 |
44 | # Multiple iterables
45 | print(max([1, 6], [1, 5, 2, 4]))
46 | """)
47 |
48 | def test_default(self):
49 | self.assertCodeExecution("""
50 | # Empty iterable
51 | print(max([], default=42))
52 |
53 | # Single iterable argument
54 | print(max([1, 5, 2, 4], default=42))
55 |
56 | # Multiple iterables
57 | try:
58 | print(max([1, 6], [1, 5, 2, 4], default=42))
59 | except TypeError:
60 | print("Threw an error as expected")
61 | """)
62 |
63 | def test_key(self):
64 | self.assertCodeExecution("""
65 | # key applied over args
66 | print(max(51, 42, 33, 24, key=lambda v: v % 10))
67 |
68 | # key applied over iterable
69 | print(max([51, 42, 33, 24], key=lambda v: v % 10))
70 | """)
71 |
72 |
73 | class BuiltinMaxFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
74 | functions = ["max"]
75 |
--------------------------------------------------------------------------------
/tests/builtins/test_memoryview.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class MemoryviewTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinMemoryviewFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["memoryview"]
10 |
11 | not_implemented = [
12 | 'test_bool',
13 | 'test_bytearray',
14 | 'test_bytes',
15 | 'test_class',
16 | 'test_complex',
17 | 'test_dict',
18 | 'test_float',
19 | 'test_frozenset',
20 | 'test_int',
21 | 'test_list',
22 | 'test_None',
23 | 'test_NotImplemented',
24 | 'test_range',
25 | 'test_set',
26 | 'test_slice',
27 | 'test_str',
28 | 'test_tuple',
29 | 'test_obj',
30 | ]
31 |
--------------------------------------------------------------------------------
/tests/builtins/test_min.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class MinTests(TranspileTestCase):
5 | def test_args(self):
6 | self.assertCodeExecution("""
7 | try:
8 | min()
9 | except TypeError:
10 | print("Threw an error as expected")
11 |
12 | # Single integer
13 | try:
14 | min(4)
15 | except TypeError:
16 | print("Threw an error as expected")
17 |
18 | # Multiple integers
19 | print(min(1, 5, 2, 4))
20 |
21 | # Mixed types
22 | print(min(2, 5.0, True))
23 | print(min(5.0, 2, True))
24 | print(min(True, 5.0, 2))
25 |
26 | # String (an iterable)
27 | print(min("Hello World"))
28 |
29 | # Multiple strings
30 | print(min("Hello World", "Goodbye World"))
31 | """)
32 |
33 | def test_iterable(self):
34 | self.assertCodeExecution("""
35 | # Empty iterable
36 | try:
37 | min([])
38 | except ValueError:
39 | print("Threw an error as expected")
40 |
41 | # Single iterable argument
42 | print(min([1, 5, 2, 4]))
43 |
44 | # Multiple iterables
45 | print(min([1, 6], [1, 5, 2, 4]))
46 | """)
47 |
48 | def test_default(self):
49 | self.assertCodeExecution("""
50 | # Empty iterable
51 | print(min([], default=42))
52 |
53 | # Single iterable argument
54 | print(min([1, 5, 2, 4], default=42))
55 |
56 | # Multiple iterables
57 | try:
58 | print(min([1, 6], [1, 5, 2, 4], default=42))
59 | except TypeError:
60 | print("Threw an error as expected")
61 | """)
62 |
63 | def test_key(self):
64 | self.assertCodeExecution("""
65 | # key applied over args
66 | print(min(51, 42, 33, 24, key=lambda v: v % 10))
67 |
68 | # key applied over iterable
69 | print(min([51, 42, 33, 24], key=lambda v: v % 10))
70 |
71 | print(min([(2, 4), (5, 0), (4, 0), (9, 3)], key=lambda t: t[1]))
72 | """)
73 |
74 |
75 | class BuiltinMinFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
76 | functions = ["min"]
77 |
78 | not_implemented = [
79 | 'test_tuple',
80 | ]
81 |
--------------------------------------------------------------------------------
/tests/builtins/test_next.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class NextTests(TranspileTestCase):
5 | def test_next_success(self):
6 | self.assertCodeExecution("""
7 | i = iter([1])
8 | print(next(i))
9 | """)
10 |
11 | def test_next_success_with_default(self):
12 | self.assertCodeExecution("""
13 | i = iter([1])
14 | print(next(i, 0))
15 | """)
16 |
17 | def test_next_exhausted_with_default(self):
18 | self.assertCodeExecution("""
19 | i = iter([])
20 | print(next(i, 0))
21 | """)
22 |
23 | def test_next_exhausted_without_default(self):
24 | self.assertCodeExecution("""
25 | i = iter([])
26 | try:
27 | print(next(i))
28 | except StopIteration as err:
29 | print(err)
30 | print('Done.')
31 | """)
32 |
33 |
34 | class BuiltinNextFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
35 | functions = ["next"]
36 |
37 | not_implemented = [
38 | ]
39 |
--------------------------------------------------------------------------------
/tests/builtins/test_object.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class ObjectTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinObjectFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["object"]
10 |
11 | not_implemented = [
12 | ]
13 |
--------------------------------------------------------------------------------
/tests/builtins/test_oct.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class OctTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinOctFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["oct"]
10 |
11 | not_implemented = [
12 | ]
13 |
--------------------------------------------------------------------------------
/tests/builtins/test_open.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class OpenTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinOpenFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["open"]
10 |
11 | not_implemented = [
12 | 'test_bool',
13 | 'test_bytearray',
14 | 'test_bytes',
15 | 'test_class',
16 | 'test_complex',
17 | 'test_dict',
18 | 'test_float',
19 | 'test_frozenset',
20 | 'test_int',
21 | 'test_list',
22 | 'test_None',
23 | 'test_NotImplemented',
24 | 'test_range',
25 | 'test_set',
26 | 'test_slice',
27 | 'test_str',
28 | 'test_tuple',
29 | 'test_obj',
30 | ]
31 |
--------------------------------------------------------------------------------
/tests/builtins/test_ord.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class OrdTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinOrdFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["ord"]
10 |
11 | not_implemented = [
12 | 'test_bytes',
13 | 'test_bytearray',
14 | ]
15 |
--------------------------------------------------------------------------------
/tests/builtins/test_print.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class PrintTests(TranspileTestCase):
5 | def test_fileobj(self):
6 | self.assertCodeExecution("""
7 | class FileLikeObject:
8 | def __init__(self):
9 | self.buffer = ''
10 |
11 | def write(self, content):
12 | self.buffer = self.buffer + (content * 2)
13 |
14 | out = FileLikeObject()
15 |
16 | print('hello', 'world', file=out)
17 | print('goodbye', 'world', file=out)
18 | print()
19 | """)
20 |
21 | def test_sep(self):
22 | self.assertCodeExecution("""
23 | print('hello world', 'goodbye world', sep='-')
24 | print()
25 | """)
26 |
27 | def test_end(self):
28 | self.assertCodeExecution("""
29 | print('hello world', 'goodbye world', end='-')
30 | print()
31 | """)
32 |
33 | def test_flush(self):
34 | self.assertCodeExecution("""
35 | print('hello world', 'goodbye world', flush=True)
36 | print()
37 | """)
38 |
39 | def test_combined(self):
40 | self.assertCodeExecution("""
41 | class FileLikeObject:
42 | def __init__(self):
43 | self.buffer = ''
44 |
45 | def write(self, content):
46 | self.buffer = self.buffer + (content * 2)
47 |
48 | def flush(self):
49 | self.buffer = self.buffer + '<<<'
50 |
51 | out = FileLikeObject()
52 |
53 | print('hello', 'world', sep='*', end='-', file=out, flush=True)
54 | print('goodbye', 'world', file=out, sep='-', end='*')
55 | print()
56 | """)
57 |
58 |
59 | class BuiltinPrintFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
60 | functions = ["print"]
61 |
62 | not_implemented = [
63 | 'test_class',
64 | ]
65 |
--------------------------------------------------------------------------------
/tests/builtins/test_property.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class PropertyTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinPropertyFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["property"]
10 |
11 | not_implemented = [
12 | ]
13 |
--------------------------------------------------------------------------------
/tests/builtins/test_range.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class RangeTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinRangeFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["range"]
10 |
11 | not_implemented = [
12 | 'test_bool',
13 | ]
14 |
--------------------------------------------------------------------------------
/tests/builtins/test_repr.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class ReprTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinReprFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["repr"]
10 |
11 | not_implemented = [
12 | 'test_class',
13 | 'test_complex',
14 | ]
15 |
--------------------------------------------------------------------------------
/tests/builtins/test_reversed.py:
--------------------------------------------------------------------------------
1 | from .. utils import SAMPLE_DATA, TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | def _iterate_test(datatype):
5 |
6 | def test_func(self):
7 | code = '\n'.join([
8 | '\nfor x in {value}:\n print(x)\n'.format(value=value)
9 | for value in SAMPLE_DATA[datatype]
10 | ])
11 | self.assertCodeExecution(code)
12 |
13 | return test_func
14 |
15 |
16 | class ReversedTests(TranspileTestCase):
17 | test_iterate_bytearray = _iterate_test('bytearray')
18 | test_iterate_bytes = _iterate_test('bytes')
19 | test_iterate_list = _iterate_test('list')
20 | test_iterate_range = _iterate_test('range')
21 | test_iterate_str = _iterate_test('str')
22 | test_iterate_tuple = _iterate_test('tuple')
23 |
24 |
25 | class BuiltinReversedFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
26 | functions = ["reversed"]
27 |
--------------------------------------------------------------------------------
/tests/builtins/test_round.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase, BuiltinTwoargFunctionTestCase
2 |
3 |
4 | class RoundTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinRoundFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["round"]
10 |
11 |
12 | class BuiltinRoundTwoargFunctionTests(BuiltinTwoargFunctionTestCase, TranspileTestCase):
13 | functions = ["round"]
14 |
15 | not_implemented = [
16 | 'test_obj_class'
17 | ]
18 |
--------------------------------------------------------------------------------
/tests/builtins/test_set.py:
--------------------------------------------------------------------------------
1 | from .. utils import (
2 | TranspileTestCase,
3 | BuiltinFunctionTestCase,
4 | SAMPLE_SUBSTITUTIONS
5 | )
6 |
7 |
8 | class SetTests(TranspileTestCase):
9 | pass
10 |
11 |
12 | class BuiltinSetFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
13 | functions = ["set"]
14 |
15 | not_implemented = [
16 | 'test_bytes',
17 | 'test_str',
18 | ]
19 |
20 | not_implemented_versions = {
21 | }
22 |
23 | is_flakey = [
24 | 'test_dict',
25 | ]
26 |
27 | substitutions = {
28 | "{3, 1.2, True}": [
29 | "{1.2, 3, True}", "{True, 1.2, 3}", "{True, 3, 1.2}", "{3, True, 1.2}", "{1.2, True, 3}"
30 | ]
31 | }
32 | substitutions.update(SAMPLE_SUBSTITUTIONS)
33 |
--------------------------------------------------------------------------------
/tests/builtins/test_setattr.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase
2 |
3 |
4 | class SetattrTests(TranspileTestCase):
5 | def test_minimal(self):
6 | self.assertCodeExecution("""
7 | class MyClass(object):
8 | class_value = 42
9 |
10 | def __init__(self, val):
11 | self.value = val
12 |
13 | print("On class: ")
14 | setattr(MyClass, 'class_value', 37)
15 | setattr(MyClass, 'other_class_value', 42)
16 | print(' class_value =', MyClass.class_value)
17 | print(' other_class_value =', MyClass.other_class_value)
18 |
19 | obj = MyClass(37)
20 |
21 | print("On instance:")
22 | setattr(obj, 'value', 37)
23 | setattr(obj, 'other_value', 42)
24 | print(' value =', obj.value)
25 | print(' other_value =', obj.other_value)
26 | """, run_in_function=False)
27 |
--------------------------------------------------------------------------------
/tests/builtins/test_slice.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class SliceTests(TranspileTestCase):
5 | def test_slice_repr_stop(self):
6 | self.assertCodeExecution("""
7 | print(slice(0))
8 | print(slice('foo'))
9 | """)
10 |
11 | def test_slice_repr_start_stop(self):
12 | self.assertCodeExecution("""
13 | print(slice(0, 100))
14 | print(slice('foo', Exception))
15 | """)
16 |
17 | def test_slice_repr_start_stop_step(self):
18 | self.assertCodeExecution("""
19 | print(slice(0, 100, 2))
20 | print(slice('foo', Exception, object()))
21 | """)
22 |
23 |
24 | class BuiltinSliceFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
25 | functions = ["slice"]
26 |
27 | not_implemented = [
28 | 'test_class',
29 | 'test_complex',
30 | ]
31 |
--------------------------------------------------------------------------------
/tests/builtins/test_sorted.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class SortedTests(TranspileTestCase):
5 | def test_minimal(self):
6 | self.assertCodeExecution("""
7 | samples = [
8 | ([1, 5, 3, 2, 4, 9, 12], None),
9 | (["foo", "bar"], None),
10 | (["foo", "bar"], "invalid"),
11 | (["one", "two", "three", "four"], len),
12 | ([(1, 2), (5, 6), (3, 4)], None),
13 | ([(1, 2), (3, 4), (5, 6, 7)], len),
14 | ]
15 | for seq, key in samples:
16 | try:
17 | print('Sample:', seq)
18 | print('Sorted:', sorted(seq, key=key))
19 | print('Reverse sorted:', sorted(seq, key=key, reverse=True))
20 | except Exception as e:
21 | print(e)
22 | """, run_in_function=False)
23 |
24 |
25 | class BuiltinSortedFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
26 | functions = ["sorted"]
27 |
28 | not_implemented = [
29 | 'test_fozenset',
30 | ]
31 |
--------------------------------------------------------------------------------
/tests/builtins/test_staticmethod.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class StaticmethodTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinStaticmethodFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["staticmethod"]
10 |
11 | not_implemented = [
12 | 'test_bool',
13 | 'test_bytearray',
14 | 'test_bytes',
15 | 'test_class',
16 | 'test_complex',
17 | 'test_dict',
18 | 'test_float',
19 | 'test_frozenset',
20 | 'test_int',
21 | 'test_list',
22 | 'test_None',
23 | 'test_NotImplemented',
24 | 'test_range',
25 | 'test_set',
26 | 'test_slice',
27 | 'test_str',
28 | 'test_tuple',
29 | 'test_obj',
30 | ]
31 |
--------------------------------------------------------------------------------
/tests/builtins/test_str.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class StrTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinStrFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["str"]
10 |
11 | not_implemented = [
12 | 'test_class',
13 | ]
14 |
--------------------------------------------------------------------------------
/tests/builtins/test_sum.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class SumTests(TranspileTestCase):
5 | def test_sum_list(self):
6 | self.assertCodeExecution("""
7 | print(sum([1, 2, 3, 4, 5, 6, 7]))
8 | print(sum([[1, 2], [3, 4], [5, 6]], []))
9 | """)
10 |
11 | def test_sum_tuple(self):
12 | self.assertCodeExecution("""
13 | print(sum((1, 2, 3, 4, 5, 6, 7)))
14 | """)
15 |
16 | def test_sum_iterator(self):
17 | self.assertCodeExecution("""
18 | i = iter([1, 2])
19 | print(sum(i))
20 | print(sum(i))
21 | """)
22 |
23 | def test_sum_mix_floats_and_ints(self):
24 | self.assertCodeExecution("""
25 | print(sum([1, 1.414, 2, 3.14159]))
26 | """)
27 |
28 | def test_sum_frozenset(self):
29 | self.assertCodeExecution("""
30 | print(sum(frozenset([1, 1.414, 2, 3.14159])))
31 | """)
32 |
33 | def test_sum_set(self):
34 | self.assertCodeExecution("""
35 | print(sum({1, 1.414, 2, 3.14159}))
36 | """)
37 |
38 | def test_sum_dict(self):
39 | self.assertCodeExecution("""
40 | print(sum({1: 1.414, 2: 3.14159}))
41 | """)
42 |
43 | def test_sum_generator_expressions(self):
44 | self.assertCodeExecution("""
45 | print(sum(x ** 2 for x in [3, 4]))
46 | """)
47 |
48 |
49 | class BuiltinSumFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
50 | functions = ["sum"]
51 |
52 | not_implemented = [
53 | ]
54 |
--------------------------------------------------------------------------------
/tests/builtins/test_super.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class SuperTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinSuperFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["super"]
10 |
11 | not_implemented = [
12 | 'test_bool',
13 | 'test_bytearray',
14 | 'test_bytes',
15 | 'test_class',
16 | 'test_complex',
17 | 'test_dict',
18 | 'test_float',
19 | 'test_frozenset',
20 | 'test_int',
21 | 'test_list',
22 | 'test_None',
23 | 'test_NotImplemented',
24 | 'test_range',
25 | 'test_set',
26 | 'test_slice',
27 | 'test_str',
28 | 'test_tuple',
29 | 'test_obj',
30 | ]
31 |
--------------------------------------------------------------------------------
/tests/builtins/test_tuple.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase, SAMPLE_SUBSTITUTIONS
2 |
3 |
4 | class TupleTests(TranspileTestCase):
5 | pass
6 |
7 |
8 | class BuiltinTupleFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
9 | functions = ["tuple"]
10 |
11 | not_implemented = [
12 | 'test_tuple',
13 | ]
14 |
15 | substitutions = {
16 | "('one', 'two', 'six')": [
17 | "('two', 'one', 'six')", "('six', 'one', 'two')", "('one', 'six', 'two')", "('two', 'six', 'one')", "('six', 'two', 'one')"
18 | ],
19 | "('on', 'to', 'an')": [
20 | "('to', 'on', 'an')", "('an', 'on', 'to')", "('on', 'an', 'to')", "('to', 'an', 'on')", "('an', 'to', 'on')"
21 | ],
22 | "(1, 2.3456, 7)": [
23 | "(2.3456, 1, 7)", "(7, 1, 2.3456)", "(1, 7, 2.3456)", "(2.3456, 7, 1)", "(7, 2.3456, 1)"
24 | ],
25 | "('a', 'c', 'd')": [
26 | "('c', 'a', 'd')", "('d', 'a', 'c')", "('a', 'd', 'c')", "('c', 'd', 'a')", "('d', 'c', 'a')"
27 | ]
28 | }
29 |
30 | substitutions.update(SAMPLE_SUBSTITUTIONS)
31 |
--------------------------------------------------------------------------------
/tests/builtins/test_type.py:
--------------------------------------------------------------------------------
1 | from unittest import expectedFailure
2 |
3 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
4 |
5 |
6 | class TypeTests(TranspileTestCase):
7 |
8 | @expectedFailure
9 | def test_dynamic_class_definitions_leak_state(self):
10 | self.assertCodeExecution("""
11 | my_class_obj = type("MyClass", (object,), {})
12 | print("my_class_obj: ", my_class_obj)
13 |
14 | obj = object
15 | print("obj: ", object)
16 |
17 | dynamic_obj = type("object", (object,), {})
18 | print("dynamic_obj: ", dynamic_obj)
19 |
20 | # Check state leak
21 | print("my_class_obj: ", my_class_obj)
22 | print("obj: ", obj)
23 | """)
24 |
25 |
26 | class BuiltinTypeFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
27 | functions = ["type"]
28 |
29 | not_implemented = [
30 | ]
31 |
--------------------------------------------------------------------------------
/tests/builtins/test_vars.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 | from unittest import expectedFailure
4 |
5 |
6 | class VarsTests(TranspileTestCase):
7 | @expectedFailure
8 | def test_simple(self):
9 | self.assertCodeExecution("""
10 | print("There are %s vars" % len(vars()))
11 | x = 1
12 | y = 'z'
13 | print("There are %s vars" % len(vars()))
14 |
15 | def method():
16 | print("In method: there are %s vars" % len(vars()))
17 |
18 | print("vars()['x'] =", vars()['x'])
19 | print("vars()['y'] =", vars()['y'])
20 | try:
21 | print("vars()['z'] =", vars()['z'])
22 | except KeyError:
23 | print("Variable z not defined")
24 |
25 | vars()[y] = 2
26 |
27 | print("In method: there are %s vars" % len(vars()))
28 |
29 | method()
30 |
31 | print("There are %s vars" % len(vars()))
32 | print("vars()['x'] =", vars()['x'])
33 | print("vars()['y'] =", vars()['y'])
34 | print("vars()['z'] =", vars()['z'])
35 | print('x', x)
36 | print('y', y)
37 | print('z', z)
38 |
39 | print('Done')
40 | """, run_in_function=False)
41 |
42 | @expectedFailure
43 | def test_preloaded_vars(self):
44 | self.assertCodeExecution("""
45 | v = vars
46 | print("There are %s vars" % len(v()))
47 |
48 | x = 1
49 | y = 'z'
50 | print("There are %s vars" % len(v()))
51 |
52 | def method():
53 | print("There are %s vars" % len(v()))
54 | x = 1
55 | y = 'z'
56 | print("There are %s vars" % len(v()))
57 |
58 | method()
59 | """, run_in_function=False)
60 |
61 |
62 | class BuiltinVarsFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
63 | functions = ["vars"]
64 |
65 | not_implemented = [
66 | 'test_bool',
67 | 'test_bytearray',
68 | 'test_bytes',
69 | 'test_class',
70 | 'test_complex',
71 | 'test_dict',
72 | 'test_float',
73 | 'test_frozenset',
74 | 'test_int',
75 | 'test_list',
76 | 'test_None',
77 | 'test_NotImplemented',
78 | 'test_set',
79 | 'test_str',
80 | 'test_tuple',
81 | 'test_range',
82 | 'test_slice',
83 | 'test_obj',
84 | ]
85 |
--------------------------------------------------------------------------------
/tests/builtins/test_zip.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, BuiltinFunctionTestCase
2 |
3 |
4 | class ZipTests(TranspileTestCase):
5 | def test_zip(self):
6 | self.assertCodeExecution("""
7 | lst=['a','b','c','d','e']
8 | str="TestString"
9 | tup=(1,2,5,9,4,8,0,4)
10 | print(list(zip(lst,str,tup)))
11 | print(list(zip(lst,tup,"hi there")))
12 | """)
13 |
14 | def test_zip_expectedFailure(self):
15 | self.assertCodeExecution("""
16 | lst=['a','b','c','d','e']
17 | str="TestString"
18 | tup=(1,2,5,9,4,8,0,4)
19 | try:
20 | print(list(zip(5)))
21 | except TypeError as err:
22 | print(err)
23 | try:
24 | print(list(zip(lst,str,tup,7.9)))
25 | except TypeError as err:
26 | print(err)
27 | try:
28 | print(list(zip(True,lst,tup,"hi there")))
29 | except TypeError as err:
30 | print(err)
31 | """)
32 |
33 |
34 | class BuiltinZipFunctionTests(BuiltinFunctionTestCase, TranspileTestCase):
35 | functions = ["zip"]
36 |
37 | not_implemented = [
38 | 'test_bytearray',
39 | 'test_bytes',
40 | 'test_dict',
41 | 'test_frozenset',
42 | 'test_list',
43 | 'test_range',
44 | 'test_set',
45 | 'test_str',
46 | 'test_tuple',
47 | ]
48 |
--------------------------------------------------------------------------------
/tests/datatypes/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beeware/voc/dd9f15a7d56d00d8c9e501a57194694e601ea401/tests/datatypes/__init__.py
--------------------------------------------------------------------------------
/tests/datatypes/test_NoneType.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, UnaryOperationTestCase, BinaryOperationTestCase, InplaceOperationTestCase
2 |
3 |
4 | class NoneTypeTests(TranspileTestCase):
5 | def test_setattr(self):
6 | self.assertCodeExecution("""
7 | x = None
8 | try:
9 | x.thing = 42
10 | except AttributeError as err:
11 | print(err)
12 | """)
13 |
14 | def test_getattr(self):
15 | self.assertCodeExecution("""
16 | x = None
17 | try:
18 | y = x.thing
19 | except AttributeError as err:
20 | print(err)
21 | """)
22 |
23 |
24 | class UnaryNoneTypeOperationTests(UnaryOperationTestCase, TranspileTestCase):
25 | data_type = 'None'
26 |
27 |
28 | class BinaryNoneTypeOperationTests(BinaryOperationTestCase, TranspileTestCase):
29 | data_type = 'None'
30 |
31 |
32 | class InplaceNoneTypeOperationTests(InplaceOperationTestCase, TranspileTestCase):
33 | data_type = 'None'
34 |
--------------------------------------------------------------------------------
/tests/datatypes/test_NotImplemented.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, UnaryOperationTestCase, BinaryOperationTestCase, InplaceOperationTestCase
2 |
3 |
4 | class NotImplementedTests(TranspileTestCase):
5 | def test_truth(self):
6 | self.assertCodeExecution("""
7 | x = NotImplemented
8 | print(x == True)
9 | """)
10 |
11 |
12 | class UnaryNotImplementedOperationTests(UnaryOperationTestCase, TranspileTestCase):
13 | data_type = 'NotImplemented'
14 |
15 |
16 | class BinaryNotImplementedOperationTests(BinaryOperationTestCase, TranspileTestCase):
17 | data_type = 'NotImplemented'
18 |
19 |
20 | class InplaceNotImplementedOperationTests(InplaceOperationTestCase, TranspileTestCase):
21 | data_type = 'NotImplemented'
22 |
--------------------------------------------------------------------------------
/tests/datatypes/test_bool.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, UnaryOperationTestCase, BinaryOperationTestCase, InplaceOperationTestCase
2 |
3 |
4 | class BoolTests(TranspileTestCase):
5 |
6 | def test_setattr(self):
7 | self.assertCodeExecution("""
8 | x = True
9 | try:
10 | x.attr = 42
11 | except AttributeError as err:
12 | print(err)
13 | """)
14 |
15 | def test_getattr(self):
16 | self.assertCodeExecution("""
17 | x = True
18 | try:
19 | print(x.attr)
20 | except AttributeError as err:
21 | print(err)
22 | """)
23 |
24 | def test_setitem(self):
25 | self.assertCodeExecution("""
26 | x = True
27 | try:
28 | x[0] = 1
29 | except TypeError as err:
30 | print(err)
31 | """)
32 |
33 | def test_too_many_arguments(self):
34 | self.assertCodeExecution("""
35 | try:
36 | print(bool(1, 2))
37 | except TypeError as err:
38 | print(err)
39 | """)
40 |
41 |
42 | class UnaryBoolOperationTests(UnaryOperationTestCase, TranspileTestCase):
43 | data_type = 'bool'
44 |
45 |
46 | class BinaryBoolOperationTests(BinaryOperationTestCase, TranspileTestCase):
47 | data_type = 'bool'
48 |
49 |
50 | class InplaceBoolOperationTests(InplaceOperationTestCase, TranspileTestCase):
51 | data_type = 'bool'
52 |
--------------------------------------------------------------------------------
/tests/datatypes/test_complex.py:
--------------------------------------------------------------------------------
1 | from .. utils import TranspileTestCase, UnaryOperationTestCase, BinaryOperationTestCase, InplaceOperationTestCase
2 |
3 |
4 | class ComplexTests(TranspileTestCase):
5 | def test_conjugate(self):
6 | self.assertCodeExecution("""
7 | x = complex(1.5, 1)
8 | print(x.conjugate())
9 | """)
10 |
11 | def test_real_imag(self):
12 | self.assertCodeExecution("""
13 | x = complex(1, 2.0)
14 | print(x.real)
15 | print(x.imag)
16 | """)
17 |
18 | def test_equality_with_numbers_when_zero_imag(self):
19 | self.assertCodeExecution("""
20 | x = 2
21 | y = complex(2, 0)
22 | print(x == y)
23 | print(y.__eq__(x))
24 | print(x != y)
25 | print(y.__ne__(x))
26 |
27 | x = 2.0
28 | y = complex(3, 0)
29 | print(x == y)
30 | print(y.__eq__(x))
31 | print(x != y)
32 | print(y.__ne__(x))
33 |
34 | x = True
35 | y = complex(1, 0)
36 | print(x == y)
37 | print(y.__eq__(x))
38 | print(x != y)
39 | print(y.__ne__(x))
40 | """)
41 |
42 |
43 | class UnaryComplexOperationTests(UnaryOperationTestCase, TranspileTestCase):
44 | data_type = 'complex'
45 |
46 |
47 | class BinaryComplexOperationTests(BinaryOperationTestCase, TranspileTestCase):
48 | data_type = 'complex'
49 |
50 | substitutions = {
51 | "(-161.18751321137705+195.77962956590406j)": [
52 | "(-161.18751321137705+195.77962956590403j)"
53 | ],
54 | "(2.6460893340172016e-18+0.04321391826377225j)": [
55 | "(2.6460019439688186e-18+0.04321391826377225j)"
56 | ],
57 | "(-9.8368221286278e-14-535.4916555247646j)": [
58 | "(-9.836497256617357e-14-535.4916555247646j)"
59 | ]
60 | }
61 |
62 | is_flakey = [
63 | 'test_power_complex',
64 | 'test_power_float',
65 | ]
66 |
67 |
68 | class InplaceComplexOperationTests(InplaceOperationTestCase, TranspileTestCase):
69 | data_type = 'complex'
70 |
--------------------------------------------------------------------------------
/tests/stdlib/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beeware/voc/dd9f15a7d56d00d8c9e501a57194694e601ea401/tests/stdlib/__init__.py
--------------------------------------------------------------------------------
/tests/stdlib/test_os.py:
--------------------------------------------------------------------------------
1 | import unittest
2 |
3 | from ..utils import TranspileTestCase
4 |
5 |
6 | class OsModuleTests(TranspileTestCase):
7 | def test_getenv(self):
8 | self.assertCodeExecution("""
9 | import os
10 | print(os.getenv('USER'))
11 | print(os.getenv('NOT_HERE', default='something'))
12 | print(os.getenv('NOT_HERE', 'something'))
13 | print(os.getenv('NOT_HERE'))
14 | """)
15 | self.assertCodeExecution("""
16 | import os
17 | try:
18 | print(os.getenv(None))
19 | except Exception as e:
20 | print(type(e), e)
21 | try:
22 | print(os.getenv(1))
23 | except Exception as e:
24 | print(type(e), e)
25 | try:
26 | print(os.getenv())
27 | except Exception as e:
28 | print(type(e), e)
29 | """)
30 |
31 | @unittest.expectedFailure
32 | def test_getcwd(self):
33 | self.assertCodeExecution("""
34 | import os
35 | print(os.getcwd())
36 | """)
37 |
38 | def test_cpu_count(self):
39 | self.assertCodeExecution("""
40 | import os
41 | print(os.cpu_count())
42 | """)
43 |
--------------------------------------------------------------------------------
/tests/structures/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beeware/voc/dd9f15a7d56d00d8c9e501a57194694e601ea401/tests/structures/__init__.py
--------------------------------------------------------------------------------
/tests/structures/test_SimpleNamespace.py:
--------------------------------------------------------------------------------
1 | from ..utils import TranspileTestCase
2 |
3 |
4 | class SimpleNamespaceTests(TranspileTestCase):
5 | def test_creation(self):
6 | self.assertCodeExecution("""
7 | import types
8 |
9 | s = types.SimpleNamespace(a=1, b=2)
10 | print(s)
11 | print(s.a)
12 | print(s.b)
13 |
14 | try:
15 | s = types.SimpleNamespace(1, b=2)
16 | print("should not print this")
17 | except TypeError as e:
18 | print(e)
19 | """)
20 |
21 | def test_eq(self):
22 | self.assertCodeExecution("""
23 | import types
24 |
25 | s1 = types.SimpleNamespace(a=1, b=2)
26 | s2 = types.SimpleNamespace(b=2, a=1)
27 | print(s1 == s2)
28 |
29 | s3 = types.SimpleNamespace(b=2, a=1, c=3)
30 | print(s1 == s3)
31 | """)
32 |
--------------------------------------------------------------------------------
/tests/structures/test_assert.py:
--------------------------------------------------------------------------------
1 | from ..utils import TranspileTestCase
2 |
3 |
4 | class AssertTests(TranspileTestCase):
5 | def test_assert(self):
6 | self.assertCodeExecution("""
7 | x = 10
8 | print("Pre assert 1")
9 | assert x > 0, "It's big"
10 | print("Pre assert 2")
11 | try:
12 | assert x < 0, "It isn't big"
13 | except AssertionError as err:
14 | print(err)
15 | print("Done.")
16 | """)
17 |
18 | def test_assert_without_message(self):
19 | self.assertCodeExecution("""
20 | x = 10
21 | print("Pre assert 1")
22 | assert x > 0
23 | print("Pre assert 2")
24 | try:
25 | assert x < 0
26 | except AssertionError as err:
27 | print(err)
28 | print("Done.")
29 | """)
30 |
--------------------------------------------------------------------------------
/tests/structures/test_closure.py:
--------------------------------------------------------------------------------
1 | from unittest import expectedFailure
2 |
3 | from ..utils import TranspileTestCase
4 |
5 |
6 | class ClosureTests(TranspileTestCase):
7 | def test_deep_nested(self):
8 | self.assertCodeExecution("""
9 | def level3():
10 | def level2():
11 | def level1():
12 | print("hello")
13 | level1()
14 | level2()
15 | level3()
16 | """, run_in_function=False)
17 |
18 | def test_rebind_closure_var_before_closure_construction(self):
19 | self.assertCodeExecution("""
20 | def func():
21 | closure_var = 'before nested is defined'
22 | def nested():
23 | print(closure_var)
24 | closure_var = 'after nested is defined'
25 | nested()
26 | func()
27 | """)
28 |
29 | def test_generator_closure(self):
30 | self.assertCodeExecution("""
31 | def func():
32 | closure_var = 'hello world'
33 | def gen():
34 | print(closure_var)
35 | yield
36 | next(gen())
37 | func()
38 |
39 | def gen():
40 | closure_var = 'hello world'
41 | def func():
42 | print(closure_var)
43 | func()
44 | yield
45 | next(gen())
46 | """)
47 |
48 | @expectedFailure
49 | def test_class_closure(self):
50 | self.assertCodeExecution("""
51 | def func():
52 | closure_var = 'hello world'
53 | class Inner:
54 | print(closure_var)
55 | Inner()
56 | func()
57 |
58 | def gen():
59 | closure_var = 'hello world'
60 | class Inner:
61 | print(closure_var)
62 | Inner()
63 | yield
64 | next(gen())
65 | """)
66 |
67 | @expectedFailure
68 | def test_method_closure(self):
69 | self.assertCodeExecution("""
70 | def func():
71 | closure_var = 'hello world'
72 | class Inner:
73 | def method(self):
74 | print(closure_var)
75 | Inner().method()
76 | func()
77 |
78 | def gen():
79 | closure_var = 'hello world'
80 | class Inner:
81 | def method(self):
82 | print(closure_var)
83 | Inner().method()
84 | yield
85 | next(gen())
86 | """)
87 |
--------------------------------------------------------------------------------
/tests/structures/test_decorators.py:
--------------------------------------------------------------------------------
1 | from ..utils import TranspileTestCase
2 |
3 |
4 | class DecoratorTests(TranspileTestCase):
5 | def test_simple_decorator(self):
6 | self.assertCodeExecution("""
7 | def thing(fn):
8 | def _dec(value):
9 | print("Start decoration.")
10 | result = fn(value)
11 | print("End decoration.")
12 | return result * 42
13 | return _dec
14 |
15 | @thing
16 | def calculate(value):
17 | print("Do a calculation")
18 | return 37 * value
19 |
20 | print("Decorated result is", calculate(5))
21 | print("Done.")
22 | """)
23 |
24 | def test_decorator_with_argument(self):
25 | self.assertCodeExecution("""
26 | def thing(multiplier):
27 | def _dec(fn):
28 | def _fn(value):
29 | print("Start decoration.")
30 | result = fn(value)
31 | print("End decoration.")
32 | return result * multiplier
33 | return _fn
34 | return _dec
35 |
36 | @thing(42)
37 | def calculate(value):
38 | print("Do a calculation")
39 | return 37 * value
40 |
41 | print("Decorated result is", calculate(5))
42 | print("Done.")
43 | """)
44 |
--------------------------------------------------------------------------------
/tests/structures/test_dict_comprehension.py:
--------------------------------------------------------------------------------
1 | from ..utils import TranspileTestCase
2 |
3 |
4 | class DictComprehensionTests(TranspileTestCase):
5 | def test_syntax(self):
6 | self.assertCodeExecution("""
7 | x = [1, 2, 3, 4, 5]
8 | d = {v: v**2 for v in x}
9 | print(len(d))
10 | print(d[1])
11 | print(d[2])
12 | print(d[3])
13 | print(d[4])
14 | print(d[5])
15 | """)
16 |
17 | def test_method(self):
18 | self.assertCodeExecution("""
19 | x = [1, 2, 3, 4, 5]
20 | d = dict((v, v**2) for v in x)
21 | print(len(d))
22 | print(d[1])
23 | print(d[2])
24 | print(d[3])
25 | print(d[4])
26 | print(d[5])
27 | """)
28 |
--------------------------------------------------------------------------------
/tests/structures/test_docstrings.py:
--------------------------------------------------------------------------------
1 | from ..utils import TranspileTestCase
2 |
3 |
4 | class DocstringTests(TranspileTestCase):
5 | def test_method_docstring(self):
6 | self.assertCodeExecution("""
7 | def test():
8 | "This is the docstring"
9 | return 3
10 |
11 | print(test())
12 | print(test.__doc__)
13 | """)
14 |
15 | def test_naked_string(self):
16 | self.assertCodeExecution("""
17 | def test():
18 | x = 3
19 | "This is a naked string"
20 | return x
21 |
22 | print(test())
23 | print(test.__doc__)
24 | """)
25 |
--------------------------------------------------------------------------------
/tests/structures/test_iterator.py:
--------------------------------------------------------------------------------
1 | from unittest import expectedFailure
2 |
3 | from ..utils import TranspileTestCase
4 |
5 |
6 | class IteratorTests(TranspileTestCase):
7 | def test_iterable(self):
8 | self.assertCodeExecution("""
9 | class TestSet:
10 | def __init__(self, values):
11 | self.values = values
12 | self.i = -1
13 |
14 | def __iter__(self):
15 | return self
16 |
17 | def __next__(self):
18 | try:
19 | self.i += 1
20 | if self.values[self.i] % 2 == 0:
21 | return 'even'
22 | else:
23 | return self.values[self.i]
24 | except IndexError:
25 | raise StopIteration()
26 |
27 | s = TestSet([1, 2, 3, 4, 5])
28 | for val in s:
29 | print(val)
30 |
31 | """)
32 |
33 | def test_generator_as_iterable(self):
34 | self.assertCodeExecution("""
35 | class Interview:
36 | def __init__(self, start, stop):
37 | self.start = start
38 | self.stop = stop
39 |
40 | def __iter__(self):
41 | for i in range(self.start, self.stop):
42 | found = False
43 | if i % 2 == 0:
44 | yield 'fizz'
45 | found = True
46 | if i % 3 == 0:
47 | yield 'buzz'
48 | found = True
49 | if not found:
50 | yield i
51 |
52 | myinterview = Interview(1, 20)
53 |
54 | for i in myinterview:
55 | print(i)
56 | """)
57 |
58 | @expectedFailure
59 | def test_bad_iter(self):
60 | self.assertCodeExecution("""
61 | try:
62 | x = iter()
63 | except TypeError as err:
64 | print(err)
65 | """)
66 |
--------------------------------------------------------------------------------
/tests/structures/test_list_comprehension.py:
--------------------------------------------------------------------------------
1 | from ..utils import TranspileTestCase
2 |
3 |
4 | class ListComprehensionTests(TranspileTestCase):
5 | def test_syntax(self):
6 | self.assertCodeExecution("""
7 | x = [1, 2, 3, 4, 5]
8 | print([v**2 for v in x])
9 |
10 | print([v for v in x])
11 | """)
12 |
13 | def test_list_comprehension_with_if_condition(self):
14 | self.assertCodeExecution("""
15 | print([v for v in range(100) if v % 2 == 0])
16 | print([v for v in range(100) if v % 2 == 0 if v % 3 == 0])
17 | print([v for v in range(100) if v % 2 == 0 if v % 3 == 0 if v > 10 if v < 80])
18 | """)
19 |
20 | def test_method(self):
21 | self.assertCodeExecution("""
22 | x = [1, 2, 3, 4, 5]
23 | print(list(v**2 for v in x))
24 | """)
25 |
--------------------------------------------------------------------------------
/tests/structures/test_return.py:
--------------------------------------------------------------------------------
1 | from ..utils import TranspileTestCase
2 |
3 |
4 | class ReturnTests(TranspileTestCase):
5 | def test_return_methods(self):
6 | # Empty return
7 | self.assertCodeExecution("""
8 | def m():
9 | print('before return')
10 | return
11 | print('after return')
12 |
13 | print(m())
14 | """)
15 |
16 | # Single return
17 | self.assertCodeExecution("""
18 | def m():
19 | print('before return')
20 | return 1
21 | print('after return')
22 |
23 | print(m() + 1)
24 | """)
25 |
26 | # Multiple return
27 | self.assertCodeExecution("""
28 | def m():
29 | print('before return')
30 | return 1, 2
31 | print('after return')
32 |
33 | print(m())
34 | """)
35 |
--------------------------------------------------------------------------------
/tests/structures/test_scope.py:
--------------------------------------------------------------------------------
1 | from ..utils import TranspileTestCase
2 |
3 |
4 | class ScopeTests(TranspileTestCase):
5 | def test_simple(self):
6 | # This test will run both in global scope, and in a
7 | # function.
8 | self.assertCodeExecution("""
9 | x = 1
10 | print('x =', x)
11 | """)
12 |
13 | def test_local_scope(self):
14 | self.assertCodeExecution("""
15 | x = 1
16 |
17 | def foo():
18 | print("1: x =", x)
19 | x = 2
20 | print("2: x =", x)
21 |
22 | print("3: x =", x)
23 | try:
24 | foo()
25 | except UnboundLocalError as err:
26 | print(err)
27 | print("4: x =", x)
28 | """, run_in_function=False)
29 |
30 | def test_global_scope(self):
31 | self.assertCodeExecution("""
32 | x = 1
33 |
34 | def foo():
35 | global x
36 | print("1: x =", x)
37 | x = 2
38 | print("2: x =", x)
39 |
40 | print("3: x =", x)
41 | foo()
42 | print("4: x =", x)
43 |
44 | """, run_in_function=False)
45 |
46 | def test_class_scope(self):
47 | self.assertCodeExecution("""
48 | x = 1
49 |
50 | class Foo:
51 | def __init__(self, y):
52 | print("1: y =", y)
53 | x = 2
54 | print("2: x =", x)
55 | self.z = y
56 |
57 | w = x
58 | v = abs(x)
59 | x = 4
60 |
61 | print("3: x =", x)
62 | f = Foo(3)
63 | print("3: Foo.v =", Foo.v)
64 | print("3: f.v =", f.v)
65 | print("3: Foo.w =", Foo.w)
66 | print("3: f.w =", f.w)
67 | print("3: x =", x)
68 | try:
69 | print("3: f.x =", f.x)
70 | except AttributeError:
71 | pass
72 | try:
73 | print("3: f.y =", f.y)
74 | except AttributeError:
75 | pass
76 | print("3: f.z =", f.z)
77 | """, run_in_function=False)
78 |
--------------------------------------------------------------------------------
/tests/structures/test_sequences.py:
--------------------------------------------------------------------------------
1 | import unittest
2 |
3 | from ..utils import TranspileTestCase
4 |
5 |
6 | class SequenceTests(TranspileTestCase):
7 | def test_unpack_sequence(self):
8 | self.assertCodeExecution("""
9 | x = [1, 2, 3]
10 | a, b, c = x
11 | print(a)
12 | print(b)
13 | print(c)
14 | """)
15 |
16 | @unittest.expectedFailure
17 | def test_unpack_sequence_overflow(self):
18 | self.assertCodeExecution("""
19 | x = [1, 2, 3]
20 | a, b = x
21 | print(a)
22 | print(b)
23 | """)
24 |
25 | @unittest.expectedFailure
26 | def test_unpack_sequence_underflow(self):
27 | self.assertCodeExecution("""
28 | x = [1, 2]
29 | a, b, c = x
30 | print(a)
31 | print(b)
32 | print(c)
33 | """)
34 |
--------------------------------------------------------------------------------
/tests/structures/test_set_comprehension.py:
--------------------------------------------------------------------------------
1 | from ..utils import TranspileTestCase
2 |
3 |
4 | class SetComprehensionTests(TranspileTestCase):
5 | def test_syntax(self):
6 | self.assertCodeExecution("""
7 | x = [1, 2, 3, 4, 5]
8 | s = {v**2 for v in x}
9 | print(len(s))
10 | print(1 in s)
11 | print(4 in s)
12 | print(9 in s)
13 | print(16 in s)
14 | print(25 in s)
15 | """)
16 |
17 | def test_method(self):
18 | self.assertCodeExecution("""
19 | x = [1, 2, 3, 4, 5]
20 | s = set(v**2 for v in x)
21 | print(len(s))
22 | print(1 in s)
23 | print(4 in s)
24 | print(9 in s)
25 | print(16 in s)
26 | print(25 in s)
27 | """)
28 |
--------------------------------------------------------------------------------
/tests/test_benchmarks.py:
--------------------------------------------------------------------------------
1 | import os
2 |
3 | from .utils import adjust, TranspileTestCase
4 |
5 |
6 | TESTDIR = os.path.dirname(__file__)
7 |
8 |
9 | class BenchmarkTests(TranspileTestCase):
10 | def test_binary_trees(self):
11 | with open(os.path.join(TESTDIR + "/benchmarks/", "binary-trees.py")) as javafile:
12 | out = self.runAsJava(adjust(javafile.read()), args=["5", "5"], timed=True)
13 |
14 | self.assertIn("stretch tree of depth", out)
15 |
16 | def test_call_simple(self):
17 | with open(os.path.join(TESTDIR + "/benchmarks/", "call_simple.py")) as javafile:
18 | out = self.runAsJava(adjust(javafile.read()), args=["2"])
19 |
20 | self.assertIn("Time elapsed: ", out)
21 |
22 | def test_unpack_sequence(self):
23 | with open(os.path.join(TESTDIR + "/benchmarks/", "unpack_sequence.py")) as javafile:
24 | out = self.runAsJava(adjust(javafile.read()), args=["10"])
25 |
26 | self.assertIn("Time elapsed: ", out)
27 |
28 | def test_pystone(self):
29 | with open(os.path.join(TESTDIR + "/benchmarks/", "pystone.py")) as javafile:
30 | out = self.runAsJava(adjust(javafile.read()), args=["10"])
31 |
32 | self.assertIn("Pystone(1.2) time for 10 passes = ", out)
33 |
--------------------------------------------------------------------------------
/tests/test_large_code.py:
--------------------------------------------------------------------------------
1 | import unittest
2 |
3 | from voc.transpiler import Transpiler
4 | from voc.python.blocks import BlockCodeTooLarge
5 | from voc.python.methods import MethodCodeTooLarge
6 |
7 |
8 | class LargeCodeTest(unittest.TestCase):
9 |
10 | def test_block_large_code(self):
11 | "Test exception for large code of an anonymous block."
12 | large_code = 'print(1 + 2)\n' * 3000
13 | transpiler = Transpiler(verbosity=0)
14 | self.assertRaises(BlockCodeTooLarge, transpiler.transpile_string,
15 | "test.py", large_code)
16 |
17 | def test_method_large_code(self):
18 | "Test exception for large code of a method."
19 | large_code = 'def test():\n' + ' print(1 + 2)\n' * 3000
20 | transpiler = Transpiler(verbosity=0)
21 | self.assertRaises(MethodCodeTooLarge, transpiler.transpile_string,
22 | "test.py", large_code)
23 |
--------------------------------------------------------------------------------
/voc/__init__.py:
--------------------------------------------------------------------------------
1 | # Examples of valid version strings
2 | # __version__ = '1.2.3.dev1' # Development release 1
3 | # __version__ = '1.2.3a1' # Alpha Release 1
4 | # __version__ = '1.2.3b1' # Beta Release 1
5 | # __version__ = '1.2.3rc1' # RC Release 1
6 | # __version__ = '1.2.3' # Final Release
7 | # __version__ = '1.2.3.post1' # Post Release 1
8 |
9 | __version__ = '0.1.6'
10 |
--------------------------------------------------------------------------------
/voc/__main__.py:
--------------------------------------------------------------------------------
1 | import voc
2 | import argparse
3 |
4 | from .transpiler import transpile
5 |
6 |
7 | def main():
8 | parser = argparse.ArgumentParser(
9 | prog='voc',
10 | description='Transpiles Python code to Java class files.'
11 | )
12 |
13 | parser.add_argument(
14 | '-o', '--output',
15 | help='The directory where class files should be output.',
16 | default='.'
17 | )
18 | parser.add_argument(
19 | '-p', '--prefix',
20 | help='The prefix to strip from all source file paths.',
21 | default='.'
22 | )
23 | parser.add_argument(
24 | '-n', '--namespace',
25 | help='The namespace for the generated Java classfiles.',
26 | default='python'
27 | )
28 | parser.add_argument(
29 | '-v', '--verbosity',
30 | action='count',
31 | default=0
32 | )
33 | parser.add_argument(
34 | '--version',
35 | action='version',
36 | version='voc %s' % voc.__version__,
37 | )
38 | parser.add_argument(
39 | 'input',
40 | metavar='source file',
41 | nargs='+',
42 | help='The source file or directory to compile'
43 | )
44 |
45 | args = parser.parse_args()
46 |
47 | transpile(
48 | input=args.input,
49 | prefix=args.prefix,
50 | outdir=args.output,
51 | namespace=args.namespace,
52 | verbosity=args.verbosity
53 | )
54 |
55 |
56 | if __name__ == '__main__':
57 | main()
58 |
--------------------------------------------------------------------------------
/voc/java/__init__.py:
--------------------------------------------------------------------------------
1 | import codecs
2 |
3 | from . import mutf_8
4 | from .attributes import * # noqa
5 | from .constants import * # noqa
6 | from .fields import Field # noqa
7 | from .klass import Class # noqa
8 | from .methods import Method # noqa
9 | from .opcodes import * # noqa
10 |
11 | # Register the MUTF-8 codec
12 | codecs.register(mutf_8.search_function)
13 |
--------------------------------------------------------------------------------
/voc/java/__main__.py:
--------------------------------------------------------------------------------
1 | import sys
2 | import argparse
3 | import voc
4 |
5 | from .klass import Class
6 |
7 |
8 | def dump(filename):
9 | with open(filename, 'rb') as infile:
10 | Class.read(infile, debug=sys.stdout)
11 |
12 |
13 | def main():
14 | parser = argparse.ArgumentParser(
15 | prog='vod',
16 | description='Debugging tool to decompile class files.'
17 | )
18 |
19 | parser.add_argument(
20 | '--version', '-v',
21 | action='version',
22 | version='voc %s' % voc.__version__,
23 | )
24 |
25 | parser.add_argument(
26 | 'file',
27 | )
28 |
29 | args = parser.parse_args()
30 | dump(vars(args)['file'])
31 |
32 |
33 | if __name__ == "__main__":
34 | main()
35 |
--------------------------------------------------------------------------------
/voc/python/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beeware/voc/dd9f15a7d56d00d8c9e501a57194694e601ea401/voc/python/__init__.py
--------------------------------------------------------------------------------
/voc/python/types/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/beeware/voc/dd9f15a7d56d00d8c9e501a57194694e601ea401/voc/python/types/__init__.py
--------------------------------------------------------------------------------