def test(): loop = asyncio.get_event_loop() orm.create_pool(loop=loop, host='127.0.0.1', port=3306, user='******', password='******', db='awesome') u = User(name='Test', email='*****@*****.**', passwd='1234567890', image='about:blank') u.save()
def init(loop): yield from orm.create_pool(loop=loop, user='******', password='******', db='wallpaper') app = web.Application(loop=loop, middlewares=[logger_factory, response_factory], client_max_size=1024**8) cors = aiohttp_cors.setup(app, defaults={ "*": aiohttp_cors.ResourceOptions( allow_credentials=True, expose_headers="*", allow_headers="*", ) }) logging.info(aiohttp_cors.ResourceOptions) init_jinja2(app, filters=dict(datetime=datetime_filter)) add_routes(app, 'handlers', cors) add_static(app) add_upload(app) add_emoticon(app) srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 8088) logging.info('server started at http://127.0.0.1:8088...') return srv
def test_findNumber(loop): yield from orm.create_pool(user='******', password='******', db='johnietest', host='mysql01-db.sh.cn.ao.ericsson.se', port =3508, loop = loop) u = User() rs = yield from u.findNumber('*', where="`email` like ?", args=['test%']) #rs = yield from u.findNumber('name') yield from orm.close_pool() print(rs)
def test(loop): yield from orm.create_pool(loop=loop, user='******', password='******', db='awesome') u = User(name='Test', email='*****@*****.**', passwd='1234567890', image='about:blank') yield from u.save()
def connect_mysql(loop): yield from orm.create_pool(loop=loop, user='******', host='localhost', port=3307, password='******', db='awesome')
def init(loop): yield from orm.create_pool(loop=loop, host='127.0.0.1', port=3306, user='******', password='******', db='awesome') app = web.Application(loop=loop) # app.router.add_route('GET', '/', index) src = yield from loop.create_server(app.make_handler(), '127.0.0.1', 9000) logging.info('server started at http://127.0.0.1:9000...') return src
def test(): yield from orm.create_pool(loop=loop, host='127.0.0.1', port=3306, user = '******', password='******', db='monkeyfarm') # findAll r = yield from User.findAll() print(r) # insert # u = User(name='Test3', email='*****@*****.**', password='******', image='about:blank') # yield from u.save() # update # if len(r) != 0: for user in r: # if user.name == 'Test2': # user.name = 'Test222' # user.email = '*****@*****.**' # user.admin = True # yield from user.update() # delete if user.name == 'Test3': yield from user.remove() r = yield from User.findAll() print(r) yield from orm.destroy_pool()
def init(loop): ''' app=web.Application(loop=loop) app.router.add_route('GET','/',index) srv=await loop.create_server(app.make_handler(),'127.0.0.1',9000) logging.info('server started at http://127.0.0.1:9000...') return srv ''' ''' await orm.create_pool(loop=loop, host='127.0.0.1', port=3306, user='******', password='******', db='python_jun') app = web.Application(loop=loop, middlewares=[ logger_factory, response_factory ]) init_jinja2(app, filters=dict(datetime=datetime_filter)) add_routes(app, 'handlers') add_static(app) srv = await loop.create_server(app.make_handler(), '127.0.0.1', 9000) logging.info('server started at http://127.0.0.1:9000...') return srv ''' yield from orm.create_pool(loop=loop, **configs.db) app = web.Application(loop=loop, middlewares=[ logger_factory, response_factory ]) init_jinja2(app, filters=dict(datetime=datetime_filter)) add_routes(app, 'handlers') add_static(app) srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 9000) logging.info('server started at http://127.0.0.1:9000...') return srv
def test(lp): yield from orm.create_pool(lp, user='******', password='******', db='awesome') u = User(name='Test', email='*****@*****.**', passwd='123456', image='about:blank') print(getattr(u, 'email'))
def test_save(loop): yield from orm.create_pool(loop, user='******', password='******', db='awesome') u = User(name='hi', email='*****@*****.**', passwd='hi', image='about:blank') # pdb.set_trace() yield from u.save()
def test(): yield from orm.create_pool(user='******', password='******', database='awesome') u = User(name = 'Test', email='*****@*****.**', passwd='123456789', image='about:blank') yield from u.save() for x in test(): pass
def test(loop): yield from orm.create_pool(loop=loop, user="******", password="******", db="awesome") u = User(name="Test", email="*****@*****.**", passwd="123", image="about:blank") yield from u.save()
def init(loop): # 连接 ORM yield from orm.create_pool(loop=loop,user='******', password='', db='awesome') # summary = "Try something new," \ # " lead to the new life." # # blogs = [ # Blog(id='1', user_id='1',user_name='Test Blog', user_image='about:blank', name='11', content='B1', summary=summary, created_at=time.time() - 120), # Blog(id='2', user_id='2',user_name='Something New', user_image='about:blank', name='22',content='B2', summary=summary, created_at=time.time() - 3600), # Blog(id='3', user_id='3',user_name='Learn Swift',user_image='about:blank', name='33', content='B3', summary=summary, created_at=time.time() - 7200) # ] # for blog in blogs: # yield from blog.save() # 创建Web服务器实例app,也就是aiohttp.web.Application类的实例,该实例的作用是处理URL、HTTP协议 app = web.Application(loop=loop, middlewares=[logger_factory, auth_factory, response_factory]) # 为 app 添加 __templating__ 参数 init_jinja2(app, filters=dict(datetime=datetime_filter)) # url处理函数, 对 aiohttp 的http 响应进行处理 add_routes(app, 'handlers') # app.router.add_route('GET', '/', index)#增加协程,异步io add_static(app) srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 9000) logging.info('server start at http://127.0.0.1:9000...') return srv #返回服务器
def test_remove(loop): yield from orm.create_pool(user='******', password='******', database='awesome',loop=loop) users = yield from User.findAll(where='email=?', args=('*****@*****.**',)) for u in users: if isinstance(u, orm.Model): # 一定要注意加上yield from yield from u.remove()
def init(loop): # 创建连接池, db参数传配置文件里的配置db yield from orm.create_pool(loop = loop, **configs.db) # 创建web应用 循环类型是消息循环 app = web.Application(loop=loop, middlewares=[logger_factory, auth_factory, response_factory]) # middlewares(中间件)设置3个中间处理函数(都是装饰器) # middlewares中的每个factory接受两个参数,app 和 handler(即middlewares中的下一个handler) # 譬如这里logger_factory的handler参数其实就是auth_factory # middlewares的最后一个元素的handler会通过routes查找到相应的,其实就是routes注册的对应handler # 这其实是装饰模式的典型体现,logger_factory, auth_factory, response_factory都是URL处理函数前(如handler.index)的装饰功能 # 设置模板为jiaja2,并以时间为过滤器 init_jinja2(app, filters = dict(datetime = datetime_filter)) # 添加请求的handlers,即各请求相对应的处理函数 add_routes(app, 'handlers') # 添加静态文件所在地址 add_static(app) # 调用子协程:创建一个TCP服务器,绑定到"127.0.0.1:9000"socket,并返回一个服务器对象 srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 9000) '''app.make_hander()中对middleware的处理: (装饰器原理) for factory in reversed(self._middlewares): handler = yield from factory(app, handler) resp = yield from handler(request) middleware的代码示意:m1( m2( m3( doFoo()))) middleware调用流程: req -> m1 -> m2 -> m3 -> doFoo()- 一路return 原路返回 <- m1 <- m2 <- m2 <- resq - <-''' logging.info('server started at http://127.0.0.1:9000...') return srv
def init (loop): # 创建数据库连接池 yield from orm.create_pool(loop = loop, **configs.db) # 创建一个web.app的实例, event loop used for processing HTTP request. # 文档:If param is None asyncio.get_event_loop() used for getting default event loop, but we strongly recommend to use explicit loops everywhere.(所以传不传入loop都行) app = web.Application(loop=loop,middlewares=[logger_factory, auth_factory, response_factory]) # 设置模板为jiaja2, 并以时间为过滤器 init_jinja2(app,filters = dict(datetime = datetime_filter)) # 注册所有url处理函数 #调用coroweb的注册函数,传入模版的名称/地址,从而逐个注册handler模版里面的每一个url add_routes(app,'handlers') # 将当前目录下的static目录装入app目录 add_static(app) # app.router.add_route('GET','/',index) # 测试首页用 # 调用协程:创建一个TCP服务器,绑定到"127.0.0.1:9000"socket,并返回一个服务器对象 # 用协程创建监听服务,其中loop为传入函数的协程,调用其类方法创建一个监听服务 # yield from 返回一个创建好的,绑定IP、端口、HTTP协议簇的监听服务的协程。yield from的作用是使srv的行为模式和 loop.create_server()一致 srv = yield from loop.create_server(app.make_handler(),'127.0.0.1',9000) logging.info('app模块------服务启动-------server started at http://127.0.0.1:9000...') logging.info('***********************************************\n\n') return srv
def init(loop): yield from orm.create_pool(loop=loop, host="12.7.0.0.1", prot=3306, user="******", password="******", db="awesome") app = web.Application(loop=loop) app.router.add_route("GET", "/", index) srv = yield from loop.create_server(app.make_handler(), "127.0.0.1", 9000) logging.info("server startted") return srv
def test(loop): yield from orm.create_pool(loop=loop, user='******', db='awesome') u = User(name='hujierr', email='*****@*****.**', passwd='f**k', image='about:blank') yield from u.save()
def mytest(loop): yield from orm.create_pool(loop=loop, user='******', password='******', db='awesome') u = User(name='my', email='*****@*****.**', passwd='wushi', image='1111') yield from u.save()
def init(loop) : yield from orm.create_pool(loop = loop, **configs.db) app = web.Application(loop = loop, debug = True, middlewares = [ response_factory, logger_factory, auth_factory #过滤时,依该list的顺序来过滤;不过影响不大 #在过滤方法中,调用yield from handler(request)相当于调用下一个过滤方法;若方法所有过滤已完成 #则调用call方法 ]) init_jinja2(app, filters = dict(datetime = datetime_filter)) add_routes(app, 'handlers') add_static(app) logger.info('init complete!') #print(ip) r = input('run at local(1) or temp test at web(2)?') if r == '1' : _ip = '127.0.0.1' port = 9000 else : port = 80 _ip = ip srv = yield from loop.create_server(app.make_handler(), _ip, port) logger.info('server started at http://%s:%s...' % (_ip, port)) return srv
def test(loop): logging.error('1111111') yield from orm.create_pool(loop=loop,user='******',password='******',db='pyblog') logging.error('2222222') u=User(name='Test',email='*****@*****.**',passwd='1234567890',image='blank') logging.error('333333') yield from u.save()
def test_findAll(loop): yield from orm.create_pool(loop, user='******', password='******', db='pure_blog') # 这里给的关键字参数按照xxx='xxx'的形式给出,会自动分装成dict rs = yield from User.findAll(email='*****@*****.**') # rs是一个元素为dict的list # pdb.set_trace() for i in range(len(rs)): print(rs[i])
def getItem(battleTag, heroId, itemList): # 先删除,再保存入库 yield from orm.create_pool(loop=loop, host=dbHost, user=dbUser, password=dbPassword, db=dbName) heroItems = HeroItems(battleTag=battleTag, heroId=heroId) yield from heroItems.delete() for item in itemList: m = re.match(r'.+item/(.+)', item) if m is not None: data = m.group(1) itemData = yield from wget( 'http://www.battlenet.com.cn/api/d3/data/item/' + data) if len(itemData) > 100: heroItems = HeroItems(battleTag=battleTag, heroId=heroId, itemData=itemData) yield from heroItems.save() jsonData = json.loads(itemData) if 'set' in jsonData: icon = jsonData['set']['items'][0]['icon'] else: icon = jsonData['icon'] # 保存装备 yield from curl_items.getItemImg(icon) else: return
def run(): yield from orm.create_pool(host='127.0.0.1', port=3306, user='******', password='******', db='awesome', loop=loop) users_table = yield from User.findAll() print(users_table)
def init(loop): # 创建数据库池:数据库的账户和密码,以及db需要首先创建好!!! yield from orm.create_pool(loop=loop, **configs.db) # middleware是一种拦截器,URL在被某个函数处理前,可以经过一系列的 middleware 的处理 app = web.Application( loop=loop, middlewares=[logger_factory, auth_factory, response_factory]) # 适配python3.0 app = web_runner.AppRunner(app=app).app # 手动添加路由: # app.router.add_route('GET','/testIndex',index) # app.router.add_route('GET','/testHello',hello) # 初始化模板引擎:绑定了block 和 init_jinja2(app, filters=dict(datetime=datetime_filter)) # 给web app添加路由,统一放在handlers模块中处理 add_routes(app, 'handlers') # 注册静态文件 add_static(app) logging.info('server before...') # 创建1个服务器对象 host = '127.0.0.1' # 或 'localhost' == '127.0.0.1' port = 9003 server = yield from loop.create_server(app.make_handler(), host, port) logging.info('server start at http://%s:%s' % (host, port)) return server
def getItem(battleTag,heroId,itemList): # 先删除,再保存入库 yield from orm.create_pool(loop=loop,host=dbHost, user=dbUser, password=dbPassword, db=dbName) heroItems = HeroItems(battleTag=battleTag,heroId=heroId) yield from heroItems.delete() for item in itemList: m = re.match(r'.+item/(.+)', item) if m is not None: data = m.group(1) itemData = yield from wget('http://www.battlenet.com.cn/api/d3/data/item/'+data) if len(itemData) > 100: heroItems = HeroItems(battleTag= battleTag, heroId = heroId, itemData = itemData ) yield from heroItems.save() jsonData = json.loads(itemData) if 'set' in jsonData: icon = jsonData['set']['items'][0]['icon'] else: icon = jsonData['icon'] # 保存装备 yield from curl_items.getItemImg(icon) else: return
def test(): yield from create_pool(user='******', password='******', db='awesome') u = User(name='Test', email='*****@*****.**', passwd='1234567890', image='about:blank') yield from u.save()
def test(): yield from orm.create_pool( user='******', password='******', db='awesome', loop=loop, host='localhost', port=3306, ) ## 添加数据测试 u = User( name='Test', email='*****@*****.**', passwd='1234567890', image= 'http://www.cnad.com/upload/ueditor/image/2016/0519/6359927486765338695280691.jpg' ) #重复执行会报错,因为email 有建立unique Key 约束 print(u) yield from u.save() print(u) ## 查找数据测试 # ## 删除数据测试 # yield from User(id='001540027464067ced49eb8e4904d2e9a4ef14b9c5924d8000').remove() # r = yield from User.findAll() # print(r) yield from destory_pool()
def test(loop): yield from orm.create_pool(loop=loop, user='******', password='******', db='awesome') u1 = User(name='test1', email='*****@*****.**', passwd='test1', image='about:blank') yield from u1.save() u2 = User(name='test224', email='*****@*****.**', passwd='test2', image='about:blank') yield from u2.save() u3 = User(name='test224', email='*****@*****.**', passwd='test3', image='about:blank') yield from u3.save() u4 = User(name='test224', email='*****@*****.**', passwd='test4', image='about:blank') yield from u4.save()
def init(loop): #orm.create_pool()创建数据库连接: yield from orm.create_pool(loop=loop, host='127.0.0.1', port=3306, user='******', password='******', db='awesome') #创建 middlewares 请求响应处理器(字典类型)对象,可以通过‘请求处理程序’返回对应数据: app = web.Application( loop=loop, middlewares=[logger_factory, auth_factory, response_factory]) #初始化jinja2模板,添加filter(过滤器): init_jinja2(app, filters=dict(datetime=datetime_filter)) #'handelers'模块自动注册,也就是取代aiohttp.web.UrlDispatcher.add_route()单个增加响应规则: add_routes(app, 'handlers') #aiohttp.web.UrlDispatcher.add_route():增加响应规则;即设置请求条件(请求方式,地址等...)和对应的处理程序: #app.router.add_route('GET', '/', index) #给文件添加静态地址: add_static(app) #loop.create_server()利用asyncio创建TCP服务: #make_handler()创建HTTP协议处理器来处理请求: srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 9000) #打印日志信息: logging.info('server started at http://127.0.0.1:9000...') print('server started at http://127.0.0.1:9000...') return srv
def test_findNumber(loop): yield from orm.create_pool(loop, user='******', password='******', db='pure_blog') count = yield from User.findNumber('email') print(count)
def test(): yield from orm.create_pool(user='******', password='******', db='mysql') u = User(name='Test', email='*****@*****.**', passwd='123456', image='about:blank') yield from u.save()
def create_users(loop): yield from orm.create_pool(loop=loop, user='******', password='******', db='check_in_system') user_dict = { 'u1': { 'name': 'tonyyeti', 'passwd': 'Tonyalston911', 'admin': True}, 'u2': { 'name': 'feifei', 'passwd': '123456', 'admin': False}, 'u3': { 'name': 'maomao', 'passwd': '123456', 'admin': False} } for user in user_dict.values(): uid = next_id() sha1_passwd = '%s:%s' % (uid, user['passwd']) u = User(id=uid, name=user['name'], passwd=hashlib.sha1(sha1_passwd.encode('utf-8')).hexdigest(), image='about:blank', admin=user['admin']) yield from u.save() print(user['name'] + 'saved.') feifei = yield from User.findAll('name=?', ['feifei']) maomao = yield from User.findAll('name=?', ['maomao']) r1 = Relation(active_user_id=feifei[0].id, active_user_name=feifei[0].name, passive_user_id=maomao[0].id, passive_user_name=maomao[0].name) r2 = Relation(active_user_id=maomao[0].id, active_user_name=maomao[0].name, passive_user_id=feifei[0].id, passive_user_name=feifei[0].name) yield from r1.save() print('r1 saved.') yield from r2.save() print('r2 saved')
def saveTop(): yield from orm.create_pool(loop=loop, host=dbHost, user=dbUser, password=dbPassword, db=dbName) heroTop = HeroTop(id=1, body=json.dumps(topDic), createTime=time.time()) yield from heroTop.update()
def test(loop): print('begin create pool') yield from orm.create_pool(loop=loop, host='localhost', port=3306, user='******', password='******', db='awesome') print('end create pool') u = User(name='test77',email='*****@*****.**',passwd='test',image='about:blank') print('begin save') yield from u.save() print('end save')
def init(loop): yield from orm.create_pool(loop = loop, **configs.db); app = web.Application(loop = loop, middlewares=[logger_factory, auth_factory, response_factory]); init_jinja2(app, filters=dict(datetime=datetime_filter)); add_routes(app, 'handler'); srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 9000); logging.info('server started at http://127.0.0.1:9000...'); return srv;
def test(): print('OK. Step 2 ... ') loop = asyncio.get_event_loop() yield from orm.create_pool(loop, user='******', password='******', database='awesome') print("OK. finished.")
def test_remove_direct(loop): yield from orm.create_pool(user='******', password='******', database='awesome', loop=loop) affected = yield from User.deleteAll(where='email=?', args=('*****@*****.**', )) print(affected)
def test(): yield from orm.create_pool(user='******', password='******', database='awesome') u = User(name='Test', email='*****@*****.**', passwd='123456', image='about:blank') yield from u.save() for x in test(): pass
def test_remove(loop): yield from orm.create_pool(loop, user='******', password='******', db='pure_blog') # 用id初始化一个实例对象 u = User(id='0014531826762080b29033a78624bc68c867550778f64d6000') yield from u.remove()
def test_update(loop): yield from orm.create_pool(loop, user='******', password='******', db='pure_blog') # 必须按照列的顺序来初始化:'update `users` set `created_at`=?, `passwd`=?, `image`=?, # `admin`=?, `name`=?, `email`=? where `id`=?' 注意这里要使用time()方法,否则会直接返回个时间戳对象,而不是float值 u = User(id='00145318300622886f186530ee74afabecedb42f9cd590a000', created_at=time.time(), passwd='test', image='about:blank', admin=True, name='test', email='*****@*****.**') # id必须和数据库一直,其他属性可以设置成新的值,属性要全 # pdb.set_trace() yield from u.update()
def init(loop): yield from orm.create_pool(loop=loop, **configs.db) app = web.Application(loop=loop, middlewares=[logger_factory, auth_factory, response_factory]) init_jinja2(app, filters=dict(datetime=datetime_filter)) add_routes(app, "handlers") add_static(app) srv = yield from loop.create_server(app.make_handler(), "127.0.0.1", 9000) logging.info("server started at http://127.0.0.1:9000...") return srv
def init(loop): yield from orm.create_pool(loop=loop,**config['db']) app=web.Application(loop=loop,middlewares=[logger_factory,response_factory,auth_factory]) init_jinja2(app, filters=dict(datetime=datetime_filter)) add_routes(app,'handlers') add_static(app) srv = yield from loop.create_server(app.make_handler(),'127.0.0.1',9000) logging.info('server started at http://127.0.0.1:9000...') return srv
def test(): yield from orm.create_pool(user='******', password='******', database='awesome') u = User(name='Test', email='*****@*****.**', passwd='1234567890', image='about:blank') yield from u.save()
def init(loop): yield from orm.create_pool(loop=loop, **configs.db) app = web.Application(loop=loop, middlewares=[logger_factory, response_factory]) add_routes(app, 'handlers') srv = yield from loop.create_server(app.make_handler(), '', 8000) logging.info('server started at http://127.0.0.1:8000...') return srv
def init(loop): yield from orm.create_pool(loop=loop, user='******', password='******', db='awesome') app = web.Application(loop=loop, middlewares=[ logger_factory, response_factory ]) init_jinja2(app, filters=dict(datetime=datetime_filter)) add_routes(app, 'handlers') add_static(app) srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 9000) logging.info('server started at http://127.0.0.1:9000...') return srv
def init(loop): yield from orm.create_pool(loop=loop, host='127.0.0.1', port=3306, user='******', password='******', db='awesome') app = web.Application(loop=loop, middlewares=[logger_factory, response_factory, auth_factory]) init_jinja2(app, filters=dict(datetime=datetime_filter)) add_routes(app, 'handlers') add_static(app) srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 9000) logging.info('server started at http://127.0.0.1:9000') return srv
def test(loop): yield from orm.create_pool(loop=loop, user='******', password='******', db='awesome') email_d = random.randrange(1, 100) emailTxt = '*****@*****.**' % email_d u = User(name='test3', email=emailTxt, passwd='test', image='about:blank') yield from u.save()
def test_db(loop): #创建数据库连接池,用户名:www-data, 密码:www-data ,访问的数据库为:awesome #在这之前必须现在mysql里创建好awesome数据库,以及对应的表,否则会显示can't connect #可以通过命令行输入:mysql -u root -p <schema.sql ,来执行schema.sql脚本来实现数据库的初始化,schema.sql和本文件在同一目录下 yield from orm.create_pool(loop = loop, user = '******', password='******', db='awesome') #创建User model u = User(name = 'Test', email = '*****@*****.**', passwd = '123', image = 'about:blank') #同时同步到awesome数据库的users表下,插入一条user数据,对应字段的值就是u的传参 yield from u.save()
def init(loop): yield from orm.create_pool(loop=loop,**configs['db']) #reate pool connect db app=web.Application(loop=loop,middlewares=[logger_factory, auth_factory, response_factory])#create app #两个middleware,相当与两个对handler(url处理函数)的装饰器。接收一个handler,返回一个装饰后的handler。 init_jinja2(app,filters=dict(datetime=datetime_filter))#init jinja2 setting for app webtool.add_routes(app,'handlers') #add routes for app, 'handlers' is modual name webtool.add_static(app) #add static for app #创建web应用 srv=yield from loop.create_server(app.make_handler(),'127.0.0.1',9000) #新建服务器由执行者(分出来的协程?)监听'127.0.0.1:9000'端口 logging.info('server started at http://127.0.0.1:9000...') return srv
def test(loop) : print() print('start connect') r = yield from orm.create_pool(loop = loop, host = 'localhost', port = 3306, user = '******', password = '******', db = 'awesome') print('connect success!') print(r) u = User(name = 'Test', email = '*****@*****.**' + str(uuid.uuid1())[0 : 3], passwd = '1234567890', image = 'about:blank') print(next_id()) yield from u.save() print('////')
def init(loop): yield from orm.create_pool(loop=loop, **configs.db) app = web.Application(loop=loop, middlewares=[ logger_factory, response_factory ]) init_jinja2(app, filters=dict(datetime=datetime_filter)) add_routes(app, 'handlers') add_static(app) srv = yield from loop.create_server(app.make_handler(), '10.163.183.192', 9000) logging.info('server started at http://10.163.183.192:9000...') return srv
def init(loop): yield from orm.create_pool(loop=loop, **configs.db) app = web.Application(loop=loop, middlewares=[ logger_factory, response_factory ]) add_routes(app, 'handlers')) srv = yield from loop.create_server(app.make_handler(),'192.168.15.135', 8888) logging.info('server started at http://192.168.15.135:8888...') return srv
def init(loop): yield from create_pool(loop, **configs.db) app = web.Application(loop=loop, middlewares = [ logger_factory, auth_factory, response_factory ]) init_jinja2(app, filters=dict(datetime=datetime_filter)) add_routes(app, 'handlers') add_static(app) srv = yield from loop.create_server(app.make_handler(), '0.0.0.0', 9000) logging.info('server start at port 9000') return srv
def init(loop): yield from orm.create_pool(loop=loop, host='127.0.0.1', port=3306, user='******', password='******', db='online_learning') app = web.Application(loop=loop, middlewares=[ logger_factory, auth_factory, response_factory ]) init_jinja2(app, filters=dict(datetime=datetime_filter)) add_routes(app, 'handlers') add_static(app) srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 9100) logging.info('server started at http://127.0.0.1:9100...') return srv
def go(): global _pool _pool =yield from orm.create_pool() with (yield from _pool) as conn: cur = yield from conn.cursor() yield from cur.execute("SELECT 10") # print(cur.description) (r,) = yield from cur.fetchone() print((r,)) pool.close() yield from pool.wait_closed()
def init(loop): yield from orm.create_pool(loop=loop, **configs.db) app = web.Application(loop=loop, middlewares=[logger_factory, auth_factory, response_factory]) # 初始化jinja2模板 init_jinja2(app, filters=dict(datetime=datetime_filter)) # 增加handlers的处理函数 add_routes(app, 'handlers') # 静态文件 add_static(app) srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 9000) logging.info('server start.....') return srv
def test(loop): yield from orm.create_pool(loop=loop,user='******',password='******',db='first') u=User(name='3',email='31',passwd='311') yield from u.save() u=User(name='4',email='41',passwd='411') yield from u.save() us=yield from User.findAll('name','1') print(us) print(type(us[0].getValue(us[0].__primary_key__))) num=yield from us[0].remove() print(num)