<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Cehaith2</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Cehaith2"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Cehaith2"/>
	<updated>2026-05-10T19:49:53Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_S1454_ccc&amp;diff=90371</id>
		<title>CSC/ECE 517 Fall 2014/OSS S1454 ccc</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_S1454_ccc&amp;diff=90371"/>
		<updated>2014-10-29T03:34:01Z</updated>

		<summary type="html">&lt;p&gt;Cehaith2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Sahana Eden: Extract The Progress Details = &lt;br /&gt;
== Introduction to Sahana Eden ==&lt;br /&gt;
Sahana is a software foundation with the express intent of “saving lives by providing information management solutions that enable organizations and communities to better prepare for and respond to disasters.” [http://sahanafoundation.org/about-us/] This is achieved&lt;br /&gt;
by developing free and open source software to make disaster response coordination more efficient. Eden (or Emergency Development ENvironment for Rapid Deployment Humanitarian Response Management), one of their main products is a feature-rich and rapidly customizable humanitarian platform that allows its modules to be specialized for particular organizations and management needs. Eden has been used to help address the wildfires in Chile, earthquakes and tsunamis in Japan, flooding in Colombia, flooding in Venezuela, flooding in Pakistan, and hurricane in Veracruz, Mexico [http://sahanafoundation.org/products/eden/]. The idea is to&lt;br /&gt;
mix and match several modules that Eden has to best suit the needs and context of an organization. The main modules are an Organization Registry, which can create databases of organizations to help facilitate coordination; Project Tracking, which tells who is doing what where and when and can tell who is working on similar projects to help facilitate collaboration; Human Resources, a tool that helps track and manage the people involved including what skills those people have; Inventory Management, which allows for recording and automating shipments and deliveries of supplies; Asset Management, which helps facilitate management of assets like vehicles, communication equipment, and generators as well as tell to whom each are assigned; Assessments, which can be used to collect and analyze information; Shelter Management, which helps facilitate the management of temporary shelters including required resources, staff and volunteer assignments, and check-in/check-out systems; Scenario and Event planning, which helps facilitate planning for various emergency scenarios; Mapping, which enables location-based visualization on maps; and Messaging, which facilitates communications over various protocol and social media mediums. Eden’s WebSetup is the tool that facilitates the setup process of a new Eden tool. The process of setting up a new Eden project entails many moving parts, so detecting bugs and troubleshooting issues in the process can be tricky. A developer created a New Enhancement ticket that requested work on being able to extract the progress details of the setup into a single local file, not dissimilar to a log file. [http://eden.sahanafoundation.org/ticket/1468]&lt;br /&gt;
== Web2Py Tasks and Task Scheduler ==&lt;br /&gt;
Sahana Eden uses the Web2Py; an application development framework written in Python that uses a typical MVC pattern. In order to best manage work on large and complicated functionality in the background, Web2Py implemented a scheduler that allows control over processes. A task is a function defined in a model:&lt;br /&gt;
&lt;br /&gt;
 def task_getParity(i):&lt;br /&gt;
     if i % 2 == 0:&lt;br /&gt;
         return “even”&lt;br /&gt;
     return “odd”&lt;br /&gt;
===== Queuing Tasks =====&lt;br /&gt;
Tasks can then be queued up with additional meta-parameters for running the function, such as when the task should die, how long can the process run until timeout occurs, how many times to repeat the function, what parameters to send to the task (if applicable), et cetera.&lt;br /&gt;
 scheduler.queue_task(‘task_getParity’, [8], …)&lt;br /&gt;
===== Scheduler Creation =====&lt;br /&gt;
The scheduler is the manager for the tasks and workers. Creating a scheduler requires a database at the least in order to store the states of tasks. However, the scheduler can be instantiated with additional parameters that allow specifications for the time between each check of the queue, specific names of functions to queue, the amount of times the queue is checked before a worker must be terminated, et cetera.&lt;br /&gt;
 from gluon.scheduler import Scheduler&lt;br /&gt;
 scheduler = Scheduler(database [,…])&lt;br /&gt;
===== Task Lifecycle [http://www.web2py.com/books/default/chapter/29/04/the-core#web2py-Scheduler] =====&lt;br /&gt;
&lt;br /&gt;
Similar to Java threads and Linux processes, a Web2Py process (interchangeable at this point with task) lifecycle is as follows:&lt;br /&gt;
* '''Queued''' a task is queued to be picked up by a worker.&lt;br /&gt;
* '''Expired''' the task died in the queue (the amount of time designated to cause the task to die has passed).&lt;br /&gt;
* '''Assigned''' a worker is assigned to this task.&lt;br /&gt;
* '''Running''' the task is being carried out.&lt;br /&gt;
* '''Timeout''' the task timed out (the amount of time designated to case the task to timeout during processing has passed).&lt;br /&gt;
* '''Failed''' an error was detected or an exception was thrown.&lt;br /&gt;
* '''Completed''' the task finished correctly.&lt;br /&gt;
===== Worker Management =====&lt;br /&gt;
Also similar to Linux is the ability to control the workers (processes in Linux are manageable via jobs, synonymous with workers managing Web2Py tasks). Workers can be controlled with the following functions:&lt;br /&gt;
 disable()   # Put the worker to sleep&lt;br /&gt;
 terminate() # The worker dies gracefully as soon as possible&lt;br /&gt;
 kill()      # The worker dies immediately&lt;br /&gt;
== Sahana Eden-specific Tasks ==&lt;br /&gt;
The Sahana Eden developers created a wrapper class for the Web2Py tasks. The wrapper, s3task.py, is a very “thin” and adds only minimal functionality to the Web2Py tasks.&lt;br /&gt;
Specifically, it allows a task to be run asynchronously, the database to handle CRUD actions including setting defaults and hiding unnecessary fields, duplicate task checking, determination&lt;br /&gt;
of whether or not at least one worker is alive, and requeueing failed tasks. At the request of the mentors for this ticket, the functionality was generalized to all processes. Due to limitations of reporting the details of the progress of tasks, the logging is based on the status available via the scheduler. Explicit logging of steps would need to be on a per function basis, with each function logging their own progress.&lt;br /&gt;
&lt;br /&gt;
The functionality of logging was added to the s3task.py and a timer was added to the s3utils.py file. If report_progress was set to true when scheduling a new task (default is false), then a logfile is created whose name contains the date and time the task was started and the task name. A timer is created. While this timer is running, it will check the status of the task and log the status of the task to the log file. The default is currently to log every second for ten seconds.&lt;br /&gt;
===== The Repeated Timer =====&lt;br /&gt;
 class RepeatedTimer(object):&lt;br /&gt;
     # Create a timer and start a timer. Any additional arguments are&lt;br /&gt;
     # passed to the task for the tasks to handle&lt;br /&gt;
     def __init__(self, interval, function, *args, **kwargs):&lt;br /&gt;
         self._timer     = None&lt;br /&gt;
         self.interval   = interval&lt;br /&gt;
         self.function   = function&lt;br /&gt;
         self.args       = args&lt;br /&gt;
         self.kwargs     = kwargs&lt;br /&gt;
         self.is_running = False&lt;br /&gt;
         self.start()&lt;br /&gt;
     # Start the timer and the task &lt;br /&gt;
     def _run(self):&lt;br /&gt;
         self.is_running = False&lt;br /&gt;
         self.start()&lt;br /&gt;
         self.function(*self.args, **self.kwargs) &lt;br /&gt;
     # Start the timer and the task if the timer is currently not running&lt;br /&gt;
     def start(self):&lt;br /&gt;
         if not self.is_running:&lt;br /&gt;
             self._timer = Timer(self.interval, self._run)&lt;br /&gt;
             self._timer.start()&lt;br /&gt;
             self.is_running = True &lt;br /&gt;
     # Stop the timer&lt;br /&gt;
     def stop(self):&lt;br /&gt;
         self._timer.cancel()&lt;br /&gt;
         self.is_running = False&lt;br /&gt;
===== Logging the Status of a Task =====&lt;br /&gt;
 def check_status(user_id, log_name, task_id, scheduler, task_name):&lt;br /&gt;
     # The log file’s parent directory&lt;br /&gt;
     log_path = &amp;quot;/home/dev/web2py/applications/eden/logs/tasks/&amp;quot;&lt;br /&gt;
     # Connect to the task status database&lt;br /&gt;
     from gluon import DAL, Field&lt;br /&gt;
     db = DAL('sqlite://storage.db', folder='applications/eden/databases', auto_import=True)        &lt;br /&gt;
     # Grab the status of the current task from the database connection&lt;br /&gt;
     table = db.scheduler_task&lt;br /&gt;
     query = (table.id == task_id)&lt;br /&gt;
     task_status = db(query).select(table.status).first().status                     &lt;br /&gt;
     # Make the log directory if it doesn’t exist&lt;br /&gt;
     import os&lt;br /&gt;
     if not os.path.exists(log_path):&lt;br /&gt;
         os.makedirs(log_path)&lt;br /&gt;
     # Open the log and write the status&lt;br /&gt;
     with open(log_path + log_name, &amp;quot;a+&amp;quot;) as log:&lt;br /&gt;
         log.write('%s is currently in the %s state\n' % (task_name, task_status))&lt;br /&gt;
=====Constructing and Running the Timer=====&lt;br /&gt;
 if report_progress:&lt;br /&gt;
     # Construct the name of the log with current time, date, and task name&lt;br /&gt;
     log_name = datetime.datetime.now().strftime(&amp;quot;%y-%m-%d-%H-%M&amp;quot;) + &amp;quot;_&amp;quot; + task + &amp;quot;.txt&amp;quot;&lt;br /&gt;
     # Import the sleep module&lt;br /&gt;
     from time import sleep&lt;br /&gt;
     # Create the timer that runs check_status on the task every 1 second&lt;br /&gt;
     rt = RepeatedTimer(1, self.check_status, log_name, record.id, self.scheduler, task)  &lt;br /&gt;
     # Allow the timer to run 10 seconds then stop it. &lt;br /&gt;
     try:&lt;br /&gt;
         sleep(10)&lt;br /&gt;
     finally:&lt;br /&gt;
         rt.stop()&lt;/div&gt;</summary>
		<author><name>Cehaith2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_S1454_ccc&amp;diff=90351</id>
		<title>CSC/ECE 517 Fall 2014/OSS S1454 ccc</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_S1454_ccc&amp;diff=90351"/>
		<updated>2014-10-29T03:21:45Z</updated>

		<summary type="html">&lt;p&gt;Cehaith2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Sahana Eden: Extract The Progress Details = &lt;br /&gt;
== Introduction to Sahana Eden ==&lt;br /&gt;
Sahana is a software foundation with the express intent of “saving lives by providing information management solutions that enable organizations and communities to better prepare for and respond to disasters.” [http://sahanafoundation.org/about-us/] This is achieved&lt;br /&gt;
by developing free and open source software to make disaster response coordination more efficient. Eden (or Emergency Development ENvironment for Rapid Deployment Humanitarian Response Management), one of their main products is a feature-rich and rapidly customizable humanitarian platform that allows its modules to be specialized for particular organizations and management needs. Eden has been used to help address the wildfires in Chile, earthquakes and tsunamis in Japan, flooding in Colombia, flooding in Venezuela, flooding in Pakistan, and hurricane in Veracruz, Mexico [http://sahanafoundation.org/products/eden/]. The idea is to&lt;br /&gt;
mix and match several modules that Eden has to best suit the needs and context of an organization. The main modules are an Organization Registry, which can create databases of organizations to help facilitate coordination; Project Tracking, which tells who is doing what where and when and can tell who is working on similar projects to help facilitate collaboration; Human Resources, a tool that helps track and manage the people involved including what skills those people have; Inventory Management, which allows for recording and automating shipments and deliveries of supplies; Asset Management, which helps facilitate management of assets like vehicles, communication equipment, and generators as well as tell to whom each are assigned; Assessments, which can be used to collect and analyze information; Shelter Management, which helps facilitate the management of temporary shelters including required resources, staff and volunteer assignments, and check-in/check-out systems; Scenario and Event planning, which helps facilitate planning for various emergency scenarios; Mapping, which enables location-based visualization on maps; and Messaging, which facilitates communications over various protocol and social media mediums. Eden’s WebSetup is the tool that facilitates the setup process of a new Eden tool. The process of setting up a new Eden project entails many moving parts, so detecting bugs and troubleshooting issues in the process can be tricky. A developer created a New Enhancement ticket that requested work on being able to extract the progress details of the setup into a single local file, not dissimilar to a log file. [http://eden.sahanafoundation.org/ticket/1468]&lt;br /&gt;
== Web2Py Tasks and Task Scheduler ==&lt;br /&gt;
Sahana Eden uses the Web2Py; an application development framework written in Python that uses a typical MVC pattern. In order to best manage work on large and complicated functionality in the background, Web2Py implemented a scheduler that allows control over processes. A task is a function defined in a model:&lt;br /&gt;
&lt;br /&gt;
 def task_getParity(i):&lt;br /&gt;
     if i % 2 == 0:&lt;br /&gt;
         return “even”&lt;br /&gt;
     return “odd”&lt;br /&gt;
===== Queuing Tasks =====&lt;br /&gt;
Tasks can then be queued up with additional meta-parameters for running the function, such as when the task should die, how long can the process run until timeout occurs, how many times to repeat the function, what parameters to send to the task (if applicable), et cetera.&lt;br /&gt;
 scheduler.queue_task(‘task_getParity’, [8], …)&lt;br /&gt;
===== Scheduler Creation =====&lt;br /&gt;
The scheduler is the manager for the tasks and workers. Creating a scheduler requires a database at the least in order to store the states of tasks. However, the scheduler can be instantiated with additional parameters that allow specifications for the time between each check of the queue, specific names of functions to queue, the amount of times the queue is checked before a worker must be terminated, et cetera.&lt;br /&gt;
 from gluon.scheduler import Scheduler&lt;br /&gt;
 scheduler = Scheduler(database [,…])&lt;br /&gt;
===== Task Lifecycle =====&lt;br /&gt;
Similar to Java threads and Linux processes, a Web2Py process (interchangeable at this point with task) lifecycle is as follows:&lt;br /&gt;
* '''Queued''' a task is queued to be picked up by a worker.&lt;br /&gt;
* '''Expired''' the task died in the queue (the amount of time designated to cause the task to die has passed).&lt;br /&gt;
* '''Assigned''' a worker is assigned to this task.&lt;br /&gt;
* '''Running''' the task is being carried out.&lt;br /&gt;
* '''Timeout''' the task timed out (the amount of time designated to case the task to timeout during processing has passed).&lt;br /&gt;
* '''Failed''' an error was detected or an exception was thrown.&lt;br /&gt;
* '''Completed''' the task finished correctly.&lt;/div&gt;</summary>
		<author><name>Cehaith2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_S1454_ccc&amp;diff=90347</id>
		<title>CSC/ECE 517 Fall 2014/OSS S1454 ccc</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/OSS_S1454_ccc&amp;diff=90347"/>
		<updated>2014-10-29T03:15:35Z</updated>

		<summary type="html">&lt;p&gt;Cehaith2: Created page with &amp;quot;= Sahana Eden: Extract The Progress Details =  == Introduction to Sahana Eden == Sahana is a software foundation with the express intent of “saving lives by providing informati...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Sahana Eden: Extract The Progress Details = &lt;br /&gt;
== Introduction to Sahana Eden ==&lt;br /&gt;
Sahana is a software foundation with the express intent of “saving lives by providing information management solutions that enable organizations and communities to better prepare for and respond to disasters.” [http://sahanafoundation.org/about-us/] This is achieved&lt;br /&gt;
by developing free and open source software to make disaster response coordination more efficient. Eden (or Emergency Development ENvironment for Rapid Deployment Humanitarian Response Management), one of their main products is a feature-rich and rapidly customizable humanitarian platform that allows its modules to be specialized for particular organizations and management needs. Eden has been used to help address the wildfires in Chile, earthquakes and tsunamis in Japan, flooding in Colombia, flooding in Venezuela, flooding in Pakistan, and hurricane in Veracruz, Mexico [http://sahanafoundation.org/products/eden/]. The idea is to&lt;br /&gt;
mix and match several modules that Eden has to best suit the needs and context of an organization. The main modules are an Organization Registry, which can create databases of organizations to help facilitate coordination; Project Tracking, which tells who is doing what where and when and can tell who is working on similar projects to help facilitate collaboration; Human Resources, a tool that helps track and manage the people involved including what skills those people have; Inventory Management, which allows for recording and automating shipments and deliveries of supplies; Asset Management, which helps facilitate management of assets like vehicles, communication equipment, and generators as well as tell to whom each are assigned; Assessments, which can be used to collect and analyze information; Shelter Management, which helps facilitate the management of temporary shelters including required resources, staff and volunteer assignments, and check-in/check-out systems; Scenario and Event planning, which helps facilitate planning for various emergency scenarios; Mapping, which enables location-based visualization on maps; and Messaging, which facilitates communications over various protocol and social media mediums. Eden’s WebSetup is the tool that facilitates the setup process of a new Eden tool. The process of setting up a new Eden project entails many moving parts, so detecting bugs and troubleshooting issues in the process can be tricky. A developer created a New Enhancement ticket that requested work on being able to extract the progress details of the setup into a single local file, not dissimilar to a log file. [http://eden.sahanafoundation.org/ticket/1468]&lt;br /&gt;
== Web2Py Tasks and Task Scheduler ==&lt;br /&gt;
Sahana Eden uses the Web2Py; an application development framework written in Python that uses a typical MVC pattern. In order to best manage work on large and complicated functionality in the background, Web2Py implemented a scheduler that allows control over processes. A task is a function defined in a model:&lt;br /&gt;
&lt;br /&gt;
 def task_getParity(i):&lt;br /&gt;
     if i % 2 == 0:&lt;br /&gt;
         return “even”&lt;br /&gt;
     return “odd”&lt;br /&gt;
&lt;br /&gt;
Tasks can then be queued up with additional meta-parameters for running the function, such as when the task should die, how long can the process run until timeout occurs, how many times to repeat the function, what parameters to send to the task (if applicable), et cetera.&lt;br /&gt;
 scheduler.queue_task(‘task_getParity’, [8], …)&lt;br /&gt;
The scheduler is the manager for the tasks and workers. Creating a scheduler requires a database at the least in order to store the states of tasks. However, the scheduler can be instantiated with additional parameters that allow specifications for the time between each check of the queue, specific names of functions to queue, the amount of times the queue is checked before a worker must be terminated, et cetera.&lt;br /&gt;
 from gluon.scheduler import Scheduler&lt;br /&gt;
 scheduler = Scheduler(database [,…])&lt;/div&gt;</summary>
		<author><name>Cehaith2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014&amp;diff=90325</id>
		<title>CSC/ECE 517 Fall 2014</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014&amp;diff=90325"/>
		<updated>2014-10-29T03:00:14Z</updated>

		<summary type="html">&lt;p&gt;Cehaith2: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*[[CSC/ECE_517_Fall_2014/sample_page]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a 22 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 19 mx]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 3 zq]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 4 lf]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 4 wl]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a a7 ch]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 25 rs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 25 jf]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 8 os]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 8 sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 15 gs]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 10 hu]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 20 kv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 21 as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 24 sa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 26 sn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 6 rl]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 2 ss]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 16 av]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 1 rm]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 1 sj]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 23 ss]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 20 rn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 22 sp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss M1454 rss]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 26 gn]]&lt;br /&gt;
&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 13 va]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 9 aa]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 9 kn]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 11 ap]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 25 ks]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 7 kz]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a_6_bn]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a 10 zz]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a 16 va]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a F1415 rv]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a_3_cp]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1b 26 sa]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b_28_cg]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b 29 ry]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b 30 cs]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b_33_jy]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1b_27_js]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1463 vpd]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss E1465 oak]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss_M1456_kdv]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss_M1453_sst]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/oss_E1456_akk]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_M1455_asa]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_E1458_sst]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_E1457_ags]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_E1466_gjf]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_M1452_jns]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/oss_E1462_nms]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_S1455_ajp]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/OSS_S1454_ccc]]&lt;/div&gt;</summary>
		<author><name>Cehaith2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_cp&amp;diff=88176</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 cp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_cp&amp;diff=88176"/>
		<updated>2014-09-24T21:21:43Z</updated>

		<summary type="html">&lt;p&gt;Cehaith2: /* CherryPy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;='''CherryPy'''=&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
[http://www.cherrypy.org/ CherryPy] is an [http://en.wikipedia.org/wiki/Object-oriented_programming Object-Oriented] [http://en.wikipedia.org/wiki/Web_application_framework Web Application Framework] meant to be [http://en.wikipedia.org/wiki/Python_%28programming_language%29 Python]-like (sparse and clean code).&amp;lt;br/&amp;gt;&lt;br /&gt;
It is important to note that it is not a complete stack such as [http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails], [http://en.wikipedia.org/wiki/Laravel Laravel], or [http://en.wikipedia.org/wiki/Django Django]. Complete stack web frameworks offer frontend utilities and storage communications along with other abilities. These aspects that make the frameworks so powerful, however, also contribute to the framework being bulky making development of small web applications such as blogs a bit cumbersome. CherryPy instead prefers to defer decisions such as storage management and interface utilities to the developer &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/intro.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
Because CherryPy is nothing more than a Python library, it needs a Python environment (Python 2.3 through to 3.4) and can also run on various implementations of Python including [http://en.wikipedia.org/wiki/IronPython IronPython] for [http://en.wikipedia.org/wiki/.NET_Framework .NET]  and [http://en.wikipedia.org/wiki/Jython Jython] for [http://en.wikipedia.org/wiki/Java_%28programming_language%29 Java].&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/install.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Requirements===&lt;br /&gt;
CherryPy requires a Python version between 2.3 and 3.4 inclusively. Certain features require packages but none are mandatory for installation.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/install.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[http://routes.readthedocs.org/en/latest/ routes] for declarative URL mapping dispatcher&lt;br /&gt;
*[http://pythonhosted.org//psycopg2/ psycopg2] for [http://en.wikipedia.org/wiki/PostgreSQL PostgreSQL] database backend session&lt;br /&gt;
*[http://sourceforge.net/projects/pywin32/ pywin32] for Windows services&lt;br /&gt;
*[https://github.com/linsomniac/python-memcached python-memcached] for [http://en.wikipedia.org/wiki/Memcached Memcached] backend session&lt;br /&gt;
*[https://github.com/simplejson/simplejson simplejson] for a better [http://en.wikipedia.org/wiki/JSON JSON] support&lt;br /&gt;
*[https://github.com/pyca/pyopenssl pyOpenSSL] if your Python environment does not have the built in [http://en.wikipedia.org/wiki/Transport_Layer_Security ssl] module&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Installing===&lt;br /&gt;
CherryPy can be installed through common Python package managers with the following commands:&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/install.html&amp;lt;/ref&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Install (choose on of the following commands appropriately):&lt;br /&gt;
    $ easy_install cherrypy&lt;br /&gt;
    $ pip install cherrypy&lt;br /&gt;
    $ yum install python-cherrypy&lt;br /&gt;
    $ apt-get install python python-dev&lt;br /&gt;
&lt;br /&gt;
===Install via yum===&lt;br /&gt;
CherryPy is provided by the fedora base repository. In [http://en.wikipedia.org/wiki/Fedora_%28operating_system%29 Fedora] (and other [http://en.wikipedia.org/wiki/RPM_Package_Manager RPM] based Linux distributions, such as [http://en.wikipedia.org/wiki/CentOS CentOS] and [http://en.wikipedia.org/wiki/Red_Hat_Enterprise_Linux Red Hat Enterprise Linux]):&amp;lt;br/&amp;gt;&lt;br /&gt;
    $ yum install python-cherrypy&lt;br /&gt;
&lt;br /&gt;
===Install via apt-get=== &lt;br /&gt;
CherryPy is also provided in the [http://en.wikipedia.org/wiki/Ubuntu_(operating_system) Ubuntu] base repository. In Ubuntu (and other [http://en.wikipedia.org/wiki/Debian Debian]-based Linux distributions such as Debian and [http://en.wikipedia.org/wiki/Linux_Mint Linux Mint]):&lt;br /&gt;
    $ apt-get install python python-dev&lt;br /&gt;
&lt;br /&gt;
===Installation from source===&lt;br /&gt;
The source code is hosted on [http://en.wikipedia.org/wiki/Bitbucket BitBucket] and requires [http://en.wikipedia.org/wiki/Mercurial Mercurial] to pull and install from the site itself.&lt;br /&gt;
    $ hg clone https://bitbucket.org/cherrypy/cherrypy&lt;br /&gt;
    $ cd cherrypy&lt;br /&gt;
    $ python setup.py install&lt;br /&gt;
&lt;br /&gt;
Alternatively, the source can be manually downloaded from [https://bitbucket.org/cherrypy/cherrypy/downloads here] in a tarball.&lt;br /&gt;
    $ tar -xvf CherryPy-#.#.#.tar.gz&lt;br /&gt;
    $ cd CherryPy-#.#.#&lt;br /&gt;
    $ python setup.py install&lt;br /&gt;
&lt;br /&gt;
===Install for Windows===&lt;br /&gt;
*If you are using Windows, install Linux and follow any of the a forementioned methods.&lt;br /&gt;
*If you absolutely must use windows, you can download the .exe file to install CherryPy from [https://bitbucket.org/cherrypy/cherrypy/downloads here].&lt;br /&gt;
&lt;br /&gt;
==Interface==&lt;br /&gt;
&lt;br /&gt;
CherryPy is meant to be pythonic, meaning that development time  is meant to be minimized and code is meant to be sparse and clean &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/intro.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Basic Example===&lt;br /&gt;
Lets look at a hello world example&amp;lt;ref&amp;gt;https://cherrypy.readthedocs.org/en/3.2.6/concepts/basics.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/419163/what-does-if-name-main-do&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Use the cherrypy python library&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
#Hello World project&lt;br /&gt;
class HelloWorld(object):&lt;br /&gt;
&lt;br /&gt;
#   index page&lt;br /&gt;
    def index(self):&lt;br /&gt;
#       Return the page contents&lt;br /&gt;
        return “Hello World!”&lt;br /&gt;
&lt;br /&gt;
#   Allow the page to be visible&lt;br /&gt;
    index.exposed = True&lt;br /&gt;
&lt;br /&gt;
#designates this module as main&lt;br /&gt;
if __name__ == ‘__main__’:&lt;br /&gt;
&lt;br /&gt;
#   instantiates app and starts server&lt;br /&gt;
    cherrypy.quickstart(HelloWorld())&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The above script sets up a basic Hello World application, by defining the index page (http://localhost:8080/) as an object that returns the string “Hello World!”. The page is exposed, meaning that the method can be called to answer a [http://en.wikipedia.org/wiki/Representational_state_transfer RESTful] request. Otherwise, the method is internal only. This is similar to making a method public in Java. &amp;lt;ref&amp;gt;http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Routing, Parameters, and Exposure===&lt;br /&gt;
Routing is the act of finding the appropriate code to handle a request. CherryPy uses a dispatcher to perform most of these, but premade dispatchers exist to handle more sophisticated handling of request. The most common is a page handler (the name of the object). Parameters can be passed into the handler via http query strings. These strings are appended to the URL of a site after a &amp;quot;?&amp;quot;. Exposure is just the way CherryPy prevents access to objects from the users. Without the exposed attribute set to true, an object won't be accessible to the user.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#import python library&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
#More Routes application&lt;br /&gt;
class MoreRoutes(object):&lt;br /&gt;
&lt;br /&gt;
#   Method decorator for index and equates to index.exposed = True&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#   http://localhost:8080/route1&lt;br /&gt;
    def route1(self, id=”charles”):&lt;br /&gt;
#       http://localhost:8080/route1?id=somestring&lt;br /&gt;
        return “Your name is ” + id&lt;br /&gt;
&lt;br /&gt;
#   Params passed as a GET request.&lt;br /&gt;
#   Default string is “charles”&lt;br /&gt;
    route1.exposed = True&lt;br /&gt;
&lt;br /&gt;
#   No explicit indication of exposure so calling this route will generate a 404 error&lt;br /&gt;
    def route2(self):&lt;br /&gt;
        return “Still another one”&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    cherrypy.quickstart(MoreRoutes())&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above shows how multiple routes are handled from the Hello World application and the expose decorator. Since route2 is not exposed, the user can not access it and will be shown a 404 HTTP status code (Not Found error).&lt;br /&gt;
&lt;br /&gt;
===Multiple Applications=== &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
#blog module&lt;br /&gt;
class Blog(object):&lt;br /&gt;
    ...&amp;lt;blog code&amp;gt;...&lt;br /&gt;
#forum module&lt;br /&gt;
class Forum(object):&lt;br /&gt;
    ...&amp;lt;forum code&amp;gt;...&lt;br /&gt;
#”main” method&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
#designates the blog to be under /blog route&lt;br /&gt;
    cherrypy.tree.mount(Blog(), ‘/blog’, “blog.conf”)&lt;br /&gt;
#designates the forum to be under /forum route&lt;br /&gt;
    cherrypy.tree.mount(Forum(), ‘/forum’, “forum.conf”)&lt;br /&gt;
&amp;lt;/pre&amp;gt; &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/basics.html#multiple-applications&amp;lt;/ref&amp;gt;&lt;br /&gt;
In the above example, the blog would be found under /blog in the URL, wheras the forum will be mounted at /forum in the application tree. The XXX.conf files are configuration files, which are dictionaries containing string keys and polymorphic values and can be used to set attributes on the engine, server, request, response, and log objects. &amp;lt;ref&amp;gt;https://cherrypy.readthedocs.org/en/3.2.6/concepts/config.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Database Support===&lt;br /&gt;
CherryPy offers multiple database integration possibilities including&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Relational_database Relational]: [http://en.wikipedia.org/wiki/PostgreSQL PostgreSQL], [http://en.wikipedia.org/wiki/SQLite SQLite], [http://en.wikipedia.org/wiki/MariaDB MariaDB], [http://en.wikipedia.org/wiki/Firebird_%28database_server%29 Firebird]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Column-oriented_DBMS Column-Oriented]: [http://en.wikipedia.org/wiki/Apache_HBase HBase], [http://en.wikipedia.org/wiki/Apache_Cassandra Cassandra]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/NoSQL#Key.E2.80.93value_stores Key-Store]: [http://en.wikipedia.org/wiki/Redis Redis], [http://en.wikipedia.org/wiki/Memcached Memcached]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Document-oriented_database Document-Oriented]: [http://en.wikipedia.org/wiki/CouchDB Couchdb], [http://en.wikipedia.org/wiki/MongoDB MongoDB]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Graph_database Graph-Oriented]: [http://en.wikipedia.org/wiki/Neo4j Neo4j]&amp;lt;br/&amp;gt;&lt;br /&gt;
Unfortunately, unlike [https://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails], CherryPy does not have a sophisticated [https://en.wikipedia.org/wiki/Active_record_pattern#Ruby Active Record Pattern] based class for database abstraction, and the database connection has to be established manually. The queries are constructed as static [https://en.wikipedia.org/wiki/SQL SQL] strings with values concatenated during function calls.&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example of how it would look like&amp;lt;ref&amp;gt;http://cherrypy.readthedocs.org/en/latest/tutorials.html#tutorial-9-data-is-all-my-life&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# import the Handles&lt;br /&gt;
import MySQLdb&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
# defining the connection function&lt;br /&gt;
def connect(thread_index):&lt;br /&gt;
#   Create a connection and store it in the current thread&lt;br /&gt;
    cherrypy.thread_data.db = MySQLdb.connect('host', 'user', 'password', 'dbname')&lt;br /&gt;
&lt;br /&gt;
# tell cherrypy to  call connect function for each thread&lt;br /&gt;
cherrypy.engine.subscribe('start_thread', connect)&lt;br /&gt;
&lt;br /&gt;
# example query function&lt;br /&gt;
@cherrypy.expose&lt;br /&gt;
def count(val)&lt;br /&gt;
#   fetching instance of db connection&lt;br /&gt;
    c = cherrypy.thread_data.db.cursor()&lt;br /&gt;
#   executing query&lt;br /&gt;
    c.execute( 'select count(‘ + val + ’) from table' )&lt;br /&gt;
#   fetching results from db&lt;br /&gt;
    res = c.fetchone()&lt;br /&gt;
#   releasing instance of the connection&lt;br /&gt;
    c.close()&lt;br /&gt;
#   returning the count value&lt;br /&gt;
    return res&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==RESTful CherryPy==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Representational_state_transfer REST] (Representational State Transfer) is an abstraction of the architectural elements within a distributed hypermedia system. It ignores the details of component implementation and protocol syntax in order to focus on the roles of components, the constraints upon their interaction with other components, and their interpretation of significant data elements. It encompasses the fundamental constraints upon components, connectors, and data that define the basis of the Web architecture, and thus the essence of its behavior as a network-based application. &amp;lt;ref&amp;gt;http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm&amp;lt;/ref&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
In othe words, REST is defined by four interface constraints: identification of resources, manipulation of resources through representations, self-descriptive messages, and hypermedia as the engine of application state.&amp;lt;ref&amp;gt;https://cherrypy.readthedocs.org/en/3.2.6/progguide/REST.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Identification of Resources===&lt;br /&gt;
Since Cherrypy is an HTTP service provider, resources are referenced by HTTP URIs (Uniform Resource Identifiers), which consist of a scheme, hierarchical identitfier, query, and fragment.&amp;lt;ref&amp;gt;https://cherrypy.readthedocs.org/en/3.3.0/progguide/REST.html#implementing-rest-in-cherrypy&amp;lt;/ref&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
*Scheme: in [http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol http], the scheme is always http or [http://en.wikipedia.org/wiki/HTTP_Secure https].&lt;br /&gt;
*Hierarchical Identifier: consists of an authority and a path (host/port and a path similar to the system file path but not the actual path). The path is mapped to Python Objects via a dispatch mechanism.&lt;br /&gt;
&lt;br /&gt;
===Manipulation of Resources Through Representations===&lt;br /&gt;
The standard [http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html HTTP methods] are as follows&amp;lt;ref&amp;gt;https://cherrypy.readthedocs.org/en/3.3.0/progguide/REST.html#manipulation-of-resources-through-representations&amp;lt;/ref&amp;gt;&lt;br /&gt;
*&amp;lt;code&amp;gt;GET&amp;lt;/code&amp;gt; retrieves the state of a specific resource&lt;br /&gt;
*&amp;lt;code&amp;gt;PUT&amp;lt;/code&amp;gt; creates or replaces the state of a specific resource&lt;br /&gt;
*&amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt; passes information to a resource to use as it sees fit&lt;br /&gt;
*&amp;lt;code&amp;gt;DELETE&amp;lt;/code&amp;gt; removes resources&lt;br /&gt;
&lt;br /&gt;
===Self-Descriptive Messages===&lt;br /&gt;
REST requires messages to be self-descriptive, meaning everything about a message is within the message itself. Such information can be found in the method headers or the definitions of the message’s media type. cherrypy.request.headers and cherrypy.response.headers are used to get this information. Custom-Types are allowed as well.&amp;lt;ref&amp;gt;https://cherrypy.readthedocs.org/en/3.3.0/progguide/REST.html#self-descriptive-messages&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Hypermedia as the Engine of the Application State===&lt;br /&gt;
Since REST is stateless and the state is maintained by the application in question, sessions are not maintained by REST, so, by association, CherryPy does not enable sessions by default. However, the REST server helps clients maintain a meaningful state through meaningful URIs&amp;lt;ref&amp;gt;https://cherrypy.readthedocs.org/en/3.3.0/progguide/REST.html#hypermedia-as-the-engine-of-application-state&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Crash Course==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Development===&lt;br /&gt;
Create an application. Application requirements: &lt;br /&gt;
*The module needs to define a &amp;lt;code&amp;gt;__main__ &amp;lt;/code&amp;gt;&lt;br /&gt;
*&amp;lt;code&amp;gt;cherrypy.quickstart(&amp;lt;Application Name&amp;gt;())&amp;lt;/code&amp;gt; for hosting a single application. For example: cherrypy.quickstart(Blog())&lt;br /&gt;
*&amp;lt;code&amp;gt;cherrypy.tree.mount(&amp;lt;Application Name&amp;gt;(), ‘/&amp;lt;hosting path segment&amp;gt;’, &amp;lt;configuration&amp;gt;)&amp;lt;/code&amp;gt; for hosting multiple applications. For example: &amp;lt;code&amp;gt;cherrypy.tree.mount(Blog(), ‘/blog’, blog_conf) &amp;lt;/code&amp;gt;&lt;br /&gt;
*All parts the users will see must be exposed with either the decorator &amp;lt;code&amp;gt;@cherrypy.expose or attribues exposed = True&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;route.exposed = True.&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
class HelloWorld(object):&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return “Hello World!”&lt;br /&gt;
    index.exposed = True&lt;br /&gt;
if __name__ == ‘__main__’:&lt;br /&gt;
    cherrypy.quickstart(HelloWorld())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Deployment===&lt;br /&gt;
The application can be run as a python script in the Python interpreter.&lt;br /&gt;
    $ python &amp;lt;app file&amp;gt;.py&lt;br /&gt;
It will hosted at http://127.0.0.1:8080/&lt;br /&gt;
It can also be run as a daemon process with&lt;br /&gt;
    $cherryd -c &amp;lt;config file&amp;gt; -d -p &amp;lt;PID file&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Extensions==&lt;br /&gt;
&lt;br /&gt;
CherryPy provides a flexible open framework. Similar to [http://en.wikipedia.org/wiki/RubyGems RubyGems] in [http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] which add a range of functionality to the framework CherryPy also supports plugins in the the following forms&lt;br /&gt;
&lt;br /&gt;
===Server Wide Functions (Plugins)===&lt;br /&gt;
This type of extension is typically used to provide the application server itself with additional functionality. Such functions are executed with respect to events in the server even when there is no client request processing taking place.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/extend.html#id13&amp;lt;/ref&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
Typical use case involve&lt;br /&gt;
*Background Tasks (Tasks which involve server mentainance, data management etc. which are independent of user requests)&lt;br /&gt;
*External Connections (For establishing and maintaining threaded connections to external database or other servers)&lt;br /&gt;
*Delayed/Queued Processing (Cases when certain tasks are required by the user request which take a long time process and the HTTP response should not be blocked.)&amp;lt;br/&amp;gt;&lt;br /&gt;
These function utilize the [http://en.wikipedia.org/wiki/Publish–subscribe_pattern Publish-Subscribe Framework] implementation of CherryPy. Each function subscribes to one or more events on the bus which are published by the CherryPy engine.&amp;lt;br/&amp;gt; The database connection is a good example of such a function&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# import the Handles&lt;br /&gt;
import MySQLdb&lt;br /&gt;
import cherrypy&lt;br /&gt;
# defining the connection function&lt;br /&gt;
def connect(thread_index): &lt;br /&gt;
    # Create a connection and store it in the current thread &lt;br /&gt;
    cherrypy.thread_data.db = MySQLdb.connect('host', 'user', 'password', 'dbname')&lt;br /&gt;
&lt;br /&gt;
# tell cherrypy to  call connect function for each thread&lt;br /&gt;
cherrypy.engine.subscribe('start_thread', connect)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here the function connect subscribes to the &amp;lt;code&amp;gt;start_thread&amp;lt;/code&amp;gt; channel. An event is published on the &amp;lt;code&amp;gt;start_thread&amp;lt;/code&amp;gt; channel whenever a server thread is started. Here &amp;lt;code&amp;gt;engine&amp;lt;/code&amp;gt; is the central bus of the CherryPy server.&amp;lt;br/&amp;gt;&lt;br /&gt;
Similarly it is also possible to create new channels and even buses themselves.&lt;br /&gt;
&lt;br /&gt;
===Per-Request Functions (Tools)===&lt;br /&gt;
This type of extension is typically used to insert functionality between stages of request processing. Also known as [http://docs.cherrypy.org/en/latest/extend.html#tools Tools] these are simple call-back functions registered with a [http://docs.cherrypy.org/en/latest/extend.html#hookpoint Hook Point]. Hook Points are predefined stages of request processing. CherryPy provides a [http://tools.cherrypy.org/ Default ToolBox] containing many tools. Users have the freedom to create their own tools and add them to the default toolbox or create a new one.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/extend.html#per-request-functions&amp;lt;/ref&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
An example for creating a tool&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# defining the function to be called&lt;br /&gt;
def my_tool():&lt;br /&gt;
    # put tool functunality here&lt;br /&gt;
    print (“Super Amazing Tool”);&lt;br /&gt;
&lt;br /&gt;
# creating the decorator for the tool&lt;br /&gt;
# specifying the hook point and function to be called&lt;br /&gt;
cherrypy.tools.mytool = cherrypy.Tool(‘on_end_request’, my_tool())&lt;br /&gt;
&lt;br /&gt;
#Sample Usage&lt;br /&gt;
&lt;br /&gt;
class Root(object):&lt;br /&gt;
@cherrypy.expose()&lt;br /&gt;
@cherrypy.tools.mytool()&lt;br /&gt;
def index()&lt;br /&gt;
    return “Hello World”&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Watch It In Action==&lt;br /&gt;
&lt;br /&gt;
CherryPy is used as a building block for [http://www.hulu.com/ Hulu]&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu&amp;lt;/ref&amp;gt; and [https://www.netflix.com/ Netflix]&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Cehaith2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_cp&amp;diff=88173</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 cp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_cp&amp;diff=88173"/>
		<updated>2014-09-24T20:44:38Z</updated>

		<summary type="html">&lt;p&gt;Cehaith2: /* Multiple Applications */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;='''CherryPy'''=&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
[http://www.cherrypy.org/ CherryPy] is an [http://en.wikipedia.org/wiki/Object-oriented_programming Object-Oriented] [http://en.wikipedia.org/wiki/Web_application_framework Web Application Framework] meant to be [http://en.wikipedia.org/wiki/Python_%28programming_language%29 Python]-like (sparse and clean code).&amp;lt;br/&amp;gt;&lt;br /&gt;
It is important to note that it is not a complete stack such as [http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails], [http://en.wikipedia.org/wiki/Laravel Laravel], or [http://en.wikipedia.org/wiki/Django Django]. Complete stack web frameworks offer frontend utilities and storage communications along with other abilities. These aspects that make the frameworks so powerful, however, also contribute to the framework being bulky making development of small web applications such as blogs a bit cumbersome. CherryPy instead prefers to defer decisions such as storage management and interface utilities to the developer &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/intro.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
Because CherryPy is nothing more than a Python library, it needs a Python environment (Python 2.3 through to 3.4) and can also run on various implementations of Python including [http://en.wikipedia.org/wiki/IronPython IronPython] for [http://en.wikipedia.org/wiki/.NET_Framework .NET]  and [http://en.wikipedia.org/wiki/Jython Jython] for [http://en.wikipedia.org/wiki/Java_%28programming_language%29 Java].&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/install.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Requirements===&lt;br /&gt;
CherryPy requires a Python version between 2.3 and 3.4 inclusively. Certain features require packages but none are mandatory for installation.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/install.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[http://routes.readthedocs.org/en/latest/ routes] for declarative URL mapping dispatcher&lt;br /&gt;
*[http://pythonhosted.org//psycopg2/ psycopg2] for [http://en.wikipedia.org/wiki/PostgreSQL PostgreSQL] database backend session&lt;br /&gt;
*[http://sourceforge.net/projects/pywin32/ pywin32] for Windows services&lt;br /&gt;
*[https://github.com/linsomniac/python-memcached python-memcached] for [http://en.wikipedia.org/wiki/Memcached Memcached] backend session&lt;br /&gt;
*[https://github.com/simplejson/simplejson simplejson] for a better [http://en.wikipedia.org/wiki/JSON JSON] support&lt;br /&gt;
*[https://github.com/pyca/pyopenssl pyOpenSSL] if your Python environment does not have the built in [http://en.wikipedia.org/wiki/Transport_Layer_Security ssl] module&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Installing===&lt;br /&gt;
CherryPy can be installed through common Python package managers with the following commands:&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/install.html&amp;lt;/ref&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Install (choose on of the following commands appropriately):&lt;br /&gt;
    $ easy_install cherrypy&lt;br /&gt;
    $ pip install cherrypy&lt;br /&gt;
    $ yum install python-cherrypy&lt;br /&gt;
    $ apt-get install python python-dev&lt;br /&gt;
&lt;br /&gt;
Refer [[#Additional Installation Instructions| Additional Instructions]] for more details.&lt;br /&gt;
&lt;br /&gt;
==Interface==&lt;br /&gt;
&lt;br /&gt;
CherryPy is meant to be pythonic, meaning that development time  is meant to be minimized and code is meant to be sparse and clean &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/intro.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Basic Example===&lt;br /&gt;
Lets look at a hello world example&amp;lt;ref&amp;gt;https://cherrypy.readthedocs.org/en/3.2.6/concepts/basics.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/419163/what-does-if-name-main-do&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Use the cherrypy python library&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
#Hello World project&lt;br /&gt;
class HelloWorld(object):&lt;br /&gt;
&lt;br /&gt;
#   index page&lt;br /&gt;
    def index(self):&lt;br /&gt;
#       Return the page contents&lt;br /&gt;
        return “Hello World!”&lt;br /&gt;
&lt;br /&gt;
#   Allow the page to be visible&lt;br /&gt;
    index.exposed = True&lt;br /&gt;
&lt;br /&gt;
#designates this module as main&lt;br /&gt;
if __name__ == ‘__main__’:&lt;br /&gt;
&lt;br /&gt;
#   instantiates app and starts server&lt;br /&gt;
    cherrypy.quickstart(HelloWorld())&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The above script sets up a basic Hello World application, by defining the index page (http://localhost:8080/) as an object that returns the string “Hello World!”. The page is exposed, meaning that the method can be called to answer a [http://en.wikipedia.org/wiki/Representational_state_transfer RESTful] request. Otherwise, the method is internal only. This is similar to making a method public in Java. &amp;lt;ref&amp;gt;http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Routing, Parameters, and Exposure===&lt;br /&gt;
Routing is the act of finding the appropriate code to handle a request. CherryPy uses a dispatcher to perform most of these, but premade dispatchers exist to handle more sophisticated handling of request. The most common is a page handler (the name of the object). Parameters can be passed into the handler via http query strings. These strings are appended to the URL of a site after a &amp;quot;?&amp;quot;. Exposure is just the way CherryPy prevents access to objects from the users. Without the exposed attribute set to true, an object won't be accessible to the user.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#import python library&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
#More Routes application&lt;br /&gt;
class MoreRoutes(object):&lt;br /&gt;
&lt;br /&gt;
#   Method decorator for index and equates to index.exposed = True&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#   http://localhost:8080/route1&lt;br /&gt;
    def route1(self, id=”charles”):&lt;br /&gt;
#       http://localhost:8080/route1?id=somestring&lt;br /&gt;
        return “Your name is ” + id&lt;br /&gt;
&lt;br /&gt;
#   Params passed as a GET request.&lt;br /&gt;
#   Default string is “charles”&lt;br /&gt;
    route1.exposed = True&lt;br /&gt;
&lt;br /&gt;
#   No explicit indication of exposure so calling this route will generate a 404 error&lt;br /&gt;
    def route2(self):&lt;br /&gt;
        return “Still another one”&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    cherrypy.quickstart(MoreRoutes())&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above shows how multiple routes are handled from the Hello World application and the expose decorator. Since route2 is not exposed, the user can not access it and will be shown a 404 HTTP status code (Not Found error).&lt;br /&gt;
&lt;br /&gt;
===Multiple Applications=== &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
#blog module&lt;br /&gt;
class Blog(object):&lt;br /&gt;
    ...&amp;lt;blog code&amp;gt;...&lt;br /&gt;
#forum module&lt;br /&gt;
class Forum(object):&lt;br /&gt;
    ...&amp;lt;forum code&amp;gt;...&lt;br /&gt;
#”main” method&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
#designates the blog to be under /blog route&lt;br /&gt;
    cherrypy.tree.mount(Blog(), ‘/blog’, “blog.conf”)&lt;br /&gt;
#designates the forum to be under /forum route&lt;br /&gt;
    cherrypy.tree.mount(Forum(), ‘/forum’, “forum.conf”)&lt;br /&gt;
&amp;lt;/pre&amp;gt; &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/basics.html#multiple-applications&amp;lt;/ref&amp;gt;&lt;br /&gt;
In the above example, the blog would be found under /blog in the URL, wheras the forum will be mounted at /forum in the application tree. The XXX.conf files are configuration files, which are dictionaries containing string keys and polymorphic values and can be used to set attributes on the engine, server, request, response, and log objects. &amp;lt;ref&amp;gt;https://cherrypy.readthedocs.org/en/3.2.6/concepts/config.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Database Support===&lt;br /&gt;
CherryPy offers multiple database integration possibilities including&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Relational_database Relational]: [http://en.wikipedia.org/wiki/PostgreSQL PostgreSQL], [http://en.wikipedia.org/wiki/SQLite SQLite], [http://en.wikipedia.org/wiki/MariaDB MariaDB], [http://en.wikipedia.org/wiki/Firebird_%28database_server%29 Firebird]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Column-oriented_DBMS Column-Oriented]: [http://en.wikipedia.org/wiki/Apache_HBase HBase], [http://en.wikipedia.org/wiki/Apache_Cassandra Cassandra]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/NoSQL#Key.E2.80.93value_stores Key-Store]: [http://en.wikipedia.org/wiki/Redis Redis], [http://en.wikipedia.org/wiki/Memcached Memcached]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Document-oriented_database Document-Oriented]: [http://en.wikipedia.org/wiki/CouchDB Couchdb], [http://en.wikipedia.org/wiki/MongoDB MongoDB]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Graph_database Graph-Oriented]: [http://en.wikipedia.org/wiki/Neo4j Neo4j]&amp;lt;br/&amp;gt;&lt;br /&gt;
Unfortunately, unlike [https://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails], CherryPy does not have a sophisticated [https://en.wikipedia.org/wiki/Active_record_pattern#Ruby Active Record Pattern] based class for database abstraction, and the database connection has to be established manually. The queries are constructed as static [https://en.wikipedia.org/wiki/SQL SQL] strings with values concatenated during function calls.&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example of how it would look like&amp;lt;ref&amp;gt;http://cherrypy.readthedocs.org/en/latest/tutorials.html#tutorial-9-data-is-all-my-life&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# import the Handles&lt;br /&gt;
import MySQLdb&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
# defining the connection function&lt;br /&gt;
def connect(thread_index):&lt;br /&gt;
#   Create a connection and store it in the current thread&lt;br /&gt;
    cherrypy.thread_data.db = MySQLdb.connect('host', 'user', 'password', 'dbname')&lt;br /&gt;
&lt;br /&gt;
# tell cherrypy to  call connect function for each thread&lt;br /&gt;
cherrypy.engine.subscribe('start_thread', connect)&lt;br /&gt;
&lt;br /&gt;
# example query function&lt;br /&gt;
@cherrypy.expose&lt;br /&gt;
def count(val)&lt;br /&gt;
#   fetching instance of db connection&lt;br /&gt;
    c = cherrypy.thread_data.db.cursor()&lt;br /&gt;
#   executing query&lt;br /&gt;
    c.execute( 'select count(‘ + val + ’) from table' )&lt;br /&gt;
#   fetching results from db&lt;br /&gt;
    res = c.fetchone()&lt;br /&gt;
#   releasing instance of the connection&lt;br /&gt;
    c.close()&lt;br /&gt;
#   returning the count value&lt;br /&gt;
    return res&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==RESTful CherryPy==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Representational_state_transfer REST] (Representational State Transfer) is an abstraction of the architectural elements within a distributed hypermedia system. It ignores the details of component implementation and protocol syntax in order to focus on the roles of components, the constraints upon their interaction with other components, and their interpretation of significant data elements. It encompasses the fundamental constraints upon components, connectors, and data that define the basis of the Web architecture, and thus the essence of its behavior as a network-based application. &amp;lt;ref&amp;gt;http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm&amp;lt;/ref&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
In othe words, REST is defined by four interface constraints: identification of resources, manipulation of resources through representations, self-descriptive messages, and hypermedia as the engine of application state.&amp;lt;ref&amp;gt;https://cherrypy.readthedocs.org/en/3.2.6/progguide/REST.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Identification of Resources===&lt;br /&gt;
Since Cherrypy is an HTTP service provider, resources are referenced by HTTP URIs (Uniform Resource Identifiers), which consist of a scheme, hierarchical identitfier, query, and fragment.&amp;lt;ref&amp;gt;https://cherrypy.readthedocs.org/en/3.3.0/progguide/REST.html#implementing-rest-in-cherrypy&amp;lt;/ref&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
*Scheme: in [http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol http], the scheme is always http or [http://en.wikipedia.org/wiki/HTTP_Secure https].&lt;br /&gt;
*Hierarchical Identifier: consists of an authority and a path (host/port and a path similar to the system file path but not the actual path). The path is mapped to Python Objects via a dispatch mechanism.&lt;br /&gt;
&lt;br /&gt;
===Manipulation of Resources Through Representations===&lt;br /&gt;
The standard [http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html HTTP methods] are as follows&amp;lt;ref&amp;gt;https://cherrypy.readthedocs.org/en/3.3.0/progguide/REST.html#manipulation-of-resources-through-representations&amp;lt;/ref&amp;gt;&lt;br /&gt;
*&amp;lt;code&amp;gt;GET&amp;lt;/code&amp;gt; retrieves the state of a specific resource&lt;br /&gt;
*&amp;lt;code&amp;gt;PUT&amp;lt;/code&amp;gt; creates or replaces the state of a specific resource&lt;br /&gt;
*&amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt; passes information to a resource to use as it sees fit&lt;br /&gt;
*&amp;lt;code&amp;gt;DELETE&amp;lt;/code&amp;gt; removes resources&lt;br /&gt;
&lt;br /&gt;
===Self-Descriptive Messages===&lt;br /&gt;
REST requires messages to be self-descriptive, meaning everything about a message is within the message itself. Such information can be found in the method headers or the definitions of the message’s media type. cherrypy.request.headers and cherrypy.response.headers are used to get this information. Custom-Types are allowed as well.&amp;lt;ref&amp;gt;https://cherrypy.readthedocs.org/en/3.3.0/progguide/REST.html#self-descriptive-messages&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Hypermedia as the Engine of the Application State===&lt;br /&gt;
Since REST is stateless and the state is maintained by the application in question, sessions are not maintained by REST, so, by association, CherryPy does not enable sessions by default. However, the REST server helps clients maintain a meaningful state through meaningful URIs&amp;lt;ref&amp;gt;https://cherrypy.readthedocs.org/en/3.3.0/progguide/REST.html#hypermedia-as-the-engine-of-application-state&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Crash Course==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Development===&lt;br /&gt;
Create an application. Application requirements: &lt;br /&gt;
*The module needs to define a &amp;lt;code&amp;gt;__main__ &amp;lt;/code&amp;gt;&lt;br /&gt;
*&amp;lt;code&amp;gt;cherrypy.quickstart(&amp;lt;Application Name&amp;gt;())&amp;lt;/code&amp;gt; for hosting a single application. For example: cherrypy.quickstart(Blog())&lt;br /&gt;
*&amp;lt;code&amp;gt;cherrypy.tree.mount(&amp;lt;Application Name&amp;gt;(), ‘/&amp;lt;hosting path segment&amp;gt;’, &amp;lt;configuration&amp;gt;)&amp;lt;/code&amp;gt; for hosting multiple applications. For example: &amp;lt;code&amp;gt;cherrypy.tree.mount(Blog(), ‘/blog’, blog_conf) &amp;lt;/code&amp;gt;&lt;br /&gt;
*All parts the users will see must be exposed with either the decorator &amp;lt;code&amp;gt;@cherrypy.expose or attribues exposed = True&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;route.exposed = True.&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
class HelloWorld(object):&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return “Hello World!”&lt;br /&gt;
    index.exposed = True&lt;br /&gt;
if __name__ == ‘__main__’:&lt;br /&gt;
    cherrypy.quickstart(HelloWorld())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Deployment===&lt;br /&gt;
The application can be run as a python script in the Python interpreter.&lt;br /&gt;
    $ python &amp;lt;app file&amp;gt;.py&lt;br /&gt;
It will hosted at http://127.0.0.1:8080/&lt;br /&gt;
It can also be run as a daemon process with&lt;br /&gt;
    $cherryd -c &amp;lt;config file&amp;gt; -d -p &amp;lt;PID file&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Extensions==&lt;br /&gt;
&lt;br /&gt;
CherryPy provides a flexible open framework. Similar to [http://en.wikipedia.org/wiki/RubyGems RubyGems] in [http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] which add a range of functionality to the framework CherryPy also supports plugins in the the following forms&lt;br /&gt;
&lt;br /&gt;
===Server Wide Functions (Plugins)===&lt;br /&gt;
This type of extension is typically used to provide the application server itself with additional functionality. Such functions are executed with respect to events in the server even when there is no client request processing taking place.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/extend.html#id13&amp;lt;/ref&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
Typical use case involve&lt;br /&gt;
*Background Tasks (Tasks which involve server mentainance, data management etc. which are independent of user requests)&lt;br /&gt;
*External Connections (For establishing and maintaining threaded connections to external database or other servers)&lt;br /&gt;
*Delayed/Queued Processing (Cases when certain tasks are required by the user request which take a long time process and the HTTP response should not be blocked.)&amp;lt;br/&amp;gt;&lt;br /&gt;
These function utilize the [http://en.wikipedia.org/wiki/Publish–subscribe_pattern Publish-Subscribe Framework] implementation of CherryPy. Each function subscribes to one or more events on the bus which are published by the CherryPy engine.&amp;lt;br/&amp;gt; The database connection is a good example of such a function&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# import the Handles&lt;br /&gt;
import MySQLdb&lt;br /&gt;
import cherrypy&lt;br /&gt;
# defining the connection function&lt;br /&gt;
def connect(thread_index): &lt;br /&gt;
    # Create a connection and store it in the current thread &lt;br /&gt;
    cherrypy.thread_data.db = MySQLdb.connect('host', 'user', 'password', 'dbname')&lt;br /&gt;
&lt;br /&gt;
# tell cherrypy to  call connect function for each thread&lt;br /&gt;
cherrypy.engine.subscribe('start_thread', connect)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here the function connect subscribes to the &amp;lt;code&amp;gt;start_thread&amp;lt;/code&amp;gt; channel. An event is published on the &amp;lt;code&amp;gt;start_thread&amp;lt;/code&amp;gt; channel whenever a server thread is started. Here &amp;lt;code&amp;gt;engine&amp;lt;/code&amp;gt; is the central bus of the CherryPy server.&amp;lt;br/&amp;gt;&lt;br /&gt;
Similarly it is also possible to create new channels and even buses themselves.&lt;br /&gt;
&lt;br /&gt;
===Per-Request Functions (Tools)===&lt;br /&gt;
This type of extension is typically used to insert functionality between stages of request processing. Also known as [http://docs.cherrypy.org/en/latest/extend.html#tools Tools] these are simple call-back functions registered with a [http://docs.cherrypy.org/en/latest/extend.html#hookpoint Hook Point]. Hook Points are predefined stages of request processing. CherryPy provides a [http://tools.cherrypy.org/ Default ToolBox] containing many tools. Users have the freedom to create their own tools and add them to the default toolbox or create a new one.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/extend.html#per-request-functions&amp;lt;/ref&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
An example for creating a tool&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# defining the function to be called&lt;br /&gt;
def my_tool():&lt;br /&gt;
    # put tool functunality here&lt;br /&gt;
    print (“Super Amazing Tool”);&lt;br /&gt;
&lt;br /&gt;
# creating the decorator for the tool&lt;br /&gt;
# specifying the hook point and function to be called&lt;br /&gt;
cherrypy.tools.mytool = cherrypy.Tool(‘on_end_request’, my_tool())&lt;br /&gt;
&lt;br /&gt;
#Sample Usage&lt;br /&gt;
&lt;br /&gt;
class Root(object):&lt;br /&gt;
@cherrypy.expose()&lt;br /&gt;
@cherrypy.tools.mytool()&lt;br /&gt;
def index()&lt;br /&gt;
    return “Hello World”&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Watch It In Action==&lt;br /&gt;
&lt;br /&gt;
CherryPy is used as a building block for [http://www.hulu.com/ Hulu]&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu&amp;lt;/ref&amp;gt; and [https://www.netflix.com/ Netflix]&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Additional Instructions==&lt;br /&gt;
&lt;br /&gt;
===Install via yum===&lt;br /&gt;
CherryPy is provided by the fedora base repository. In [http://en.wikipedia.org/wiki/Fedora_%28operating_system%29 Fedora] (and other [http://en.wikipedia.org/wiki/RPM_Package_Manager RPM] based Linux distributions, such as [http://en.wikipedia.org/wiki/CentOS CentOS] and [http://en.wikipedia.org/wiki/Red_Hat_Enterprise_Linux Red Hat Enterprise Linux]):&amp;lt;br/&amp;gt;&lt;br /&gt;
    $ yum install python-cherrypy&lt;br /&gt;
&lt;br /&gt;
===Install via apt-get=== &lt;br /&gt;
CherryPy is also provided in the [http://en.wikipedia.org/wiki/Ubuntu_(operating_system) Ubuntu] base repository. In Ubuntu (and other [http://en.wikipedia.org/wiki/Debian Debian]-based Linux distributions such as Debian and [http://en.wikipedia.org/wiki/Linux_Mint Linux Mint]):&lt;br /&gt;
    $ apt-get install python python-dev&lt;br /&gt;
&lt;br /&gt;
===Installation from source===&lt;br /&gt;
The source code is hosted on [http://en.wikipedia.org/wiki/Bitbucket BitBucket] and requires [http://en.wikipedia.org/wiki/Mercurial Mercurial] to pull and install from the site itself.&lt;br /&gt;
    $ hg clone https://bitbucket.org/cherrypy/cherrypy&lt;br /&gt;
    $ cd cherrypy&lt;br /&gt;
    $ python setup.py install&lt;br /&gt;
&lt;br /&gt;
Alternatively, the source can be manually downloaded from [https://bitbucket.org/cherrypy/cherrypy/downloads here] in a tarball.&lt;br /&gt;
    $ tar -xvf CherryPy-#.#.#.tar.gz&lt;br /&gt;
    $ cd CherryPy-#.#.#&lt;br /&gt;
    $ python setup.py install&lt;br /&gt;
&lt;br /&gt;
===Install for Windows===&lt;br /&gt;
*If you are using Windows, install Linux and follow any of the a forementioned methods.&lt;br /&gt;
*If you absolutely must use windows, you can download the .exe file to install CherryPy from [https://bitbucket.org/cherrypy/cherrypy/downloads here].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Cehaith2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_cp&amp;diff=88172</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 cp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_cp&amp;diff=88172"/>
		<updated>2014-09-24T20:44:24Z</updated>

		<summary type="html">&lt;p&gt;Cehaith2: /* Multiple Applications */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;='''CherryPy'''=&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
[http://www.cherrypy.org/ CherryPy] is an [http://en.wikipedia.org/wiki/Object-oriented_programming Object-Oriented] [http://en.wikipedia.org/wiki/Web_application_framework Web Application Framework] meant to be [http://en.wikipedia.org/wiki/Python_%28programming_language%29 Python]-like (sparse and clean code).&amp;lt;br/&amp;gt;&lt;br /&gt;
It is important to note that it is not a complete stack such as [http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails], [http://en.wikipedia.org/wiki/Laravel Laravel], or [http://en.wikipedia.org/wiki/Django Django]. Complete stack web frameworks offer frontend utilities and storage communications along with other abilities. These aspects that make the frameworks so powerful, however, also contribute to the framework being bulky making development of small web applications such as blogs a bit cumbersome. CherryPy instead prefers to defer decisions such as storage management and interface utilities to the developer &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/intro.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
Because CherryPy is nothing more than a Python library, it needs a Python environment (Python 2.3 through to 3.4) and can also run on various implementations of Python including [http://en.wikipedia.org/wiki/IronPython IronPython] for [http://en.wikipedia.org/wiki/.NET_Framework .NET]  and [http://en.wikipedia.org/wiki/Jython Jython] for [http://en.wikipedia.org/wiki/Java_%28programming_language%29 Java].&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/install.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Requirements===&lt;br /&gt;
CherryPy requires a Python version between 2.3 and 3.4 inclusively. Certain features require packages but none are mandatory for installation.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/install.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[http://routes.readthedocs.org/en/latest/ routes] for declarative URL mapping dispatcher&lt;br /&gt;
*[http://pythonhosted.org//psycopg2/ psycopg2] for [http://en.wikipedia.org/wiki/PostgreSQL PostgreSQL] database backend session&lt;br /&gt;
*[http://sourceforge.net/projects/pywin32/ pywin32] for Windows services&lt;br /&gt;
*[https://github.com/linsomniac/python-memcached python-memcached] for [http://en.wikipedia.org/wiki/Memcached Memcached] backend session&lt;br /&gt;
*[https://github.com/simplejson/simplejson simplejson] for a better [http://en.wikipedia.org/wiki/JSON JSON] support&lt;br /&gt;
*[https://github.com/pyca/pyopenssl pyOpenSSL] if your Python environment does not have the built in [http://en.wikipedia.org/wiki/Transport_Layer_Security ssl] module&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Installing===&lt;br /&gt;
CherryPy can be installed through common Python package managers with the following commands:&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/install.html&amp;lt;/ref&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Install (choose on of the following commands appropriately):&lt;br /&gt;
    $ easy_install cherrypy&lt;br /&gt;
    $ pip install cherrypy&lt;br /&gt;
    $ yum install python-cherrypy&lt;br /&gt;
    $ apt-get install python python-dev&lt;br /&gt;
&lt;br /&gt;
Refer [[#Additional Installation Instructions| Additional Instructions]] for more details.&lt;br /&gt;
&lt;br /&gt;
==Interface==&lt;br /&gt;
&lt;br /&gt;
CherryPy is meant to be pythonic, meaning that development time  is meant to be minimized and code is meant to be sparse and clean &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/intro.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Basic Example===&lt;br /&gt;
Lets look at a hello world example&amp;lt;ref&amp;gt;https://cherrypy.readthedocs.org/en/3.2.6/concepts/basics.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/419163/what-does-if-name-main-do&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Use the cherrypy python library&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
#Hello World project&lt;br /&gt;
class HelloWorld(object):&lt;br /&gt;
&lt;br /&gt;
#   index page&lt;br /&gt;
    def index(self):&lt;br /&gt;
#       Return the page contents&lt;br /&gt;
        return “Hello World!”&lt;br /&gt;
&lt;br /&gt;
#   Allow the page to be visible&lt;br /&gt;
    index.exposed = True&lt;br /&gt;
&lt;br /&gt;
#designates this module as main&lt;br /&gt;
if __name__ == ‘__main__’:&lt;br /&gt;
&lt;br /&gt;
#   instantiates app and starts server&lt;br /&gt;
    cherrypy.quickstart(HelloWorld())&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The above script sets up a basic Hello World application, by defining the index page (http://localhost:8080/) as an object that returns the string “Hello World!”. The page is exposed, meaning that the method can be called to answer a [http://en.wikipedia.org/wiki/Representational_state_transfer RESTful] request. Otherwise, the method is internal only. This is similar to making a method public in Java. &amp;lt;ref&amp;gt;http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Routing, Parameters, and Exposure===&lt;br /&gt;
Routing is the act of finding the appropriate code to handle a request. CherryPy uses a dispatcher to perform most of these, but premade dispatchers exist to handle more sophisticated handling of request. The most common is a page handler (the name of the object). Parameters can be passed into the handler via http query strings. These strings are appended to the URL of a site after a &amp;quot;?&amp;quot;. Exposure is just the way CherryPy prevents access to objects from the users. Without the exposed attribute set to true, an object won't be accessible to the user.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#import python library&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
#More Routes application&lt;br /&gt;
class MoreRoutes(object):&lt;br /&gt;
&lt;br /&gt;
#   Method decorator for index and equates to index.exposed = True&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#   http://localhost:8080/route1&lt;br /&gt;
    def route1(self, id=”charles”):&lt;br /&gt;
#       http://localhost:8080/route1?id=somestring&lt;br /&gt;
        return “Your name is ” + id&lt;br /&gt;
&lt;br /&gt;
#   Params passed as a GET request.&lt;br /&gt;
#   Default string is “charles”&lt;br /&gt;
    route1.exposed = True&lt;br /&gt;
&lt;br /&gt;
#   No explicit indication of exposure so calling this route will generate a 404 error&lt;br /&gt;
    def route2(self):&lt;br /&gt;
        return “Still another one”&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    cherrypy.quickstart(MoreRoutes())&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above shows how multiple routes are handled from the Hello World application and the expose decorator. Since route2 is not exposed, the user can not access it and will be shown a 404 HTTP status code (Not Found error).&lt;br /&gt;
&lt;br /&gt;
===Multiple Applications=== &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
#blog module&lt;br /&gt;
class Blog(object):&lt;br /&gt;
    ...&amp;lt;blog code&amp;gt;...&lt;br /&gt;
#forum module&lt;br /&gt;
class Forum(object):&lt;br /&gt;
    ...&amp;lt;forum code&amp;gt;...&lt;br /&gt;
#”main” method&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
#designates the blog to be under /blog route&lt;br /&gt;
    cherrypy.tree.mount(Blog(), ‘/blog’, “blog.conf”)&lt;br /&gt;
#designates the forum to be under /forum route&lt;br /&gt;
    cherrypy.tree.mount(Forum(), ‘/forum’, “forum.conf”)&lt;br /&gt;
&amp;lt;/pre&amp;gt; &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/basics.html#multiple-applications&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the above example, the blog would be found under /blog in the URL, wheras the forum will be mounted at /forum in the application tree. The XXX.conf files are configuration files, which are dictionaries containing string keys and polymorphic values and can be used to set attributes on the engine, server, request, response, and log objects. &amp;lt;ref&amp;gt;https://cherrypy.readthedocs.org/en/3.2.6/concepts/config.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Database Support===&lt;br /&gt;
CherryPy offers multiple database integration possibilities including&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Relational_database Relational]: [http://en.wikipedia.org/wiki/PostgreSQL PostgreSQL], [http://en.wikipedia.org/wiki/SQLite SQLite], [http://en.wikipedia.org/wiki/MariaDB MariaDB], [http://en.wikipedia.org/wiki/Firebird_%28database_server%29 Firebird]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Column-oriented_DBMS Column-Oriented]: [http://en.wikipedia.org/wiki/Apache_HBase HBase], [http://en.wikipedia.org/wiki/Apache_Cassandra Cassandra]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/NoSQL#Key.E2.80.93value_stores Key-Store]: [http://en.wikipedia.org/wiki/Redis Redis], [http://en.wikipedia.org/wiki/Memcached Memcached]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Document-oriented_database Document-Oriented]: [http://en.wikipedia.org/wiki/CouchDB Couchdb], [http://en.wikipedia.org/wiki/MongoDB MongoDB]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Graph_database Graph-Oriented]: [http://en.wikipedia.org/wiki/Neo4j Neo4j]&amp;lt;br/&amp;gt;&lt;br /&gt;
Unfortunately, unlike [https://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails], CherryPy does not have a sophisticated [https://en.wikipedia.org/wiki/Active_record_pattern#Ruby Active Record Pattern] based class for database abstraction, and the database connection has to be established manually. The queries are constructed as static [https://en.wikipedia.org/wiki/SQL SQL] strings with values concatenated during function calls.&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example of how it would look like&amp;lt;ref&amp;gt;http://cherrypy.readthedocs.org/en/latest/tutorials.html#tutorial-9-data-is-all-my-life&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# import the Handles&lt;br /&gt;
import MySQLdb&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
# defining the connection function&lt;br /&gt;
def connect(thread_index):&lt;br /&gt;
#   Create a connection and store it in the current thread&lt;br /&gt;
    cherrypy.thread_data.db = MySQLdb.connect('host', 'user', 'password', 'dbname')&lt;br /&gt;
&lt;br /&gt;
# tell cherrypy to  call connect function for each thread&lt;br /&gt;
cherrypy.engine.subscribe('start_thread', connect)&lt;br /&gt;
&lt;br /&gt;
# example query function&lt;br /&gt;
@cherrypy.expose&lt;br /&gt;
def count(val)&lt;br /&gt;
#   fetching instance of db connection&lt;br /&gt;
    c = cherrypy.thread_data.db.cursor()&lt;br /&gt;
#   executing query&lt;br /&gt;
    c.execute( 'select count(‘ + val + ’) from table' )&lt;br /&gt;
#   fetching results from db&lt;br /&gt;
    res = c.fetchone()&lt;br /&gt;
#   releasing instance of the connection&lt;br /&gt;
    c.close()&lt;br /&gt;
#   returning the count value&lt;br /&gt;
    return res&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==RESTful CherryPy==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Representational_state_transfer REST] (Representational State Transfer) is an abstraction of the architectural elements within a distributed hypermedia system. It ignores the details of component implementation and protocol syntax in order to focus on the roles of components, the constraints upon their interaction with other components, and their interpretation of significant data elements. It encompasses the fundamental constraints upon components, connectors, and data that define the basis of the Web architecture, and thus the essence of its behavior as a network-based application. &amp;lt;ref&amp;gt;http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm&amp;lt;/ref&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
In othe words, REST is defined by four interface constraints: identification of resources, manipulation of resources through representations, self-descriptive messages, and hypermedia as the engine of application state.&amp;lt;ref&amp;gt;https://cherrypy.readthedocs.org/en/3.2.6/progguide/REST.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Identification of Resources===&lt;br /&gt;
Since Cherrypy is an HTTP service provider, resources are referenced by HTTP URIs (Uniform Resource Identifiers), which consist of a scheme, hierarchical identitfier, query, and fragment.&amp;lt;ref&amp;gt;https://cherrypy.readthedocs.org/en/3.3.0/progguide/REST.html#implementing-rest-in-cherrypy&amp;lt;/ref&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
*Scheme: in [http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol http], the scheme is always http or [http://en.wikipedia.org/wiki/HTTP_Secure https].&lt;br /&gt;
*Hierarchical Identifier: consists of an authority and a path (host/port and a path similar to the system file path but not the actual path). The path is mapped to Python Objects via a dispatch mechanism.&lt;br /&gt;
&lt;br /&gt;
===Manipulation of Resources Through Representations===&lt;br /&gt;
The standard [http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html HTTP methods] are as follows&amp;lt;ref&amp;gt;https://cherrypy.readthedocs.org/en/3.3.0/progguide/REST.html#manipulation-of-resources-through-representations&amp;lt;/ref&amp;gt;&lt;br /&gt;
*&amp;lt;code&amp;gt;GET&amp;lt;/code&amp;gt; retrieves the state of a specific resource&lt;br /&gt;
*&amp;lt;code&amp;gt;PUT&amp;lt;/code&amp;gt; creates or replaces the state of a specific resource&lt;br /&gt;
*&amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt; passes information to a resource to use as it sees fit&lt;br /&gt;
*&amp;lt;code&amp;gt;DELETE&amp;lt;/code&amp;gt; removes resources&lt;br /&gt;
&lt;br /&gt;
===Self-Descriptive Messages===&lt;br /&gt;
REST requires messages to be self-descriptive, meaning everything about a message is within the message itself. Such information can be found in the method headers or the definitions of the message’s media type. cherrypy.request.headers and cherrypy.response.headers are used to get this information. Custom-Types are allowed as well.&amp;lt;ref&amp;gt;https://cherrypy.readthedocs.org/en/3.3.0/progguide/REST.html#self-descriptive-messages&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Hypermedia as the Engine of the Application State===&lt;br /&gt;
Since REST is stateless and the state is maintained by the application in question, sessions are not maintained by REST, so, by association, CherryPy does not enable sessions by default. However, the REST server helps clients maintain a meaningful state through meaningful URIs&amp;lt;ref&amp;gt;https://cherrypy.readthedocs.org/en/3.3.0/progguide/REST.html#hypermedia-as-the-engine-of-application-state&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Crash Course==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Development===&lt;br /&gt;
Create an application. Application requirements: &lt;br /&gt;
*The module needs to define a &amp;lt;code&amp;gt;__main__ &amp;lt;/code&amp;gt;&lt;br /&gt;
*&amp;lt;code&amp;gt;cherrypy.quickstart(&amp;lt;Application Name&amp;gt;())&amp;lt;/code&amp;gt; for hosting a single application. For example: cherrypy.quickstart(Blog())&lt;br /&gt;
*&amp;lt;code&amp;gt;cherrypy.tree.mount(&amp;lt;Application Name&amp;gt;(), ‘/&amp;lt;hosting path segment&amp;gt;’, &amp;lt;configuration&amp;gt;)&amp;lt;/code&amp;gt; for hosting multiple applications. For example: &amp;lt;code&amp;gt;cherrypy.tree.mount(Blog(), ‘/blog’, blog_conf) &amp;lt;/code&amp;gt;&lt;br /&gt;
*All parts the users will see must be exposed with either the decorator &amp;lt;code&amp;gt;@cherrypy.expose or attribues exposed = True&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;route.exposed = True.&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
class HelloWorld(object):&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return “Hello World!”&lt;br /&gt;
    index.exposed = True&lt;br /&gt;
if __name__ == ‘__main__’:&lt;br /&gt;
    cherrypy.quickstart(HelloWorld())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Deployment===&lt;br /&gt;
The application can be run as a python script in the Python interpreter.&lt;br /&gt;
    $ python &amp;lt;app file&amp;gt;.py&lt;br /&gt;
It will hosted at http://127.0.0.1:8080/&lt;br /&gt;
It can also be run as a daemon process with&lt;br /&gt;
    $cherryd -c &amp;lt;config file&amp;gt; -d -p &amp;lt;PID file&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Extensions==&lt;br /&gt;
&lt;br /&gt;
CherryPy provides a flexible open framework. Similar to [http://en.wikipedia.org/wiki/RubyGems RubyGems] in [http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] which add a range of functionality to the framework CherryPy also supports plugins in the the following forms&lt;br /&gt;
&lt;br /&gt;
===Server Wide Functions (Plugins)===&lt;br /&gt;
This type of extension is typically used to provide the application server itself with additional functionality. Such functions are executed with respect to events in the server even when there is no client request processing taking place.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/extend.html#id13&amp;lt;/ref&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
Typical use case involve&lt;br /&gt;
*Background Tasks (Tasks which involve server mentainance, data management etc. which are independent of user requests)&lt;br /&gt;
*External Connections (For establishing and maintaining threaded connections to external database or other servers)&lt;br /&gt;
*Delayed/Queued Processing (Cases when certain tasks are required by the user request which take a long time process and the HTTP response should not be blocked.)&amp;lt;br/&amp;gt;&lt;br /&gt;
These function utilize the [http://en.wikipedia.org/wiki/Publish–subscribe_pattern Publish-Subscribe Framework] implementation of CherryPy. Each function subscribes to one or more events on the bus which are published by the CherryPy engine.&amp;lt;br/&amp;gt; The database connection is a good example of such a function&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# import the Handles&lt;br /&gt;
import MySQLdb&lt;br /&gt;
import cherrypy&lt;br /&gt;
# defining the connection function&lt;br /&gt;
def connect(thread_index): &lt;br /&gt;
    # Create a connection and store it in the current thread &lt;br /&gt;
    cherrypy.thread_data.db = MySQLdb.connect('host', 'user', 'password', 'dbname')&lt;br /&gt;
&lt;br /&gt;
# tell cherrypy to  call connect function for each thread&lt;br /&gt;
cherrypy.engine.subscribe('start_thread', connect)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here the function connect subscribes to the &amp;lt;code&amp;gt;start_thread&amp;lt;/code&amp;gt; channel. An event is published on the &amp;lt;code&amp;gt;start_thread&amp;lt;/code&amp;gt; channel whenever a server thread is started. Here &amp;lt;code&amp;gt;engine&amp;lt;/code&amp;gt; is the central bus of the CherryPy server.&amp;lt;br/&amp;gt;&lt;br /&gt;
Similarly it is also possible to create new channels and even buses themselves.&lt;br /&gt;
&lt;br /&gt;
===Per-Request Functions (Tools)===&lt;br /&gt;
This type of extension is typically used to insert functionality between stages of request processing. Also known as [http://docs.cherrypy.org/en/latest/extend.html#tools Tools] these are simple call-back functions registered with a [http://docs.cherrypy.org/en/latest/extend.html#hookpoint Hook Point]. Hook Points are predefined stages of request processing. CherryPy provides a [http://tools.cherrypy.org/ Default ToolBox] containing many tools. Users have the freedom to create their own tools and add them to the default toolbox or create a new one.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/extend.html#per-request-functions&amp;lt;/ref&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
An example for creating a tool&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# defining the function to be called&lt;br /&gt;
def my_tool():&lt;br /&gt;
    # put tool functunality here&lt;br /&gt;
    print (“Super Amazing Tool”);&lt;br /&gt;
&lt;br /&gt;
# creating the decorator for the tool&lt;br /&gt;
# specifying the hook point and function to be called&lt;br /&gt;
cherrypy.tools.mytool = cherrypy.Tool(‘on_end_request’, my_tool())&lt;br /&gt;
&lt;br /&gt;
#Sample Usage&lt;br /&gt;
&lt;br /&gt;
class Root(object):&lt;br /&gt;
@cherrypy.expose()&lt;br /&gt;
@cherrypy.tools.mytool()&lt;br /&gt;
def index()&lt;br /&gt;
    return “Hello World”&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Watch It In Action==&lt;br /&gt;
&lt;br /&gt;
CherryPy is used as a building block for [http://www.hulu.com/ Hulu]&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu&amp;lt;/ref&amp;gt; and [https://www.netflix.com/ Netflix]&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Additional Instructions==&lt;br /&gt;
&lt;br /&gt;
===Install via yum===&lt;br /&gt;
CherryPy is provided by the fedora base repository. In [http://en.wikipedia.org/wiki/Fedora_%28operating_system%29 Fedora] (and other [http://en.wikipedia.org/wiki/RPM_Package_Manager RPM] based Linux distributions, such as [http://en.wikipedia.org/wiki/CentOS CentOS] and [http://en.wikipedia.org/wiki/Red_Hat_Enterprise_Linux Red Hat Enterprise Linux]):&amp;lt;br/&amp;gt;&lt;br /&gt;
    $ yum install python-cherrypy&lt;br /&gt;
&lt;br /&gt;
===Install via apt-get=== &lt;br /&gt;
CherryPy is also provided in the [http://en.wikipedia.org/wiki/Ubuntu_(operating_system) Ubuntu] base repository. In Ubuntu (and other [http://en.wikipedia.org/wiki/Debian Debian]-based Linux distributions such as Debian and [http://en.wikipedia.org/wiki/Linux_Mint Linux Mint]):&lt;br /&gt;
    $ apt-get install python python-dev&lt;br /&gt;
&lt;br /&gt;
===Installation from source===&lt;br /&gt;
The source code is hosted on [http://en.wikipedia.org/wiki/Bitbucket BitBucket] and requires [http://en.wikipedia.org/wiki/Mercurial Mercurial] to pull and install from the site itself.&lt;br /&gt;
    $ hg clone https://bitbucket.org/cherrypy/cherrypy&lt;br /&gt;
    $ cd cherrypy&lt;br /&gt;
    $ python setup.py install&lt;br /&gt;
&lt;br /&gt;
Alternatively, the source can be manually downloaded from [https://bitbucket.org/cherrypy/cherrypy/downloads here] in a tarball.&lt;br /&gt;
    $ tar -xvf CherryPy-#.#.#.tar.gz&lt;br /&gt;
    $ cd CherryPy-#.#.#&lt;br /&gt;
    $ python setup.py install&lt;br /&gt;
&lt;br /&gt;
===Install for Windows===&lt;br /&gt;
*If you are using Windows, install Linux and follow any of the a forementioned methods.&lt;br /&gt;
*If you absolutely must use windows, you can download the .exe file to install CherryPy from [https://bitbucket.org/cherrypy/cherrypy/downloads here].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Cehaith2</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_cp&amp;diff=88171</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 cp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_cp&amp;diff=88171"/>
		<updated>2014-09-24T20:20:21Z</updated>

		<summary type="html">&lt;p&gt;Cehaith2: /* CherryPy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;='''CherryPy'''=&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
[http://www.cherrypy.org/ CherryPy] is an [http://en.wikipedia.org/wiki/Object-oriented_programming Object-Oriented] [http://en.wikipedia.org/wiki/Web_application_framework Web Application Framework] meant to be [http://en.wikipedia.org/wiki/Python_%28programming_language%29 Python]-like (sparse and clean code).&amp;lt;br/&amp;gt;&lt;br /&gt;
It is important to note that it is not a complete stack such as [http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails], [http://en.wikipedia.org/wiki/Laravel Laravel], or [http://en.wikipedia.org/wiki/Django Django]. Complete stack web frameworks offer frontend utilities and storage communications along with other abilities. These aspects that make the frameworks so powerful, however, also contribute to the framework being bulky making development of small web applications such as blogs a bit cumbersome. CherryPy instead prefers to defer decisions such as storage management and interface utilities to the developer &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/intro.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Installation==&lt;br /&gt;
&lt;br /&gt;
===Overview===&lt;br /&gt;
Because CherryPy is nothing more than a Python library, it needs a Python environment (Python 2.3 through to 3.4) and can also run on various implementations of Python including [http://en.wikipedia.org/wiki/IronPython IronPython] for [http://en.wikipedia.org/wiki/.NET_Framework .NET]  and [http://en.wikipedia.org/wiki/Jython Jython] for [http://en.wikipedia.org/wiki/Java_%28programming_language%29 Java].&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/install.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Requirements===&lt;br /&gt;
CherryPy requires a Python version between 2.3 and 3.4 inclusively. Certain features require packages but none are mandatory for installation.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/install.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
*[http://routes.readthedocs.org/en/latest/ routes] for declarative URL mapping dispatcher&lt;br /&gt;
*[http://pythonhosted.org//psycopg2/ psycopg2] for [http://en.wikipedia.org/wiki/PostgreSQL PostgreSQL] database backend session&lt;br /&gt;
*[http://sourceforge.net/projects/pywin32/ pywin32] for Windows services&lt;br /&gt;
*[https://github.com/linsomniac/python-memcached python-memcached] for [http://en.wikipedia.org/wiki/Memcached Memcached] backend session&lt;br /&gt;
*[https://github.com/simplejson/simplejson simplejson] for a better [http://en.wikipedia.org/wiki/JSON JSON] support&lt;br /&gt;
*[https://github.com/pyca/pyopenssl pyOpenSSL] if your Python environment does not have the built in [http://en.wikipedia.org/wiki/Transport_Layer_Security ssl] module&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Installing===&lt;br /&gt;
CherryPy can be installed through common Python package managers with the following commands:&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/install.html&amp;lt;/ref&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Install (choose on of the following commands appropriately):&lt;br /&gt;
    $ easy_install cherrypy&lt;br /&gt;
    $ pip install cherrypy&lt;br /&gt;
    $ yum install python-cherrypy&lt;br /&gt;
    $ apt-get install python python-dev&lt;br /&gt;
&lt;br /&gt;
Refer [[#Additional Installation Instructions| Additional Instructions]] for more details.&lt;br /&gt;
&lt;br /&gt;
==Interface==&lt;br /&gt;
&lt;br /&gt;
CherryPy is meant to be pythonic, meaning that development time  is meant to be minimized and code is meant to be sparse and clean &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/intro.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Basic Example===&lt;br /&gt;
Lets look at a hello world example&amp;lt;ref&amp;gt;https://cherrypy.readthedocs.org/en/3.2.6/concepts/basics.html&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://stackoverflow.com/questions/419163/what-does-if-name-main-do&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#Use the cherrypy python library&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
#Hello World project&lt;br /&gt;
class HelloWorld(object):&lt;br /&gt;
&lt;br /&gt;
#   index page&lt;br /&gt;
    def index(self):&lt;br /&gt;
#       Return the page contents&lt;br /&gt;
        return “Hello World!”&lt;br /&gt;
&lt;br /&gt;
#   Allow the page to be visible&lt;br /&gt;
    index.exposed = True&lt;br /&gt;
&lt;br /&gt;
#designates this module as main&lt;br /&gt;
if __name__ == ‘__main__’:&lt;br /&gt;
&lt;br /&gt;
#   instantiates app and starts server&lt;br /&gt;
    cherrypy.quickstart(HelloWorld())&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The above script sets up a basic Hello World application, by defining the index page (http://localhost:8080/) as an object that returns the string “Hello World!”. The page is exposed, meaning that the method can be called to answer a [http://en.wikipedia.org/wiki/Representational_state_transfer RESTful] request. Otherwise, the method is internal only. This is similar to making a method public in Java. &amp;lt;ref&amp;gt;http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Routing, Parameters, and Exposure===&lt;br /&gt;
Routing is the act of finding the appropriate code to handle a request. CherryPy uses a dispatcher to perform most of these, but premade dispatchers exist to handle more sophisticated handling of request. The most common is a page handler (the name of the object). Parameters can be passed into the handler via http query strings. These strings are appended to the URL of a site after a &amp;quot;?&amp;quot;. Exposure is just the way CherryPy prevents access to objects from the users. Without the exposed attribute set to true, an object won't be accessible to the user.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#import python library&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
#More Routes application&lt;br /&gt;
class MoreRoutes(object):&lt;br /&gt;
&lt;br /&gt;
#   Method decorator for index and equates to index.exposed = True&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello world!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#   http://localhost:8080/route1&lt;br /&gt;
    def route1(self, id=”charles”):&lt;br /&gt;
#       http://localhost:8080/route1?id=somestring&lt;br /&gt;
        return “Your name is ” + id&lt;br /&gt;
&lt;br /&gt;
#   Params passed as a GET request.&lt;br /&gt;
#   Default string is “charles”&lt;br /&gt;
    route1.exposed = True&lt;br /&gt;
&lt;br /&gt;
#   No explicit indication of exposure so calling this route will generate a 404 error&lt;br /&gt;
    def route2(self):&lt;br /&gt;
        return “Still another one”&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    cherrypy.quickstart(MoreRoutes())&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above shows how multiple routes are handled from the Hello World application and the expose decorator. Since route2 is not exposed, the user can not access it and will be shown a 404 HTTP status code (Not Found error).&lt;br /&gt;
&lt;br /&gt;
===Multiple Applications===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
#blog module&lt;br /&gt;
class Blog(object):&lt;br /&gt;
    ...&amp;lt;blog code&amp;gt;...&lt;br /&gt;
#forum module&lt;br /&gt;
class Forum(object):&lt;br /&gt;
    ...&amp;lt;forum code&amp;gt;...&lt;br /&gt;
#”main” method&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
#designates the blog to be under /blog route&lt;br /&gt;
    cherrypy.tree.mount(Blog(), ‘/blog’, “blog.conf”)&lt;br /&gt;
#designates the forum to be under /forum route&lt;br /&gt;
    cherrypy.tree.mount(Forum(), ‘/forum’, “forum.conf”)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/basics.html#multiple-applications&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Database Support===&lt;br /&gt;
CherryPy offers multiple database integration possibilities including&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Relational_database Relational]: [http://en.wikipedia.org/wiki/PostgreSQL PostgreSQL], [http://en.wikipedia.org/wiki/SQLite SQLite], [http://en.wikipedia.org/wiki/MariaDB MariaDB], [http://en.wikipedia.org/wiki/Firebird_%28database_server%29 Firebird]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Column-oriented_DBMS Column-Oriented]: [http://en.wikipedia.org/wiki/Apache_HBase HBase], [http://en.wikipedia.org/wiki/Apache_Cassandra Cassandra]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/NoSQL#Key.E2.80.93value_stores Key-Store]: [http://en.wikipedia.org/wiki/Redis Redis], [http://en.wikipedia.org/wiki/Memcached Memcached]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Document-oriented_database Document-Oriented]: [http://en.wikipedia.org/wiki/CouchDB Couchdb], [http://en.wikipedia.org/wiki/MongoDB MongoDB]&lt;br /&gt;
*[http://en.wikipedia.org/wiki/Graph_database Graph-Oriented]: [http://en.wikipedia.org/wiki/Neo4j Neo4j]&amp;lt;br/&amp;gt;&lt;br /&gt;
Unfortunately, unlike [https://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails], CherryPy does not have a sophisticated [https://en.wikipedia.org/wiki/Active_record_pattern#Ruby Active Record Pattern] based class for database abstraction, and the database connection has to be established manually. The queries are constructed as static [https://en.wikipedia.org/wiki/SQL SQL] strings with values concatenated during function calls.&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here is an example of how it would look like&amp;lt;ref&amp;gt;http://cherrypy.readthedocs.org/en/latest/tutorials.html#tutorial-9-data-is-all-my-life&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# import the Handles&lt;br /&gt;
import MySQLdb&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
# defining the connection function&lt;br /&gt;
def connect(thread_index):&lt;br /&gt;
#   Create a connection and store it in the current thread&lt;br /&gt;
    cherrypy.thread_data.db = MySQLdb.connect('host', 'user', 'password', 'dbname')&lt;br /&gt;
&lt;br /&gt;
# tell cherrypy to  call connect function for each thread&lt;br /&gt;
cherrypy.engine.subscribe('start_thread', connect)&lt;br /&gt;
&lt;br /&gt;
# example query function&lt;br /&gt;
@cherrypy.expose&lt;br /&gt;
def count(val)&lt;br /&gt;
#   fetching instance of db connection&lt;br /&gt;
    c = cherrypy.thread_data.db.cursor()&lt;br /&gt;
#   executing query&lt;br /&gt;
    c.execute( 'select count(‘ + val + ’) from table' )&lt;br /&gt;
#   fetching results from db&lt;br /&gt;
    res = c.fetchone()&lt;br /&gt;
#   releasing instance of the connection&lt;br /&gt;
    c.close()&lt;br /&gt;
#   returning the count value&lt;br /&gt;
    return res&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==RESTful CherryPy==&lt;br /&gt;
[http://en.wikipedia.org/wiki/Representational_state_transfer REST] (Representational State Transfer) is an abstraction of the architectural elements within a distributed hypermedia system. It ignores the details of component implementation and protocol syntax in order to focus on the roles of components, the constraints upon their interaction with other components, and their interpretation of significant data elements. It encompasses the fundamental constraints upon components, connectors, and data that define the basis of the Web architecture, and thus the essence of its behavior as a network-based application. &amp;lt;ref&amp;gt;http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm&amp;lt;/ref&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
In othe words, REST is defined by four interface constraints: identification of resources, manipulation of resources through representations, self-descriptive messages, and hypermedia as the engine of application state.&amp;lt;ref&amp;gt;https://cherrypy.readthedocs.org/en/3.2.6/progguide/REST.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Identification of Resources===&lt;br /&gt;
Since Cherrypy is an HTTP service provider, resources are referenced by HTTP URIs (Uniform Resource Identifiers), which consist of a scheme, hierarchical identitfier, query, and fragment.&amp;lt;ref&amp;gt;https://cherrypy.readthedocs.org/en/3.3.0/progguide/REST.html#implementing-rest-in-cherrypy&amp;lt;/ref&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
*Scheme: in [http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol http], the scheme is always http or [http://en.wikipedia.org/wiki/HTTP_Secure https].&lt;br /&gt;
*Hierarchical Identifier: consists of an authority and a path (host/port and a path similar to the system file path but not the actual path). The path is mapped to Python Objects via a dispatch mechanism.&lt;br /&gt;
&lt;br /&gt;
===Manipulation of Resources Through Representations===&lt;br /&gt;
The standard [http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html HTTP methods] are as follows&amp;lt;ref&amp;gt;https://cherrypy.readthedocs.org/en/3.3.0/progguide/REST.html#manipulation-of-resources-through-representations&amp;lt;/ref&amp;gt;&lt;br /&gt;
*&amp;lt;code&amp;gt;GET&amp;lt;/code&amp;gt; retrieves the state of a specific resource&lt;br /&gt;
*&amp;lt;code&amp;gt;PUT&amp;lt;/code&amp;gt; creates or replaces the state of a specific resource&lt;br /&gt;
*&amp;lt;code&amp;gt;POST&amp;lt;/code&amp;gt; passes information to a resource to use as it sees fit&lt;br /&gt;
*&amp;lt;code&amp;gt;DELETE&amp;lt;/code&amp;gt; removes resources&lt;br /&gt;
&lt;br /&gt;
===Self-Descriptive Messages===&lt;br /&gt;
REST requires messages to be self-descriptive, meaning everything about a message is within the message itself. Such information can be found in the method headers or the definitions of the message’s media type. cherrypy.request.headers and cherrypy.response.headers are used to get this information. Custom-Types are allowed as well.&amp;lt;ref&amp;gt;https://cherrypy.readthedocs.org/en/3.3.0/progguide/REST.html#self-descriptive-messages&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Hypermedia as the Engine of the Application State===&lt;br /&gt;
Since REST is stateless and the state is maintained by the application in question, sessions are not maintained by REST, so, by association, CherryPy does not enable sessions by default. However, the REST server helps clients maintain a meaningful state through meaningful URIs&amp;lt;ref&amp;gt;https://cherrypy.readthedocs.org/en/3.3.0/progguide/REST.html#hypermedia-as-the-engine-of-application-state&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Crash Course==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Development===&lt;br /&gt;
Create an application. Application requirements: &lt;br /&gt;
*The module needs to define a &amp;lt;code&amp;gt;__main__ &amp;lt;/code&amp;gt;&lt;br /&gt;
*&amp;lt;code&amp;gt;cherrypy.quickstart(&amp;lt;Application Name&amp;gt;())&amp;lt;/code&amp;gt; for hosting a single application. For example: cherrypy.quickstart(Blog())&lt;br /&gt;
*&amp;lt;code&amp;gt;cherrypy.tree.mount(&amp;lt;Application Name&amp;gt;(), ‘/&amp;lt;hosting path segment&amp;gt;’, &amp;lt;configuration&amp;gt;)&amp;lt;/code&amp;gt; for hosting multiple applications. For example: &amp;lt;code&amp;gt;cherrypy.tree.mount(Blog(), ‘/blog’, blog_conf) &amp;lt;/code&amp;gt;&lt;br /&gt;
*All parts the users will see must be exposed with either the decorator &amp;lt;code&amp;gt;@cherrypy.expose or attribues exposed = True&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;route.exposed = True.&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
class HelloWorld(object):&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return “Hello World!”&lt;br /&gt;
    index.exposed = True&lt;br /&gt;
if __name__ == ‘__main__’:&lt;br /&gt;
    cherrypy.quickstart(HelloWorld())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Deployment===&lt;br /&gt;
The application can be run as a python script in the Python interpreter.&lt;br /&gt;
    $ python &amp;lt;app file&amp;gt;.py&lt;br /&gt;
It will hosted at http://127.0.0.1:8080/&lt;br /&gt;
It can also be run as a daemon process with&lt;br /&gt;
    $cherryd -c &amp;lt;config file&amp;gt; -d -p &amp;lt;PID file&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Extensions==&lt;br /&gt;
&lt;br /&gt;
CherryPy provides a flexible open framework. Similar to [http://en.wikipedia.org/wiki/RubyGems RubyGems] in [http://en.wikipedia.org/wiki/Ruby_on_Rails Ruby on Rails] which add a range of functionality to the framework CherryPy also supports plugins in the the following forms&lt;br /&gt;
&lt;br /&gt;
===Server Wide Functions (Plugins)===&lt;br /&gt;
This type of extension is typically used to provide the application server itself with additional functionality. Such functions are executed with respect to events in the server even when there is no client request processing taking place.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/extend.html#id13&amp;lt;/ref&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
Typical use case involve&lt;br /&gt;
*Background Tasks (Tasks which involve server mentainance, data management etc. which are independent of user requests)&lt;br /&gt;
*External Connections (For establishing and maintaining threaded connections to external database or other servers)&lt;br /&gt;
*Delayed/Queued Processing (Cases when certain tasks are required by the user request which take a long time process and the HTTP response should not be blocked.)&amp;lt;br/&amp;gt;&lt;br /&gt;
These function utilize the [http://en.wikipedia.org/wiki/Publish–subscribe_pattern Publish-Subscribe Framework] implementation of CherryPy. Each function subscribes to one or more events on the bus which are published by the CherryPy engine.&amp;lt;br/&amp;gt; The database connection is a good example of such a function&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# import the Handles&lt;br /&gt;
import MySQLdb&lt;br /&gt;
import cherrypy&lt;br /&gt;
# defining the connection function&lt;br /&gt;
def connect(thread_index): &lt;br /&gt;
    # Create a connection and store it in the current thread &lt;br /&gt;
    cherrypy.thread_data.db = MySQLdb.connect('host', 'user', 'password', 'dbname')&lt;br /&gt;
&lt;br /&gt;
# tell cherrypy to  call connect function for each thread&lt;br /&gt;
cherrypy.engine.subscribe('start_thread', connect)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here the function connect subscribes to the &amp;lt;code&amp;gt;start_thread&amp;lt;/code&amp;gt; channel. An event is published on the &amp;lt;code&amp;gt;start_thread&amp;lt;/code&amp;gt; channel whenever a server thread is started. Here &amp;lt;code&amp;gt;engine&amp;lt;/code&amp;gt; is the central bus of the CherryPy server.&amp;lt;br/&amp;gt;&lt;br /&gt;
Similarly it is also possible to create new channels and even buses themselves.&lt;br /&gt;
&lt;br /&gt;
===Per-Request Functions (Tools)===&lt;br /&gt;
This type of extension is typically used to insert functionality between stages of request processing. Also known as [http://docs.cherrypy.org/en/latest/extend.html#tools Tools] these are simple call-back functions registered with a [http://docs.cherrypy.org/en/latest/extend.html#hookpoint Hook Point]. Hook Points are predefined stages of request processing. CherryPy provides a [http://tools.cherrypy.org/ Default ToolBox] containing many tools. Users have the freedom to create their own tools and add them to the default toolbox or create a new one.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/extend.html#per-request-functions&amp;lt;/ref&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;
An example for creating a tool&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# defining the function to be called&lt;br /&gt;
def my_tool():&lt;br /&gt;
    # put tool functunality here&lt;br /&gt;
    print (“Super Amazing Tool”);&lt;br /&gt;
&lt;br /&gt;
# creating the decorator for the tool&lt;br /&gt;
# specifying the hook point and function to be called&lt;br /&gt;
cherrypy.tools.mytool = cherrypy.Tool(‘on_end_request’, my_tool())&lt;br /&gt;
&lt;br /&gt;
#Sample Usage&lt;br /&gt;
&lt;br /&gt;
class Root(object):&lt;br /&gt;
@cherrypy.expose()&lt;br /&gt;
@cherrypy.tools.mytool()&lt;br /&gt;
def index()&lt;br /&gt;
    return “Hello World”&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Watch It In Action==&lt;br /&gt;
&lt;br /&gt;
CherryPy is used as a building block for [http://www.hulu.com/ Hulu]&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu&amp;lt;/ref&amp;gt; and [https://www.netflix.com/ Netflix]&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Additional Instructions==&lt;br /&gt;
&lt;br /&gt;
===Install via yum===&lt;br /&gt;
CherryPy is provided by the fedora base repository. In [http://en.wikipedia.org/wiki/Fedora_%28operating_system%29 Fedora] (and other [http://en.wikipedia.org/wiki/RPM_Package_Manager RPM] based Linux distributions, such as [http://en.wikipedia.org/wiki/CentOS CentOS] and [http://en.wikipedia.org/wiki/Red_Hat_Enterprise_Linux Red Hat Enterprise Linux]):&amp;lt;br/&amp;gt;&lt;br /&gt;
    $ yum install python-cherrypy&lt;br /&gt;
&lt;br /&gt;
===Install via apt-get=== &lt;br /&gt;
CherryPy is also provided in the [http://en.wikipedia.org/wiki/Ubuntu_(operating_system) Ubuntu] base repository. In Ubuntu (and other [http://en.wikipedia.org/wiki/Debian Debian]-based Linux distributions such as Debian and [http://en.wikipedia.org/wiki/Linux_Mint Linux Mint]):&lt;br /&gt;
    $ apt-get install python python-dev&lt;br /&gt;
&lt;br /&gt;
===Installation from source===&lt;br /&gt;
The source code is hosted on [http://en.wikipedia.org/wiki/Bitbucket BitBucket] and requires [http://en.wikipedia.org/wiki/Mercurial Mercurial] to pull and install from the site itself.&lt;br /&gt;
    $ hg clone https://bitbucket.org/cherrypy/cherrypy&lt;br /&gt;
    $ cd cherrypy&lt;br /&gt;
    $ python setup.py install&lt;br /&gt;
&lt;br /&gt;
Alternatively, the source can be manually downloaded from [https://bitbucket.org/cherrypy/cherrypy/downloads here] in a tarball.&lt;br /&gt;
    $ tar -xvf CherryPy-#.#.#.tar.gz&lt;br /&gt;
    $ cd CherryPy-#.#.#&lt;br /&gt;
    $ python setup.py install&lt;br /&gt;
&lt;br /&gt;
===Install for Windows===&lt;br /&gt;
*If you are using Windows, install Linux and follow any of the a forementioned methods.&lt;br /&gt;
*If you absolutely must use windows, you can download the .exe file to install CherryPy from [https://bitbucket.org/cherrypy/cherrypy/downloads here].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Cehaith2</name></author>
	</entry>
</feed>