CherryPy Essentials

Rapid Python Web Application Development Design, develop, test, and deploy your Python web applications easily Rapid Python Web Application Development Design, develop, test, and deploy your Python web applications easily Rapid Python Web Application Development All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations...

Installation from Subversion

Subversion is often viewed as the successor of CVS and is considered much friendlier. However, other revision systems also exist such as Monotone or Darcs. Under Linux, you can either install Subversion from its sources or using a package manager. Let's describe the procedure for the source code. 1. Get the latest tarball from http subversion.tigris.org 2. Then type the following command in the command console tar zxvf subversion-x.y.z.tar.gz 3. Enter the newly created directory and type ....

Installation through Easy Install

Easy_install is a Python module that can be found on the Python Enterprise Application Kit (PEAK) website to facilitate the deployment of Python packages and modules. From the developer's point of view, it provides an easy API to import Python modules either for a given version or a range of versions. For instance, here is what you would do to load the first CherryPy version greater than 2.2 found in your environment > > > from pkg_resources import require > > > require(cherrypy>...

Uniform Resource Identifier

REST is about naming resources on a network and providing a unified mechanism to perform operations on these resources. That's why REST tells us that a resource is identified by at least one identifier. When implementing a REST infrastructure based on the HTTP protocol, these identifiers are defined as Uniform Resource Identifiers (URIs). Two common subsets of the URI set are Uniform Resource Locator (URL), such as Uniform Resource Name (URN), such as The interesting aspect of URLs is that they...

Unit Testing Web Applications

In the previous section, we have presented two standard modules to perform unit testing in Python applications and packages. Unfortunately as they stand they lack some common features to help in specific contexts such as web applications. The Python community has obviously come up with solutions and there are several good extensions to unittest or completely distinct test packages to help us. We will use an extension to unittest, provided by CherryPy, called webtest and developed by Robert...

Error and Exception Handling

CherryPy tries hard to help the developer see a web application as close as a rich application. This means that from your page handler you may raise a Python error or exception as in any other Python application. CherryPy will catch those and transform them into HTTP messages depending on the type of errors. Note that when an exception is raised and not caught by any other part of the application, CherryPy will return the corresponding HTTP 500 error code. For example, the following example...

Hook into Cherry Pys Core Engine

Call Handling Process

One of the most powerful aspects of CherryPy is how its core lets you modify its normal behavior with a very fine granularity. Indeed, CherryPy offers a mechanism called hooking to customize the core engine. A hook is an entry point for Python callables to be applied at specific points during the request processing. CherryPy provides the following entry points Called at the beginning of the process. Called before CherryPy tries to read the request body. It allows a tool to inform CherryPy...

Application under Test

Before we explain how Selenium components work, we must introduce an application example. This application will simply provide one web page with two links. One of them will replace the current page with a new one. The second link will fetch data using Ajax. We use this example rather than our photoblog application for the sake of simplicity. The code of the application is as follows _header lt html gt lt head gt lt title gt Selenium test lt title gt lt head gt lt script type application...

Authentication using Digest or Basic Schemes

The open method of XMLHttpRequest can take username and password parameters to be sent along with the request. The authentication schemes supported by XMLHttpRequest are defined in RFC 2617, namely basic and digest. These two schemes are as follows Basic scheme The basic scheme is simply the transfer of the username and password encoded using the base64 algorithm. The issue with this is that, if a third-party fetches the encoded value, nothing can be done to prevent it from being decoded. This...