Installing from Source Files

If you're on an operating system for which no Twisted binary packages are available, you'll need to install from source. Don't worry, though; as source installs go, Python packages are among the easiest you'll find.

1.2.1. How Do I Do That?

First, download the full "Sumo" source package for Twisted (choosing the version with documentation) from http://twistedmatrix.com/projects/core/. The Sumo package is the core of Twisted, plus a number of bundled modules from other projects developed under the Twisted umbrella; you'll need the modules in the Sumo package to run most of the examples in this book. Once you've downloaded the package, extract it to a working directory:


 $ tar -xjvf ~/downloads/TwistedSumo-2005-03-22.tar.bz2

 TwistedSumo-2005-03-22/

 TwistedSumo-2005-03-22/bin/

 ...

 TwistedSumo-2005-03-22/README

 TwistedSumo-2005-03-22/LICENSE

 TwistedSumo-2005-03-22/setup.py

 TwistedSumo-2005-03-22/ZopeInterface-3.0.1.tgz

Next, enter the TwistedSumo-version directory. Twisted depends on the zope.interface package, which is bundled in the Twisted Sumo distribution. Unzip the ZopeInterface tarball:


 $ tar -xzvf ZopeInterface-3.0.1.tgz

 ZopeInterface-3.0.1/

 ZopeInterface-3.0.1/Support/

 ZopeInterface-3.0.1/Support/zpkgsetup/

 ZopeInterface-3.0.1/Support/zpkgsetup/publication.py

 ...

 ZopeInterface-3.0.1/setup.py

 ZopeInterface-3.0.1/setup.cfg

 ZopeInterface-3.0.1/MANIFEST

Enter the ZopeInterface- directory, and run the command python setup.py install. This command will build and install the zope.interface package in your python installation's lib/site-packages/twisted directory. You'll need to have administrative/root permissions to do this, so use su or sudo to increase your permission level if necessary:


 $ cd ZopeInterface-3.0.1

 $ python setup.py install

 running install

 running build

 running build_py

 running build_ext

 building 'zope.interface._zope_interface_coptimizations' extension

 ...

 running install_lib

 copying build/lib.linux-i686-2.4/zope/interface/_zope_interface_coptimizations.so ->

 /usr/lib/python2.4/site-packages/zope/interface

 writing byte-compilation script '/tmp/tmpdY9dA9.py'

 /usr/bin/python -O /tmp/tmpdY9dA9.py

 removing /tmp/tmpdY9dA9.py

Once zope.interface is installed, you're ready to install Twisted. In this TwistedSumo- directory, run the command python setup.py install. The command will compile the Twisted C modules and install Twisted:


 $ cd TwistedSumo-2005-03-22

 $ python setup.py install

 Password:

 running install

 running build

 running build_py

 ...

 running install_data

If you have more than one version of Python installed, keep in mind that Twisted will be installed for only the version of Python you're using when you run setup.py. The examples in this book require Python 2.3 or higher. To check your Python version, run python -V.

Congratulationsyou've installed Twisted! You can make sure the installation worked by importing the Twisted package from an interactive Python prompt:


 $ python

 Python 2.3 (#1, Sep 13 2003, 00:49:11)

 [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin

 Type "help", "copyright", "credits" or "license" for more information.

 >>> import twisted

 >>>

If the import twisted statement runs with no errors, you have a working Twisted install.

Next, download the latest release of PyOpenSSL from http://pyopenssl.sourceforge.net. PyOpenSSL works on top of the OpenSSL library, so you'll need to make sure you have OpenSSL installed first. Mac OS X comes with OpenSSL installed, along with its header files, and all Linux and BSD distributions should have a package available (if not installed by default).

If you're using a really obscure operating system that doesn't include OpenSSL, you can download and compile the source package from http://www.openssl.org.

To install PyOpenSSL, follow the same steps you did when installing Twisted. First, extract the contents of the downloaded file:


 $ tar -zxvf pyOpenSSL-0.6.tar.gz

 pyOpenSSL-0.6/

 pyOpenSSL-0.6/doc/

 pyOpenSSL-0.6/doc/html/

 ...

 pyOpenSSL-0.6/_ _init_ _.py

 pyOpenSSL-0.6/ChangeLog

 pyOpenSSL-0.6/COPYING

 pyOpenSSL-0.6/version.py

Next, switch to the PyOpenSSL directory and run python setup.py install as root or an administrative user:


 $ cd pyOpenSSL-0.6

 $ python setup.py install

 running install

 running build

 running build_py

 creating build

 ...

 byte-compiling

 /System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/

 OpenSSL/__init__.py to _ _init_ _.pyc

 byte-compiling

 /System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/

 OpenSSL/version.py to version.pyc

When the installation is complete, test to confirm that the OpenSSL package is now available, and that Twisted is making use of it in its internet.ssl module:


 $ python

 Python 2.3 (#1, Sep 13 2003, 00:49:11)

 [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin

 Type "help", "copyright", "credits" or "license" for more information.

 >>> import OpenSSL

 >>> import twisted.internet.ssl

 >>> twisted.internet.ssl.SSL

 

If you don't see any errors, you've successfully added SSL support to your Twisted installation.

The final package to install is PyCrypto. PyCrypto, the Python Cryptography Toolkit, is a package developed by A. M. Kuchling that contains implementations of many cryptographic functions. Twisted uses PyCrypto to support SSH connections.

Start by downloading PyCrypto from http://www.amk.ca/python/code/crypto.html. Then extract the package:


 $ tar -xzvf pycrypto-2.0.tar.gz

 pycrypto-2.0/

 pycrypto-2.0/_ _init_ _.py

 pycrypto-2.0/ACKS

 pycrypto-2.0/ChangeLog

 ...

 pycrypto-2.0/Util/test/prime_speed.py

 pycrypto-2.0/Util/test.py

Run the now-familiar python setup.py install (as root or an administrative user) in the PyCrypto directory:


 $ cd pycrypto-2.0

 $ python setup.py install

 running install

 running build

 running build_py

 creating build

 ...

 byte-compiling

 /System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/

 Crypto/Util/RFC1751.py to RFC1751.pyc

 byte-compiling

 /System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/

 Crypto/Util/test.py to test.pyc

To verify that the package installed correctly, import it from an interactive Python prompt. You can also make sure Twisted's twisted.conch.ssh.transport module is now using PyCrypto's RSA implementation:


 $ python

 Python 2.3 (#1, Sep 13 2003, 00:49:11)

 [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin

 Type "help", "copyright", "credits" or "license" for more information.

 >>> import Crypto

 >>> import twisted.conch.ssh.transport

 >>> twisted.conch.ssh.transport.RSA

 

And that's it! You've installed PyCrypto from source. At this point you have a complete, working Twisted installation, including support for SSL and SSH connections.

Getting Started

Building Simple Clients and Servers

Web Clients

Web Servers

Web Services and RPC

Authentication

Mail Clients

Mail Servers

NNTP Clients and Servers

SSH

Services, Processes, and Logging



Twisted Network Programming Essentials
Twisted Network Programming Essentials
ISBN: 0596100329
EAN: 2147483647
Year: 2004
Pages: 107
Authors: Abe Fettig

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net