GitHub - Tsche/magic_codec · GitHub
/" data-turbo-transient="true" />
Skip to content
Search or jump to...
Search code, repositories, users, issues, pull requests...
-->
Search
Clear
Search syntax tips
Provide feedback
--><br>We read every piece of feedback, and take your input very seriously.
Include my email address so I can be contacted
Cancel
Submit feedback
Saved searches
Use saved searches to filter your results more quickly
-->
Name
Query
To see all available qualifiers, see our documentation.
Cancel
Create saved search
Sign in
/;ref_cta:Sign up;ref_loc:header logged out"}"<br>Sign up
Appearance settings
Resetting focus
You signed in with another tab or window. Reload to refresh your session.<br>You signed out in another tab or window. Reload to refresh your session.<br>You switched accounts on another tab or window. Reload to refresh your session.
Dismiss alert
{{ message }}
Tsche
magic_codec
Public
Notifications<br>You must be signed in to change notification settings
Fork
Star<br>39
master
BranchesTags
Go to file
CodeOpen more actions menu
Folders and files<br>NameNameLast commit message<br>Last commit date<br>Latest commit
History<br>8 Commits<br>8 Commits
example
example
src
src
tests
tests
.gitignore
.gitignore
LICENSE
LICENSE
README.md
README.md
pyproject.toml
pyproject.toml
requirements.txt
requirements.txt
requirements_dev.txt
requirements_dev.txt
setup.py
setup.py
View all files
Repository files navigation
magic codec - preprocessing for the python interpreter
magic_codec is a small utility to make writng preprocessors for Python easier. This uses a custom codec to kick off preprocessing before passing the result to the Python interpreter. You can find a more in-depth explanation of how this works over at pydong.org
Loading builtins
Currently the following preprocessors are available:
braces Python with braces - inspired by Bython
magic line: # coding: magic.braces
example: python tests/braces/test.by
incdec Extends python with unary prefix ++i and postfix i++ increment/decrement expressions
magic line: # coding: magic.incdec
example: python tests/incdec/incdec.py
cpp lets the Python interpreter interpret C++ via cppyy
magic line: #define CODEC "coding:magic.cpp"
example: python tests/cpp/test.cpp
toml validate toml files using json schemas
magic line: # coding: magic.toml
example: python tests/toml/data_valid.toml -s tests/toml/schema.json
Builtins can be loaded by setting the codec to magic.builtin_name where builtin_name is the name of the builtin.
Loading extensions
To extend magic_codec with your own preprocessors, you can create another Python package whose name is prefixed with magic_. Setting the codec to magic_foo would load the magic_foo package and check if it has a function preprocess.
The expected signature of preprocess is as follows:
str:<br>raise NotImplementedError">def preprocess(data: str) -> str:<br>raise NotImplementedError
You can find an example extension in example.
About<br>No description, website, or topics provided.<br>Resources<br>Readme<br>MIT license<br>Activity<br>Stars<br>39 stars<br>Watchers<br>2 watching<br>Forks<br>1 fork<br>Report repository
Releases
Packages
Used by
Contributors
Languages
You can’t perform that action at this time.