1.0 Quick Start
Before using twisted for development, you should download and install it. This chapter describes the installation process in various operating systems. It also includes adding the twisted utility to the path and getting familiar with the documentation. For other questions, go to the twisted community.
--------------------------------
1.1 install twisted
Download twisted for installation. You can download it at http://twistedmatrix.com/projects/core. (By gashero) two other optional software packages can be installed to install additional properties.
1.1.1 what should I do next?
Download the latest version of twisted to the http://twistedmatrix.com. Then install pyopenssl (a python open-source OpenSSL Library), which is used to provide twisted with encrypted transmission support (SSL ). Finally, install pycrypto, a package containing the python security algorithm, to provide SSH support. The software packages are specified in the subsequent sections.
To use twisted, you do not have to install pyopenssl and pycrypto. If you do not install these functions, you will not be able to use the SSL and SSH functions of twisted. Other functions are still available.
1.1.1.1 windows
Go to http://twistedmatrix.com/projects/core/download the Windows version python2.4installation package. This binary package contains the core features of twisted, including a large number of extension packages and protocol support. To install more examples, go to http://twistedmatrix.com/products/downloadto download "Twisted dependencies for Windows ". The installation package includes pyopenssl and pycrypto.
These pages may have been moved to other pages and some new features have been added. If you cannot find these connections, you can try to access them from the http://twistedmatrix.com.
If you download these three packages at a time, run the twisted installer. This is a small installation package, which can automatically detect the python installation path. Next, run the pyopenssl and pycrypto installation packages. These are simple, and they only take a few seconds.
It may take some time to compile the twisted module. The progress bar displays the current status. Unpacking also takes several minutes.
To verify the installation is to import the twisted package.
$ Python
......
>>> Import twisted
>>>
If "Import twisted" is successfully executed without errors, twisted has been installed.
1.1.1.2 Mac OS X, Linux, and BSD
Many Linux and BSD releases, including Debian, Ubuntu, Gentoo, Red Hat, And FreeBSD, have pre-installed twisted, and pyopenssl and pycrypto are also available. You can check whether your OS is mentioned on the twisted download page or search for the installation package history. If the version is already installed, make sure that the version is twisted 2.0 or later, instead of the release version of 1.3.
If twisted is not pre-installed, download the source code to install it.
--------------------------------
1.2 install from source code
If twisted is not pre-installed on your operating system, you need to install it from the source code. Don't worry, it's easy to install python from the source code.
1.2.1 What to Do below
First, download the complete twisted source code package. (By gashero) packages can provide more twisted functions. Most examples of running this book require complete installation. Once the software package is downloaded, decompress it to the working directory.
$ Tar-xjvf ~ /Downloads/TwistedSumo-2005-03-22.tar.bz2
Next, go to the extracted directory. Twisted depends on the Zope. Interface package, which is included in the twisted sumo release package. Decompress the zopeinterface package:
$ Tar-xzvf ZopeInterface-3.0.1.tgz
Go to the zopeinterface directory and run "Python setup. py install ". This command will build and install the Zope. Interface package to the LIB/Site-packages/twisted directory in the python installation directory. Administrator/root permissions are required. Therefore, Su or sudo is used to increase the permission level.
$ ZopeInterface-3.0.1 CD
$ Python setup. py install
Once Zope. interface is installed, twisted can be installed. Run "Python setup. py install" in the twisted directory ". This command will compile the twisted C Module and install twisted:
$ TwistedSumo-2005-03-22 CD
$ Python setup. py install
If you have installed multiple versions of Python, make sure that twisted is installed on the version corresponding to the python command you are running. The example of the book can run in Python 2.3 or later. Check whether your Python version is "Python-V ".
Congratulations, you have successfully installed twisted. Run the python prompt to test whether the installation is successful:
$ Python
>>> Import twisted
>>>
If the "Import twisted" statement is successfully executed, the twisted installation is successful.
Next, download pyopenssl (http://pyopenssl.sourceforge.net), the latest version ). Pyopenssl runs on the OpenSSL library, so you need to ensure that OpenSSL has been installed. Mac OS X has been installed with OpenSSL by default and contains header files. Most releases of Linux and BSD also include these files by default.
If you happen to have a default release without an OpenSSL library installed, You need to download and install the source package from here (http://www.openssl.org ).
To install pyopenssl, follow these steps. First extract the downloaded file:
$ Tar-zxvf PyOpenSSL-0.6.tar.gz
Then, select the pyopenssl library and run "Python setup. py install" to use the root user.
$ PyOpenSSL-0.6 CD
$ Python setup. py install
After the installation is complete, make sure that the OpenSSL package is available. You can use import to test the package:
$ Python
>>> Import OpenSSL
>>> Import twisted. Internet. SSL
>>> Twisted. Internet. SSL. SSL
<Module 'openssl. SSL 'from
'...'>
If no error is displayed, SSL support is successfully installed for twisted.
The last package to be installed is pycrypto. Pycrypto is a python encryption tool set. It is a package developed by a.m. kuchling and contains many encryption algorithm implementations. Twisted uses pycrypto to support SSH connections.
Download from (http://www.amk.ca/python/code/crypto.html) and unzip:
$ Tar-xzvf pycrypto-2.0.tar.gz
Run the familiar "Python setup. py install" to install it, in the pycrypto directory.
$ Pycrypto-2.0 CD
$ Python setup. py install
Make sure that the package is successfully installed. You can use import to test the package. You can test the twisted. Conch. Ssh. transport module by using the RSA implementation of pycrypto:
$ Python
>>> Import crypto
>>> Import twisted. Conch. Ssh. Transport
>>> Twisted. Conch. Ssh. Transport. RSA
<Module 'crypto. publickey. RSA 'from
'...'>
If it is shown above, you have successfully installed pycrypto. At this point, you can use twisted and use SSL and SSH functions.
--------------------------------
1.3 Add the twisted utility to path parameters
Twisted contains some utility scripts. For ease of use, you should add them to a location that can be found in path.
1.3.1 what to do below
Generally, all paths added to the path can be found by the OS. Follow these steps.
1.3.1.1 windows
Twisted tools will be installed in the scripts directory of Python (typical: C:/python23/scripts ). Twisted contains some menu setup programs. You can use programs-> twisted command prompt. . You can use the prompt mode to run the utility, and the path has been set automatically.
1.3.1.2 Linux
Twisted tools will be installed in the same folder (possibly/usr/bin or/usr/local/bin) in the python binary directory, so you need to add this path to the path.
1.3.1.3 Mac OS X
If you are using Mac OS X 2.3 (jaruar) or an updated version, twisted is installed in (/system/library/frameworks/python. Framework/versions/current/bin by default. Add this path to the PATH variable.
$ Set Path = $ path:/system/library/frameworks/python. Framework/versions/current/bin
--------------------------------
1.4 twisted document
Twisted contains different types of documents, including extended API documents, howto documents, Quick Start and example programs. We recommend that you familiarize yourself with these documents as soon as possible and provide help during the development process.
1.4.1 what to do below
Twisted documents are viewed online on the website. A complete API documentation in (http://twistedmatrix.com/documents/current/api ). For programming, you need to use this document multiple times. This API document is automatically generated by the code. The tool used is a twisted component called lore.
Twisted consists of several subprojects, each of which contains its own documents. For example, the core module documentation is in (http://twistedmatrix.com/projects/core/documentation), while the documentation about the web module is in (http://twistedmatrix.com/projects/web/documentation ). There is a link on the home page to access each sub-project.
Each sub-project contains the following types of documents:
· Howtos
Describes special features and how to use these features. (By gashero) does not cover all but provides a quick start to a specific task. The Quick Start (Tutorial) included in howtos is called "Twisted from scratch". It explains how to develop an application and how to expand it to some advanced content.
· Examples
The brief and special twisted code is a bit like howtos, but it can be used to provide effective help for specific functions.
· Manual pages
This is an html version of manpages, which describes how to use the twisted utility.
1.4.2 about
If you want to browse documents without using a browser, you can directly use the pydoc tool. Pydoc does not display all the marks in the twisted document. It is still useful. Figure 1-1 shows the information about twisted. Web. HTTP in pydoc.
Of course, if you really want to understand the work of twisted, you can read the source code of twisted. Some modules use the C language for performance purposes. In addition, you can view them in the site-packages/twisted directory. Or open the appropriate. py file.
--------------------------------
1.5 find answers to your questions
Most questions can be answered by yourself in the document or from the community.
1.5.1 what to do below
There are some useful community resources to help. The first is the mail list. The "Twisted-Python" list is generally discussed. The "Twisted-web" list provides a discussion of Web applications. If the problem is raised incorrectly, it will be automatically transferred to another discussion group. You can apply for a discussion group at the following address:
Http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
Second, you can discuss the issue (http://freenode.net) in the # twisted and # twisted. Web IRC channels ). These channels are always open and interesting, so you can get answers to your questions in a timely manner. If you do not need to get a response in time, it is best to go to the email list for discussion. This method provides more extensive attention and can be shared by more people.
The final available resource is the planet twisted community. Address in http://planet.twistedmatrix.com, this site's weblog provides a lot of knowledge. This is a good way to get knowledge. It also provides the RSS subscription method http://planet.twistedmatrix.com/rss.xml.