ObpLovelyPython/AbtEurasia

status

校对

沈崴

完成度 100%

Eurasia3

关注高性能的原创框架

作者

概述

Eurasia 沿革

Eurasia3 简介

   1 from eurasia.web import config, mainloop
   2 def controller(httpfile):
   3     httpfile['Content-Type'] = 'text/plain'
   4     httpfile.write('hello world!')
   5     httpfile.close()
   6 
   7 config(controller=controller, port=8080)
   8 mainloop()

表单词典       = Form(httpfile)
文件句柄       = SimpleUpload(httpfile)
请求头部       = httpfile['Http-Header']
请求报文       = httpfile.read(size) / httpfile.readline(size)

   1 from eurasia.shelve2 import open, Persistent, BTree
   2 
   3 # 定义持久化对象 (Persistent) User, User 对象可以直接以对象形式保存在数据库中,
   4 # 不需要进行对象关系映射 (Object Relational Mapping), 这也是对象数据库的特点
   5 #
   6 class User(Persistent):
   7     def __init__(self, username, password):
   8         self.username = username
   9         self.password = password
  10 
  11     def hello(self):
  12         print 'Hello Im %s, can I make friends with you?' %self.username
  13 
  14 db = open('test.fs', 'c')       # 创建并打开数据库 "test.fs"
  15 db['user'] = BTree()            # 创建 BTree 结点 "user", 相当于在关系数据库中建表
  16 obj = User('william', '******') # 创建一个 User 对象
  17 db['user']['william'] = obj     # 把 User 对象存入数据库
  18 db.close()
  19 
  20 db = open('test.fs')            # 重新打开数据库
  21 db['user']['william'].hello()   # 访问数据库中的对象

   1 # -*- coding: utf-8 -*-
   2 html = '''\ # HTML 页面
   3 HTTP/1.1 200 OK
   4 Content-Type: text/html
   5 
   6 <html>
   7 <head>
   8     <title>Comet Example</title>
   9 </head>
  10 <body>
  11 <script language="JavaScript">
  12 
  13 // 待会服务器会远程调用这个函数
  14 function message(msg)
  15 {
  16     confirm(msg);
  17 };
  18 
  19 </script>
  20 <!-- 建立 Comet 长连接, 借助 iframe -->
  21 <iframe src="comet" style="display: none;"></iframe>
  22 </body>
  23 </html>'''
  24 
  25 import eurasia
  26 from eurasia.web import config, mainloop, Comet
  27 
  28 sleep = eurasia.modules['time'].sleep
  29 
  30 def controller(httpfile):
  31     # 输出普通页面 (当 URL 不是 comet 时)
  32     if httpfile.path[-5:] != 'comet':
  33         httpfile.write(html)
  34         return httpfile.close()
  35 
  36     browser = Comet(httpfile)
  37     browser.begin()           # 开始和客户端之间的通讯
  38     browser.message('start')  # 使用原生 Python 代码直接调用浏览器端
  39                               # 名为 "message" 的 JavaScript 函数
  40                               # 发送消息 "start"
  41 
  42     sleep(2)                  # 每隔 2 秒调用一次客户端 message 函数
  43     for i in xrange(1, 3):
  44         browser.message(i)
  45         sleep(2)
  46 
  47     browser.message('finish')
  48     browser.end()             # 断开长连接
  49 
  50 config(controller=controller,
  51     port = 8080, verbose=True)
  52 mainloop()

Eurasia3 VS Django

   1 from eurasia.web import config, mainloop
   2 def echo(sockfile):
   3     while True:
   4         data = sockfile.readline(1024)
   5         if data == 'quit':
   6             sockfile.close()
   7             break
   8         else:
   9             sockfile.write(data)
  10 
  11 config(tcphandler=echo, port=8080) # 与前面不同, 这里使用 tcphandler
  12 mainloop()

开始使用 Eurasia3


反馈

创建 by -- ::-- ZoomQuiet [2008-09-30 14:18:41]

ObpLovelyPython/AbtEurasia (last edited 2009-12-25 07:17:02 by localhost)