Coder Social home page Coder Social logo

yeast's Introduction

yeast

Work together like yeast in dough

asvr

single process

from yeast import asvr

def WsgiApp(env, start_response):
    start_response(200, {})
    return 'Hallo World\r\n'

asvr.start_server(WsgiApp)

Then visit http://localhost:8080/ , you will get Hallo World

multi process

import sys
import socket
from time import sleep
from subprocess import Popen

from yeast import asvr
from yeast import acore


def run(fd):
    l = acore.Listener(fd=fd, worker=asvr.WsgiHandler)
    asvr.WsgiHandler.app = staticmethod(asvr.WsgiApp)
    asvr.WsgiHandler.env['SERVER_PORT'] = '8080'
    l.start()
    l.loop()


def start(proc_num):
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    sock.bind(('', 8080))
    sock.setblocking(0)
    sock.listen(500)
    for i in range(proc_num):
        p = Popen((sys.argv[0], str(sock.fileno())))
    while True:
        sleep(10)


def main():
    if len(sys.argv) == 2:
        run(int(sys.argv[1]))
    else:
        start(2)


main()

tpl

Treat template as DOM, use css selector to manipulate it

set inner text of "a" with id=line_cnt

from yeast.tpl import MyHtmlParser
tpl = MyHtmlParser(filename='./tpl/index.tpl')
tpl.root_node('a#line_cnt')[0].set_inner_text("123")

adbs

We define a database "nfc" and table "test" like this:

from yeast import adbs

class NFC(adbs.MySQLSVR):
    _name = 'nfc'
    _user = 'nfc'
    _pass = 'password'
    #_host = 'localhost'
    #_port = 3306
    #_readonly = True
    #_cursor = Cursor
    #_charset = 'utf8'

class TST(adbs.Table):
    _name = 'test'
    uid = adbs.Column(0, name="id", autoid=True)
    time = adbs.Column(0)
    name = adbs.Column('noname')

sync way to use adbs

db = NFC().connect()
tsts = db.select(TST, TST.time > 0)
for tst in tsts:
    print tst.name, tst.time

async way to use adbs

class WK(acore.Acore):
    def run(self):
        self.clt = adbs.DBClt()
        self.clt.connect(NFC())
        for y in self.clt.select(TST, TST.name > ''):
            yield y
        for tst in self.clt.db_result:
            print tst.name, tst.time

wk = WK()
wk.start()
wk.loop()

select

tsts = db.select(TST, TST.time > 0)

or only return one

tst = db.select_one(TST, TST.time > 0)

or only return selected column "name"

tsts = db.select(TST.sel("name"), TST.time > 0)

or use Where and RAW

tsts = db.select(TST, adbs.Where(TST.name, "is", adbs.RAW("NULL"), False))

or use where and more

tsts = db.select(TST.sel("name"), "where time > 0 order by name desc")

insert

db.insert(tst)

or update selected column if has duplicate entry

fdb.insert(tst.sel('time'))

update

This will update tst.time who's name is Name

db.update(tst.sel("time"), TST.name == "Name")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.