Zope简介
之前一直使用Django在開發web應用, 覺得Django易學, 好用. 后來看到Zope, 覺得兩者的scope有重合, 所以大概學習了下Zope, 記錄一下.
了解Zope可以先看看這篇Blog, zope系列一: zope的悲劇 (http://www.douban.com/group/topic/11400495/)
Zope(Z Object Publishing Environment)是一個企業級的web應用服務器的開發平臺, 它很強大, 也比較復雜, 所以從某種程度上而言, 它無法被Python社區所接受, 因為它不夠簡單和美麗, 而python的哲學是大道至簡. 由于推廣問題, 策略問題, 等等問題導致這樣一個平臺沒有紅起來, 但是毋庸置疑它很牛, 很值得學習, 因為基于它開發出了Plone (Plone是免費的、開放源代碼的內容管理系統(Content Management System,CMS)), 我個人沒用過, 據說相當強大, 相當牛...所以我就先簡單學習一下, 等以后用到再仔細研究吧.
以下內容來自Zope Book,
Fundamental Zope Concepts
Object Orientation
Unlike common file-based Web templating systems such as ASP or PHP, Zope is a highly "object-oriented" Web development platform.
Zope不同于其他web開放框架的是, 他不是基于文件的, 之前我們在使用jsp, 或django, 都是基于文件的, 而Zope是完全基于對象的, 任何東西, 網頁模板, 邏輯代碼, 數據都抽象為對象.
Object Publishing
The technology that would become Zope was founded on the realization that the Web is fundamentally object-oriented.
A URL to a Web resource is really just a path to an object in a set of containers, and the HTTP protocol provides a way to send messages to that object and receive its response.
既然基于對象, 所以就是基于對象的發布, 任何URL都是訪問某一對象, 或發送message給某對象. 而不象一般的開放框架, 是基于文件發布的.
Through-The-Web Management
To create and work with Zope objects, you use your Web browser to access the Zope management interface. All management and application development can be done completely through the Web using only a browser.
這點是Zope很牛比的地方, 你只需要通過瀏覽器去訪問Zope服務器, 就能完成任何服務器的管理, 更牛的是, 你還可以完成應用的開發. 可以想象, 只需要一臺Zope服務器, 你可以在任何地方方便的管理并開發應用. 多么美好的場景.
Security and Safe Delegation
One of the things that sets Zope apart from other application servers is that it was designed from the start to be tightly coupled not only with the Web object model, but also the Web development model. Today's successful Web applications require the participation of many people across an organization who have different areas of expertise. Zope is specifically designed to accommodate this model, allowing site managers to safely delegate control to design experts, database experts and content managers.
Objects in Zope provide a much richer set of possible permissions than a conventional file-based system. Permissions vary by object type based on the capabilities of that object. This makes it possible to implement fine-grained access control.
對于一個大型的Web應用而言, 需要很多角色的開發者, 當他們協同開發的時候, 出于安全性和可維護性的考慮, 需要分配不同的權限, Zope對這個也有很好的支持.
Native Object Persistence and Transactions
Zope objects are stored in a high-performance transactional object database known as the Zope Object Database (ZODB). Each Web request is treated as a separate transaction by the object database.The Zope framework makes all of the details of persistence and transactions totally transparent to the application developer.The Zope framework makes all of the details of persistence and transactions totally transparent to the application developer.
Zope Object Database (ZODB), Zope不但提供開放框架, 還提供了一套面向對象數據庫的solution來支持它的面向對象發布, 而其他開發框架往往都是基于現有的關系數據庫.
據說這個數據庫很好用, 很牛比, 現在流行的No Sql數據庫都沒這個牛, 沒研究過, 沒發言權.
等后面有空了, 來好好研究一下這個數據庫.
Acquisition
One of the most powerful aspects of Zope is "Acquisition", and the core concept is simply that:
?·? Zope objects are contained inside other objects (such as Folders).
?·? Objects can "acquire" attributes and behavior from their containers.
這個是Zope在它的對象層次架構上的一個創新, 這個概念是Zope發明的, 以前沒有聽說過. 其實很簡單, 就是基于包含(contain)關系的功能繼承.
說白了, Object可以繼承container的behavior. 這非常適合Zope的對象層次架構,?很像文件系統, 一級一級不斷的包含下去, 所以非常便于service的提供和發布.
Zope Is Extensible
Zope is highly extensible, and advanced users can create new kinds of Zope objects, either by writing new Zope add-ons in Python or by building them completely through the Web.?
?
Fundamental Zope Components
下面列出Zope的架構圖,
ZServer — Zope comes with a built in web server that serves content to you and your users. This web server also serves Zope content via FTP, WebDAV, and XML-RPC (a remote procedure call facility).
Web Server — Of course, you may already have an existing web server, such as Apache or Microsoft IIS and you may not want to use Zope's. Zope works with these web servers also, and any other web server that supports the Common Gateway Interface (CGI).
Zope本身就提供ZServer, 如果你喜歡用其他的Server, 如Apache...隨便
Zope Core — This is the engine which coordinates the show, driving the management interface and object database.
這個就是核心engine, 用來run這個Zope server
Object Database — When you work with Zope, you are usually working with objects that are stored in Zope's object database.
Relational database — You don't have to store your information in Zope's object database if you don't want to. Zope works with other relational databases such as Oracle , PostgreSQL , Sybase , MySQL and others.
File System — Zope can of course work with documents and other files stored on your server's file system.
Zope開發了很牛比的面向對象數據庫, 你可以把一齊都當對象存進去. 當然你如果想用, 關系型數據庫和文件系統, 也沒問題.
ZClasses — Zope allows site managers to add new object types to Zope using the Zope Management Interface. ZClasses are these kinds of objects.
Products — Zope also allows site managers to add new object types to Zope by installing "Product" files on their Zope server's filesystem.
?
Using Basic Zope Objects
對于Zope的核心就是對象, 下面就來介紹一下Zope對象, 這就是典型的MVC架構...
In general, basic Zope objects take on one of three types of roles:
Content — Zope objects such as documents, images and files hold different kinds of textual and binary data. In addition to objects in Zope containing content, Zope can work with content stored externally, for example, in a relational database.
Presentation — You can control the look and feel of your site with Zope objects that act as web page "templates". Zope comes with two facilities to help you manage presentation: DTML (which also handles "logic"), and Zope Page Templates (ZPT). The difference between DTML and ZPT is that DTML allows you to mix presentation and logic, while ZPT does not.
Logic — Zope has facilities for scripting business logic. Zope allows you to script behavior using three facilities: Document Template Markup Language (DTML), Python, and Perl (Perl is only available as an add-on).
Content Objects: Folders, Files, and Images
Folders
You've already met one of the fundamental Zope objects: the Folder . Folders are the building blocks of Zope. The purpose of a folder is simple: a Folder's only job in life is contain other objects.Folders can contain any other kind of Zope object, including other folders. You can nest folders inside each other to form a tree of folders. Good structure is very important, as Zope security and presentation is influenced by your site's folder structure.
Files
Zope Files contain raw data, just as the files on your computer do. Files do not consider their contents to be of any special format, textual or otherwise. Every File object has a particular content type which is a standard Internet MIME designation for types of content.
Images
Image objects contain the data from image files such as GIF, JPEG, and PNG files.
Zope Page Templates are objects which allow you to define dynamic presentation for a web page. The HTML in your template is made dynamic by inserting special XML namespace elements into your HTML which define the dynamic behavior for that page.
<title tal:content="here/title">Page Title</title>
Document Template Markup Language objects are object which also allow you to define presentation for a web page. The HTML in your template is made dynamic by inserting special "tags" (directives surrounded by angle brackets, typically) into your HTML with define the dynamic behavior for that page.
<dtml-in mySequence>
??? <!-- this is an HTML comment inside the in tag block -->
</dtml-in>
Both ZPT and DTML are "server-side" scripting languages, like SSI, PHP, embperl, or JSP. This means that DTML and ZPT commands are executed by Zope on the server, and the result of that execution is sent to your web browser.
Zope's original dynamic presentation language was DTML. It soon became apparent that DTML was great at allowing programmers to quickly generate dynamic web pages, but many times failed at allowing programmers to work effectively together with nontechnical graphics designers. Thus, ZPT was born. ZPT is an "attribute-based" presentation language that tries to allow for the "round-trippping" of templates between programmers and nontechnical designers.
大家是否都覺得, 為什么需要兩個View solution, 是啊, 這就是Zope靈活的地方, 你想怎么用就怎么用, 但是這就違反了python的簡單原則, 對于一個問題, 最好只有唯一的答案, 太多選擇有時候也是件煩惱的事.上面也說了, 本來是只有DTML的, 它很靈活, 適用于開發者, 不但可以開放view, 里面可以加上logic, 這樣雖然影響MVC分層的理念, 但只要做過相關開發都應該體會到, 絕對的分開view和logic,有時候是很麻煩的, 很不實用的, 雖然看上去很美. 他最大的問題就是, 直接在Html增加Tag, 這樣開發的view是無法直接用瀏覽器預覽的,因為他的結果非標準Html, 有很多自定義的Tag. 這樣就無法和UI設計人員合作開發,?你無法要求UI人員熟悉使用DTML,?而他用HTML設計的UI模板, 在DTML里無法直接使用.
所以產生了?Zope Page Templates (ZPT ), 它只會在Html屬性上加上特殊的XML命名空間, 這樣是不影響網頁被瀏覽器預覽的, 這樣就解決了剛才的問題, 不過ZPT不允許插入任何邏輯, 對于開發人員而言不是那么方便, 各有所長, 愛用誰用誰......
Logic Objects: Script (Python) Objects and External Methods
"Logic" objects in Zope are objects which typically perform some sort of "heavy lifting" or "number crunching" in support of presentation objects.
?
Acquisition
Acquisition is the technology that allows dynamic behavior to be shared between Zope objects via containment .
Acquisition's flavor permeates Zope. It can be used almost everywhere within Zope: in DTML, in Zope Page Templates, in Script (Python) objects, and even in Zope URLs. Because of its ubiquity in Zope, a basic understanding of acquisition is important.
Acquisition vs. Inheritance
Inheritance stipulates that an object can learn about its behavior from its superclasses via an inheritance hierarchy .
Acquisition , on the other hand, stipulates that an object can additionally learn about its behavior its through its containment hierarchy . In Zope, an object's inheritance hierarchy is always searched for behavior before its acquisition hierarchy. If the method or attribute is not found in the object's inheritance hierarchy, the acquisition hierarchy is searched.
總結
- 上一篇: cocos2d精灵教程(三篇)
- 下一篇: Udev 使用