Python
  Home arrow Python arrow Page 2 - Karrigell for Python
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
Moblin 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PYTHON

Karrigell for Python
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 11
    2006-01-03

    Table of Contents:
  • Karrigell for Python
  • Scripts and Services
  • Being HIP
  • A Few More Features

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Karrigell for Python - Scripts and Services


    (Page 2 of 4 )

    The first two methods Karrigell presents to developers are scripts and services. A script is simply a Python script that uses print to output to the user's browser. If you haven't done so already, create a testarea directory, and we can begin our first script. Create the file test.py:

    print "<center>"
    print "Hello!"
    print "<br /><br />"
    print "Karrigell is configured and working."
    print "</center>"

    Point your browser to the file, and if you have Karrigell set up as described above, you should see the message described above.

    Form data is fairly easy to handle with Python scripts. Let's create a simple script whose output differs depending on whether the user has specified his or her name in a form. Name it askName.py:

    if QUERY.has_key ( "name" ):
       print "Your name is", _name + "."
    else:
       print "What is your name?<br />"
       print "<form>"
       print "<input type='text' name='name' /><br />"
       print "<input type='submit' value='Proceed' />"
       print "</form>"

    Services are written like Python scripts, too. However, they are designed to map requests to functions defined by the user. The desired function is passed along in the URL after the name of the service. For example, the following URL would call the test function of the service test.ks:

    http://localhost/testarea/test.ks/test

    Let's actually create the test.ks service:

    def index():
       print "Index function."
    def test():
       print "Test function."

    If you call the script without passing a function name, then you will be redirected to the index function. If you call the script passing the test function name, then the test function will be executed. Attempting to call a function not defined will produce an error.

    Configuring services to accept form data is quite easy. Let's recreate askName.py as the service askName.ks:

    def index():
       print "What is your name?<br />"
       print "<form action='nameSubmit'>"
       print "<input type='text' name='name' /><br />"
       print "<input type='submit' value='Proceed' />"
       print "</form>"
    def nameSubmit ( name ):
       print "Your name is", name + "."

    Of course, making every single one of your service's functions accessible to the outside world could be a security hazard. To prevent users from accessing certain functions, simply prefix them with an underscore:

    def _private():
       pass

    Attempting to access the _private function will result in an error message.

    More Python Articles
    More By Peyton McCullough


       · Hello, all.Karrigell definitely isn't the most popular Python framework out...
       · I figure for heavy lifting we have either TurboGears, or CherryPy(unadorned)....
     

       

    PYTHON ARTICLES

    - SSH with Twisted
    - Mobile Programming in Python using PyS60: UI...
    - Python: Count on It
    - Python Strings: Spinning Yarns
    - Python: More Fun with Strings
    - Python: Stringing You Along
    - Python Operators
    - Bluetooth Programming in Python: Network Pro...
    - Python Sets
    - Python Conditionals, Lists, Dictionaries, an...
    - Python: Input and Variables
    - Introduction to Python Programming
    - Mobile Programming in Python using PyS60: Ge...
    - Bluetooth Programming using Python
    - Finishing the PyMailGUI Client: User Help To...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway