个人工具

Zope3宝典

来自Ubuntu中文

219.142.249.150讨论2013年3月8日 (五) 21:26的版本 附录 

(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航, 搜索

Zope3宝典


原文出处:The Zope 3 Developers Book - An Introduction for Python Programmers

原文作者:StephanRichter, zope.org

授权许可:创作共用协议

翻译人员:

校对人员:Leal

适用版本:Zope 3

文章状态:草译阶段


The Zope 3 Developers Book aims to provide a solid, but gentle, introduction into the advanced concepts and implementations of the Zope 3 Framework. This book requires some knowledge about Python itself and is therefore aimed at Python and Zope developers, which are interested in the Zope 3 internals, instead of developing Web-based applications. It is the hope of the Zope 3 development community that this complete rewrite of Zope will attract a wider range of Python developers, since many components can be reused completely independent of Zope.

Zope 3 开发人员用书 旨在可靠而又不失轻松的介绍 Zope 3 框架的高级概念及其实现。本书要求读者具备Python语言本身的一些知识,目标读者是那些对Zope 3内部运作而非对开发基于Web的应用感兴趣的Python和Zope开发人员。Zope 3 开发社区希望这个完全重写的 Zope 可以吸引更大范围的 Python 开发人员,因为许多组件可以在完全独立于Zope的情况下被重用。

This book is not intended to cover every single aspect of the Zope 3 core software, but serve as a starting point by providing chapters that go into great detail instead of covering a wide range of information. The reader should be able to go to a chapter, read it and after understanding the material know how to complete the original task.

本书并不打算包罗万象,介绍 Zope 3 核心软件的方方面面,而是想通过所提供的章节来充当一个起点,这些章节深入探讨了细节而非只是介绍泛泛的信息。读者可以径直跳到某一章,阅读并在理解其内容后,知道如何完成最初的任务。

The completed book will be published by Sams Publishing under a free content license in the second or third quarter of 2004. It will be part of the Developer's Library. Much thanks goes to Shelley Johnston (Acquisitions Editor for Sams) for giving us this opportunity. The main author of the book is Stephan Richter and the technical editing will be done by Jim Fulton and Steve Alexander.

本书完成后将基于自由内容许可(free content license)在2004年第二或三季由 Sams Publishing出版发行。它将成为开发人员资料库的一部分。非常感谢 Shelley Johnston(Sams 的责任编辑)给了我们这个机会。本书的主要作者是 Stephan Richter,技术编辑则是由 jim Fulton 和 Steve Alexander 完成的。

I appreciate any contribution to the book, whatever form it may take from correcting spelling/grammar, making technical comments and even writing a chapter/recipe. All contributions will be properly credited in any publication form of the book. If you have any questions, do not hesitate to contact me on the Zope 3 Dev list or at [email protected]

对本书任何形式的贡献深感谢意,无论是拼写/语法检查、技术评论、甚或撰写一个章节/解决方法。所有贡献都会在本书任何出版形式中给予相应致谢。如有任何问题,请别犹豫,可通过Zope 3 Dev邮件列表或邮件 [email protected] 和我联系。

Thanks, StephanRichter

再次谢过! StephanRichter


Preface(序言)

Preface - A brief introduction to Zope.

序言 - Zope简介

Zope 3 from a User's Point of View(从用户视角看Zope3)

This section concentrates on getting Zope 3 setup on your computer.

这一节主要介绍如何在计算机上安装设置Zope 3。

  • Installing Zope 3 - Before you can go on trying all the code snippets provided by the following chapters and recipes, you need to install Zope 3 on your system. This introduction chapter will only cover the basic installation and leave advanced setups for the following chapters to cover.
    安装 Zope 3 - 在你可以尝试后面章节和方法所提供的所有代码片断之前,你必须要在你系统上安装 Zope 3。本章只介绍基本安装同时忽略会在后面章节涵盖的高级设置。

  • The new Web-based User Interface - WebGUI While this has not much to do with Python development, one must be comfortable with the GUI interface, so that s/he can test the features of the new code effectively. Furthermore, the TTW development interface will be briefly introduced.
    新的web用户界面 - Web 图形界面对于用 Python 开发来说并不需要太多,一个需要就是要图形界面接口使用起来方便舒适,以便她/他能够有效地测试新代码的功能,此外,还会简单介绍一下 TTW 开发接口
    Note: The original futuristic version of this chapter is still available as Zope3GUI. Since Zope X3 3.0.0 does not ship with any scripter or TTW development support, these sections have been removed from the current text.
    注意:本章的下一个版本可以在Zope3GUI看到。因为 Zope X3 3.0.0 不能提供对任何脚本编写者或 TTW 开发的支持,所以这些章节已从当前的文本中删除。


  • Installing new Zope Packages - A simple chapter for installing packages in your Zope 3 installation.
    安装新的Zope包(Zope Packages) - 一个关于在你的 Zope 3 安装中安装包的简单章节

  • Setting up a Virtual Hosting Environment with Apache - This chapter describes how to setup virtual hosting in Zope 3, such as it is required for using Apache in front of Zope 3.
    和Apache一起设置一个虚拟主机环境 - 本章讲述了如何在 Zope 3 中设置虚似主机,它需要使用 Apache 来做为 Zope 3 的前端。

  • Synchronizing Through-The-Web Code with the Filesystem - Zope 3 will come with an advanced ZODB to Filesystem synchronization tool, similar to CVS. This will allow people to make local copies of their sites work on it and check in the changes and much more. This recipe will explain how to effectively use this tool.
    利用 Web 编写代码(Through-The-Web Code)并与文件系统同步 - Zope 3 将有一个先进的类似CVS的 ZODB 到文件系统的同步工具,它允许人们在它之上建立一份网站在本地的拷贝,并报告诸如变动的更多信息。这个方法将说明如何有效地使用该工具。
    Note: This chapter will not be included in the first version of the book, since Zope X3 3.0.0 will not ship with it and it is not actively maintained at this point.
    注意:本章并没有出现在本书的第一版中,因为 Zope X3 3.0.0 还不能提供它,因此也由于这方面的原因它也没有得到很好地维护。


The Ten-Thousand Foot View(一万英尺鸟瞰)

Here an overview over some of the fundamental ideas in Zope 3 is given without jumping into the technical detail. The reader might prefer to read these chapters after reading some of the more hands on sections, like the ones that follow.
这里对 Zope 3 的一些基本概念而非技术细节进行了概述。读者也许更喜欢在看完其他方面之后再来看下面的这些章节。

  • The Zope 3 Development Process - This chapter briefly introduces the process that is used to develop and fix components for Zope 3.
    Zope 3 开发过程 - 本章简单介绍 Zope 3 开发和修复组件的过程

  • An Introduction to Interfaces - Since Interfaces play a special role in Zope 3, it is important to understand what they are used for and what they offer to the developer.
    接口(Interfaces)的介绍 - 在 Zope 3 里接口(Interfaces)扮演一个特殊的角色,本章对于理解它们能用于什么和能向开发者提供什么是十分重要。

  • The Component Architecture - An Introduction - An overview over components and their possible interaction.
    介绍组件架构(Component Architecture) - 对组件及其可能的交互做个概述

  • Zope Schemas and Widgets (Forms) - One of the powerful features coming up over and over again in Zope 3, are schemas, an extention to interfaces that allows attributes to be specified in more detail allowing autogeneration of forms as well as the conversion and validation of the inputted data.
    ZOPE的模式和部件(表单) - 在 Zope 3 中被一遍又一遍提及的强大功能之一就是模式(Schemas),一个对接口的扩展以便允许指定属性的更多细节,如允许表单的自动生成以及输入数据的转换和验证

  • Introduction to the Zope Configuration Markup Language (ZCML) - While you are probably familiar with ZCML by now, it is always good to review.
    介绍 Zope 配置标记语言(ZCML) - 现在也许是你要熟悉 ZCML 的时候了,它总是便于复查的。

  • Introduction to Zope's I18n and L10n Support - This introduction presents the new I18n and L10n features of Zope 3 and demonstrates how a developer can completely internationalize his/her Zope application. I18n in ZPT, DTML, ZCML and Python code will be discussed.
    介绍Zope的I18n和L10n支持 - 介绍 Zope 3 新的 I18n 和 L10n 功能并演示开发人员是怎样完成对他/她应用程序的国际化的。

  • Meta Data and the Dublin Core - Everyone knows about it, everyone talks about it, but few know the details. Naturally, the fields of the Dublin Core will be discussed and how they can and should be used.
    元数据和都柏林核心(Dublin Core) - 每个人都知道它,每个人都在谈论它,但很少人知道详情。毫无疑问在这里都柏林核心(Dublin Core)域将被讨论,并且展示可以和应该如何使用它们。

  • Porting Applications - For many developers it is very important to have a migration path from their Zope 2 applications to Zope 3. This chapter will concentrate on the technical aspects and discuss the design changes that have to be applied to make an old Zope application fit the new model. The port of ZWiki? will be used as an example.
    移植应用 - 对于许多开发人员来说从 Zope 2 移植到 Zope 3 上来是非常重要的。本章将集中在技术层面上来讨论设计上的改变,以便可以使老的 Zope 应用程序能适用新的模型。

Content Components - The Basics(内容组件 - 基础)

This section deals with the creation of content objects and basic functionality around them. In order to make the recipes flow better, they will be all guided by the creation of a simple message board.
本单元介绍内容对象的创建及其基本功能。为了使各章节衔接更好,将通过创建一个简单的留言薄示例来进行引导。

  • Writing a new Content Object - This recipe will describe how to implement a new simple Content Object.
    编写一个新的内容对象 - 本章将讲述如何实现一个新的、简单的内容对象

  • Adding Views - This recipe will demonstrate various methods to create Browser-specific views for a component.
    添加视图 - 本章将示范用不同的方法来创建组件的特定浏览器视图

  • Custom Schema Fields and Form Widgets - This recipe basically tells you how to implement your own field and corresponding widget. It will then be demonstrated how this Field and Widget can be used in a Content object.
    定制模式域和表单部件 - 本章主要讲述如何实现你自己的域和相应的部件。然后示范在内容对象中是如何使用该域和部件的。

  • Securing Components - Zope 3 comes with an incredible security system; but the best system is only as good as the end developer using it. This recipe will give some hands-on tips and tricks on how to make your code secure.
    保障组件安全 - Zope 3 有一个令人难以置信的安全系统;但也只有系统在最终开发人员能最好地使用它时才能被称之为最好。本章将给出一些实际技巧和诀窍以保障你代码的安全。

  • Changing Size Information - There exists a small interface for content objects that will allow them to display and compare their size. This is a short recipe explaining this feature.
    改变尺寸信息 - 有一个内容对象的小接口用来显示和比较它们的尺寸。这里用了一小章来说明该功能。

  • Internationalizing a Package - This recipe will give step by step instructions on how to internationalize the content object we developed in the previous recipes and how to create a German translation for it.
    国际化软件包 - 本章将一步步地介绍如何国际化我们在上一章开发的内容对象,并为它创建一个德语翻译。

Content Components - Advanced Techniques(内容组件 - 高级技术)

Having a well-working basic message board is great, but it is certainly not blowing away anyone. In this section some more advanced APIs are presented.
拥有一个工作良好的基本留言薄是不错,但它无疑还不够吸引人。在本部分将介绍一些更高级的API。

  • Events and Subscribers - Events Events et al are a very powerful idea. This chapter will explain how to write your own event subscribers by implementing a mail subscription feature for messages.


事件与订阅 - 事件是个功能十分强大的概念,本章将通过为留言实现一个邮件订阅功能来说明如何编写自己的事件订阅接口


消息的审批工作流 - 本章将展示如何将一个可编辑的工作流集成到内容组件中。


提供在线帮助屏幕 - 任何好的应用都应该提供在线帮助屏幕,本章大概地讲述了一下这方面的问题

  • Object to File System mapping using FTP as example - While there are standard hooks for content objects to be handled by FTP, it is often useful to write your own FTP handlers, so that the file-to-object conversion (and the other way around) seems more natural.


使用FTP为例介绍对象到文件系统的映射 - 尽管已经存在一些标准的hooks以便内容对象可被FTP处理,不过编写自己的FTP处理器(handler)通常也很有用,这样文件到对象(file-to-object)的转换(反之亦然)可以显得更自然。

  • Availability via XML-RPC - If you want to make XML-RPC calls on your content objects, you must write a view declaring the methods and define how their output is mapped to a type that XML-RPC understands.


使用XML-RPC访问如果想在内容(content)对象中进行XML-RPC调用,你必须编写一个视图(view)声明这些方法,并定义这些方法的输出是如何映射到XML-RPC可理解的类型上的。

  • Developing new Skins - This chapter gives instructions on how to implement a new skin, so that sites can be developed that do not look like the Zope Management Interface, but still allows us to make use of all the auto-generation of forms.


开发新的皮肤 - 本章给出了如何实现一个新外观(skin)的步骤,这样就能开发此类站点:它们外观不象是Zope管理界面(Zope Management Interface),但仍允许我们利用表单的自动生成功能

Other Components(其他组件)

From the introduction chapters you know that content objects are not the only type of component you want to write. This section covers several of these various other components, such as utilities and resources.

  • Building and Storing Annotations (PDF) - Since it is desirable to leave an object as untouched as possible, we developed a mechanism for attaching meta data to an object without the object knowing about it.
  • New Principal-source plugins (PDF) - Many people have very different requirements on the mechanism an authentication service should function and Zope 3 respects this need. There exists an Authentication Service that accepts plugins to provide principal data from external data sources.
  • Principal Annotations (PDF) - A common task is to append data to principals. Since principals are often imported from external data sources, they are not attribute annotatable. This chapter will make use of the Principal Annotation service to store additional data.
  • New Resources (PDF) - This is a short chapter telling the reader how to implement a new file system based resource (a context independent view).
  • Registries with Global Utilities (PDF) - Utilties can be used to implement Zope-wide registries. Since registries are so very useful, this chapter is a must.
  • Local Utilities (PDF) - While we saw already how simple it is to write global utilities, there is some more work to do for local utilities, which will be introduced in this chapter.
  • Developing a Lucene-based Text Index - While there are many indices that will be shipped with Zope 3, it is sometimes necessary to write an index that makes use of external indexing software for example, such as Lucene or many other. This recipe will explain in detail on how to connect Lucene to Zope 3 as a full-text indexing engine.
    Note: This chapter will not be included in the first version of the book, since Zope X3 3.0.0 will not ship with index support and it has already been totally rewritten for 3.1.
  • Vocabularies and Related Fields/Widgets (PDF) - Vocabularies are a powerful extension to the schema framework and provide a generic method to create fields with variable and context dependent selection lists.
  • Exception Views (PDF) - For Zope 3, exceptions are simply objects, which can have views that make them representable on any output medium (usually the browser). Every exception has a standard view, but for a professional Web site you will need better screens.

Advanced Topics

Not everything you ever want to develop are components that you would allow the user to add and manipulate. This section contains a collection of chapters that deal mainly with the packages outside of zope.app. These packages are often useful outside of Zope 3 as well.

  • Writing new ZCML Directives (PDF) - Here we iscusses how new directives can be added to a ZCML namespace using meta-directives and/or how to create a new namespace from scratch.
  • Implementing a TALES Namespace (PDF) - In Zope 3, Zope Page Templates (TALES expressions) can contain namespaces to provide easier access to an object's data and meta-data. While Zope 3 provides a zope namespace, it is sometimes extremely helpful to develop your own to expose your product-specific API.
  • Changing Traversal Behavior (PDF) - Similar to Zope 2, one can change the traversal (lookup) behavior for an object, except that this functionality is much more flexible in Zope 3.
  • Registering new WebDAV Namespaces (PDF) - WebDAV? is allowed to store and request any namespace on any resource. However, we want to have some control over the namespaces and their values. This chapter explains how to bind Zope 3 attributes and annotations to WebDAV? namespaces.
  • Using TALES outside of Page Templates (PDF) - TALES is a powerful expression mechanism that certainly does not only find usage in Page Templates. This chapter tells you how to incorporate TALES into your own Python applications and scripts.
  • Developing a new TALES expression (PDF) - While TALES is powerful in itself, one can make it even more powerful by implementing custom expressions. The chapter will explain step by step how the sql expression was created.
  • Spacesuits -- Objects in Hostile Environements (PDF) - While the term "spacesuits" is not used in the Zope 3 terminology anymore, it best describes the approach of the new security model, which will be introduced in this chapter.
  • The life of a Request (PDF) - This chapter will show the request's exciting journey through the server, publisher and publication frameworks.

Writing Tests

Writing tests for every bit of functionality is of upmost importance in Zope 3. Testing can be done in many ways, from Java-like unit tests to pythonic Doc Testing.

  • Writing Basic Unit Tests (PDF) - This chapter shows you how to develop basic unit tests for your code and explains in detail how various pieces of functionality can be tested.
  • Doctests: Example-driven Unit Tests (PDF) - Sometimes regular unit tests are not as instructive to someone reviewing the code. In these cases it is shown how example-driven doctests can be useful.
  • Writing Functional Tests (PDF) - Unit tests are great for testing isolated components, but are impractical for testing entire sections of the system. For these type of tests we use a functional testing framework, which is introduced here in some detail.
  • Writing Function Doc Tests (PDF) - For the same reason doctests were developed to supercede unit tests, functional doctests are intended to be a more descriptive solution to develop functional tests.
  • Writing Tests Against Interfaces (PDF) - If an interface is commonly implemented multiple times, it is a good idea to write tests directly against the interface as a base for the implementation tests. This chapter will show you how to do that and expand on the motivation.

=

附录 

附录 A: 汇编

这本书的汇编. 不同于 Wiki 官方的汇编, 有着不同的观点. 暂且忽视现行的汇编或者汇编词汇, 本书将给您展现一个独特的观点.

附录 B: 鸣谢

这个小段落包含了一个所有贡献者的列表. 向他们每一个人献上我敬意.

Appendix C: Creative Commons License

This book is licensed under the Creative Commons Attribution-NoDerivs-NonCommercialLicense 1.0.

Appendix D: Zope Public License 2.1

The example code is maintained in the Zope CVS under the ZopePublicLicense.