Added documentation

This commit is contained in:
Veit Heller
2014-09-17 18:22:31 +02:00
parent 5092d371c6
commit 1cf2f7a573

View File

@@ -3,6 +3,7 @@ import sys
import imp
def to_i(num, b):
"""String to integer."""
n = 0
for d in num:
if int(d) > b:
@@ -11,11 +12,13 @@ def to_i(num, b):
return n
def to_c(digit):
"""Integer to char."""
if digit < 10:
return str(digit)
return chr(ord('a') + digit - 10)
def to_s(number, base):
"""Integer to string."""
if number < 0:
return '-' + to_s(-number, base)
(d, m) = divmod(number, base)
@@ -30,6 +33,7 @@ def chunks(li, n):
return r
def __script__(src):
"""For a documentation, consult the README."""
code = []
src = [list(to_s(ord(c), 6).rjust(3, "0")) for c in src]
src = [int(x, base=6)+1 for sub in src for x in sub]
@@ -48,6 +52,7 @@ def __py_script__(src):
return "import _\n\n" + __script__(src)
def to_be_exec(name):
"""Decodes _ to a fragment."""
global code
global fragment
code.extend(fragment)
@@ -58,6 +63,7 @@ def to_be_exec(name):
code = []
fragment = []
def _():
"""Decodes all fragments to code and executes it."""
global code
global fragment
if not code and not fragment:
@@ -74,6 +80,7 @@ def _to_code(filename):
_()
def _install_importer():
"""Installs the module finder."""
sys.meta_path.insert(0, Finder())
class Finder:
@@ -84,8 +91,11 @@ class Finder:
filename = os.path.join(dirname, fullname)
if os.path.exists(filename):
return UnderScoreLoader(filename)
else if os.path.exists(filename + ".py"):
return UnderScoreLoader(filename + ".py")
class UnderScoreLoader:
"""Custom module loader for _ files."""
def __init__(self, filename):
self.filename = filename