GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Tsche/magic_codec

BranchesTags
Open more actions menu

Latest commit

 

History

8 Commits
8 Commits

Folders and files

NameName
Last commit message
Last commit date
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
 
 

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:

def preprocess(data: str) -> str:
    raise NotImplementedError

You can find an example extension in example.

About

No description, website, or topics provided.

Resources

Readme
MIT license
Activity

Stars

41 stars

Watchers

2 watching

Forks

1 fork
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.