三十分钟学会Zope3(已完成,请参阅本站 Wiki)

软件和网站开发以及相关技术探讨
头像
leal
帖子: 1119
注册时间: 2005-08-29 14:49
来自: 杭州
联系:

#31

帖子 leal »

A good introductory book is also available in print, visit: http://worldcookery.com/
还有一本不错的介绍书籍,请访问: http://worldcookery.com/
还有一本已出版的介绍性图书,很不错,请访问:……
Just one more thing: I want to improve this document, so don't hesitate to write your feedback to: baiju.m.mail AT gmail.com
还有就是我想让这篇文档变得更好,所以请将你的反馈意见发到:[email protected]
还有一点:我想不断完善这份文档,因此有何意见/建议千万别犹豫,请发送到:……
用心×恒 | 豆瓣 | 门户 | Blog
头像
leal
帖子: 1119
注册时间: 2005-08-29 14:49
来自: 杭州
联系:

#32

帖子 leal »

firehair兄辛苦了 :)

整理成一个贴吧 :)
用心×恒 | 豆瓣 | 门户 | Blog
头像
firehare
帖子: 2625
注册时间: 2005-04-10 16:54
来自: 温州大学
联系:

#33

帖子 firehare »

其实辛苦的是leal兄,水平有限,没有办法,只好劳动兄弟你了!
我心无畏,源自于我心无知。
图片
头像
leal
帖子: 1119
注册时间: 2005-08-29 14:49
来自: 杭州
联系:

#34

帖子 leal »

嘻嘻,完美合作 :)

说句实话,我还挺喜欢修修补补的活 呵呵

great!
用心×恒 | 豆瓣 | 门户 | Blog
头像
annerose
帖子: 105
注册时间: 2005-04-07 20:15

#35

帖子 annerose »

到底是什么东西啊?python的什么不明白啊,web容器?
试着用它来代替windows吧,你会重新找回当年的感动!
头像
leal
帖子: 1119
注册时间: 2005-08-29 14:49
来自: 杭州
联系:

#36

帖子 leal »

Python 是一种解释性语言

Zope是一个用Python编写的Web应用服务器,可以在其上用Python开发应用
用心×恒 | 豆瓣 | 门户 | Blog
头像
firehare
帖子: 2625
注册时间: 2005-04-10 16:54
来自: 温州大学
联系:

#37

帖子 firehare »

Hey! What's time now?
嗨!现在什么时候了?

Oh! it's only 10 minutes since we started reading this article. We got 20 more minutes to explain what's happened here. So let's look back again.
哦!从我们开始看这篇文章到现在才花了10分钟。我们还有20分钟的时间来解释这里发生了什么。那么让我们回过去看看

Installation and Configuration
安装和配置

You can download Zope 3.1.0 or later for your major works. Install Zope3 as root, though it is not necessary. When you experiment with Zope3, make instance as a normal user. For production systems, you get the additional advantage of OS level security. Since we manually installed Zope3 (as root), the default installation path will be /usr/local/Zope-3.1.x . When making zope instance, you have to specify zope manager's user name and password. You can make more instances, if required.
你可以下载 Zope 3.1.0 或以后的版本。作为根用户安装 Zope3,虽然并不需要这样做。当你用 Zope3 来做实验时,可以做为一个普通用户来创建实例。而对于产品系统而言,你可以从操作系统的安全等级中得到额外的好处。由于我们手动安装 Zope3 (作为根用户),所以缺省的安装路径将是 /usr/local/Zope-3.1.x。当生成 Zope 实例时,你必须要指定 Zope 的管理用户名和密码。如果需要的话,你可以生成更多的实例。

In your Zope 3 instance directory, there are few directories with specific purposes. Here ownwards I will be using $ZOPE3INSTANCE to refer your instance directory
在你的 Zope 3 实例目录中,有一些指定用途的目录。在这样,我将使用 $ZOPE3INSTANCE 来代表你的实例目录

$ZOPE3INSTANCE/etc
In 'etc' you can see some configuration files. In $ZOPE3INSTANCE/etc/zope.conf you can edit port numbers of http and ftp servers.
在 'etc' 中你可以看到一些配置文件。在 $ZOPE3INSTANCE/etc/zope.conf 文件中你可以编辑 http 服务和 ftp 服务的端口号。

$ZOPE3INSTANCE/var
Zope saving all data here. Backup this directory regulary. If 'Data.fs' is missing, it will be automatically created when you run zope again.
Zope 将所有数据保存在这里。定期备份该目录。如果 'Data.fs' 文件丢失的话,它会在你再次运行 Zope 时被自动创建。

$ZOPE3INSTANCE/bin
Few utility scripts. 'runzope' and 'test' are already familiar to you. 'pyskel' script will be very useful for creating template codes from interfaces, Example:
一些工具脚本。 'runzope' 和 'test' 已经被你所熟知。'pyskel' 脚本对于从接口创建模板代码也是非常有用的。如:

$ $ZOPE3INSTANCE/bin/pyskel boom.interfaces.IMark > file.py

$ZOPE3INSTANCE/lib/python
As I said earlier you can place your Zope3 packages here. By default this won't be in your Python path. You can also place your package in any standard Python path.
正如我先前所说,你可以将你的 Zope3 包放在这里。缺省状态下,它不会在你的 Python 目录里。你也可以将你的包放在任何标准的 Python 目录中。
上次由 firehare 在 2006-01-05 13:17,总共编辑 1 次。
我心无畏,源自于我心无知。
图片
头像
id_sonic
帖子: 339
注册时间: 2005-04-08 18:08
来自: Chongqing
联系:

#38

帖子 id_sonic »

标题应该改为 30分钟学会安装运行 zope3 ,
要真正操作zope,不用python就不是真正的使用了。
目前是 tinkpad r400 上的 debian 用户
my blog Trust Dating
头像
firehare
帖子: 2625
注册时间: 2005-04-10 16:54
来自: 温州大学
联系:

#39

帖子 firehare »

id_sonic 写了:标题应该改为 30分钟学会安装运行 zope3 ,
要真正操作zope,不用python就不是真正的使用了。
不妥,这里面明明有编程!虽然只是一个小项目,但也不只是运行 Zope3 的程度!
我心无畏,源自于我心无知。
图片
头像
firehare
帖子: 2625
注册时间: 2005-04-10 16:54
来自: 温州大学
联系:

#40

帖子 firehare »

Why should I code like this?
为什么我要这样编写代码呢?

When we started discussing BookMarker, the first word I coined is Extreme Programming (XP). I strongly recommend you to read about Extreme Programming. It will really influence you to write code in Zope3 way (directly and indirectly). Ok, one causion: many XPers believe that frameworks are bad. Here, I can not give an answer in one sentence, so you find out yourself. "Extreme Programming Explained" by Kent Beck will be a good starting point for your study. By the way, another classic book which you can read is "Design Patterns" by Gang of Four. In this book they say : 'Program to an interface, not to an implementation'. To simulate a formal definition of interfaces in C++, they used classes with virtual functions. Just like this, in Python we will use zope.interface.Interfce inherited metaclass for defining an interface. There is every chance for an 'interface' concept in Python language by version 3.0 . According to Extreme Programming: 'The four basic activities of development are coding, testing, listening, and designing.' Zope3 makes your software testing, a breeze. You can write unit and functional tests very easily.
当我们开始讨论书签时,我提出的第一个词是极限编程(XP),我强烈推荐你去看看极限编程的相关内容。它能够真正改变你,让你用 Zope3 的方式去编写代码(直接或间接)。OK,一个原因:许多极限编程人员都相信框架是不好的。在这里,我不能用一句话来回答,因此你可以自已去找出答案。Kent Beck的《极限编程说明》对你学习极限编程来说将是一个好的起点。另外,另一本你可以看的经典书籍就是 Gang of Four 的《设计模式》。在这本书中他们提到:“程序是一个接口,而不是一个实现”。与 C++ 中接口的形式定义相同,他们用类来虚拟函数。为此,在 Python 中我们为定义一个接口可以用 zope.interface.Interfce 来继承元类。There is every chance for an 'interface' concept in Python language by version 3.0 . 根据极限编程的说法:“开发的四个基本活动就是编码,测试,监听和设计” Zope3 可以轻易地测试你的软件。你可以非常容易地编写单元测试和功能测试。
我心无畏,源自于我心无知。
图片
头像
firehare
帖子: 2625
注册时间: 2005-04-10 16:54
来自: 温州大学
联系:

#41

帖子 firehare »

Let's look into interfaces
让我们研究接口

I hope you are familiar with the concept of interfaces. Anyway, when we speak about an interface, we meant it to use with reference to an object (i.e, an instance of a class). For example if 'A' is a class which implements 'IA', and 'a' is an instance of 'A', then 'IA' is the interface of 'a', got it? But normally we only deals with the interface and its implementing class.
我希望你熟悉接口的概念。无论如何,当我们讲到接口时,我们的意思就是引用一个对象(如一个类的实例)。举个例子,如果“A”是一个类,实现了“IA”,“a”是“A”的一个实例,那么“IA”就是“a”的接口,明白吗?但通常我们只讨论接口和实现它的类。

In our interfaces.py we defined three interfaces. The first interface 'IMark' defines a book mark object. A book mark has two attributes, one is the url and another one is the description. We used schemas available at zope.schema package to specify these attributes.
在我们的 interfaces.py 文件中,我们定义了三个接口。第一个接口“IMark”定义了一个书签对象。一个书签有两个属性,一个是 url 而另一个是 描述。我们使zope.schema 包中的 schemas 有效,以指定这些属性。

As we mentioned earlier IBookMarker is a container interface. We extended IContainer interface with one name attribute. Also we put one item type pre-condition. So IBookMarker object can only contain an IMark object. Now before moving to the next section, please note from which packages and modules we imported different classes/interfaces. Just open the sources of those packages, and see how well documented they are!. Some documentation are written in seperate ReStructuredText files with unit testing, this is the Zope3 way of unit testing.
正如我们先前提到的,IBookMarker是一个容器接口。我们扩展了带一个名字属性的 IContainer 接口。我们放入一个类型为 pre-condition 的项。因此 IBookMarker 对象就只能包含一个 IMark 对象了。在进入下一节之前,请注意我们从哪个包和模块中导入不同的类/接口。打开这些包的源代码,看看它们多么适当地被证实。一些文档被写在带单元测试的 seperate ReStructuredText 文件中,这些都是 Zope3 方式的单元测试方法。
我心无畏,源自于我心无知。
图片
头像
firehare
帖子: 2625
注册时间: 2005-04-10 16:54
来自: 温州大学
联系:

#42

帖子 firehare »

Unit testing re-visited
再看看单元测试

We wrote our test in a file named tests.py. You can also write tests in a package named tests. All test modules under this package should have test_ prefix. We also automated our doctests written along with implementation. To test our BookMarker container, we inherited TestSampleContainer. For testing containers, you can stick with unittest module. Also use it where you want more reusablity. Anyway, we will integrate all doctests with unittest module. This will help us to run tests automatically, from a single point.
Let's talk about implementations
我们在文件 tests.py 中编写我们的测试。你也可以在 tests 包中编写测试。所有在该包中的测试模块将有一个 test_ 的前缀。我们也与实现一起自动进行我们的 doctests。为了测试我们的 BookMarker 容器,我们继承了 TestSampleContainer。为了测试 containers,你可以加入 unittest 模块。你也可以在你其他需要重用的地方使用它。无论如何,我们将用 unittest 模块集成所有的 doctests。这将帮助我们从单一的点开始自动进行测试。

In the first line of bookmarker.py we set a special variable attribute __docformat__ = 'restructuredtext'. Our documentation strings are written in ReStructuredText format. I strongly reccomend you to use ReST for all kinds of Python documentations. (This article is written in ReST: svn co svn://svn.berlios.de/zissue/trunk/z3in30m).
在 bookmarker.py 文件的第一行,我们设置了一个特殊的可变属性 __docformat__ = 'restructuredtext'。我们的文档字符串是用 ReStructuredText 格式写的。我强烈建议你在 Python 所有类型文档中都用 ReST。(本文的 ReST 格式在:svn co svn://svn.berlios.de/zissue/trunk/z3in30m)

First we imported implements function from zope.interface package. Using this function we can say a class implements one or more interfaces. BTreeContainer is full implementation of IContainer interface. We inherit it to implement our Container interfaces. Similarly Contained is an implementation of IContained. Mark class implements both IMark and IMarkContained. IMarkContained is an extended interface of IContained. So by inheriting Contained class we get a partial implementation of our interfaces. Now the remaining things to implement is two attributes, url and description. Similarly majority of IBookMarker is implemented in BTreeContainer. I hope documentation strings are self explanatory.
首先我们从 zope.interface 包中导入实现函数。使用该函数,我们可以说一个类实现一个或更多的接口。BTreeContainer是 IContainer 接口的完全实现。我们继承它以实现我们的 Container 接口。同样 Contained 是 IContained 的实现。Mark 类实现 IMark 和 IMarkContained。IMarkContained 是 IContained 的一个扩展。因此通过继承 Contained 类,我们得到了我们接口的部分实现。现在剩下来要实现的事就是两个属性,url和描述了。同样 IBookMarker 的大部分功能都在 BTreeContainer 中被实现。我希望文档字符串是可以自说明的。
我心无畏,源自于我心无知。
图片
头像
firehare
帖子: 2625
注册时间: 2005-04-10 16:54
来自: 温州大学
联系:

#43

帖子 firehare »

ZCML Explained
ZCML 说明

Let me ask one question, which you are going to face many times later. Do you think a Programming language should be used to write configuration files? If yes, why?. Why we can not use a text files with some conventions or markups.
让我来问个问题,在这之后你常常打算面对什么。你认为编程语言应该被用来编写配置文件吗?如果是的话,为什么?为什么我们不能用有着一些约定或标识的文本文件呢?

Anyway, ZCML is the XML based configuration system for Zope3. The base tag 'configure' specifies namespaces to use. In our configuration we used two namespaces, 'zope' and 'browser'. 'zope' namespace contains the basic elements required to register our content objects. 'browser' is for view related configuration.
无论如何,ZCML是 Zope3 中基于 XML 的配置系统。基本标识 “configure”指定所用的名称空间。在我们的配置中,我们使用两个名称空间,“zope”和“browser”。“zope”名称空间包括要求注册我们内容对象的基本元素,而“browser”则是用于与视图相关的配置。

The first tag we used is 'interface'. It is called a directive. In our configuration 'iterface' is a simple directive and 'content' is a complex directive.
我们用的第一个标识是“interface”。这被称为一个语句。在我们的配置中,'iterface'是一个简单语句,'content'是一个复合语句。
我心无畏,源自于我心无知。
图片
头像
firehare
帖子: 2625
注册时间: 2005-04-10 16:54
来自: 温州大学
联系:

#44

帖子 firehare »

Views and ZPT
视图和 ZPT

Your objects are finally saved in ZODB, you may choose other storage mechanisms also. In zope you can present your objects in different ways. I mean, through different protocols like http, ftp, xmlrpc etc. In our case, we created a view for browser (yes, through http). We put all logics for presentation in browser.py. And created a Zope Page Template (ZPT) for real presentation. Normally you should avoid any information retrieval logic in ZPT.
你的对象最终被保存在 ZODB中,你也可以选择其他保存机制。 在 zope 中你可以通过不同的方式来描述你的对象。我的意思是通过不同的协议如 http,ftp,xmlrpc等。在我们的示例中,我们为浏览器创建一个视图(是的,通过 http)。我们在 browser.py 文件中为表现放入所有的逻辑,并为真正的表现创建一个 Zope 页面模板(ZPT)。通常你应该避免在 ZPT 中放入任何逻辑信息。
我心无畏,源自于我心无知。
图片
头像
firehare
帖子: 2625
注册时间: 2005-04-10 16:54
来自: 温州大学
联系:

#45

帖子 firehare »

The things we didn't mentioned
我们没有提及的事

Please go to the last section, otherwise you can not finish this article in 30 minutes :)
请到最后一节,否则你不可能在30分钟之内看完这篇文章 :)

Ofcourse, in an introductory document we can only cover a fraction of the whole technology. Here I have omitted many things for various reasons.
当然,在一篇介绍性文章中我们只能提及整个技术的一部分。这里由于各种原因我省略了很多东西。

In the beginning, I said just one assumptiion about you. I really meant many other things. Surely you should be a Python programmer. You should know basic administration. Basic understanding of web technologies. And ofcourse, willing to spend time :)
在开始,对于你我只做了一个假定,其实我有很多其他的意思。确信你应该是一个Python程序员、你应该知道基本管理、基本理解 Web 技术,当然还有就是愿意花时间 :)

While installation you might get error due to Python development libraries not installed. If you know Python and system administration you will just run: apt-get install python-dev Similary you have created __init__.py file to make our package working.
在安装过程中,你也许会得到一个没有安装 Python 开发库的错误提示。如果你知道 Python 和系统管理权的话,你只需运行:apt-get install python-dev 就象你创建 _init__.py 文件用来运行你的包一样。

If you are interested in Zope3 by now, surely you will explore more in future. While you exploring, you will see that doctests can be written in stand alone text files. Similarly you will understand lots of other things.
如果你现在对 Zope3 感兴趣的话,确定你以后会进行更多的研究。在你研究过程中,你将发现 doctests 可以写在单独的文本文件中。同时你也会理解很多其他事物。

One thing I can assure you is that zope is really a matured framework. It has almost 9 year history of successfull running. Many technologies evolved through zope. Infact zope and zope developers has influenced Python language itself. Yes! it is one of the gratest Python application ever written.
我可以向你确保的就是 zope 是一个真正成熟的框架。它已经有 9 年成功运行的历史了。许多技术都是通过 zope 改善的。事实上 zope 和 zope 开发人员也影响了 Python 语言自身。是的,它是最伟大的 Python 应用之一。
我心无畏,源自于我心无知。
图片
回复