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
《逍遥游(绘本版)》内容简介:《逍遥游》是战国时期哲学家、文学家庄子的代表作,无论在艺术上还是思想上均可视为《庄子》一书的
由塞贝尔编著的《实用CommonLisp编程》是一本不同寻常的CommonLisp入门书。《实用CommonLisp编程》首先从作者的学习经过及语言历
《Odoo快速入门与实战:Python开发ERP指南》内容简介:本书包括基础篇、研发技术篇和实战篇,按照由基础到进阶,再到实战的顺序讲解
《碳中和时代:未来40年财富大转移》内容简介:碳中和代表一个新时代的开始,在这个时代中,所有人的财富都将通过碳排放这个媒介进
笔记本电脑维修高级教程-芯片级 本书特色 《笔记本电脑维修高级教程(芯片级)》主要内容:笔记本电脑芯片级维修基础;笔记本电脑电路部分(保护隔离电路,3V、5V单...
《大众媒介研究导论》(第7版)是一本经典的媒介研究方法教材。两位作者都是资深的媒介研究者,维曼博士是一家市场研究公司的总裁和
《链接:社交时代的品牌法则》内容简介:社交时代,个体崛起,个体成为经济的基本单元,链接个体成社群是商业的核心逻辑。本书作者
《见字如来》内容简介:※ 张大春的字里人生,见字,如见故人来——“酒”字从酉,老而变化,却是青春里的落花一盅;“冰”字冷冽,
《智能机器时代》内容简介:身处AI(人工智能)世界,人类所有生活领域都面临着一场巨大变革。人工智能的未来发展将走向何处?我们
《深度学习:智能时代的核心驱动力量》内容简介:全球科技巨头纷纷拥抱深度学习,自动驾驶、AI医疗、语音识别、图像识别、智能翻译
《汉字的故事(中华文化故事)》内容简介:《汉字的故事》以生动活泼的笔调介绍了汉字的创制演变与造字方法,并精选出133个与日常生
《重复数据删除技术:面向大数据管理的缩减技术》内容简介:本书面向从事大数据存储系统设计及相关技术研究和开发工作的读者。既可
21天精通SEO-网站流量快速提升实战攻略-(附赠光盘) 本书特色 本书由22章组成,融入了系统学习seo的完整过程,内容共分为7篇,分别是seo**知识入门篇...
《推手》内容简介:王志纲二十年磨一剑的战略思路与实践,中国著名民间智库的思想和案例精华,政府及企业决策者、执行者必读!在中
《古画新品录》内容简介:《古画新品录:一部眼睛的历史》是艺术史学者黄小峰对中国古画的品读。作者选取了流传于世的35件国画作品
E.F.BensonsstrikinglyoriginalcomiccreationMissMappisanarch-schemerandsocialclimb...
《苍穹信步》内容简介:《漫步太空书系》是一套有关航天知识的系统科普教育丛书,尽量满足广大航天爱好者的求知需求,我们希望帮助
二级MS Office高级应用-2016年全国计算机等级考试无纸化真考套装三合一-(全二册)-赠428元等考大礼包 本书特色 本书严格依据*新颁布的《全国计算机...
《JSP设计》(第3版)自1999处JSP1.0发布以来,JavaServerPages(JSP)可谓掀起了一场风暴,其追随者蜂拥而至。JSP为企业Java开发...
《中国众筹行业发展研究(2019)》内容简介:众筹是一种创新模式,自2011年我国出现第一家众筹平台以来,中国众筹已发展了近十年。