This book covers the CherryPy library for Python web development from its history and installation through its main features and core concepts to its integration with Python and other products to construct, test, and deploy a sample photoblog application. The author Sylvain Hellegouarch is dedicated to the development of free software projects and has been coordinating and administrating the community efforts around the CherryPy project since 2004. The approach based on an example application introduces many other common Python libraries, providing transferable skills also relevant for non-web Python projects. CherryPy is a Python library for web development that allows developers to build web applications in the same way as any other object-oriented Python program. Enriched by several years of active development, it has become one of the most established toolkits for building solid and high-performance web applications in Python. CherryPy abstracts the complex low-level HTTP protocol into an easy-to-use interface that respects Python idioms. The library aims at being simple to learn for a beginner while offering the most advanced features to fluent Python developers. For these reasons CherryPy was chosen to be at the heart of the popular and feature-rich TurboGears web framework. CherryPy-powered web applications are stand-alone Python applications with their own embedded multi-threaded web server, but can also run behind Apache or IIS for scalability. . CherryPy installation using tarball, egg, and subversion . The CherryPy library in depth: its design and how to use it . Using CherryPy with common Python and non-Python products . Object Relational Mapping with SQLObject, SQLAlchemy, and Dejavu . Web Services via REST and the Atom Publishing Protocol . AJAX and client-side scripting via MochiKit . Unit, functional, and load testing . CherryPy, Apache, and lighttpd deployment solurions The book starts with two chapters dedicated to CherryPy itself, its history and installation. Then it moves through a gentle introduction to the main features and concepts of CherryPy to a thorough review of its core capabilities. After laying this foundation the book dives into a real-world example, detailing important steps in the creation of a photoblog application. These chapters cover database manipulation via Object Relational Mapping (ORM), using web services to enhance the application, and client-side scripting through AJAX. Finally, the book covers the need for unit, functional, and performance testing before closing with deployment solutions for a CherryPy-based application. Who this book is written for This book is principally geared towards Python web developers, who are looking to add the power of the CherryPy library to their existing Python skillset. It assumes a good working knowledge of Python . Although the CherryPy toolkit is at the core of the book, many other common libraries are introduced. TABLE OF CONTENTS SUMMARY 1.Introduction to CherryPy 2.Download and Install CherryPy 3.Overview of CherryPy 4.CherryPy in depth 5.A photoblog application 6.Web Services 7.The presentation layer 8.Ajax 9.Testing 10.Deployment
Preface 1
Chapter 1: Introduction to CherryPy 7
Overview 7
History of CherryPy 8
The Community 9
CherryPy Project Strengths 10
Beyond CherryPy 11
Through the Book 11
Summary 12
Chapter 2: Download and Install CherryPy 13
Requirements 13
Overview 14
Installation from a Tarball 16
Installation through Easy Install 18
Installation from Subversion 20
Testing your Installation 23
Keeping CherryPy Up to Date 23
Summary 24
Chapter 3: Overview of CherryPy 25
Vocabulary 25
Basic Example 26
Built-In HTTP Server 32
Internal Engine 32
Configuration 33
Object Publisher Engine 36
Library 38
The Autoreload Feature 39
The Caching Module 39
Table of Contents
[ ii ]
The Coverage Module 39
The Encoding/Decoding Module 40
The HTTP Module 40
The Httpauth Module 40
The Profiler Module 40
The Sessions Module 41
The Static Module 42
The Tidy Module 42
The Wsgiapp Module 42
The XML-RPC Module 42
Tools 43
Error and Exception Handling 44
Summary 49
Chapter 4: CherryPy in Depth 51
HTTP Compliance 51
Multiple HTTP Servers 52
Multi-Threaded Application Server 54
URI Dispatching 55
HTTP Method Dispatcher 55
Routes Dispatcher 57
Virtual Host Dispatcher 58
Hook into CherryPy's Core Engine 59
CherryPy Toolbox 61
Basic Authentication Tool 62
Caching Tool 63
Decoding Tool 64
Digest Authentication Tool 65
Encode Tool 66
Error Redirect Tool 67
Etag Tool 67
Gzip Tool 69
Ignore Headers Tool 69
Log Headers Tool 70
Log Tracebacks Tool 71
Proxy Tool 72
Referer Tool 73
Response Headers Tool 74
Trailing Slash Tool 75
XML-RPC Tool 76
Toolbox 77
Creating a Tool 77
Table of Contents
[ iii ]
Static Resource Serving 81
Using the Staticfile Tool to Serve a Single File 81
Using the Staticdir Tool to Serve a Complete Directory 83
Bypassing Static Tools to Serve Static Content 85
WSGI Support 86
Hosting a WSGI Application within the CherryPy WSGI Server 87
Hosting a CherryPy WSGI Application within a
Third-Party WSGI Server 89
Summary 90
Chapter 5: A Photoblog Application 91
A Photoblog Application 91
Photoblog Entities 92
Vocabulary 94
DBMSes Overview 95
Relational Database Management System (RDBMS) 95
Object-Oriented Database Management System (OODBMS) 96
XML Database Management System (XMLDBMS) 97
Object-Relational Mapping 97
Python Object-Relational Mappers 98
Photoblog Application Entity Modeling 108
Mapping Entities 109
Units and UnitProperties 111
Associating Units 112
The Sandbox Interface 112
Querying Units 113
Extending the Data Access Layer 114
Summary 117
Chapter 6: Web Services 119
Traditional Web Development 119
Separation of Concerns 121
REST 122
Uniform Resource Identifier 123
HTTP Methods 124
Putting it Together 128
REST Interface through CherryPy 130
Atom Publishing Protocol 131
Atom XML-Document Format 132
APP Implementation 134
Summary 136
Table of Contents
[ iv ]
Chapter 7: The Presentation Layer 137
HTML 137
XML 138
XHTML 138
CSS 139
DHTML 141
Templating 142
Kid—The Templating Engine 142
Overview 142
Kid's Attributes 144
XML-Based Templating Language 144
Variable Substitution 144
Conditional Statement 144
Looping Mechanism 145
Extensibility 146
Other Attributes 147
Photoblog Design Preparation 147
Targetting the User Agent 147
Tools 148
Global Design Goals 148
Design Directory Layout 149
CherryPy—Encapsulating the Template Rendering Process 149
Photoblog Design in Detail 151
Basic Structure 151
Mochikit 156
Developing the Photoblog Design 157
HTML Code 157
Adding a Link 158
Handling the End-User Actions 158
Amending the Template 159
Amending the CSS 159
Let's be More Flexible... 160
Summary 161
Chapter 8: Ajax 163
Rise of the Rich-Client Applications 163
Ajax 164
Ajax—Advantages and Drawbacks 165
Behind the Scene: XMLHttpRequest 166
Performing a GET Request 167
Performing a Content-Negotiated GET Request 168
Performing a POST Request 169
Performing PUT, HEAD, or DELETE Requests 170
Table of Contents
Cookies 170
Authentication using Digest or Basic Schemes 170
JSON 176
Applying Ajax to our Application 178
Defining the Required Namespaces 178
Implementing Namespaces 179
Adding Methods to the Classes 179
Method to Create a New Album 183
Method to Update an Existing Album 190
Method to Delete an Existing Album 190
Summary 191
Chapter 9: Testing 193
Why Testing 193
Planning a Test 194
Common Testing Approach 195
Unit Testing 195
unittest 196
doctest 201
Unit Testing Web Applications 205
Performance and Load Testing 213
Functional Testing 218
Application under Test 219
Selenium Core 222
Selenium IDE 227
Selenium Remote Control 231
Summary 233
Chapter 10: Deployment 235
Configuration 235
CherryPy—Web and Engine Configuration System 235
Photoblog Application Configuration System 238
Deployment 240
Apache with mod_rewrite Module 241
Lighttpd with mod_proxy Module 243
Apache with mod_python Module 244
mod_python with WSGI Application 246
SSL 246
Creating a Certificate and a Private Key 247
Using the CherryPy SSL Support 248
Using the lighttpd SSL Support 250
Using the Apache mod_ssl Support 251
Summary 251
Index 253
本书是《俄罗斯航空发动机制造史》丛书的下册,涵盖了以M.B.伏龙芝命名的第24号工厂——库兹涅佐夫开放式股份公司的创立和发展历
网络文化与虚拟社会管理 内容简介 近年来,网络文化对公众社会实践活动的影响呈现出明显增强的态势,虚拟空问中的许多社会现象、网络言行均与此相关,已经成为虚拟社会管...
《美的找寻者:汝信传》内容简介:汝信为江苏吴江人,他14岁走进大学校门,17岁加入中共地下党,18岁参加人民解放军,在朝鲜战场的
《威柄在御》内容简介:“大礼议”之争、追尊生父并为之立庙,是嘉靖帝“天性至情、君亲大义”,还是“醉翁之意不在酒”?李福达狱
《外语能力标准的国别研究:加拿大与英国》内容简介:本书主要研究了英国和加拿大的语言能力标准。加拿大篇从语言能力标准的概述、
BookDescriptionUbiquitouscomputing--almostimperceptible,buteverywherearoundus--i...
《叶秀山全集·第六卷》内容简介:本选题分类结集叶秀山先生全部已经出版的专著,在学术期刊上发表的所有论文,以及部分笔记、札记
《漫画流体力学》以轻松有趣、通俗易懂的漫画及故事的方式将抽象、复杂的流体力学知识融会其中,让人们在看故事的过程中就能完成
《古城卫士:阮仪三传》内容简介:沧桑平遥、风情丽江、烟雨周庄、古雅苏州、水墨乌镇……都是因为一位老人的守护,其最初样貌与生
《把孩子交给爸爸》内容简介:在当下家庭教育中,普遍存在父亲教育缺失或不足的现象,本书作者作为一个相当称职的爸爸,给千万个家
《C++GUIQt4编程》(第2版)详细讲述了用最新的Qt版本进行图形用户界面应用程序开发的各个方面。前5章主要涉及Qt基础知识,后两个部
SEO实战密码-60天网站流量提高20倍-第3版 本书特色 本书是畅销书升级版,详细和系统地介绍了正规、有效的seo实战技术,包括为什么要做seo、搜索引擎工作...
新编中文版AutoCAD 2008入门与提高 本书特色 精选常用软件,紧跟版本更新,连续推出配套图书通俗易懂,简洁实用,由“入门”起步,注重“提高”,使新手老手...
《土地制度、结构转型与经济发展》内容简介:本书内容主要分五个部分:部分是制度背景与分析框架,包括第1-2章,梳理土地制度、结构
Youdontneedprogrammingexperiencetoaddinteractiveandvisualeffectstoyourwebpageswi...
《动物们的生存艺术》内容简介:本书是“德浩谢尔动物与人书系”(全套7本)之一。“德浩谢尔动物与人书系”是德国家喻户晓的动物学
《数字信号处理:使用MATLAB》系Brooks/Cole出版公司(ThomsonLearning出版集团的下属子公司)2000年推出的BookWare系列丛书...
JavaScript曾是“世界上最被误解的语言”,因为它担负太多的特性,包括糟糕的交互和失败的设计,但随着Ajax的到来,JavaScript“
《高配人生的7个法则》内容简介:本书是一本倡导“她力量”的女性成长励志书籍。作者邵英是一名成功的女性互联网创业者,书中作者详
《睹物》内容简介:本书将文明的传承形式——历史学、文学和视觉艺术作为研究对象,通过对大家耳熟能详的艺术文学作品进行耳目一新