예제 #1
0
파일: test.py 프로젝트: Xython/wisepy
from wisepy.talking import Talking
talking = Talking()


@talking
def add(left: 'an integer', right: 'another integer'):
    """
    add up two numbers.
    """
    left = int(left)
    right = int(right)
    return left + right


@talking.alias('sum')
def another(*args,
            to_float: bool = False,
            double=None,
            additional_add: int = None):
    """
    my sum command
    """

    # using type annotation in keyword argument makes the argument
    # cast to the specific type.

    ret = sum(map(int, args))

    if double:
        ret = ret * 2
예제 #2
0
from .pycompat import sys
from .reley_import import get_reley_module_spec_from_path, get_context_from_spec
from wisepy.talking import Talking
from Redy.Tools.PathLib import Path
from importlib._bootstrap_external import MAGIC_NUMBER
import marshal
import struct, time

talking = Talking()


@talking
def cc(f: 'input filename', o: 'output filename'):
    """
    compile reley source code into pyc files
    """
    spec = get_reley_module_spec_from_path('main', f)
    code = get_context_from_spec(spec).bc.to_code()
    timestamp = struct.pack('i', int(time.time()))
    marshalled_code_object = marshal.dumps(code)
    with Path(o).open('wb') as f:
        f.write(MAGIC_NUMBER)
        f.write(timestamp)
        f.write(b'A\x00\x00\x00')
        f.write(marshalled_code_object)


@talking
def run(f: 'input filename'):
    """
    compile reley source code into pyc files
예제 #3
0
파일: cli.py 프로젝트: Xython/auto-contract
from wisepy.talking import Talking
from importlib import util
from contract.base import Contract
from contract import perform

cli = Talking()


def _check_contract(it):
    if it is Contract:
        return False
    if isinstance(it, type):
        return issubclass(it, Contract)
    return isinstance(it, Contract)


@cli.alias('gen')
def contract_gen(c: 'files to define contracts', i: 'input filename'):
    """
    perform static contracts and generate python stub files.
    """
    with open(i, 'r') as fr:
        source = fr.read()

    spec = util.spec_from_file_location('<contract definition>', c)
    mod = util.module_from_spec(spec)
    spec.loader.exec_module(mod)

    concrete_contracts = [
        value for value in getattr(mod, '__dict__').values()
        if _check_contract(value)
예제 #4
0
from auto_orm.database.dbg_grammar import *
from auto_orm.database.dbg_emit import *
from rbnf.edsl.rbnf_analyze import check_parsing_complete
from Redy.Tools.PathLib import Path
from wisepy.talking import Talking

dbg_lang = Talking()

python_ex = Talking()


@dbg_lang
def gen(i: 'input filename', o: 'output filename'):
    """
    generate python source code for dbg-lang
    """
    with Path(i).open('r') as fr:
        code = fr.read()
    res = parse(code)
    check_parsing_complete(code, res.tokens, res.state)

    with Path(o).open('w') as fw:
        fw.write(code_gen(res.result))


def dbg_lang_cli():
    dbg_lang.on()


def python_ex_cli():
    python_ex.on()
예제 #5
0
import marshal
import os
import struct
import time
from importlib._bootstrap_external import MAGIC_NUMBER
from Redy.Tools.PathLib import Path
from rbnf.edsl.rbnf_analyze import check_parsing_complete
from wisepy.talking import Talking
from yapypy.extended_python import pycompat
from yapypy.extended_python.parser import parse as parse_ext_py
from yapypy.extended_python.py_compile import py_compile

python_ex = Talking()


def compile_ex_python_from_filename(filename, is_entry_point=True):
    with Path(filename).open('r') as fr:
        source_code = fr.read()
        result = parse_ext_py(source_code)
    result.state.filename = filename
    # double check parsed result.
    check_parsing_complete(source_code, result.tokens, result.state)
    ast = result.result
    code = py_compile(ast, filename, is_entrypoint=is_entry_point)
    return code


def compile_ex_python_from_source(source_code, is_entry_point=True):
    filename = '<unknown>'
    result = parse_ext_py(source_code)
    result.state.filename = filename
예제 #6
0
파일: manage.py 프로젝트: weakish/Site-32
import json
import os.path as path
import os
from dateutil.parser import parse as parse_date
from datetime import datetime
from wisepy.talking import Talking
from Redy.Tools.PathLib import Path
from io import StringIO
from textwrap import indent
cmd = Talking()


def raw_html(html):
    html = indent(html, prefix='    ')
    return f"""
.. raw:: html


{html}
"""


panel_styles = ['danger', 'success', 'info', 'warning']
panel_count = 0


def card(title: str, link: str, keywords: list, time: datetime):
    global panel_count
    time = time.strftime("%a, %B %d, %Y.&nbsp; %H: %M ")
    keywords = '&nbsp;,&nbsp;'.join(keywords)
    panel_count += 1