<?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=Jmkubasc</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=Jmkubasc"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Jmkubasc"/>
	<updated>2026-07-02T11:48:43Z</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_E1459_jjr&amp;diff=91140</id>
		<title>CSC/ECE 517 Fall 2014/oss E1459 jjr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1459_jjr&amp;diff=91140"/>
		<updated>2014-10-30T01:56:29Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* External Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= E1459 - Refactoring the signup_controller =&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based application used by students and professors to create, select, submit and review assignments.  Selection of assignments may be individual assignments or group assignments.  The assignment is configured by the professor.  Peer reviews can be conducted by fellow students in the class.  Additionally the professor can review the assignments submitted by the students.  Assignments are what Expertiza calls learning objects.  Learning objects consist of such things as articles, websites or web applications, or code.&lt;br /&gt;
&lt;br /&gt;
The Expertiza project is open source with many programmers contributing to the code base. The source code is available at [https://github.com/expertiza/expertiza github]. Due to the open source nature of this application the code is not always as clear, concise and as standardized as it could be. This project seeks to resolve some of these issues by applying sound object oriented design principles along with standard RESTful naming conventions where possible.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Scope ==&lt;br /&gt;
&lt;br /&gt;
This project is focused on the signup_controller and its fringe classes.  The role of the signup_controller is to process requests from the user to sign up for an assignment. The purpose of the controller is to process actions from the user; however, in many cases the controller is doing functions that should be provided by the model.  Any calculations should appear in the model rather than the controller.  The code should use RESTful names such as new, create, edit, and delete.  In many cases it does not.  Methods should be no more than 30-40 lines long.  Any longer and the reader needs to rely on their working memory to remember what code that is outside of their view does which is an inefficient and error prone way to read code.  Other classes that are involved in this process include the sign_up_sheet_controller a number of views that pertain to assignments, topics and fixtures and functional tests and model classes such as sign_up_sheet.rb and sign_up_topic.rb.  The sign_up_sheet_controller handles actions pertaining to creating assignments.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Formatting Changes ==&lt;br /&gt;
&lt;br /&gt;
On the first round of refinement the code was simply cleaned up by untabifying the code and using the Rails and Expertiza coding standard of using two spaces for indentation.  Untabifying the code eliminates variations in tab stop configuration in programmers editors. This makes the code more readable to those who view the source code so that blocks don’t look like run together.&lt;br /&gt;
&lt;br /&gt;
== Rails Naming Conventions ==&lt;br /&gt;
&lt;br /&gt;
Some methods were renamed to ones that more closely align with Rails naming conventions.  In the app/controllers/sign_up_sheet_controller.rb the index and add_signup_topics actions were changed to index_signup and index actions respectively.  These two actions did similar functions and were made clearer by merging them.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{first image here}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The design of the SignUpSheetController class controls two different behaviors of the SignUpTopics model: creation of topics for an assignment by the instructor, and allowing students to sign up for a topic.  To clearly distinguish between these two different behaviors, all actions performed by the instructor to manage a topic (index/create/update/destroy) were renamed to follow the standard Rails naming convention.  All actions performed by the student (index/create/destroy) to sign up for a topic have the suffix _signup.&lt;br /&gt;
&lt;br /&gt;
The issue with these methods were that they didn’t follow Rails naming conventions for displaying a list of items and they were not representative of the the functions that they performed.  The add_signup_topics method displayed a list of topics for the teacher to modify the topics.  The index method although following Rails convention in naming the function name did describe its purpose with respect to the scope of the controller in which it lives.  The index method originally listed the topics for the student to sign up from.  This however is the sign up sheet controller and therefore the index method would have been expected to list topics and perform actions on them at a higher level.  The teacher is concerned with the assignment as a whole.  That is the teacher is concerned with listing and acting on a large number if not all of the topics on the assignment and better aligns with the name of the controller (signup_sheet_controller).  Therefore the add_signup_topics method was renamed to index and the original index method was renamed to index_signup.  The latter was renamed using the index convention but with the _signup suffix.  The original index method displayed the list of topics that the user could sign up for.  In this case the student is interested in acting only one one topic therefore the signup suffix reflects intent.&lt;br /&gt;
&lt;br /&gt;
In the following example from the sign_up_sheet_controller.rb file, the original programmers did not employ the DRY principle to their code.  &lt;br /&gt;
&lt;br /&gt;
== Moving logic code to the Model ==&lt;br /&gt;
&lt;br /&gt;
In the Model View Controller (MVC) paradigm code pertaining to the business logic of an application belongs in the model layer of the program. This paradigm was broken in several places in sign_up_sheet_controller.rb file. For instance, the confirm_topic method is used in the sign_up_sheet_controller.rb file to assign a topic to a user after performing several model layer checks to make sure that the user can, in fact, be assigned a topic. This code is better moved to the model layer as its performing business logic and not simple validation or control statements. The decision was made to move this method into the SignUpTopic model.&lt;br /&gt;
&lt;br /&gt;
== General Cleanup and Deletion ==&lt;br /&gt;
There were also several “utility” methods that we believe were added to the controller at some earlier point and are now obfuscated due to the efforts of previous groups of students to improve the code. For instance, the otherConfirmedTopicforUser(assignment_id, creator_id) and slotAvailable?(topic_id) methods did nothing other than call a method in the model and return the result, this sort of complexity is unnecessary. We removed these methods from the controller as they achieved nothing and did not make the code any easier to read.&lt;br /&gt;
&lt;br /&gt;
{image 2 here}&lt;br /&gt;
&lt;br /&gt;
== File change list ==&lt;br /&gt;
&lt;br /&gt;
The following is a complete list of files that were changed.&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       Gemfile.lock&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/controllers/sign_up_sheet_controller.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/controllers/signup_controller.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/models/sign_up_sheet.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/models/sign_up_topic.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/models/signed_up_user.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/models/system_settings.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/models/team.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/assignments/_reserve_topic.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/assignments/edit/_rubrics.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/bookmarks/add_tag_bookmark.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/bookmarks/view_topic_bookmarks.rhtml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;D       app/views/sign_up_sheet/_add_signup_topcis.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;D       app/views/sign_up_sheet/_add_signup_topics.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A       app/views/sign_up_sheet/_index.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A       app/views/sign_up_sheet/_index_staggered.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/sign_up_sheet/_reserve_topic.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;D       app/views/sign_up_sheet/add_signup_topics.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;D       app/views/sign_up_sheet/add_signup_topics_staggered.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/sign_up_sheet/edit.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A       app/views/sign_up_sheet/index.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A       app/views/sign_up_sheet/index_signup.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;D       app/views/sign_up_sheet/list.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/sign_up_sheet/new.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/student_task/view.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/tree_display/actions/_assignments_actions.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       config/routes.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       db/migrate/053_create_nodes.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       db/schema.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/assignments.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/invitations.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/participants.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/question_types.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/questionnaires.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/questions.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/response_maps.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/responses.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/roles.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/scores.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/sign_up_topics.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/signed_up_users.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/teams.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/teams_users.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/topic_deadlines.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/users.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/functional/sign_up_sheet_controller_test.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/functional/signup_controller_test.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Project Links ==&lt;br /&gt;
[https://github.com/jmkubasc/expertiza Forked GitHub Repository]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://152.1.13.96:3000/ VCL Instance] May be invalid after a few weeks&amp;lt;br&amp;gt;&lt;br /&gt;
[https://docs.google.com/document/d/1iU1FyPgfn5LmILBxnmcBW7kOrv3zC_FYmhRgVuj9ct0/edit?usp=sharing README]&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1459_jjr&amp;diff=91133</id>
		<title>CSC/ECE 517 Fall 2014/oss E1459 jjr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1459_jjr&amp;diff=91133"/>
		<updated>2014-10-30T01:50:40Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* External Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= E1459 - Refactoring the signup_controller =&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based application used by students and professors to create, select, submit and review assignments.  Selection of assignments may be individual assignments or group assignments.  The assignment is configured by the professor.  Peer reviews can be conducted by fellow students in the class.  Additionally the professor can review the assignments submitted by the students.  Assignments are what Expertiza calls learning objects.  Learning objects consist of such things as articles, websites or web applications, or code.&lt;br /&gt;
&lt;br /&gt;
The Expertiza project is open source with many programmers contributing to the code base. The source code is available at [https://github.com/expertiza/expertiza github]. Due to the open source nature of this application the code is not always as clear, concise and as standardized as it could be. This project seeks to resolve some of these issues by applying sound object oriented design principles along with standard RESTful naming conventions where possible.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Scope ==&lt;br /&gt;
&lt;br /&gt;
This project is focused on the signup_controller and its fringe classes.  The role of the signup_controller is to process requests from the user to sign up for an assignment. The purpose of the controller is to process actions from the user; however, in many cases the controller is doing functions that should be provided by the model.  Any calculations should appear in the model rather than the controller.  The code should use RESTful names such as new, create, edit, and delete.  In many cases it does not.  Methods should be no more than 30-40 lines long.  Any longer and the reader needs to rely on their working memory to remember what code that is outside of their view does which is an inefficient and error prone way to read code.  Other classes that are involved in this process include the sign_up_sheet_controller a number of views that pertain to assignments, topics and fixtures and functional tests and model classes such as sign_up_sheet.rb and sign_up_topic.rb.  The sign_up_sheet_controller handles actions pertaining to creating assignments.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Formatting Changes ==&lt;br /&gt;
&lt;br /&gt;
On the first round of refinement the code was simply cleaned up by untabifying the code and using the Rails and Expertiza coding standard of using two spaces for indentation.  Untabifying the code eliminates variations in tab stop configuration in programmers editors. This makes the code more readable to those who view the source code so that blocks don’t look like run together.&lt;br /&gt;
&lt;br /&gt;
== Rails Naming Conventions ==&lt;br /&gt;
&lt;br /&gt;
Some methods were renamed to ones that more closely align with Rails naming conventions.  In the app/controllers/sign_up_sheet_controller.rb the index and add_signup_topics actions were changed to index_signup and index actions respectively.  These two actions did similar functions and were made clearer by merging them.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{first image here}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The design of the SignUpSheetController class controls two different behaviors of the SignUpTopics model: creation of topics for an assignment by the instructor, and allowing students to sign up for a topic.  To clearly distinguish between these two different behaviors, all actions performed by the instructor to manage a topic (index/create/update/destroy) were renamed to follow the standard Rails naming convention.  All actions performed by the student (index/create/destroy) to sign up for a topic have the suffix _signup.&lt;br /&gt;
&lt;br /&gt;
The issue with these methods were that they didn’t follow Rails naming conventions for displaying a list of items and they were not representative of the the functions that they performed.  The add_signup_topics method displayed a list of topics for the teacher to modify the topics.  The index method although following Rails convention in naming the function name did describe its purpose with respect to the scope of the controller in which it lives.  The index method originally listed the topics for the student to sign up from.  This however is the sign up sheet controller and therefore the index method would have been expected to list topics and perform actions on them at a higher level.  The teacher is concerned with the assignment as a whole.  That is the teacher is concerned with listing and acting on a large number if not all of the topics on the assignment and better aligns with the name of the controller (signup_sheet_controller).  Therefore the add_signup_topics method was renamed to index and the original index method was renamed to index_signup.  The latter was renamed using the index convention but with the _signup suffix.  The original index method displayed the list of topics that the user could sign up for.  In this case the student is interested in acting only one one topic therefore the signup suffix reflects intent.&lt;br /&gt;
&lt;br /&gt;
In the following example from the sign_up_sheet_controller.rb file, the original programmers did not employ the DRY principle to their code.  &lt;br /&gt;
&lt;br /&gt;
== Moving logic code to the Model ==&lt;br /&gt;
&lt;br /&gt;
In the Model View Controller (MVC) paradigm code pertaining to the business logic of an application belongs in the model layer of the program. This paradigm was broken in several places in sign_up_sheet_controller.rb file. For instance, the confirm_topic method is used in the sign_up_sheet_controller.rb file to assign a topic to a user after performing several model layer checks to make sure that the user can, in fact, be assigned a topic. This code is better moved to the model layer as its performing business logic and not simple validation or control statements. The decision was made to move this method into the SignUpTopic model.&lt;br /&gt;
&lt;br /&gt;
== General Cleanup and Deletion ==&lt;br /&gt;
There were also several “utility” methods that we believe were added to the controller at some earlier point and are now obfuscated due to the efforts of previous groups of students to improve the code. For instance, the otherConfirmedTopicforUser(assignment_id, creator_id) and slotAvailable?(topic_id) methods did nothing other than call a method in the model and return the result, this sort of complexity is unnecessary. We removed these methods from the controller as they achieved nothing and did not make the code any easier to read.&lt;br /&gt;
&lt;br /&gt;
{image 2 here}&lt;br /&gt;
&lt;br /&gt;
== File change list ==&lt;br /&gt;
&lt;br /&gt;
The following is a complete list of files that were changed.&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       Gemfile.lock&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/controllers/sign_up_sheet_controller.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/controllers/signup_controller.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/models/sign_up_sheet.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/models/sign_up_topic.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/models/signed_up_user.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/models/system_settings.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/models/team.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/assignments/_reserve_topic.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/assignments/edit/_rubrics.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/bookmarks/add_tag_bookmark.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/bookmarks/view_topic_bookmarks.rhtml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;D       app/views/sign_up_sheet/_add_signup_topcis.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;D       app/views/sign_up_sheet/_add_signup_topics.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A       app/views/sign_up_sheet/_index.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A       app/views/sign_up_sheet/_index_staggered.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/sign_up_sheet/_reserve_topic.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;D       app/views/sign_up_sheet/add_signup_topics.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;D       app/views/sign_up_sheet/add_signup_topics_staggered.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/sign_up_sheet/edit.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A       app/views/sign_up_sheet/index.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A       app/views/sign_up_sheet/index_signup.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;D       app/views/sign_up_sheet/list.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/sign_up_sheet/new.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/student_task/view.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/tree_display/actions/_assignments_actions.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       config/routes.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       db/migrate/053_create_nodes.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       db/schema.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/assignments.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/invitations.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/participants.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/question_types.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/questionnaires.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/questions.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/response_maps.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/responses.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/roles.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/scores.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/sign_up_topics.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/signed_up_users.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/teams.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/teams_users.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/topic_deadlines.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/users.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/functional/sign_up_sheet_controller_test.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/functional/signup_controller_test.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
[https://github.com/jmkubasc/expertiza Forked GitHub Repository]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://152.1.13.96:3000/ VCL Instance] May be invalid after a few weeks&amp;lt;br&amp;gt;&lt;br /&gt;
[https://docs.google.com/document/d/1iU1FyPgfn5LmILBxnmcBW7kOrv3zC_FYmhRgVuj9ct0/edit?usp=sharing README]&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1459_jjr&amp;diff=91125</id>
		<title>CSC/ECE 517 Fall 2014/oss E1459 jjr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1459_jjr&amp;diff=91125"/>
		<updated>2014-10-30T01:44:32Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* External Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= E1459 - Refactoring the signup_controller =&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based application used by students and professors to create, select, submit and review assignments.  Selection of assignments may be individual assignments or group assignments.  The assignment is configured by the professor.  Peer reviews can be conducted by fellow students in the class.  Additionally the professor can review the assignments submitted by the students.  Assignments are what Expertiza calls learning objects.  Learning objects consist of such things as articles, websites or web applications, or code.&lt;br /&gt;
&lt;br /&gt;
The Expertiza project is open source with many programmers contributing to the code base. The source code is available at [https://github.com/expertiza/expertiza github]. Due to the open source nature of this application the code is not always as clear, concise and as standardized as it could be. This project seeks to resolve some of these issues by applying sound object oriented design principles along with standard RESTful naming conventions where possible.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Scope ==&lt;br /&gt;
&lt;br /&gt;
This project is focused on the signup_controller and its fringe classes.  The role of the signup_controller is to process requests from the user to sign up for an assignment. The purpose of the controller is to process actions from the user; however, in many cases the controller is doing functions that should be provided by the model.  Any calculations should appear in the model rather than the controller.  The code should use RESTful names such as new, create, edit, and delete.  In many cases it does not.  Methods should be no more than 30-40 lines long.  Any longer and the reader needs to rely on their working memory to remember what code that is outside of their view does which is an inefficient and error prone way to read code.  Other classes that are involved in this process include the sign_up_sheet_controller a number of views that pertain to assignments, topics and fixtures and functional tests and model classes such as sign_up_sheet.rb and sign_up_topic.rb.  The sign_up_sheet_controller handles actions pertaining to creating assignments.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Formatting Changes ==&lt;br /&gt;
&lt;br /&gt;
On the first round of refinement the code was simply cleaned up by untabifying the code and using the Rails and Expertiza coding standard of using two spaces for indentation.  Untabifying the code eliminates variations in tab stop configuration in programmers editors. This makes the code more readable to those who view the source code so that blocks don’t look like run together.&lt;br /&gt;
&lt;br /&gt;
== Rails Naming Conventions ==&lt;br /&gt;
&lt;br /&gt;
Some methods were renamed to ones that more closely align with Rails naming conventions.  In the app/controllers/sign_up_sheet_controller.rb the index and add_signup_topics actions were changed to index_signup and index actions respectively.  These two actions did similar functions and were made clearer by merging them.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{first image here}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The design of the SignUpSheetController class controls two different behaviors of the SignUpTopics model: creation of topics for an assignment by the instructor, and allowing students to sign up for a topic.  To clearly distinguish between these two different behaviors, all actions performed by the instructor to manage a topic (index/create/update/destroy) were renamed to follow the standard Rails naming convention.  All actions performed by the student (index/create/destroy) to sign up for a topic have the suffix _signup.&lt;br /&gt;
&lt;br /&gt;
The issue with these methods were that they didn’t follow Rails naming conventions for displaying a list of items and they were not representative of the the functions that they performed.  The add_signup_topics method displayed a list of topics for the teacher to modify the topics.  The index method although following Rails convention in naming the function name did describe its purpose with respect to the scope of the controller in which it lives.  The index method originally listed the topics for the student to sign up from.  This however is the sign up sheet controller and therefore the index method would have been expected to list topics and perform actions on them at a higher level.  The teacher is concerned with the assignment as a whole.  That is the teacher is concerned with listing and acting on a large number if not all of the topics on the assignment and better aligns with the name of the controller (signup_sheet_controller).  Therefore the add_signup_topics method was renamed to index and the original index method was renamed to index_signup.  The latter was renamed using the index convention but with the _signup suffix.  The original index method displayed the list of topics that the user could sign up for.  In this case the student is interested in acting only one one topic therefore the signup suffix reflects intent.&lt;br /&gt;
&lt;br /&gt;
In the following example from the sign_up_sheet_controller.rb file, the original programmers did not employ the DRY principle to their code.  &lt;br /&gt;
&lt;br /&gt;
== Moving logic code to the Model ==&lt;br /&gt;
&lt;br /&gt;
    In the Model View Controller (MVC) paradigm code pertaining to the business logic of an application belongs in the model layer of the program. This paradigm was broken in several places in sign_up_sheet_controller.rb file. For instance, the confirm_topic method is used in the sign_up_sheet_controller.rb file to assign a topic to a user after performing several model layer checks to make sure that the user can, in fact, be assigned a topic. This code is better moved to the model layer as its performing business logic and not simple validation or control statements. The decision was made to move this method into the SignUpTopic model.&lt;br /&gt;
&lt;br /&gt;
General Cleanup and Deletion&lt;br /&gt;
    There were also several “utility” methods that we believe were added to the controller at some earlier point and are now obfuscated due to the efforts of previous groups of students to improve the code. For instance, the otherConfirmedTopicforUser(assignment_id, creator_id) and slotAvailable?(topic_id) methods did nothing other than call a method in the model and return the result, this sort of complexity is unnecessary. We removed these methods from the controller as they achieved nothing and did not make the code any easier to read.&lt;br /&gt;
&lt;br /&gt;
{image 2 here}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== File change list ==&lt;br /&gt;
&lt;br /&gt;
The following is a complete list of files that were changed.&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       Gemfile.lock&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/controllers/sign_up_sheet_controller.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/controllers/signup_controller.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/models/sign_up_sheet.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/models/sign_up_topic.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/models/signed_up_user.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/models/system_settings.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/models/team.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/assignments/_reserve_topic.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/assignments/edit/_rubrics.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/bookmarks/add_tag_bookmark.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/bookmarks/view_topic_bookmarks.rhtml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;D       app/views/sign_up_sheet/_add_signup_topcis.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;D       app/views/sign_up_sheet/_add_signup_topics.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A       app/views/sign_up_sheet/_index.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A       app/views/sign_up_sheet/_index_staggered.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/sign_up_sheet/_reserve_topic.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;D       app/views/sign_up_sheet/add_signup_topics.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;D       app/views/sign_up_sheet/add_signup_topics_staggered.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/sign_up_sheet/edit.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A       app/views/sign_up_sheet/index.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A       app/views/sign_up_sheet/index_signup.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;D       app/views/sign_up_sheet/list.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/sign_up_sheet/new.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/student_task/view.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/tree_display/actions/_assignments_actions.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       config/routes.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       db/migrate/053_create_nodes.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       db/schema.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/assignments.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/invitations.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/participants.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/question_types.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/questionnaires.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/questions.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/response_maps.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/responses.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/roles.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/scores.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/sign_up_topics.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/signed_up_users.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/teams.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/teams_users.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/topic_deadlines.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/users.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/functional/sign_up_sheet_controller_test.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/functional/signup_controller_test.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
https://github.com/jmkubasc/expertiza&lt;br /&gt;
http://152.1.13.96:3000/&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1459_jjr&amp;diff=91121</id>
		<title>CSC/ECE 517 Fall 2014/oss E1459 jjr</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/oss_E1459_jjr&amp;diff=91121"/>
		<updated>2014-10-30T01:42:43Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* E1459 - Refactoring the signup_controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= E1459 - Refactoring the signup_controller =&lt;br /&gt;
&lt;br /&gt;
__TOC__&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is a web based application used by students and professors to create, select, submit and review assignments.  Selection of assignments may be individual assignments or group assignments.  The assignment is configured by the professor.  Peer reviews can be conducted by fellow students in the class.  Additionally the professor can review the assignments submitted by the students.  Assignments are what Expertiza calls learning objects.  Learning objects consist of such things as articles, websites or web applications, or code.&lt;br /&gt;
&lt;br /&gt;
The Expertiza project is open source with many programmers contributing to the code base. The source code is available at [https://github.com/expertiza/expertiza github]. Due to the open source nature of this application the code is not always as clear, concise and as standardized as it could be. This project seeks to resolve some of these issues by applying sound object oriented design principles along with standard RESTful naming conventions where possible.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Scope ==&lt;br /&gt;
&lt;br /&gt;
This project is focused on the signup_controller and its fringe classes.  The role of the signup_controller is to process requests from the user to sign up for an assignment. The purpose of the controller is to process actions from the user; however, in many cases the controller is doing functions that should be provided by the model.  Any calculations should appear in the model rather than the controller.  The code should use RESTful names such as new, create, edit, and delete.  In many cases it does not.  Methods should be no more than 30-40 lines long.  Any longer and the reader needs to rely on their working memory to remember what code that is outside of their view does which is an inefficient and error prone way to read code.  Other classes that are involved in this process include the sign_up_sheet_controller a number of views that pertain to assignments, topics and fixtures and functional tests and model classes such as sign_up_sheet.rb and sign_up_topic.rb.  The sign_up_sheet_controller handles actions pertaining to creating assignments.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Formatting Changes ==&lt;br /&gt;
&lt;br /&gt;
On the first round of refinement the code was simply cleaned up by untabifying the code and using the Rails and Expertiza coding standard of using two spaces for indentation.  Untabifying the code eliminates variations in tab stop configuration in programmers editors. This makes the code more readable to those who view the source code so that blocks don’t look like run together.&lt;br /&gt;
&lt;br /&gt;
== Rails Naming Conventions ==&lt;br /&gt;
&lt;br /&gt;
Some methods were renamed to ones that more closely align with Rails naming conventions.  In the app/controllers/sign_up_sheet_controller.rb the index and add_signup_topics actions were changed to index_signup and index actions respectively.  These two actions did similar functions and were made clearer by merging them.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{first image here}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The design of the SignUpSheetController class controls two different behaviors of the SignUpTopics model: creation of topics for an assignment by the instructor, and allowing students to sign up for a topic.  To clearly distinguish between these two different behaviors, all actions performed by the instructor to manage a topic (index/create/update/destroy) were renamed to follow the standard Rails naming convention.  All actions performed by the student (index/create/destroy) to sign up for a topic have the suffix _signup.&lt;br /&gt;
&lt;br /&gt;
The issue with these methods were that they didn’t follow Rails naming conventions for displaying a list of items and they were not representative of the the functions that they performed.  The add_signup_topics method displayed a list of topics for the teacher to modify the topics.  The index method although following Rails convention in naming the function name did describe its purpose with respect to the scope of the controller in which it lives.  The index method originally listed the topics for the student to sign up from.  This however is the sign up sheet controller and therefore the index method would have been expected to list topics and perform actions on them at a higher level.  The teacher is concerned with the assignment as a whole.  That is the teacher is concerned with listing and acting on a large number if not all of the topics on the assignment and better aligns with the name of the controller (signup_sheet_controller).  Therefore the add_signup_topics method was renamed to index and the original index method was renamed to index_signup.  The latter was renamed using the index convention but with the _signup suffix.  The original index method displayed the list of topics that the user could sign up for.  In this case the student is interested in acting only one one topic therefore the signup suffix reflects intent.&lt;br /&gt;
&lt;br /&gt;
In the following example from the sign_up_sheet_controller.rb file, the original programmers did not employ the DRY principle to their code.  &lt;br /&gt;
&lt;br /&gt;
== Moving logic code to the Model ==&lt;br /&gt;
&lt;br /&gt;
    In the Model View Controller (MVC) paradigm code pertaining to the business logic of an application belongs in the model layer of the program. This paradigm was broken in several places in sign_up_sheet_controller.rb file. For instance, the confirm_topic method is used in the sign_up_sheet_controller.rb file to assign a topic to a user after performing several model layer checks to make sure that the user can, in fact, be assigned a topic. This code is better moved to the model layer as its performing business logic and not simple validation or control statements. The decision was made to move this method into the SignUpTopic model.&lt;br /&gt;
&lt;br /&gt;
General Cleanup and Deletion&lt;br /&gt;
    There were also several “utility” methods that we believe were added to the controller at some earlier point and are now obfuscated due to the efforts of previous groups of students to improve the code. For instance, the otherConfirmedTopicforUser(assignment_id, creator_id) and slotAvailable?(topic_id) methods did nothing other than call a method in the model and return the result, this sort of complexity is unnecessary. We removed these methods from the controller as they achieved nothing and did not make the code any easier to read.&lt;br /&gt;
&lt;br /&gt;
{image 2 here}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== File change list ==&lt;br /&gt;
&lt;br /&gt;
The following is a complete list of files that were changed.&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       Gemfile.lock&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/controllers/sign_up_sheet_controller.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/controllers/signup_controller.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/models/sign_up_sheet.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/models/sign_up_topic.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/models/signed_up_user.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/models/system_settings.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/models/team.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/assignments/_reserve_topic.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/assignments/edit/_rubrics.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/bookmarks/add_tag_bookmark.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/bookmarks/view_topic_bookmarks.rhtml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;D       app/views/sign_up_sheet/_add_signup_topcis.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;D       app/views/sign_up_sheet/_add_signup_topics.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A       app/views/sign_up_sheet/_index.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A       app/views/sign_up_sheet/_index_staggered.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/sign_up_sheet/_reserve_topic.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;D       app/views/sign_up_sheet/add_signup_topics.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;D       app/views/sign_up_sheet/add_signup_topics_staggered.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/sign_up_sheet/edit.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A       app/views/sign_up_sheet/index.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;A       app/views/sign_up_sheet/index_signup.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;D       app/views/sign_up_sheet/list.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/sign_up_sheet/new.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/student_task/view.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       app/views/tree_display/actions/_assignments_actions.html.erb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       config/routes.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       db/migrate/053_create_nodes.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       db/schema.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/assignments.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/invitations.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/participants.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/question_types.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/questionnaires.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/questions.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/response_maps.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/responses.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/roles.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/scores.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/sign_up_topics.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/signed_up_users.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/teams.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/teams_users.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/topic_deadlines.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/fixtures/users.yml&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/functional/sign_up_sheet_controller_test.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;M       test/functional/signup_controller_test.rb&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
https://github.com/jmkubasc/expertiza&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=86731</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=86731"/>
		<updated>2014-09-18T23:47:24Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Basic Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a Python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
CherryPy is a lightweight web server framework written in Python.  It has an object-oriented design and provides a basic HTTP web server as defined in RFC 7321.  It includes built-in profiling, coverage, and testing tools to assist in development.  &lt;br /&gt;
&lt;br /&gt;
CherryPy does not have any built-in templating or database engines, and instead relies on external libraries and plugins. &amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;  Python comes with a rich library support, so this typically is not an issue.&lt;br /&gt;
&lt;br /&gt;
It is distributed under the BSD License&amp;lt;ref&amp;gt;https://bitbucket.org/cherrypy/cherrypy/src/697c7af588b8/cherrypy/LICENSE.txt&amp;lt;/ref&amp;gt;. The latest stable version is 3.6 as of August 19, 2014&amp;lt;ref&amp;gt;https://pypi.python.org/pypi/CherryPy&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some of the well known websites using CherryPy are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list can be found [http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy here].&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates a very simple web server using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
'''WebApp.py'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/code&amp;gt; tells the CherryPy framework to start the HTTP server, which is defined as a class named &amp;lt;code&amp;gt;WebApp&amp;lt;/code&amp;gt;.  The method &amp;lt;code&amp;gt;index&amp;lt;/code&amp;gt; is exposed as a URL handler by the &amp;lt;code&amp;gt;@cherrypy.expose&amp;lt;/code&amp;gt; statement.  The return value of the method is what is sent as the HTTP reposne.&lt;br /&gt;
&lt;br /&gt;
Start the application by running the above Python file &amp;quot;WebApp.py&amp;quot; and open your web browser to http://localhost:8080.  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
=== Query Strings ===&lt;br /&gt;
&lt;br /&gt;
CherryPy will automatically parse the query string of a URL.  Fields are passed as method arguments with matching names, and can take advantage of default argument values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def test(self, value=1):&lt;br /&gt;
        return &amp;quot;Value = &amp;quot; + str(value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A URL of http://localhost:8080/test?value=5 gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_06-37-27_PM.png]]&lt;br /&gt;
&lt;br /&gt;
=== Cookies ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can set browser cookies with &amp;lt;tt&amp;gt;cherrypy.response.cookie&amp;lt;/tt&amp;gt; and read browser cookies with &amp;lt;tt&amp;gt;cherrypy.request.cookie&amp;lt;/tt&amp;gt; by accessing these variables as Python dictionary objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def set(self, value = &amp;quot;Test&amp;quot;):&lt;br /&gt;
        cookie = cherrypy.response.cookie&lt;br /&gt;
        cookie['Value'] = value&lt;br /&gt;
        return &amp;quot;Cookie set&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def get(self):&lt;br /&gt;
        cookie = cherrypy.request.cookie&lt;br /&gt;
        return &amp;quot;Cookie value = &amp;quot; + str(cookie['Value'].value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Navigating to http://localhost:8080/set?value=test followed by http://localhost:8080/get gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:CherryPyCookieTest.png]]&lt;br /&gt;
&lt;br /&gt;
=== Logging ===&lt;br /&gt;
&lt;br /&gt;
CherryPy provides the following method for application logging&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.log(&amp;quot;Hello, CherryPy!&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, all logging is written to the console.  The configuration keys &amp;lt;tt&amp;gt;log.access_file&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;log.error_file&amp;lt;/tt&amp;gt; are also available for writing logging and errors to a text file.&lt;br /&gt;
&lt;br /&gt;
=== Starting the HTTP Server ===&lt;br /&gt;
CherryPy provides two ways to start the HTTP server, depending on the developer's needs.&lt;br /&gt;
&lt;br /&gt;
==== Single Application ====&lt;br /&gt;
The simplest way is to call the &amp;lt;tt&amp;gt;cherrypy.quickstart()&amp;lt;/tt&amp;gt; function. This function takes at least one argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application class 'WebApp' at http://localhost:8080/.&lt;br /&gt;
&lt;br /&gt;
It can also take 2 more arguments.&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp(), '/hello', {'/': {'tools.gzip.on': True}})&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application class 'WebApp' at http://localhost:8080/hello. &lt;br /&gt;
The third argument defines the configuration for the application. It can either be a dictionary object or a configuration file.&lt;br /&gt;
&lt;br /&gt;
==== Multiple Applications ====&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;tt&amp;gt;cherrypy.tree.mount&amp;lt;/tt&amp;gt; is used to host multiple application classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.tree.mount(MyApp1(), '/app1', app1_conf)&lt;br /&gt;
cherrypy.tree.mount(MyApp2(), '/app2', app2_conf)&lt;br /&gt;
&lt;br /&gt;
cherrypy.engine.start()&lt;br /&gt;
cherrypy.engine.block()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will host two applications classes having paths http://localhost:8080/app1 and http://localhost:8080/app2.&lt;br /&gt;
&lt;br /&gt;
=== Server Configuration ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;cherrypy.config.update&amp;lt;/tt&amp;gt; function can be used to configure the CherryPy framework&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'server.socket_port': 9999})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will start the HTTP server on port 9999 instead of the default port 8080. The application can then be accessed at http://localhost:9999/.&lt;br /&gt;
&lt;br /&gt;
A configuration file path instead can be passed as an argument to this function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.config.update(&amp;quot;WebAppServer.conf&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''WebAppServer.conf'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[global]&lt;br /&gt;
server.socket_port: 9999&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sessions ===&lt;br /&gt;
&lt;br /&gt;
In CherryPy, sessions are disabled by default.  To enable sessions, set the configuration &amp;lt;tt&amp;gt;tools.sessions.on&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;. &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/basics.html#using-sessions&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Session variables can be accessed with &amp;lt;tt&amp;gt;cherrypy.session&amp;lt;/tt&amp;gt;, which is a Python dictionary object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        if 'number' not in cherrypy.session:&lt;br /&gt;
            cherrypy.session['number'] = 0&lt;br /&gt;
        else:&lt;br /&gt;
            cherrypy.session['number'] += 1&lt;br /&gt;
        return &amp;quot;Number = &amp;quot; + str(cherrypy.session['number'])&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'tools.sessions.on': True})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example shows a number that increments by 1 every time the user navigates to [http://localhost:8080 localhost:8080].&lt;br /&gt;
&lt;br /&gt;
=== Static Content ===&lt;br /&gt;
Files with static content, such as binaries, images, or stylesheets, can be served by the HTTP server by adding the following lines to the application configuration file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[/images]&lt;br /&gt;
tools.staticdir.on = True&lt;br /&gt;
tools.staticdir.dir = &amp;quot;/site/public/images&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will allow the user to access some file &amp;quot;user.jpg&amp;quot; present in the folder &amp;quot;/site/public/images/user.jpg&amp;quot; using the url http://localhost:8080/images/user.jpg.&lt;br /&gt;
&lt;br /&gt;
=== REST APIs ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can be used to expose the APIs as RESTful Web Services. This allows third party applications to easily communicate with the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class MyAppRestMode(object):&lt;br /&gt;
    exposed = True&lt;br /&gt;
&lt;br /&gt;
    def GET(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
conf = {&lt;br /&gt;
    '/': {&lt;br /&gt;
        'request.dispatch': cherrypy.dispatch.MethodDispatcher(),&lt;br /&gt;
        'tools.response_headers.on': True,&lt;br /&gt;
        'tools.response_headers.headers': [('Content-Type', 'text/plain')],&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
cherrypy.quickstart(MyAppRestMode(), '/', conf)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code exposes the GET API with url http://localhost:8080/. The API returns the string &amp;quot;Hello, CherryPy!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== HTTP Server Port ===&lt;br /&gt;
&lt;br /&gt;
The default HTTP server started by CherryPy can be used to host the application only on one socket port (default 8080). However, it is possible to host the HTTP server on multiple ports by binding them to different socket ports.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from cherrypy._cpserver import Server&lt;br /&gt;
&lt;br /&gt;
server = Server()&lt;br /&gt;
server.socket_port = 443&lt;br /&gt;
server.subscribe()&lt;br /&gt;
&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code hosts the application with one more HTTP server which runs on port 443. It is possible to create any number of additional HTTP servers.&lt;br /&gt;
&lt;br /&gt;
=== Authentication ===&lt;br /&gt;
&lt;br /&gt;
CherryPy provides two authentication mechanisms: Simple and Digest. It follows the specification defined by [http://tools.ietf.org/html/rfc2617.html RFC 2617]&lt;br /&gt;
&lt;br /&gt;
=== WSGI Support ===&lt;br /&gt;
&lt;br /&gt;
CherryPy supports the WSGI (Web Server Gateway Interface) specification defined by [http://www.python.org/dev/peps/pep-0333 PEP 0333] and [http://www.python.org/dev/peps/pep-3333 PEP 3333]. &lt;br /&gt;
&lt;br /&gt;
This allows two things:&lt;br /&gt;
* Instead of using the default CherryPy server, a CherryPy application can be hosted on an external WSGI server.&lt;br /&gt;
* The CherryPy server can be used independently to host an external WSGI application.&lt;br /&gt;
&lt;br /&gt;
=== Test Suite ===&lt;br /&gt;
&lt;br /&gt;
The CherryPy framework provides a class, named &amp;lt;tt&amp;gt;helper&amp;lt;/tt&amp;gt; which can be used as a base class for writing functional tests. &lt;br /&gt;
&lt;br /&gt;
Running a test will start the complete application and thus can be used to simulate the scenario when a user actually tries to access the server on web.&lt;br /&gt;
&lt;br /&gt;
The sample code to run a test can be found [http://docs.cherrypy.org/en/latest/advanced.html#testing-your-application here]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=86727</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=86727"/>
		<updated>2014-09-18T23:45:04Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Test Suite */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a Python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
CherryPy is a lightweight web server framework written in Python.  It has an object-oriented design and provides a basic HTTP web server as defined in RFC 7321.  It includes built-in profiling, coverage, and testing tools to assist in development.  &lt;br /&gt;
&lt;br /&gt;
CherryPy does not have any built-in templating or database engines, and instead relies on external libraries and plugins. &amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;  Python comes with a rich library support, so this typically is not an issue.&lt;br /&gt;
&lt;br /&gt;
It is distributed under the BSD License&amp;lt;ref&amp;gt;https://bitbucket.org/cherrypy/cherrypy/src/697c7af588b8/cherrypy/LICENSE.txt&amp;lt;/ref&amp;gt;. The latest stable version is 3.6 as of August 19, 2014&amp;lt;ref&amp;gt;https://pypi.python.org/pypi/CherryPy&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some of the well known websites using CherryPy are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list can be found [http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy here].&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates a very simple web server using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
'''WebApp.py'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/code&amp;gt; tells the CherryPy framework to start the web server, which is defined as a class named &amp;lt;code&amp;gt;WebApp&amp;lt;/code&amp;gt;.  The method &amp;lt;code&amp;gt;index&amp;lt;/code&amp;gt; is exposed as a URL handler by the &amp;lt;code&amp;gt;@cherrypy.expose&amp;lt;/code&amp;gt; statement.  The return value of the method is what is sent as the HTTP reposne.&lt;br /&gt;
&lt;br /&gt;
Start the application by running the above Python file &amp;quot;WebApp.py&amp;quot; and open your web browser to http://localhost:8080.  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
=== Query Strings ===&lt;br /&gt;
&lt;br /&gt;
CherryPy will automatically parse the query string of a URL.  Fields are passed as method arguments with matching names, and can take advantage of default argument values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def test(self, value=1):&lt;br /&gt;
        return &amp;quot;Value = &amp;quot; + str(value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A URL of http://localhost:8080/test?value=5 gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_06-37-27_PM.png]]&lt;br /&gt;
&lt;br /&gt;
=== Cookies ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can set browser cookies with &amp;lt;tt&amp;gt;cherrypy.response.cookie&amp;lt;/tt&amp;gt; and read browser cookies with &amp;lt;tt&amp;gt;cherrypy.request.cookie&amp;lt;/tt&amp;gt; by accessing these variables as Python dictionary objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def set(self, value = &amp;quot;Test&amp;quot;):&lt;br /&gt;
        cookie = cherrypy.response.cookie&lt;br /&gt;
        cookie['Value'] = value&lt;br /&gt;
        return &amp;quot;Cookie set&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def get(self):&lt;br /&gt;
        cookie = cherrypy.request.cookie&lt;br /&gt;
        return &amp;quot;Cookie value = &amp;quot; + str(cookie['Value'].value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Navigating to http://localhost:8080/set?value=test followed by http://localhost:8080/get gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:CherryPyCookieTest.png]]&lt;br /&gt;
&lt;br /&gt;
=== Logging ===&lt;br /&gt;
&lt;br /&gt;
CherryPy provides the following method for application logging&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.log(&amp;quot;Hello, CherryPy!&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, all logging is written to the console.  The configuration keys &amp;lt;tt&amp;gt;log.access_file&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;log.error_file&amp;lt;/tt&amp;gt; are also available for writing logging and errors to a text file.&lt;br /&gt;
&lt;br /&gt;
=== Starting the HTTP Server ===&lt;br /&gt;
CherryPy provides two ways to start the HTTP server, depending on the developer's needs.&lt;br /&gt;
&lt;br /&gt;
==== Single Application ====&lt;br /&gt;
The simplest way is to call the &amp;lt;tt&amp;gt;cherrypy.quickstart()&amp;lt;/tt&amp;gt; function. This function takes at least one argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application class 'WebApp' at http://localhost:8080/.&lt;br /&gt;
&lt;br /&gt;
It can also take 2 more arguments.&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp(), '/hello', {'/': {'tools.gzip.on': True}})&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application class 'WebApp' at http://localhost:8080/hello. &lt;br /&gt;
The third argument defines the configuration for the application. It can either be a dictionary object or a configuration file.&lt;br /&gt;
&lt;br /&gt;
==== Multiple Applications ====&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;tt&amp;gt;cherrypy.tree.mount&amp;lt;/tt&amp;gt; is used to host multiple application classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.tree.mount(MyApp1(), '/app1', app1_conf)&lt;br /&gt;
cherrypy.tree.mount(MyApp2(), '/app2', app2_conf)&lt;br /&gt;
&lt;br /&gt;
cherrypy.engine.start()&lt;br /&gt;
cherrypy.engine.block()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will host two applications classes having paths http://localhost:8080/app1 and http://localhost:8080/app2.&lt;br /&gt;
&lt;br /&gt;
=== Server Configuration ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;cherrypy.config.update&amp;lt;/tt&amp;gt; function can be used to configure the CherryPy framework&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'server.socket_port': 9999})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will start the HTTP server on port 9999 instead of the default port 8080. The application can then be accessed at http://localhost:9999/.&lt;br /&gt;
&lt;br /&gt;
A configuration file path instead can be passed as an argument to this function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.config.update(&amp;quot;WebAppServer.conf&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''WebAppServer.conf'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[global]&lt;br /&gt;
server.socket_port: 9999&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sessions ===&lt;br /&gt;
&lt;br /&gt;
In CherryPy, sessions are disabled by default.  To enable sessions, set the configuration &amp;lt;tt&amp;gt;tools.sessions.on&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;. &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/basics.html#using-sessions&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Session variables can be accessed with &amp;lt;tt&amp;gt;cherrypy.session&amp;lt;/tt&amp;gt;, which is a Python dictionary object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        if 'number' not in cherrypy.session:&lt;br /&gt;
            cherrypy.session['number'] = 0&lt;br /&gt;
        else:&lt;br /&gt;
            cherrypy.session['number'] += 1&lt;br /&gt;
        return &amp;quot;Number = &amp;quot; + str(cherrypy.session['number'])&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'tools.sessions.on': True})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example shows a number that increments by 1 every time the user navigates to [http://localhost:8080 localhost:8080].&lt;br /&gt;
&lt;br /&gt;
=== Static Content ===&lt;br /&gt;
Files with static content, such as binaries, images, or stylesheets, can be served by the HTTP server by adding the following lines to the application configuration file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[/images]&lt;br /&gt;
tools.staticdir.on = True&lt;br /&gt;
tools.staticdir.dir = &amp;quot;/site/public/images&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will allow the user to access some file &amp;quot;user.jpg&amp;quot; present in the folder &amp;quot;/site/public/images/user.jpg&amp;quot; using the url http://localhost:8080/images/user.jpg.&lt;br /&gt;
&lt;br /&gt;
=== REST APIs ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can be used to expose the APIs as RESTful Web Services. This allows third party applications to easily communicate with the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class MyAppRestMode(object):&lt;br /&gt;
    exposed = True&lt;br /&gt;
&lt;br /&gt;
    def GET(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
conf = {&lt;br /&gt;
    '/': {&lt;br /&gt;
        'request.dispatch': cherrypy.dispatch.MethodDispatcher(),&lt;br /&gt;
        'tools.response_headers.on': True,&lt;br /&gt;
        'tools.response_headers.headers': [('Content-Type', 'text/plain')],&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
cherrypy.quickstart(MyAppRestMode(), '/', conf)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code exposes the GET API with url http://localhost:8080/. The API returns the string &amp;quot;Hello, CherryPy!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== HTTP Server Port ===&lt;br /&gt;
&lt;br /&gt;
The default HTTP server started by CherryPy can be used to host the application only on one socket port (default 8080). However, it is possible to host the HTTP server on multiple ports by binding them to different socket ports.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from cherrypy._cpserver import Server&lt;br /&gt;
&lt;br /&gt;
server = Server()&lt;br /&gt;
server.socket_port = 443&lt;br /&gt;
server.subscribe()&lt;br /&gt;
&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code hosts the application with one more HTTP server which runs on port 443. It is possible to create any number of additional HTTP servers.&lt;br /&gt;
&lt;br /&gt;
=== Authentication ===&lt;br /&gt;
&lt;br /&gt;
CherryPy provides two authentication mechanisms: Simple and Digest. It follows the specification defined by [http://tools.ietf.org/html/rfc2617.html RFC 2617]&lt;br /&gt;
&lt;br /&gt;
=== WSGI Support ===&lt;br /&gt;
&lt;br /&gt;
CherryPy supports the WSGI (Web Server Gateway Interface) specification defined by [http://www.python.org/dev/peps/pep-0333 PEP 0333] and [http://www.python.org/dev/peps/pep-3333 PEP 3333]. &lt;br /&gt;
&lt;br /&gt;
This allows two things:&lt;br /&gt;
* Instead of using the default CherryPy server, a CherryPy application can be hosted on an external WSGI server.&lt;br /&gt;
* The CherryPy server can be used independently to host an external WSGI application.&lt;br /&gt;
&lt;br /&gt;
=== Test Suite ===&lt;br /&gt;
&lt;br /&gt;
The CherryPy framework provides a class, named &amp;lt;tt&amp;gt;helper&amp;lt;/tt&amp;gt; which can be used as a base class for writing functional tests. &lt;br /&gt;
&lt;br /&gt;
Running a test will start the complete application and thus can be used to simulate the scenario when a user actually tries to access the server on web.&lt;br /&gt;
&lt;br /&gt;
The sample code to run a test can be found [http://docs.cherrypy.org/en/latest/advanced.html#testing-your-application here]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=86726</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=86726"/>
		<updated>2014-09-18T23:44:10Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Authentication */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a Python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
CherryPy is a lightweight web server framework written in Python.  It has an object-oriented design and provides a basic HTTP web server as defined in RFC 7321.  It includes built-in profiling, coverage, and testing tools to assist in development.  &lt;br /&gt;
&lt;br /&gt;
CherryPy does not have any built-in templating or database engines, and instead relies on external libraries and plugins. &amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;  Python comes with a rich library support, so this typically is not an issue.&lt;br /&gt;
&lt;br /&gt;
It is distributed under the BSD License&amp;lt;ref&amp;gt;https://bitbucket.org/cherrypy/cherrypy/src/697c7af588b8/cherrypy/LICENSE.txt&amp;lt;/ref&amp;gt;. The latest stable version is 3.6 as of August 19, 2014&amp;lt;ref&amp;gt;https://pypi.python.org/pypi/CherryPy&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some of the well known websites using CherryPy are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list can be found [http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy here].&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates a very simple web server using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
'''WebApp.py'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/code&amp;gt; tells the CherryPy framework to start the web server, which is defined as a class named &amp;lt;code&amp;gt;WebApp&amp;lt;/code&amp;gt;.  The method &amp;lt;code&amp;gt;index&amp;lt;/code&amp;gt; is exposed as a URL handler by the &amp;lt;code&amp;gt;@cherrypy.expose&amp;lt;/code&amp;gt; statement.  The return value of the method is what is sent as the HTTP reposne.&lt;br /&gt;
&lt;br /&gt;
Start the application by running the above Python file &amp;quot;WebApp.py&amp;quot; and open your web browser to http://localhost:8080.  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
=== Query Strings ===&lt;br /&gt;
&lt;br /&gt;
CherryPy will automatically parse the query string of a URL.  Fields are passed as method arguments with matching names, and can take advantage of default argument values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def test(self, value=1):&lt;br /&gt;
        return &amp;quot;Value = &amp;quot; + str(value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A URL of http://localhost:8080/test?value=5 gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_06-37-27_PM.png]]&lt;br /&gt;
&lt;br /&gt;
=== Cookies ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can set browser cookies with &amp;lt;tt&amp;gt;cherrypy.response.cookie&amp;lt;/tt&amp;gt; and read browser cookies with &amp;lt;tt&amp;gt;cherrypy.request.cookie&amp;lt;/tt&amp;gt; by accessing these variables as Python dictionary objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def set(self, value = &amp;quot;Test&amp;quot;):&lt;br /&gt;
        cookie = cherrypy.response.cookie&lt;br /&gt;
        cookie['Value'] = value&lt;br /&gt;
        return &amp;quot;Cookie set&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def get(self):&lt;br /&gt;
        cookie = cherrypy.request.cookie&lt;br /&gt;
        return &amp;quot;Cookie value = &amp;quot; + str(cookie['Value'].value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Navigating to http://localhost:8080/set?value=test followed by http://localhost:8080/get gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:CherryPyCookieTest.png]]&lt;br /&gt;
&lt;br /&gt;
=== Logging ===&lt;br /&gt;
&lt;br /&gt;
CherryPy provides the following method for application logging&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.log(&amp;quot;Hello, CherryPy!&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, all logging is written to the console.  The configuration keys &amp;lt;tt&amp;gt;log.access_file&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;log.error_file&amp;lt;/tt&amp;gt; are also available for writing logging and errors to a text file.&lt;br /&gt;
&lt;br /&gt;
=== Starting the HTTP Server ===&lt;br /&gt;
CherryPy provides two ways to start the HTTP server, depending on the developer's needs.&lt;br /&gt;
&lt;br /&gt;
==== Single Application ====&lt;br /&gt;
The simplest way is to call the &amp;lt;tt&amp;gt;cherrypy.quickstart()&amp;lt;/tt&amp;gt; function. This function takes at least one argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application class 'WebApp' at http://localhost:8080/.&lt;br /&gt;
&lt;br /&gt;
It can also take 2 more arguments.&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp(), '/hello', {'/': {'tools.gzip.on': True}})&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application class 'WebApp' at http://localhost:8080/hello. &lt;br /&gt;
The third argument defines the configuration for the application. It can either be a dictionary object or a configuration file.&lt;br /&gt;
&lt;br /&gt;
==== Multiple Applications ====&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;tt&amp;gt;cherrypy.tree.mount&amp;lt;/tt&amp;gt; is used to host multiple application classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.tree.mount(MyApp1(), '/app1', app1_conf)&lt;br /&gt;
cherrypy.tree.mount(MyApp2(), '/app2', app2_conf)&lt;br /&gt;
&lt;br /&gt;
cherrypy.engine.start()&lt;br /&gt;
cherrypy.engine.block()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will host two applications classes having paths http://localhost:8080/app1 and http://localhost:8080/app2.&lt;br /&gt;
&lt;br /&gt;
=== Server Configuration ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;cherrypy.config.update&amp;lt;/tt&amp;gt; function can be used to configure the CherryPy framework&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'server.socket_port': 9999})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will start the HTTP server on port 9999 instead of the default port 8080. The application can then be accessed at http://localhost:9999/.&lt;br /&gt;
&lt;br /&gt;
A configuration file path instead can be passed as an argument to this function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.config.update(&amp;quot;WebAppServer.conf&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''WebAppServer.conf'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[global]&lt;br /&gt;
server.socket_port: 9999&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sessions ===&lt;br /&gt;
&lt;br /&gt;
In CherryPy, sessions are disabled by default.  To enable sessions, set the configuration &amp;lt;tt&amp;gt;tools.sessions.on&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;. &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/basics.html#using-sessions&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Session variables can be accessed with &amp;lt;tt&amp;gt;cherrypy.session&amp;lt;/tt&amp;gt;, which is a Python dictionary object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        if 'number' not in cherrypy.session:&lt;br /&gt;
            cherrypy.session['number'] = 0&lt;br /&gt;
        else:&lt;br /&gt;
            cherrypy.session['number'] += 1&lt;br /&gt;
        return &amp;quot;Number = &amp;quot; + str(cherrypy.session['number'])&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'tools.sessions.on': True})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example shows a number that increments by 1 every time the user navigates to [http://localhost:8080 localhost:8080].&lt;br /&gt;
&lt;br /&gt;
=== Static Content ===&lt;br /&gt;
Files with static content, such as binaries, images, or stylesheets, can be served by the HTTP server by adding the following lines to the application configuration file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[/images]&lt;br /&gt;
tools.staticdir.on = True&lt;br /&gt;
tools.staticdir.dir = &amp;quot;/site/public/images&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will allow the user to access some file &amp;quot;user.jpg&amp;quot; present in the folder &amp;quot;/site/public/images/user.jpg&amp;quot; using the url http://localhost:8080/images/user.jpg.&lt;br /&gt;
&lt;br /&gt;
=== REST APIs ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can be used to expose the APIs as RESTful Web Services. This allows third party applications to easily communicate with the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class MyAppRestMode(object):&lt;br /&gt;
    exposed = True&lt;br /&gt;
&lt;br /&gt;
    def GET(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
conf = {&lt;br /&gt;
    '/': {&lt;br /&gt;
        'request.dispatch': cherrypy.dispatch.MethodDispatcher(),&lt;br /&gt;
        'tools.response_headers.on': True,&lt;br /&gt;
        'tools.response_headers.headers': [('Content-Type', 'text/plain')],&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
cherrypy.quickstart(MyAppRestMode(), '/', conf)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code exposes the GET API with url http://localhost:8080/. The API returns the string &amp;quot;Hello, CherryPy!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== HTTP Server Port ===&lt;br /&gt;
&lt;br /&gt;
The default HTTP server started by CherryPy can be used to host the application only on one socket port (default 8080). However, it is possible to host the HTTP server on multiple ports by binding them to different socket ports.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from cherrypy._cpserver import Server&lt;br /&gt;
&lt;br /&gt;
server = Server()&lt;br /&gt;
server.socket_port = 443&lt;br /&gt;
server.subscribe()&lt;br /&gt;
&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code hosts the application with one more HTTP server which runs on port 443. It is possible to create any number of additional HTTP servers.&lt;br /&gt;
&lt;br /&gt;
=== Authentication ===&lt;br /&gt;
&lt;br /&gt;
CherryPy provides two authentication mechanisms: Simple and Digest. It follows the specification defined by [http://tools.ietf.org/html/rfc2617.html RFC 2617]&lt;br /&gt;
&lt;br /&gt;
=== WSGI Support ===&lt;br /&gt;
&lt;br /&gt;
CherryPy supports the WSGI (Web Server Gateway Interface) specification defined by [http://www.python.org/dev/peps/pep-0333 PEP 0333] and [http://www.python.org/dev/peps/pep-3333 PEP 3333]. &lt;br /&gt;
&lt;br /&gt;
This allows two things:&lt;br /&gt;
* Instead of using the default CherryPy server, a CherryPy application can be hosted on an external WSGI server.&lt;br /&gt;
* The CherryPy server can be used independently to host an external WSGI application.&lt;br /&gt;
&lt;br /&gt;
=== Test Suite ===&lt;br /&gt;
&lt;br /&gt;
CherryPy framework provides a class, named &amp;lt;tt&amp;gt;helper&amp;lt;/tt&amp;gt; which can be used as a base class for writing functional tests. &lt;br /&gt;
&lt;br /&gt;
Running a test will start the complete application and thus can be used to simulate the scenario when a user actually tries to access the server on web.&lt;br /&gt;
&lt;br /&gt;
The sample code to run a test can be found [http://docs.cherrypy.org/en/latest/advanced.html#testing-your-application here]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=86725</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=86725"/>
		<updated>2014-09-18T23:43:22Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Multiple HTTP Servers */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a Python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
CherryPy is a lightweight web server framework written in Python.  It has an object-oriented design and provides a basic HTTP web server as defined in RFC 7321.  It includes built-in profiling, coverage, and testing tools to assist in development.  &lt;br /&gt;
&lt;br /&gt;
CherryPy does not have any built-in templating or database engines, and instead relies on external libraries and plugins. &amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;  Python comes with a rich library support, so this typically is not an issue.&lt;br /&gt;
&lt;br /&gt;
It is distributed under the BSD License&amp;lt;ref&amp;gt;https://bitbucket.org/cherrypy/cherrypy/src/697c7af588b8/cherrypy/LICENSE.txt&amp;lt;/ref&amp;gt;. The latest stable version is 3.6 as of August 19, 2014&amp;lt;ref&amp;gt;https://pypi.python.org/pypi/CherryPy&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some of the well known websites using CherryPy are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list can be found [http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy here].&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates a very simple web server using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
'''WebApp.py'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/code&amp;gt; tells the CherryPy framework to start the web server, which is defined as a class named &amp;lt;code&amp;gt;WebApp&amp;lt;/code&amp;gt;.  The method &amp;lt;code&amp;gt;index&amp;lt;/code&amp;gt; is exposed as a URL handler by the &amp;lt;code&amp;gt;@cherrypy.expose&amp;lt;/code&amp;gt; statement.  The return value of the method is what is sent as the HTTP reposne.&lt;br /&gt;
&lt;br /&gt;
Start the application by running the above Python file &amp;quot;WebApp.py&amp;quot; and open your web browser to http://localhost:8080.  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
=== Query Strings ===&lt;br /&gt;
&lt;br /&gt;
CherryPy will automatically parse the query string of a URL.  Fields are passed as method arguments with matching names, and can take advantage of default argument values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def test(self, value=1):&lt;br /&gt;
        return &amp;quot;Value = &amp;quot; + str(value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A URL of http://localhost:8080/test?value=5 gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_06-37-27_PM.png]]&lt;br /&gt;
&lt;br /&gt;
=== Cookies ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can set browser cookies with &amp;lt;tt&amp;gt;cherrypy.response.cookie&amp;lt;/tt&amp;gt; and read browser cookies with &amp;lt;tt&amp;gt;cherrypy.request.cookie&amp;lt;/tt&amp;gt; by accessing these variables as Python dictionary objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def set(self, value = &amp;quot;Test&amp;quot;):&lt;br /&gt;
        cookie = cherrypy.response.cookie&lt;br /&gt;
        cookie['Value'] = value&lt;br /&gt;
        return &amp;quot;Cookie set&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def get(self):&lt;br /&gt;
        cookie = cherrypy.request.cookie&lt;br /&gt;
        return &amp;quot;Cookie value = &amp;quot; + str(cookie['Value'].value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Navigating to http://localhost:8080/set?value=test followed by http://localhost:8080/get gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:CherryPyCookieTest.png]]&lt;br /&gt;
&lt;br /&gt;
=== Logging ===&lt;br /&gt;
&lt;br /&gt;
CherryPy provides the following method for application logging&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.log(&amp;quot;Hello, CherryPy!&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, all logging is written to the console.  The configuration keys &amp;lt;tt&amp;gt;log.access_file&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;log.error_file&amp;lt;/tt&amp;gt; are also available for writing logging and errors to a text file.&lt;br /&gt;
&lt;br /&gt;
=== Starting the HTTP Server ===&lt;br /&gt;
CherryPy provides two ways to start the HTTP server, depending on the developer's needs.&lt;br /&gt;
&lt;br /&gt;
==== Single Application ====&lt;br /&gt;
The simplest way is to call the &amp;lt;tt&amp;gt;cherrypy.quickstart()&amp;lt;/tt&amp;gt; function. This function takes at least one argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application class 'WebApp' at http://localhost:8080/.&lt;br /&gt;
&lt;br /&gt;
It can also take 2 more arguments.&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp(), '/hello', {'/': {'tools.gzip.on': True}})&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application class 'WebApp' at http://localhost:8080/hello. &lt;br /&gt;
The third argument defines the configuration for the application. It can either be a dictionary object or a configuration file.&lt;br /&gt;
&lt;br /&gt;
==== Multiple Applications ====&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;tt&amp;gt;cherrypy.tree.mount&amp;lt;/tt&amp;gt; is used to host multiple application classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.tree.mount(MyApp1(), '/app1', app1_conf)&lt;br /&gt;
cherrypy.tree.mount(MyApp2(), '/app2', app2_conf)&lt;br /&gt;
&lt;br /&gt;
cherrypy.engine.start()&lt;br /&gt;
cherrypy.engine.block()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will host two applications classes having paths http://localhost:8080/app1 and http://localhost:8080/app2.&lt;br /&gt;
&lt;br /&gt;
=== Server Configuration ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;cherrypy.config.update&amp;lt;/tt&amp;gt; function can be used to configure the CherryPy framework&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'server.socket_port': 9999})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will start the HTTP server on port 9999 instead of the default port 8080. The application can then be accessed at http://localhost:9999/.&lt;br /&gt;
&lt;br /&gt;
A configuration file path instead can be passed as an argument to this function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.config.update(&amp;quot;WebAppServer.conf&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''WebAppServer.conf'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[global]&lt;br /&gt;
server.socket_port: 9999&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sessions ===&lt;br /&gt;
&lt;br /&gt;
In CherryPy, sessions are disabled by default.  To enable sessions, set the configuration &amp;lt;tt&amp;gt;tools.sessions.on&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;. &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/basics.html#using-sessions&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Session variables can be accessed with &amp;lt;tt&amp;gt;cherrypy.session&amp;lt;/tt&amp;gt;, which is a Python dictionary object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        if 'number' not in cherrypy.session:&lt;br /&gt;
            cherrypy.session['number'] = 0&lt;br /&gt;
        else:&lt;br /&gt;
            cherrypy.session['number'] += 1&lt;br /&gt;
        return &amp;quot;Number = &amp;quot; + str(cherrypy.session['number'])&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'tools.sessions.on': True})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example shows a number that increments by 1 every time the user navigates to [http://localhost:8080 localhost:8080].&lt;br /&gt;
&lt;br /&gt;
=== Static Content ===&lt;br /&gt;
Files with static content, such as binaries, images, or stylesheets, can be served by the HTTP server by adding the following lines to the application configuration file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[/images]&lt;br /&gt;
tools.staticdir.on = True&lt;br /&gt;
tools.staticdir.dir = &amp;quot;/site/public/images&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will allow the user to access some file &amp;quot;user.jpg&amp;quot; present in the folder &amp;quot;/site/public/images/user.jpg&amp;quot; using the url http://localhost:8080/images/user.jpg.&lt;br /&gt;
&lt;br /&gt;
=== REST APIs ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can be used to expose the APIs as RESTful Web Services. This allows third party applications to easily communicate with the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class MyAppRestMode(object):&lt;br /&gt;
    exposed = True&lt;br /&gt;
&lt;br /&gt;
    def GET(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
conf = {&lt;br /&gt;
    '/': {&lt;br /&gt;
        'request.dispatch': cherrypy.dispatch.MethodDispatcher(),&lt;br /&gt;
        'tools.response_headers.on': True,&lt;br /&gt;
        'tools.response_headers.headers': [('Content-Type', 'text/plain')],&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
cherrypy.quickstart(MyAppRestMode(), '/', conf)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code exposes the GET API with url http://localhost:8080/. The API returns the string &amp;quot;Hello, CherryPy!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== HTTP Server Port ===&lt;br /&gt;
&lt;br /&gt;
The default HTTP server started by CherryPy can be used to host the application only on one socket port (default 8080). However, it is possible to host the HTTP server on multiple ports by binding them to different socket ports.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from cherrypy._cpserver import Server&lt;br /&gt;
&lt;br /&gt;
server = Server()&lt;br /&gt;
server.socket_port = 443&lt;br /&gt;
server.subscribe()&lt;br /&gt;
&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code hosts the application with one more HTTP server which runs on port 443. It is possible to create any number of additional HTTP servers.&lt;br /&gt;
&lt;br /&gt;
=== Authentication ===&lt;br /&gt;
&lt;br /&gt;
CherryPy supports two authentication mechanisms: Simple and Digest. It follows the specification defined by [http://tools.ietf.org/html/rfc2617.html RFC 2617]&lt;br /&gt;
&lt;br /&gt;
=== WSGI Support ===&lt;br /&gt;
&lt;br /&gt;
CherryPy supports the WSGI (Web Server Gateway Interface) specification defined by [http://www.python.org/dev/peps/pep-0333 PEP 0333] and [http://www.python.org/dev/peps/pep-3333 PEP 3333]. &lt;br /&gt;
&lt;br /&gt;
This allows two things:&lt;br /&gt;
* Instead of using the default CherryPy server, a CherryPy application can be hosted on an external WSGI server.&lt;br /&gt;
* The CherryPy server can be used independently to host an external WSGI application.&lt;br /&gt;
&lt;br /&gt;
=== Test Suite ===&lt;br /&gt;
&lt;br /&gt;
CherryPy framework provides a class, named &amp;lt;tt&amp;gt;helper&amp;lt;/tt&amp;gt; which can be used as a base class for writing functional tests. &lt;br /&gt;
&lt;br /&gt;
Running a test will start the complete application and thus can be used to simulate the scenario when a user actually tries to access the server on web.&lt;br /&gt;
&lt;br /&gt;
The sample code to run a test can be found [http://docs.cherrypy.org/en/latest/advanced.html#testing-your-application here]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=86723</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=86723"/>
		<updated>2014-09-18T23:40:10Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Publish REST APIs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a Python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
CherryPy is a lightweight web server framework written in Python.  It has an object-oriented design and provides a basic HTTP web server as defined in RFC 7321.  It includes built-in profiling, coverage, and testing tools to assist in development.  &lt;br /&gt;
&lt;br /&gt;
CherryPy does not have any built-in templating or database engines, and instead relies on external libraries and plugins. &amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;  Python comes with a rich library support, so this typically is not an issue.&lt;br /&gt;
&lt;br /&gt;
It is distributed under the BSD License&amp;lt;ref&amp;gt;https://bitbucket.org/cherrypy/cherrypy/src/697c7af588b8/cherrypy/LICENSE.txt&amp;lt;/ref&amp;gt;. The latest stable version is 3.6 as of August 19, 2014&amp;lt;ref&amp;gt;https://pypi.python.org/pypi/CherryPy&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some of the well known websites using CherryPy are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list can be found [http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy here].&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates a very simple web server using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
'''WebApp.py'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/code&amp;gt; tells the CherryPy framework to start the web server, which is defined as a class named &amp;lt;code&amp;gt;WebApp&amp;lt;/code&amp;gt;.  The method &amp;lt;code&amp;gt;index&amp;lt;/code&amp;gt; is exposed as a URL handler by the &amp;lt;code&amp;gt;@cherrypy.expose&amp;lt;/code&amp;gt; statement.  The return value of the method is what is sent as the HTTP reposne.&lt;br /&gt;
&lt;br /&gt;
Start the application by running the above Python file &amp;quot;WebApp.py&amp;quot; and open your web browser to http://localhost:8080.  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
=== Query Strings ===&lt;br /&gt;
&lt;br /&gt;
CherryPy will automatically parse the query string of a URL.  Fields are passed as method arguments with matching names, and can take advantage of default argument values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def test(self, value=1):&lt;br /&gt;
        return &amp;quot;Value = &amp;quot; + str(value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A URL of http://localhost:8080/test?value=5 gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_06-37-27_PM.png]]&lt;br /&gt;
&lt;br /&gt;
=== Cookies ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can set browser cookies with &amp;lt;tt&amp;gt;cherrypy.response.cookie&amp;lt;/tt&amp;gt; and read browser cookies with &amp;lt;tt&amp;gt;cherrypy.request.cookie&amp;lt;/tt&amp;gt; by accessing these variables as Python dictionary objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def set(self, value = &amp;quot;Test&amp;quot;):&lt;br /&gt;
        cookie = cherrypy.response.cookie&lt;br /&gt;
        cookie['Value'] = value&lt;br /&gt;
        return &amp;quot;Cookie set&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def get(self):&lt;br /&gt;
        cookie = cherrypy.request.cookie&lt;br /&gt;
        return &amp;quot;Cookie value = &amp;quot; + str(cookie['Value'].value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Navigating to http://localhost:8080/set?value=test followed by http://localhost:8080/get gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:CherryPyCookieTest.png]]&lt;br /&gt;
&lt;br /&gt;
=== Logging ===&lt;br /&gt;
&lt;br /&gt;
CherryPy provides the following method for application logging&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.log(&amp;quot;Hello, CherryPy!&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, all logging is written to the console.  The configuration keys &amp;lt;tt&amp;gt;log.access_file&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;log.error_file&amp;lt;/tt&amp;gt; are also available for writing logging and errors to a text file.&lt;br /&gt;
&lt;br /&gt;
=== Starting the HTTP Server ===&lt;br /&gt;
CherryPy provides two ways to start the HTTP server, depending on the developer's needs.&lt;br /&gt;
&lt;br /&gt;
==== Single Application ====&lt;br /&gt;
The simplest way is to call the &amp;lt;tt&amp;gt;cherrypy.quickstart()&amp;lt;/tt&amp;gt; function. This function takes at least one argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application class 'WebApp' at http://localhost:8080/.&lt;br /&gt;
&lt;br /&gt;
It can also take 2 more arguments.&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp(), '/hello', {'/': {'tools.gzip.on': True}})&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application class 'WebApp' at http://localhost:8080/hello. &lt;br /&gt;
The third argument defines the configuration for the application. It can either be a dictionary object or a configuration file.&lt;br /&gt;
&lt;br /&gt;
==== Multiple Applications ====&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;tt&amp;gt;cherrypy.tree.mount&amp;lt;/tt&amp;gt; is used to host multiple application classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.tree.mount(MyApp1(), '/app1', app1_conf)&lt;br /&gt;
cherrypy.tree.mount(MyApp2(), '/app2', app2_conf)&lt;br /&gt;
&lt;br /&gt;
cherrypy.engine.start()&lt;br /&gt;
cherrypy.engine.block()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will host two applications classes having paths http://localhost:8080/app1 and http://localhost:8080/app2.&lt;br /&gt;
&lt;br /&gt;
=== Server Configuration ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;cherrypy.config.update&amp;lt;/tt&amp;gt; function can be used to configure the CherryPy framework&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'server.socket_port': 9999})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will start the HTTP server on port 9999 instead of the default port 8080. The application can then be accessed at http://localhost:9999/.&lt;br /&gt;
&lt;br /&gt;
A configuration file path instead can be passed as an argument to this function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.config.update(&amp;quot;WebAppServer.conf&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''WebAppServer.conf'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[global]&lt;br /&gt;
server.socket_port: 9999&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sessions ===&lt;br /&gt;
&lt;br /&gt;
In CherryPy, sessions are disabled by default.  To enable sessions, set the configuration &amp;lt;tt&amp;gt;tools.sessions.on&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;. &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/basics.html#using-sessions&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Session variables can be accessed with &amp;lt;tt&amp;gt;cherrypy.session&amp;lt;/tt&amp;gt;, which is a Python dictionary object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        if 'number' not in cherrypy.session:&lt;br /&gt;
            cherrypy.session['number'] = 0&lt;br /&gt;
        else:&lt;br /&gt;
            cherrypy.session['number'] += 1&lt;br /&gt;
        return &amp;quot;Number = &amp;quot; + str(cherrypy.session['number'])&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'tools.sessions.on': True})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example shows a number that increments by 1 every time the user navigates to [http://localhost:8080 localhost:8080].&lt;br /&gt;
&lt;br /&gt;
=== Static Content ===&lt;br /&gt;
Files with static content, such as binaries, images, or stylesheets, can be served by the HTTP server by adding the following lines to the application configuration file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[/images]&lt;br /&gt;
tools.staticdir.on = True&lt;br /&gt;
tools.staticdir.dir = &amp;quot;/site/public/images&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will allow the user to access some file &amp;quot;user.jpg&amp;quot; present in the folder &amp;quot;/site/public/images/user.jpg&amp;quot; using the url http://localhost:8080/images/user.jpg.&lt;br /&gt;
&lt;br /&gt;
=== REST APIs ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can be used to expose the APIs as RESTful Web Services. This allows third party applications to easily communicate with the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class MyAppRestMode(object):&lt;br /&gt;
    exposed = True&lt;br /&gt;
&lt;br /&gt;
    def GET(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
conf = {&lt;br /&gt;
    '/': {&lt;br /&gt;
        'request.dispatch': cherrypy.dispatch.MethodDispatcher(),&lt;br /&gt;
        'tools.response_headers.on': True,&lt;br /&gt;
        'tools.response_headers.headers': [('Content-Type', 'text/plain')],&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
cherrypy.quickstart(MyAppRestMode(), '/', conf)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code exposes the GET API with url http://localhost:8080/. The API returns the string &amp;quot;Hello, CherryPy!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Multiple HTTP Servers ===&lt;br /&gt;
&lt;br /&gt;
The default HTTP server started by CherryPy can only be used to host the application on one port. But, it is also possible to host the application on multiple ports by starting additional servers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from cherrypy._cpserver import Server&lt;br /&gt;
&lt;br /&gt;
server = Server()&lt;br /&gt;
server.socket_port = 443&lt;br /&gt;
server.subscribe()&lt;br /&gt;
&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code hosts the application with one more server, which runs on port 443. It is possible to create any number of additional servers.&lt;br /&gt;
&lt;br /&gt;
=== Authentication ===&lt;br /&gt;
&lt;br /&gt;
CherryPy supports two authentication mechanisms: Simple and Digest. It follows the specification defined by [http://tools.ietf.org/html/rfc2617.html RFC 2617]&lt;br /&gt;
&lt;br /&gt;
=== WSGI Support ===&lt;br /&gt;
&lt;br /&gt;
CherryPy supports the WSGI (Web Server Gateway Interface) specification defined by [http://www.python.org/dev/peps/pep-0333 PEP 0333] and [http://www.python.org/dev/peps/pep-3333 PEP 3333]. &lt;br /&gt;
&lt;br /&gt;
This allows two things:&lt;br /&gt;
* Instead of using the default CherryPy server, a CherryPy application can be hosted on an external WSGI server.&lt;br /&gt;
* The CherryPy server can be used independently to host an external WSGI application.&lt;br /&gt;
&lt;br /&gt;
=== Test Suite ===&lt;br /&gt;
&lt;br /&gt;
CherryPy framework provides a class, named &amp;lt;tt&amp;gt;helper&amp;lt;/tt&amp;gt; which can be used as a base class for writing functional tests. &lt;br /&gt;
&lt;br /&gt;
Running a test will start the complete application and thus can be used to simulate the scenario when a user actually tries to access the server on web.&lt;br /&gt;
&lt;br /&gt;
The sample code to run a test can be found [http://docs.cherrypy.org/en/latest/advanced.html#testing-your-application here]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=86722</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=86722"/>
		<updated>2014-09-18T23:39:02Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Serve Static Content */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a Python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
CherryPy is a lightweight web server framework written in Python.  It has an object-oriented design and provides a basic HTTP web server as defined in RFC 7321.  It includes built-in profiling, coverage, and testing tools to assist in development.  &lt;br /&gt;
&lt;br /&gt;
CherryPy does not have any built-in templating or database engines, and instead relies on external libraries and plugins. &amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;  Python comes with a rich library support, so this typically is not an issue.&lt;br /&gt;
&lt;br /&gt;
It is distributed under the BSD License&amp;lt;ref&amp;gt;https://bitbucket.org/cherrypy/cherrypy/src/697c7af588b8/cherrypy/LICENSE.txt&amp;lt;/ref&amp;gt;. The latest stable version is 3.6 as of August 19, 2014&amp;lt;ref&amp;gt;https://pypi.python.org/pypi/CherryPy&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some of the well known websites using CherryPy are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list can be found [http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy here].&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates a very simple web server using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
'''WebApp.py'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/code&amp;gt; tells the CherryPy framework to start the web server, which is defined as a class named &amp;lt;code&amp;gt;WebApp&amp;lt;/code&amp;gt;.  The method &amp;lt;code&amp;gt;index&amp;lt;/code&amp;gt; is exposed as a URL handler by the &amp;lt;code&amp;gt;@cherrypy.expose&amp;lt;/code&amp;gt; statement.  The return value of the method is what is sent as the HTTP reposne.&lt;br /&gt;
&lt;br /&gt;
Start the application by running the above Python file &amp;quot;WebApp.py&amp;quot; and open your web browser to http://localhost:8080.  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
=== Query Strings ===&lt;br /&gt;
&lt;br /&gt;
CherryPy will automatically parse the query string of a URL.  Fields are passed as method arguments with matching names, and can take advantage of default argument values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def test(self, value=1):&lt;br /&gt;
        return &amp;quot;Value = &amp;quot; + str(value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A URL of http://localhost:8080/test?value=5 gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_06-37-27_PM.png]]&lt;br /&gt;
&lt;br /&gt;
=== Cookies ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can set browser cookies with &amp;lt;tt&amp;gt;cherrypy.response.cookie&amp;lt;/tt&amp;gt; and read browser cookies with &amp;lt;tt&amp;gt;cherrypy.request.cookie&amp;lt;/tt&amp;gt; by accessing these variables as Python dictionary objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def set(self, value = &amp;quot;Test&amp;quot;):&lt;br /&gt;
        cookie = cherrypy.response.cookie&lt;br /&gt;
        cookie['Value'] = value&lt;br /&gt;
        return &amp;quot;Cookie set&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def get(self):&lt;br /&gt;
        cookie = cherrypy.request.cookie&lt;br /&gt;
        return &amp;quot;Cookie value = &amp;quot; + str(cookie['Value'].value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Navigating to http://localhost:8080/set?value=test followed by http://localhost:8080/get gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:CherryPyCookieTest.png]]&lt;br /&gt;
&lt;br /&gt;
=== Logging ===&lt;br /&gt;
&lt;br /&gt;
CherryPy provides the following method for application logging&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.log(&amp;quot;Hello, CherryPy!&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, all logging is written to the console.  The configuration keys &amp;lt;tt&amp;gt;log.access_file&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;log.error_file&amp;lt;/tt&amp;gt; are also available for writing logging and errors to a text file.&lt;br /&gt;
&lt;br /&gt;
=== Starting the HTTP Server ===&lt;br /&gt;
CherryPy provides two ways to start the HTTP server, depending on the developer's needs.&lt;br /&gt;
&lt;br /&gt;
==== Single Application ====&lt;br /&gt;
The simplest way is to call the &amp;lt;tt&amp;gt;cherrypy.quickstart()&amp;lt;/tt&amp;gt; function. This function takes at least one argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application class 'WebApp' at http://localhost:8080/.&lt;br /&gt;
&lt;br /&gt;
It can also take 2 more arguments.&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp(), '/hello', {'/': {'tools.gzip.on': True}})&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application class 'WebApp' at http://localhost:8080/hello. &lt;br /&gt;
The third argument defines the configuration for the application. It can either be a dictionary object or a configuration file.&lt;br /&gt;
&lt;br /&gt;
==== Multiple Applications ====&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;tt&amp;gt;cherrypy.tree.mount&amp;lt;/tt&amp;gt; is used to host multiple application classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.tree.mount(MyApp1(), '/app1', app1_conf)&lt;br /&gt;
cherrypy.tree.mount(MyApp2(), '/app2', app2_conf)&lt;br /&gt;
&lt;br /&gt;
cherrypy.engine.start()&lt;br /&gt;
cherrypy.engine.block()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will host two applications classes having paths http://localhost:8080/app1 and http://localhost:8080/app2.&lt;br /&gt;
&lt;br /&gt;
=== Server Configuration ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;cherrypy.config.update&amp;lt;/tt&amp;gt; function can be used to configure the CherryPy framework&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'server.socket_port': 9999})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will start the HTTP server on port 9999 instead of the default port 8080. The application can then be accessed at http://localhost:9999/.&lt;br /&gt;
&lt;br /&gt;
A configuration file path instead can be passed as an argument to this function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.config.update(&amp;quot;WebAppServer.conf&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''WebAppServer.conf'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[global]&lt;br /&gt;
server.socket_port: 9999&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sessions ===&lt;br /&gt;
&lt;br /&gt;
In CherryPy, sessions are disabled by default.  To enable sessions, set the configuration &amp;lt;tt&amp;gt;tools.sessions.on&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;. &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/basics.html#using-sessions&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Session variables can be accessed with &amp;lt;tt&amp;gt;cherrypy.session&amp;lt;/tt&amp;gt;, which is a Python dictionary object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        if 'number' not in cherrypy.session:&lt;br /&gt;
            cherrypy.session['number'] = 0&lt;br /&gt;
        else:&lt;br /&gt;
            cherrypy.session['number'] += 1&lt;br /&gt;
        return &amp;quot;Number = &amp;quot; + str(cherrypy.session['number'])&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'tools.sessions.on': True})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example shows a number that increments by 1 every time the user navigates to [http://localhost:8080 localhost:8080].&lt;br /&gt;
&lt;br /&gt;
=== Static Content ===&lt;br /&gt;
Files with static content, such as binaries, images, or stylesheets, can be served by the HTTP server by adding the following lines to the application configuration file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[/images]&lt;br /&gt;
tools.staticdir.on = True&lt;br /&gt;
tools.staticdir.dir = &amp;quot;/site/public/images&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will allow the user to access some file &amp;quot;user.jpg&amp;quot; present in the folder &amp;quot;/site/public/images/user.jpg&amp;quot; using the url http://localhost:8080/images/user.jpg.&lt;br /&gt;
&lt;br /&gt;
=== Publish REST APIs ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can be used to expose the APIs as RESTful Web Services. This allows third party applications to easily communicate with the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class MyAppRestMode(object):&lt;br /&gt;
    exposed = True&lt;br /&gt;
&lt;br /&gt;
    def GET(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
conf = {&lt;br /&gt;
    '/': {&lt;br /&gt;
        'request.dispatch': cherrypy.dispatch.MethodDispatcher(),&lt;br /&gt;
        'tools.response_headers.on': True,&lt;br /&gt;
        'tools.response_headers.headers': [('Content-Type', 'text/plain')],&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
cherrypy.quickstart(MyAppRestMode(), '/', conf)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code exposes the GET API with url http://localhost:8080/. The API returns the string &amp;quot;Hello, CherryPy!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Multiple HTTP Servers ===&lt;br /&gt;
&lt;br /&gt;
The default HTTP server started by CherryPy can only be used to host the application on one port. But, it is also possible to host the application on multiple ports by starting additional servers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from cherrypy._cpserver import Server&lt;br /&gt;
&lt;br /&gt;
server = Server()&lt;br /&gt;
server.socket_port = 443&lt;br /&gt;
server.subscribe()&lt;br /&gt;
&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code hosts the application with one more server, which runs on port 443. It is possible to create any number of additional servers.&lt;br /&gt;
&lt;br /&gt;
=== Authentication ===&lt;br /&gt;
&lt;br /&gt;
CherryPy supports two authentication mechanisms: Simple and Digest. It follows the specification defined by [http://tools.ietf.org/html/rfc2617.html RFC 2617]&lt;br /&gt;
&lt;br /&gt;
=== WSGI Support ===&lt;br /&gt;
&lt;br /&gt;
CherryPy supports the WSGI (Web Server Gateway Interface) specification defined by [http://www.python.org/dev/peps/pep-0333 PEP 0333] and [http://www.python.org/dev/peps/pep-3333 PEP 3333]. &lt;br /&gt;
&lt;br /&gt;
This allows two things:&lt;br /&gt;
* Instead of using the default CherryPy server, a CherryPy application can be hosted on an external WSGI server.&lt;br /&gt;
* The CherryPy server can be used independently to host an external WSGI application.&lt;br /&gt;
&lt;br /&gt;
=== Test Suite ===&lt;br /&gt;
&lt;br /&gt;
CherryPy framework provides a class, named &amp;lt;tt&amp;gt;helper&amp;lt;/tt&amp;gt; which can be used as a base class for writing functional tests. &lt;br /&gt;
&lt;br /&gt;
Running a test will start the complete application and thus can be used to simulate the scenario when a user actually tries to access the server on web.&lt;br /&gt;
&lt;br /&gt;
The sample code to run a test can be found [http://docs.cherrypy.org/en/latest/advanced.html#testing-your-application here]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=86721</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=86721"/>
		<updated>2014-09-18T23:36:12Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Server Configuration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a Python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
CherryPy is a lightweight web server framework written in Python.  It has an object-oriented design and provides a basic HTTP web server as defined in RFC 7321.  It includes built-in profiling, coverage, and testing tools to assist in development.  &lt;br /&gt;
&lt;br /&gt;
CherryPy does not have any built-in templating or database engines, and instead relies on external libraries and plugins. &amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;  Python comes with a rich library support, so this typically is not an issue.&lt;br /&gt;
&lt;br /&gt;
It is distributed under the BSD License&amp;lt;ref&amp;gt;https://bitbucket.org/cherrypy/cherrypy/src/697c7af588b8/cherrypy/LICENSE.txt&amp;lt;/ref&amp;gt;. The latest stable version is 3.6 as of August 19, 2014&amp;lt;ref&amp;gt;https://pypi.python.org/pypi/CherryPy&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some of the well known websites using CherryPy are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list can be found [http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy here].&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates a very simple web server using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
'''WebApp.py'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/code&amp;gt; tells the CherryPy framework to start the web server, which is defined as a class named &amp;lt;code&amp;gt;WebApp&amp;lt;/code&amp;gt;.  The method &amp;lt;code&amp;gt;index&amp;lt;/code&amp;gt; is exposed as a URL handler by the &amp;lt;code&amp;gt;@cherrypy.expose&amp;lt;/code&amp;gt; statement.  The return value of the method is what is sent as the HTTP reposne.&lt;br /&gt;
&lt;br /&gt;
Start the application by running the above Python file &amp;quot;WebApp.py&amp;quot; and open your web browser to http://localhost:8080.  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
=== Query Strings ===&lt;br /&gt;
&lt;br /&gt;
CherryPy will automatically parse the query string of a URL.  Fields are passed as method arguments with matching names, and can take advantage of default argument values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def test(self, value=1):&lt;br /&gt;
        return &amp;quot;Value = &amp;quot; + str(value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A URL of http://localhost:8080/test?value=5 gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_06-37-27_PM.png]]&lt;br /&gt;
&lt;br /&gt;
=== Cookies ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can set browser cookies with &amp;lt;tt&amp;gt;cherrypy.response.cookie&amp;lt;/tt&amp;gt; and read browser cookies with &amp;lt;tt&amp;gt;cherrypy.request.cookie&amp;lt;/tt&amp;gt; by accessing these variables as Python dictionary objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def set(self, value = &amp;quot;Test&amp;quot;):&lt;br /&gt;
        cookie = cherrypy.response.cookie&lt;br /&gt;
        cookie['Value'] = value&lt;br /&gt;
        return &amp;quot;Cookie set&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def get(self):&lt;br /&gt;
        cookie = cherrypy.request.cookie&lt;br /&gt;
        return &amp;quot;Cookie value = &amp;quot; + str(cookie['Value'].value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Navigating to http://localhost:8080/set?value=test followed by http://localhost:8080/get gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:CherryPyCookieTest.png]]&lt;br /&gt;
&lt;br /&gt;
=== Logging ===&lt;br /&gt;
&lt;br /&gt;
CherryPy provides the following method for application logging&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.log(&amp;quot;Hello, CherryPy!&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, all logging is written to the console.  The configuration keys &amp;lt;tt&amp;gt;log.access_file&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;log.error_file&amp;lt;/tt&amp;gt; are also available for writing logging and errors to a text file.&lt;br /&gt;
&lt;br /&gt;
=== Starting the HTTP Server ===&lt;br /&gt;
CherryPy provides two ways to start the HTTP server, depending on the developer's needs.&lt;br /&gt;
&lt;br /&gt;
==== Single Application ====&lt;br /&gt;
The simplest way is to call the &amp;lt;tt&amp;gt;cherrypy.quickstart()&amp;lt;/tt&amp;gt; function. This function takes at least one argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application class 'WebApp' at http://localhost:8080/.&lt;br /&gt;
&lt;br /&gt;
It can also take 2 more arguments.&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp(), '/hello', {'/': {'tools.gzip.on': True}})&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application class 'WebApp' at http://localhost:8080/hello. &lt;br /&gt;
The third argument defines the configuration for the application. It can either be a dictionary object or a configuration file.&lt;br /&gt;
&lt;br /&gt;
==== Multiple Applications ====&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;tt&amp;gt;cherrypy.tree.mount&amp;lt;/tt&amp;gt; is used to host multiple application classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.tree.mount(MyApp1(), '/app1', app1_conf)&lt;br /&gt;
cherrypy.tree.mount(MyApp2(), '/app2', app2_conf)&lt;br /&gt;
&lt;br /&gt;
cherrypy.engine.start()&lt;br /&gt;
cherrypy.engine.block()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will host two applications classes having paths http://localhost:8080/app1 and http://localhost:8080/app2.&lt;br /&gt;
&lt;br /&gt;
=== Server Configuration ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;cherrypy.config.update&amp;lt;/tt&amp;gt; function can be used to configure the CherryPy framework&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'server.socket_port': 9999})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will start the HTTP server on port 9999 instead of the default port 8080. The application can then be accessed at http://localhost:9999/.&lt;br /&gt;
&lt;br /&gt;
A configuration file path instead can be passed as an argument to this function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.config.update(&amp;quot;WebAppServer.conf&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''WebAppServer.conf'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[global]&lt;br /&gt;
server.socket_port: 9999&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sessions ===&lt;br /&gt;
&lt;br /&gt;
In CherryPy, sessions are disabled by default.  To enable sessions, set the configuration &amp;lt;tt&amp;gt;tools.sessions.on&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;. &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/basics.html#using-sessions&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Session variables can be accessed with &amp;lt;tt&amp;gt;cherrypy.session&amp;lt;/tt&amp;gt;, which is a Python dictionary object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        if 'number' not in cherrypy.session:&lt;br /&gt;
            cherrypy.session['number'] = 0&lt;br /&gt;
        else:&lt;br /&gt;
            cherrypy.session['number'] += 1&lt;br /&gt;
        return &amp;quot;Number = &amp;quot; + str(cherrypy.session['number'])&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'tools.sessions.on': True})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example shows a number that increments by 1 every time the user navigates to [http://localhost:8080 localhost:8080].&lt;br /&gt;
&lt;br /&gt;
=== Serve Static Content ===&lt;br /&gt;
Static contents like files, images, stylesheets etc. can be easily served by adding the following lines in the the application configuration file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[/images]&lt;br /&gt;
tools.staticdir.on = True&lt;br /&gt;
tools.staticdir.dir = &amp;quot;/site/public/images&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will allow the user to access some file &amp;quot;user.jpg&amp;quot; present in the folder &amp;quot;/site/public/images/user.jpg&amp;quot; using the url http://localhost:8080/images/user.jpg.&lt;br /&gt;
&lt;br /&gt;
=== Publish REST APIs ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can be used to expose the APIs as RESTful Web Services. This allows third party applications to easily communicate with the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class MyAppRestMode(object):&lt;br /&gt;
    exposed = True&lt;br /&gt;
&lt;br /&gt;
    def GET(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
conf = {&lt;br /&gt;
    '/': {&lt;br /&gt;
        'request.dispatch': cherrypy.dispatch.MethodDispatcher(),&lt;br /&gt;
        'tools.response_headers.on': True,&lt;br /&gt;
        'tools.response_headers.headers': [('Content-Type', 'text/plain')],&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
cherrypy.quickstart(MyAppRestMode(), '/', conf)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code exposes the GET API with url http://localhost:8080/. The API returns the string &amp;quot;Hello, CherryPy!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Multiple HTTP Servers ===&lt;br /&gt;
&lt;br /&gt;
The default HTTP server started by CherryPy can only be used to host the application on one port. But, it is also possible to host the application on multiple ports by starting additional servers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from cherrypy._cpserver import Server&lt;br /&gt;
&lt;br /&gt;
server = Server()&lt;br /&gt;
server.socket_port = 443&lt;br /&gt;
server.subscribe()&lt;br /&gt;
&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code hosts the application with one more server, which runs on port 443. It is possible to create any number of additional servers.&lt;br /&gt;
&lt;br /&gt;
=== Authentication ===&lt;br /&gt;
&lt;br /&gt;
CherryPy supports two authentication mechanisms: Simple and Digest. It follows the specification defined by [http://tools.ietf.org/html/rfc2617.html RFC 2617]&lt;br /&gt;
&lt;br /&gt;
=== WSGI Support ===&lt;br /&gt;
&lt;br /&gt;
CherryPy supports the WSGI (Web Server Gateway Interface) specification defined by [http://www.python.org/dev/peps/pep-0333 PEP 0333] and [http://www.python.org/dev/peps/pep-3333 PEP 3333]. &lt;br /&gt;
&lt;br /&gt;
This allows two things:&lt;br /&gt;
* Instead of using the default CherryPy server, a CherryPy application can be hosted on an external WSGI server.&lt;br /&gt;
* The CherryPy server can be used independently to host an external WSGI application.&lt;br /&gt;
&lt;br /&gt;
=== Test Suite ===&lt;br /&gt;
&lt;br /&gt;
CherryPy framework provides a class, named &amp;lt;tt&amp;gt;helper&amp;lt;/tt&amp;gt; which can be used as a base class for writing functional tests. &lt;br /&gt;
&lt;br /&gt;
Running a test will start the complete application and thus can be used to simulate the scenario when a user actually tries to access the server on web.&lt;br /&gt;
&lt;br /&gt;
The sample code to run a test can be found [http://docs.cherrypy.org/en/latest/advanced.html#testing-your-application here]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=86720</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=86720"/>
		<updated>2014-09-18T23:34:31Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Built-in HTTP Server to host single or multiple applications */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a Python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
CherryPy is a lightweight web server framework written in Python.  It has an object-oriented design and provides a basic HTTP web server as defined in RFC 7321.  It includes built-in profiling, coverage, and testing tools to assist in development.  &lt;br /&gt;
&lt;br /&gt;
CherryPy does not have any built-in templating or database engines, and instead relies on external libraries and plugins. &amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;  Python comes with a rich library support, so this typically is not an issue.&lt;br /&gt;
&lt;br /&gt;
It is distributed under the BSD License&amp;lt;ref&amp;gt;https://bitbucket.org/cherrypy/cherrypy/src/697c7af588b8/cherrypy/LICENSE.txt&amp;lt;/ref&amp;gt;. The latest stable version is 3.6 as of August 19, 2014&amp;lt;ref&amp;gt;https://pypi.python.org/pypi/CherryPy&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some of the well known websites using CherryPy are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list can be found [http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy here].&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates a very simple web server using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
'''WebApp.py'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/code&amp;gt; tells the CherryPy framework to start the web server, which is defined as a class named &amp;lt;code&amp;gt;WebApp&amp;lt;/code&amp;gt;.  The method &amp;lt;code&amp;gt;index&amp;lt;/code&amp;gt; is exposed as a URL handler by the &amp;lt;code&amp;gt;@cherrypy.expose&amp;lt;/code&amp;gt; statement.  The return value of the method is what is sent as the HTTP reposne.&lt;br /&gt;
&lt;br /&gt;
Start the application by running the above Python file &amp;quot;WebApp.py&amp;quot; and open your web browser to http://localhost:8080.  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
=== Query Strings ===&lt;br /&gt;
&lt;br /&gt;
CherryPy will automatically parse the query string of a URL.  Fields are passed as method arguments with matching names, and can take advantage of default argument values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def test(self, value=1):&lt;br /&gt;
        return &amp;quot;Value = &amp;quot; + str(value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A URL of http://localhost:8080/test?value=5 gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_06-37-27_PM.png]]&lt;br /&gt;
&lt;br /&gt;
=== Cookies ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can set browser cookies with &amp;lt;tt&amp;gt;cherrypy.response.cookie&amp;lt;/tt&amp;gt; and read browser cookies with &amp;lt;tt&amp;gt;cherrypy.request.cookie&amp;lt;/tt&amp;gt; by accessing these variables as Python dictionary objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def set(self, value = &amp;quot;Test&amp;quot;):&lt;br /&gt;
        cookie = cherrypy.response.cookie&lt;br /&gt;
        cookie['Value'] = value&lt;br /&gt;
        return &amp;quot;Cookie set&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def get(self):&lt;br /&gt;
        cookie = cherrypy.request.cookie&lt;br /&gt;
        return &amp;quot;Cookie value = &amp;quot; + str(cookie['Value'].value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Navigating to http://localhost:8080/set?value=test followed by http://localhost:8080/get gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:CherryPyCookieTest.png]]&lt;br /&gt;
&lt;br /&gt;
=== Logging ===&lt;br /&gt;
&lt;br /&gt;
CherryPy provides the following method for application logging&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.log(&amp;quot;Hello, CherryPy!&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, all logging is written to the console.  The configuration keys &amp;lt;tt&amp;gt;log.access_file&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;log.error_file&amp;lt;/tt&amp;gt; are also available for writing logging and errors to a text file.&lt;br /&gt;
&lt;br /&gt;
=== Starting the HTTP Server ===&lt;br /&gt;
CherryPy provides two ways to start the HTTP server, depending on the developer's needs.&lt;br /&gt;
&lt;br /&gt;
==== Single Application ====&lt;br /&gt;
The simplest way is to call the &amp;lt;tt&amp;gt;cherrypy.quickstart()&amp;lt;/tt&amp;gt; function. This function takes at least one argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application class 'WebApp' at http://localhost:8080/.&lt;br /&gt;
&lt;br /&gt;
It can also take 2 more arguments.&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp(), '/hello', {'/': {'tools.gzip.on': True}})&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application class 'WebApp' at http://localhost:8080/hello. &lt;br /&gt;
The third argument defines the configuration for the application. It can either be a dictionary object or a configuration file.&lt;br /&gt;
&lt;br /&gt;
==== Multiple Applications ====&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;tt&amp;gt;cherrypy.tree.mount&amp;lt;/tt&amp;gt; is used to host multiple application classes.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.tree.mount(MyApp1(), '/app1', app1_conf)&lt;br /&gt;
cherrypy.tree.mount(MyApp2(), '/app2', app2_conf)&lt;br /&gt;
&lt;br /&gt;
cherrypy.engine.start()&lt;br /&gt;
cherrypy.engine.block()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will host two applications classes having paths http://localhost:8080/app1 and http://localhost:8080/app2.&lt;br /&gt;
&lt;br /&gt;
=== Server Configuration ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;cherrypy.config.update&amp;lt;/tt&amp;gt; function can be used to configure the HTTP server.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'server.socket_port': 9999})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will start the server on port 9999 instead of the default port 8080. The application can then be accessed at http://localhost:9999/.&lt;br /&gt;
&lt;br /&gt;
We can also pass a file (containing configuration) as an argument to this function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.config.update(&amp;quot;WebAppServer.conf&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''WebAppServer.conf'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[global]&lt;br /&gt;
server.socket_port: 9999&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sessions ===&lt;br /&gt;
&lt;br /&gt;
In CherryPy, sessions are disabled by default.  To enable sessions, set the configuration &amp;lt;tt&amp;gt;tools.sessions.on&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;. &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/basics.html#using-sessions&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Session variables can be accessed with &amp;lt;tt&amp;gt;cherrypy.session&amp;lt;/tt&amp;gt;, which is a Python dictionary object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        if 'number' not in cherrypy.session:&lt;br /&gt;
            cherrypy.session['number'] = 0&lt;br /&gt;
        else:&lt;br /&gt;
            cherrypy.session['number'] += 1&lt;br /&gt;
        return &amp;quot;Number = &amp;quot; + str(cherrypy.session['number'])&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'tools.sessions.on': True})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example shows a number that increments by 1 every time the user navigates to [http://localhost:8080 localhost:8080].&lt;br /&gt;
&lt;br /&gt;
=== Serve Static Content ===&lt;br /&gt;
Static contents like files, images, stylesheets etc. can be easily served by adding the following lines in the the application configuration file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[/images]&lt;br /&gt;
tools.staticdir.on = True&lt;br /&gt;
tools.staticdir.dir = &amp;quot;/site/public/images&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will allow the user to access some file &amp;quot;user.jpg&amp;quot; present in the folder &amp;quot;/site/public/images/user.jpg&amp;quot; using the url http://localhost:8080/images/user.jpg.&lt;br /&gt;
&lt;br /&gt;
=== Publish REST APIs ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can be used to expose the APIs as RESTful Web Services. This allows third party applications to easily communicate with the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class MyAppRestMode(object):&lt;br /&gt;
    exposed = True&lt;br /&gt;
&lt;br /&gt;
    def GET(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
conf = {&lt;br /&gt;
    '/': {&lt;br /&gt;
        'request.dispatch': cherrypy.dispatch.MethodDispatcher(),&lt;br /&gt;
        'tools.response_headers.on': True,&lt;br /&gt;
        'tools.response_headers.headers': [('Content-Type', 'text/plain')],&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
cherrypy.quickstart(MyAppRestMode(), '/', conf)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code exposes the GET API with url http://localhost:8080/. The API returns the string &amp;quot;Hello, CherryPy!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Multiple HTTP Servers ===&lt;br /&gt;
&lt;br /&gt;
The default HTTP server started by CherryPy can only be used to host the application on one port. But, it is also possible to host the application on multiple ports by starting additional servers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from cherrypy._cpserver import Server&lt;br /&gt;
&lt;br /&gt;
server = Server()&lt;br /&gt;
server.socket_port = 443&lt;br /&gt;
server.subscribe()&lt;br /&gt;
&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code hosts the application with one more server, which runs on port 443. It is possible to create any number of additional servers.&lt;br /&gt;
&lt;br /&gt;
=== Authentication ===&lt;br /&gt;
&lt;br /&gt;
CherryPy supports two authentication mechanisms: Simple and Digest. It follows the specification defined by [http://tools.ietf.org/html/rfc2617.html RFC 2617]&lt;br /&gt;
&lt;br /&gt;
=== WSGI Support ===&lt;br /&gt;
&lt;br /&gt;
CherryPy supports the WSGI (Web Server Gateway Interface) specification defined by [http://www.python.org/dev/peps/pep-0333 PEP 0333] and [http://www.python.org/dev/peps/pep-3333 PEP 3333]. &lt;br /&gt;
&lt;br /&gt;
This allows two things:&lt;br /&gt;
* Instead of using the default CherryPy server, a CherryPy application can be hosted on an external WSGI server.&lt;br /&gt;
* The CherryPy server can be used independently to host an external WSGI application.&lt;br /&gt;
&lt;br /&gt;
=== Test Suite ===&lt;br /&gt;
&lt;br /&gt;
CherryPy framework provides a class, named &amp;lt;tt&amp;gt;helper&amp;lt;/tt&amp;gt; which can be used as a base class for writing functional tests. &lt;br /&gt;
&lt;br /&gt;
Running a test will start the complete application and thus can be used to simulate the scenario when a user actually tries to access the server on web.&lt;br /&gt;
&lt;br /&gt;
The sample code to run a test can be found [http://docs.cherrypy.org/en/latest/advanced.html#testing-your-application here]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=86717</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=86717"/>
		<updated>2014-09-18T23:28:39Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* In-built HTTP Server to host single or multiple applications */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a Python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
CherryPy is a lightweight web server framework written in Python.  It has an object-oriented design and provides a basic HTTP web server as defined in RFC 7321.  It includes built-in profiling, coverage, and testing tools to assist in development.  &lt;br /&gt;
&lt;br /&gt;
CherryPy does not have any built-in templating or database engines, and instead relies on external libraries and plugins. &amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;  Python comes with a rich library support, so this typically is not an issue.&lt;br /&gt;
&lt;br /&gt;
It is distributed under the BSD License&amp;lt;ref&amp;gt;https://bitbucket.org/cherrypy/cherrypy/src/697c7af588b8/cherrypy/LICENSE.txt&amp;lt;/ref&amp;gt;. The latest stable version is 3.6 as of August 19, 2014&amp;lt;ref&amp;gt;https://pypi.python.org/pypi/CherryPy&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some of the well known websites using CherryPy are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list can be found [http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy here].&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates a very simple web server using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
'''WebApp.py'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/code&amp;gt; tells the CherryPy framework to start the web server, which is defined as a class named &amp;lt;code&amp;gt;WebApp&amp;lt;/code&amp;gt;.  The method &amp;lt;code&amp;gt;index&amp;lt;/code&amp;gt; is exposed as a URL handler by the &amp;lt;code&amp;gt;@cherrypy.expose&amp;lt;/code&amp;gt; statement.  The return value of the method is what is sent as the HTTP reposne.&lt;br /&gt;
&lt;br /&gt;
Start the application by running the above Python file &amp;quot;WebApp.py&amp;quot; and open your web browser to http://localhost:8080.  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
=== Query Strings ===&lt;br /&gt;
&lt;br /&gt;
CherryPy will automatically parse the query string of a URL.  Fields are passed as method arguments with matching names, and can take advantage of default argument values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def test(self, value=1):&lt;br /&gt;
        return &amp;quot;Value = &amp;quot; + str(value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A URL of http://localhost:8080/test?value=5 gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_06-37-27_PM.png]]&lt;br /&gt;
&lt;br /&gt;
=== Cookies ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can set browser cookies with &amp;lt;tt&amp;gt;cherrypy.response.cookie&amp;lt;/tt&amp;gt; and read browser cookies with &amp;lt;tt&amp;gt;cherrypy.request.cookie&amp;lt;/tt&amp;gt; by accessing these variables as Python dictionary objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def set(self, value = &amp;quot;Test&amp;quot;):&lt;br /&gt;
        cookie = cherrypy.response.cookie&lt;br /&gt;
        cookie['Value'] = value&lt;br /&gt;
        return &amp;quot;Cookie set&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def get(self):&lt;br /&gt;
        cookie = cherrypy.request.cookie&lt;br /&gt;
        return &amp;quot;Cookie value = &amp;quot; + str(cookie['Value'].value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Navigating to http://localhost:8080/set?value=test followed by http://localhost:8080/get gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:CherryPyCookieTest.png]]&lt;br /&gt;
&lt;br /&gt;
=== Logging ===&lt;br /&gt;
&lt;br /&gt;
CherryPy provides the following method for application logging&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.log(&amp;quot;Hello, CherryPy!&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, all logging is written to the console.  The configuration keys &amp;lt;tt&amp;gt;log.access_file&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;log.error_file&amp;lt;/tt&amp;gt; are also available for writing logging and errors to a text file.&lt;br /&gt;
&lt;br /&gt;
=== Built-in HTTP Server to host single or multiple applications ===&lt;br /&gt;
CherryPy comes with its own HTTP server which can be used to host web applications.&lt;br /&gt;
&lt;br /&gt;
==== Single application ====&lt;br /&gt;
The easiest way to do that is by calling the &amp;lt;tt&amp;gt;cherrypy.quickstart()&amp;lt;/tt&amp;gt; function. The function takes at least one argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application 'WebApp' at http://localhost:8080/.&lt;br /&gt;
&lt;br /&gt;
It can also take 2 more arguments.&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp(), '/hello', {'/': {'tools.gzip.on': True}})&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application 'WebApp' at http://localhost:8080/hello. &lt;br /&gt;
The third argument defines the configuration for our application. It can either be a dictionary object or a file.&lt;br /&gt;
&lt;br /&gt;
==== Multiple applications ====&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;tt&amp;gt;cherrypy.tree.mount&amp;lt;/tt&amp;gt; is used to host multiple applications.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.tree.mount(MyApp1(), '/app1', app1_conf)&lt;br /&gt;
cherrypy.tree.mount(MyApp2(), '/app2', app2_conf)&lt;br /&gt;
&lt;br /&gt;
cherrypy.engine.start()&lt;br /&gt;
cherrypy.engine.block()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will host two applications having paths http://localhost:8080/app1 and http://localhost:8080/app2.&lt;br /&gt;
&lt;br /&gt;
=== Server Configuration ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;cherrypy.config.update&amp;lt;/tt&amp;gt; function can be used to configure the HTTP server.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'server.socket_port': 9999})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will start the server on port 9999 instead of the default port 8080. The application can then be accessed at http://localhost:9999/.&lt;br /&gt;
&lt;br /&gt;
We can also pass a file (containing configuration) as an argument to this function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.config.update(&amp;quot;WebAppServer.conf&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''WebAppServer.conf'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[global]&lt;br /&gt;
server.socket_port: 9999&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sessions ===&lt;br /&gt;
&lt;br /&gt;
In CherryPy, sessions are disabled by default.  To enable sessions, set the configuration &amp;lt;tt&amp;gt;tools.sessions.on&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;. &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/basics.html#using-sessions&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Session variables can be accessed with &amp;lt;tt&amp;gt;cherrypy.session&amp;lt;/tt&amp;gt;, which is a Python dictionary object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        if 'number' not in cherrypy.session:&lt;br /&gt;
            cherrypy.session['number'] = 0&lt;br /&gt;
        else:&lt;br /&gt;
            cherrypy.session['number'] += 1&lt;br /&gt;
        return &amp;quot;Number = &amp;quot; + str(cherrypy.session['number'])&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'tools.sessions.on': True})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example shows a number that increments by 1 every time the user navigates to [http://localhost:8080 localhost:8080].&lt;br /&gt;
&lt;br /&gt;
=== Serve Static Content ===&lt;br /&gt;
Static contents like files, images, stylesheets etc. can be easily served by adding the following lines in the the application configuration file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[/images]&lt;br /&gt;
tools.staticdir.on = True&lt;br /&gt;
tools.staticdir.dir = &amp;quot;/site/public/images&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will allow the user to access some file &amp;quot;user.jpg&amp;quot; present in the folder &amp;quot;/site/public/images/user.jpg&amp;quot; using the url http://localhost:8080/images/user.jpg.&lt;br /&gt;
&lt;br /&gt;
=== Publish REST APIs ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can be used to expose the APIs as RESTful Web Services. This allows third party applications to easily communicate with the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class MyAppRestMode(object):&lt;br /&gt;
    exposed = True&lt;br /&gt;
&lt;br /&gt;
    def GET(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
conf = {&lt;br /&gt;
    '/': {&lt;br /&gt;
        'request.dispatch': cherrypy.dispatch.MethodDispatcher(),&lt;br /&gt;
        'tools.response_headers.on': True,&lt;br /&gt;
        'tools.response_headers.headers': [('Content-Type', 'text/plain')],&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
cherrypy.quickstart(MyAppRestMode(), '/', conf)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code exposes the GET API with url http://localhost:8080/. The API returns the string &amp;quot;Hello, CherryPy!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Multiple HTTP Servers ===&lt;br /&gt;
&lt;br /&gt;
The default HTTP server started by CherryPy can only be used to host the application on one port. But, it is also possible to host the application on multiple ports by starting additional servers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from cherrypy._cpserver import Server&lt;br /&gt;
&lt;br /&gt;
server = Server()&lt;br /&gt;
server.socket_port = 443&lt;br /&gt;
server.subscribe()&lt;br /&gt;
&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code hosts the application with one more server, which runs on port 443. It is possible to create any number of additional servers.&lt;br /&gt;
&lt;br /&gt;
=== Authentication ===&lt;br /&gt;
&lt;br /&gt;
CherryPy supports two authentication mechanisms: Simple and Digest. It follows the specification defined by [http://tools.ietf.org/html/rfc2617.html RFC 2617]&lt;br /&gt;
&lt;br /&gt;
=== WSGI Support ===&lt;br /&gt;
&lt;br /&gt;
CherryPy supports the WSGI (Web Server Gateway Interface) specification defined by [http://www.python.org/dev/peps/pep-0333 PEP 0333] and [http://www.python.org/dev/peps/pep-3333 PEP 3333]. &lt;br /&gt;
&lt;br /&gt;
This allows two things:&lt;br /&gt;
* Instead of using the default CherryPy server, a CherryPy application can be hosted on an external WSGI server.&lt;br /&gt;
* The CherryPy server can be used independently to host an external WSGI application.&lt;br /&gt;
&lt;br /&gt;
=== Test Suite ===&lt;br /&gt;
&lt;br /&gt;
CherryPy framework provides a class, named &amp;lt;tt&amp;gt;helper&amp;lt;/tt&amp;gt; which can be used as a base class for writing functional tests. &lt;br /&gt;
&lt;br /&gt;
Running a test will start the complete application and thus can be used to simulate the scenario when a user actually tries to access the server on web.&lt;br /&gt;
&lt;br /&gt;
The sample code to run a test can be found [http://docs.cherrypy.org/en/latest/advanced.html#testing-your-application here]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=86716</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=86716"/>
		<updated>2014-09-18T23:26:48Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Sessions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a Python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
CherryPy is a lightweight web server framework written in Python.  It has an object-oriented design and provides a basic HTTP web server as defined in RFC 7321.  It includes built-in profiling, coverage, and testing tools to assist in development.  &lt;br /&gt;
&lt;br /&gt;
CherryPy does not have any built-in templating or database engines, and instead relies on external libraries and plugins. &amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;  Python comes with a rich library support, so this typically is not an issue.&lt;br /&gt;
&lt;br /&gt;
It is distributed under the BSD License&amp;lt;ref&amp;gt;https://bitbucket.org/cherrypy/cherrypy/src/697c7af588b8/cherrypy/LICENSE.txt&amp;lt;/ref&amp;gt;. The latest stable version is 3.6 as of August 19, 2014&amp;lt;ref&amp;gt;https://pypi.python.org/pypi/CherryPy&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some of the well known websites using CherryPy are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list can be found [http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy here].&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates a very simple web server using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
'''WebApp.py'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/code&amp;gt; tells the CherryPy framework to start the web server, which is defined as a class named &amp;lt;code&amp;gt;WebApp&amp;lt;/code&amp;gt;.  The method &amp;lt;code&amp;gt;index&amp;lt;/code&amp;gt; is exposed as a URL handler by the &amp;lt;code&amp;gt;@cherrypy.expose&amp;lt;/code&amp;gt; statement.  The return value of the method is what is sent as the HTTP reposne.&lt;br /&gt;
&lt;br /&gt;
Start the application by running the above Python file &amp;quot;WebApp.py&amp;quot; and open your web browser to http://localhost:8080.  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
=== Query Strings ===&lt;br /&gt;
&lt;br /&gt;
CherryPy will automatically parse the query string of a URL.  Fields are passed as method arguments with matching names, and can take advantage of default argument values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def test(self, value=1):&lt;br /&gt;
        return &amp;quot;Value = &amp;quot; + str(value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A URL of http://localhost:8080/test?value=5 gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_06-37-27_PM.png]]&lt;br /&gt;
&lt;br /&gt;
=== Cookies ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can set browser cookies with &amp;lt;tt&amp;gt;cherrypy.response.cookie&amp;lt;/tt&amp;gt; and read browser cookies with &amp;lt;tt&amp;gt;cherrypy.request.cookie&amp;lt;/tt&amp;gt; by accessing these variables as Python dictionary objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def set(self, value = &amp;quot;Test&amp;quot;):&lt;br /&gt;
        cookie = cherrypy.response.cookie&lt;br /&gt;
        cookie['Value'] = value&lt;br /&gt;
        return &amp;quot;Cookie set&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def get(self):&lt;br /&gt;
        cookie = cherrypy.request.cookie&lt;br /&gt;
        return &amp;quot;Cookie value = &amp;quot; + str(cookie['Value'].value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Navigating to http://localhost:8080/set?value=test followed by http://localhost:8080/get gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:CherryPyCookieTest.png]]&lt;br /&gt;
&lt;br /&gt;
=== Logging ===&lt;br /&gt;
&lt;br /&gt;
CherryPy provides the following method for application logging&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.log(&amp;quot;Hello, CherryPy!&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, all logging is written to the console.  The configuration keys &amp;lt;tt&amp;gt;log.access_file&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;log.error_file&amp;lt;/tt&amp;gt; are also available for writing logging and errors to a text file.&lt;br /&gt;
&lt;br /&gt;
=== In-built HTTP Server to host single or multiple applications ===&lt;br /&gt;
CherryPy comes with its own HTTP server which can be used to host web applications.&lt;br /&gt;
&lt;br /&gt;
==== Single application ====&lt;br /&gt;
The easiest way to do that is by calling the &amp;lt;tt&amp;gt;cherrypy.quickstart()&amp;lt;/tt&amp;gt; function. The function takes at least one argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application 'WebApp' at http://localhost:8080/.&lt;br /&gt;
&lt;br /&gt;
It can also take 2 more arguments.&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp(), '/hello', {'/': {'tools.gzip.on': True}})&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application 'WebApp' at http://localhost:8080/hello. &lt;br /&gt;
The third argument defines the configuration for our application. It can either be a dictionary object or a file.&lt;br /&gt;
&lt;br /&gt;
==== Multiple applications ====&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;tt&amp;gt;cherrypy.tree.mount&amp;lt;/tt&amp;gt; is used to host multiple applications.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.tree.mount(MyApp1(), '/app1', app1_conf)&lt;br /&gt;
cherrypy.tree.mount(MyApp2(), '/app2', app2_conf)&lt;br /&gt;
&lt;br /&gt;
cherrypy.engine.start()&lt;br /&gt;
cherrypy.engine.block()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will host two applications having paths http://localhost:8080/app1 and http://localhost:8080/app2.&lt;br /&gt;
&lt;br /&gt;
=== Server Configuration ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;cherrypy.config.update&amp;lt;/tt&amp;gt; function can be used to configure the HTTP server.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'server.socket_port': 9999})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will start the server on port 9999 instead of the default port 8080. The application can then be accessed at http://localhost:9999/.&lt;br /&gt;
&lt;br /&gt;
We can also pass a file (containing configuration) as an argument to this function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.config.update(&amp;quot;WebAppServer.conf&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''WebAppServer.conf'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[global]&lt;br /&gt;
server.socket_port: 9999&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sessions ===&lt;br /&gt;
&lt;br /&gt;
In CherryPy, sessions are disabled by default.  To enable sessions, set the configuration &amp;lt;tt&amp;gt;tools.sessions.on&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;. &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/basics.html#using-sessions&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Session variables can be accessed with &amp;lt;tt&amp;gt;cherrypy.session&amp;lt;/tt&amp;gt;, which is a Python dictionary object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        if 'number' not in cherrypy.session:&lt;br /&gt;
            cherrypy.session['number'] = 0&lt;br /&gt;
        else:&lt;br /&gt;
            cherrypy.session['number'] += 1&lt;br /&gt;
        return &amp;quot;Number = &amp;quot; + str(cherrypy.session['number'])&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'tools.sessions.on': True})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example shows a number that increments by 1 every time the user navigates to [http://localhost:8080 localhost:8080].&lt;br /&gt;
&lt;br /&gt;
=== Serve Static Content ===&lt;br /&gt;
Static contents like files, images, stylesheets etc. can be easily served by adding the following lines in the the application configuration file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[/images]&lt;br /&gt;
tools.staticdir.on = True&lt;br /&gt;
tools.staticdir.dir = &amp;quot;/site/public/images&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will allow the user to access some file &amp;quot;user.jpg&amp;quot; present in the folder &amp;quot;/site/public/images/user.jpg&amp;quot; using the url http://localhost:8080/images/user.jpg.&lt;br /&gt;
&lt;br /&gt;
=== Publish REST APIs ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can be used to expose the APIs as RESTful Web Services. This allows third party applications to easily communicate with the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class MyAppRestMode(object):&lt;br /&gt;
    exposed = True&lt;br /&gt;
&lt;br /&gt;
    def GET(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
conf = {&lt;br /&gt;
    '/': {&lt;br /&gt;
        'request.dispatch': cherrypy.dispatch.MethodDispatcher(),&lt;br /&gt;
        'tools.response_headers.on': True,&lt;br /&gt;
        'tools.response_headers.headers': [('Content-Type', 'text/plain')],&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
cherrypy.quickstart(MyAppRestMode(), '/', conf)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code exposes the GET API with url http://localhost:8080/. The API returns the string &amp;quot;Hello, CherryPy!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Multiple HTTP Servers ===&lt;br /&gt;
&lt;br /&gt;
The default HTTP server started by CherryPy can only be used to host the application on one port. But, it is also possible to host the application on multiple ports by starting additional servers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from cherrypy._cpserver import Server&lt;br /&gt;
&lt;br /&gt;
server = Server()&lt;br /&gt;
server.socket_port = 443&lt;br /&gt;
server.subscribe()&lt;br /&gt;
&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code hosts the application with one more server, which runs on port 443. It is possible to create any number of additional servers.&lt;br /&gt;
&lt;br /&gt;
=== Authentication ===&lt;br /&gt;
&lt;br /&gt;
CherryPy supports two authentication mechanisms: Simple and Digest. It follows the specification defined by [http://tools.ietf.org/html/rfc2617.html RFC 2617]&lt;br /&gt;
&lt;br /&gt;
=== WSGI Support ===&lt;br /&gt;
&lt;br /&gt;
CherryPy supports the WSGI (Web Server Gateway Interface) specification defined by [http://www.python.org/dev/peps/pep-0333 PEP 0333] and [http://www.python.org/dev/peps/pep-3333 PEP 3333]. &lt;br /&gt;
&lt;br /&gt;
This allows two things:&lt;br /&gt;
* Instead of using the default CherryPy server, a CherryPy application can be hosted on an external WSGI server.&lt;br /&gt;
* The CherryPy server can be used independently to host an external WSGI application.&lt;br /&gt;
&lt;br /&gt;
=== Test Suite ===&lt;br /&gt;
&lt;br /&gt;
CherryPy framework provides a class, named &amp;lt;tt&amp;gt;helper&amp;lt;/tt&amp;gt; which can be used as a base class for writing functional tests. &lt;br /&gt;
&lt;br /&gt;
Running a test will start the complete application and thus can be used to simulate the scenario when a user actually tries to access the server on web.&lt;br /&gt;
&lt;br /&gt;
The sample code to run a test can be found [http://docs.cherrypy.org/en/latest/advanced.html#testing-your-application here]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=86715</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=86715"/>
		<updated>2014-09-18T23:26:31Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Cookies */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a Python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
CherryPy is a lightweight web server framework written in Python.  It has an object-oriented design and provides a basic HTTP web server as defined in RFC 7321.  It includes built-in profiling, coverage, and testing tools to assist in development.  &lt;br /&gt;
&lt;br /&gt;
CherryPy does not have any built-in templating or database engines, and instead relies on external libraries and plugins. &amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;  Python comes with a rich library support, so this typically is not an issue.&lt;br /&gt;
&lt;br /&gt;
It is distributed under the BSD License&amp;lt;ref&amp;gt;https://bitbucket.org/cherrypy/cherrypy/src/697c7af588b8/cherrypy/LICENSE.txt&amp;lt;/ref&amp;gt;. The latest stable version is 3.6 as of August 19, 2014&amp;lt;ref&amp;gt;https://pypi.python.org/pypi/CherryPy&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some of the well known websites using CherryPy are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list can be found [http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy here].&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates a very simple web server using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
'''WebApp.py'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/code&amp;gt; tells the CherryPy framework to start the web server, which is defined as a class named &amp;lt;code&amp;gt;WebApp&amp;lt;/code&amp;gt;.  The method &amp;lt;code&amp;gt;index&amp;lt;/code&amp;gt; is exposed as a URL handler by the &amp;lt;code&amp;gt;@cherrypy.expose&amp;lt;/code&amp;gt; statement.  The return value of the method is what is sent as the HTTP reposne.&lt;br /&gt;
&lt;br /&gt;
Start the application by running the above Python file &amp;quot;WebApp.py&amp;quot; and open your web browser to http://localhost:8080.  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
=== Query Strings ===&lt;br /&gt;
&lt;br /&gt;
CherryPy will automatically parse the query string of a URL.  Fields are passed as method arguments with matching names, and can take advantage of default argument values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def test(self, value=1):&lt;br /&gt;
        return &amp;quot;Value = &amp;quot; + str(value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A URL of http://localhost:8080/test?value=5 gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_06-37-27_PM.png]]&lt;br /&gt;
&lt;br /&gt;
=== Cookies ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can set browser cookies with &amp;lt;tt&amp;gt;cherrypy.response.cookie&amp;lt;/tt&amp;gt; and read browser cookies with &amp;lt;tt&amp;gt;cherrypy.request.cookie&amp;lt;/tt&amp;gt; by accessing these variables as Python dictionary objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def set(self, value = &amp;quot;Test&amp;quot;):&lt;br /&gt;
        cookie = cherrypy.response.cookie&lt;br /&gt;
        cookie['Value'] = value&lt;br /&gt;
        return &amp;quot;Cookie set&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def get(self):&lt;br /&gt;
        cookie = cherrypy.request.cookie&lt;br /&gt;
        return &amp;quot;Cookie value = &amp;quot; + str(cookie['Value'].value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Navigating to http://localhost:8080/set?value=test followed by http://localhost:8080/get gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:CherryPyCookieTest.png]]&lt;br /&gt;
&lt;br /&gt;
=== Logging ===&lt;br /&gt;
&lt;br /&gt;
CherryPy provides the following method for application logging&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.log(&amp;quot;Hello, CherryPy!&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, all logging is written to the console.  The configuration keys &amp;lt;tt&amp;gt;log.access_file&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;log.error_file&amp;lt;/tt&amp;gt; are also available for writing logging and errors to a text file.&lt;br /&gt;
&lt;br /&gt;
=== In-built HTTP Server to host single or multiple applications ===&lt;br /&gt;
CherryPy comes with its own HTTP server which can be used to host web applications.&lt;br /&gt;
&lt;br /&gt;
==== Single application ====&lt;br /&gt;
The easiest way to do that is by calling the &amp;lt;tt&amp;gt;cherrypy.quickstart()&amp;lt;/tt&amp;gt; function. The function takes at least one argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application 'WebApp' at http://localhost:8080/.&lt;br /&gt;
&lt;br /&gt;
It can also take 2 more arguments.&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp(), '/hello', {'/': {'tools.gzip.on': True}})&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application 'WebApp' at http://localhost:8080/hello. &lt;br /&gt;
The third argument defines the configuration for our application. It can either be a dictionary object or a file.&lt;br /&gt;
&lt;br /&gt;
==== Multiple applications ====&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;tt&amp;gt;cherrypy.tree.mount&amp;lt;/tt&amp;gt; is used to host multiple applications.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.tree.mount(MyApp1(), '/app1', app1_conf)&lt;br /&gt;
cherrypy.tree.mount(MyApp2(), '/app2', app2_conf)&lt;br /&gt;
&lt;br /&gt;
cherrypy.engine.start()&lt;br /&gt;
cherrypy.engine.block()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will host two applications having paths http://localhost:8080/app1 and http://localhost:8080/app2.&lt;br /&gt;
&lt;br /&gt;
=== Server Configuration ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;cherrypy.config.update&amp;lt;/tt&amp;gt; function can be used to configure the HTTP server.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'server.socket_port': 9999})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will start the server on port 9999 instead of the default port 8080. The application can then be accessed at http://localhost:9999/.&lt;br /&gt;
&lt;br /&gt;
We can also pass a file (containing configuration) as an argument to this function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.config.update(&amp;quot;WebAppServer.conf&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''WebAppServer.conf'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[global]&lt;br /&gt;
server.socket_port: 9999&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sessions ===&lt;br /&gt;
&lt;br /&gt;
In CherryPy, sessions are disabled by default.  To enable sessions, set the configuration &amp;lt;tt&amp;gt;tools.sessions.on&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;. &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/basics.html#using-sessions&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Session variables can be accessed with &amp;lt;tt&amp;gt;cherrypy.session&amp;lt;/tt&amp;gt;, which is a python dictionary object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        if 'number' not in cherrypy.session:&lt;br /&gt;
            cherrypy.session['number'] = 0&lt;br /&gt;
        else:&lt;br /&gt;
            cherrypy.session['number'] += 1&lt;br /&gt;
        return &amp;quot;Number = &amp;quot; + str(cherrypy.session['number'])&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'tools.sessions.on': True})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example shows a number that increments by 1 every time the user navigates to [http://localhost:8080 localhost:8080].&lt;br /&gt;
&lt;br /&gt;
=== Serve Static Content ===&lt;br /&gt;
Static contents like files, images, stylesheets etc. can be easily served by adding the following lines in the the application configuration file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[/images]&lt;br /&gt;
tools.staticdir.on = True&lt;br /&gt;
tools.staticdir.dir = &amp;quot;/site/public/images&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will allow the user to access some file &amp;quot;user.jpg&amp;quot; present in the folder &amp;quot;/site/public/images/user.jpg&amp;quot; using the url http://localhost:8080/images/user.jpg.&lt;br /&gt;
&lt;br /&gt;
=== Publish REST APIs ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can be used to expose the APIs as RESTful Web Services. This allows third party applications to easily communicate with the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class MyAppRestMode(object):&lt;br /&gt;
    exposed = True&lt;br /&gt;
&lt;br /&gt;
    def GET(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
conf = {&lt;br /&gt;
    '/': {&lt;br /&gt;
        'request.dispatch': cherrypy.dispatch.MethodDispatcher(),&lt;br /&gt;
        'tools.response_headers.on': True,&lt;br /&gt;
        'tools.response_headers.headers': [('Content-Type', 'text/plain')],&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
cherrypy.quickstart(MyAppRestMode(), '/', conf)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code exposes the GET API with url http://localhost:8080/. The API returns the string &amp;quot;Hello, CherryPy!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Multiple HTTP Servers ===&lt;br /&gt;
&lt;br /&gt;
The default HTTP server started by CherryPy can only be used to host the application on one port. But, it is also possible to host the application on multiple ports by starting additional servers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from cherrypy._cpserver import Server&lt;br /&gt;
&lt;br /&gt;
server = Server()&lt;br /&gt;
server.socket_port = 443&lt;br /&gt;
server.subscribe()&lt;br /&gt;
&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code hosts the application with one more server, which runs on port 443. It is possible to create any number of additional servers.&lt;br /&gt;
&lt;br /&gt;
=== Authentication ===&lt;br /&gt;
&lt;br /&gt;
CherryPy supports two authentication mechanisms: Simple and Digest. It follows the specification defined by [http://tools.ietf.org/html/rfc2617.html RFC 2617]&lt;br /&gt;
&lt;br /&gt;
=== WSGI Support ===&lt;br /&gt;
&lt;br /&gt;
CherryPy supports the WSGI (Web Server Gateway Interface) specification defined by [http://www.python.org/dev/peps/pep-0333 PEP 0333] and [http://www.python.org/dev/peps/pep-3333 PEP 3333]. &lt;br /&gt;
&lt;br /&gt;
This allows two things:&lt;br /&gt;
* Instead of using the default CherryPy server, a CherryPy application can be hosted on an external WSGI server.&lt;br /&gt;
* The CherryPy server can be used independently to host an external WSGI application.&lt;br /&gt;
&lt;br /&gt;
=== Test Suite ===&lt;br /&gt;
&lt;br /&gt;
CherryPy framework provides a class, named &amp;lt;tt&amp;gt;helper&amp;lt;/tt&amp;gt; which can be used as a base class for writing functional tests. &lt;br /&gt;
&lt;br /&gt;
Running a test will start the complete application and thus can be used to simulate the scenario when a user actually tries to access the server on web.&lt;br /&gt;
&lt;br /&gt;
The sample code to run a test can be found [http://docs.cherrypy.org/en/latest/advanced.html#testing-your-application here]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=86714</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=86714"/>
		<updated>2014-09-18T23:26:12Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Basic Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a Python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
CherryPy is a lightweight web server framework written in Python.  It has an object-oriented design and provides a basic HTTP web server as defined in RFC 7321.  It includes built-in profiling, coverage, and testing tools to assist in development.  &lt;br /&gt;
&lt;br /&gt;
CherryPy does not have any built-in templating or database engines, and instead relies on external libraries and plugins. &amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;  Python comes with a rich library support, so this typically is not an issue.&lt;br /&gt;
&lt;br /&gt;
It is distributed under the BSD License&amp;lt;ref&amp;gt;https://bitbucket.org/cherrypy/cherrypy/src/697c7af588b8/cherrypy/LICENSE.txt&amp;lt;/ref&amp;gt;. The latest stable version is 3.6 as of August 19, 2014&amp;lt;ref&amp;gt;https://pypi.python.org/pypi/CherryPy&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some of the well known websites using CherryPy are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list can be found [http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy here].&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates a very simple web server using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
'''WebApp.py'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/code&amp;gt; tells the CherryPy framework to start the web server, which is defined as a class named &amp;lt;code&amp;gt;WebApp&amp;lt;/code&amp;gt;.  The method &amp;lt;code&amp;gt;index&amp;lt;/code&amp;gt; is exposed as a URL handler by the &amp;lt;code&amp;gt;@cherrypy.expose&amp;lt;/code&amp;gt; statement.  The return value of the method is what is sent as the HTTP reposne.&lt;br /&gt;
&lt;br /&gt;
Start the application by running the above Python file &amp;quot;WebApp.py&amp;quot; and open your web browser to http://localhost:8080.  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
=== Query Strings ===&lt;br /&gt;
&lt;br /&gt;
CherryPy will automatically parse the query string of a URL.  Fields are passed as method arguments with matching names, and can take advantage of default argument values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def test(self, value=1):&lt;br /&gt;
        return &amp;quot;Value = &amp;quot; + str(value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A URL of http://localhost:8080/test?value=5 gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_06-37-27_PM.png]]&lt;br /&gt;
&lt;br /&gt;
=== Cookies ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can set browser cookies with &amp;lt;tt&amp;gt;cherrypy.response.cookie&amp;lt;/tt&amp;gt; and read browser cookies with &amp;lt;tt&amp;gt;cherrypy.request.cookie&amp;lt;/tt&amp;gt; by accessing these variables as python dictionary objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def set(self, value = &amp;quot;Test&amp;quot;):&lt;br /&gt;
        cookie = cherrypy.response.cookie&lt;br /&gt;
        cookie['Value'] = value&lt;br /&gt;
        return &amp;quot;Cookie set&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def get(self):&lt;br /&gt;
        cookie = cherrypy.request.cookie&lt;br /&gt;
        return &amp;quot;Cookie value = &amp;quot; + str(cookie['Value'].value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Navigating to http://localhost:8080/set?value=test followed by http://localhost:8080/get gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:CherryPyCookieTest.png]]&lt;br /&gt;
&lt;br /&gt;
=== Logging ===&lt;br /&gt;
&lt;br /&gt;
CherryPy provides the following method for application logging&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.log(&amp;quot;Hello, CherryPy!&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, all logging is written to the console.  The configuration keys &amp;lt;tt&amp;gt;log.access_file&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;log.error_file&amp;lt;/tt&amp;gt; are also available for writing logging and errors to a text file.&lt;br /&gt;
&lt;br /&gt;
=== In-built HTTP Server to host single or multiple applications ===&lt;br /&gt;
CherryPy comes with its own HTTP server which can be used to host web applications.&lt;br /&gt;
&lt;br /&gt;
==== Single application ====&lt;br /&gt;
The easiest way to do that is by calling the &amp;lt;tt&amp;gt;cherrypy.quickstart()&amp;lt;/tt&amp;gt; function. The function takes at least one argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application 'WebApp' at http://localhost:8080/.&lt;br /&gt;
&lt;br /&gt;
It can also take 2 more arguments.&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp(), '/hello', {'/': {'tools.gzip.on': True}})&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application 'WebApp' at http://localhost:8080/hello. &lt;br /&gt;
The third argument defines the configuration for our application. It can either be a dictionary object or a file.&lt;br /&gt;
&lt;br /&gt;
==== Multiple applications ====&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;tt&amp;gt;cherrypy.tree.mount&amp;lt;/tt&amp;gt; is used to host multiple applications.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.tree.mount(MyApp1(), '/app1', app1_conf)&lt;br /&gt;
cherrypy.tree.mount(MyApp2(), '/app2', app2_conf)&lt;br /&gt;
&lt;br /&gt;
cherrypy.engine.start()&lt;br /&gt;
cherrypy.engine.block()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will host two applications having paths http://localhost:8080/app1 and http://localhost:8080/app2.&lt;br /&gt;
&lt;br /&gt;
=== Server Configuration ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;cherrypy.config.update&amp;lt;/tt&amp;gt; function can be used to configure the HTTP server.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'server.socket_port': 9999})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will start the server on port 9999 instead of the default port 8080. The application can then be accessed at http://localhost:9999/.&lt;br /&gt;
&lt;br /&gt;
We can also pass a file (containing configuration) as an argument to this function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.config.update(&amp;quot;WebAppServer.conf&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''WebAppServer.conf'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[global]&lt;br /&gt;
server.socket_port: 9999&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sessions ===&lt;br /&gt;
&lt;br /&gt;
In CherryPy, sessions are disabled by default.  To enable sessions, set the configuration &amp;lt;tt&amp;gt;tools.sessions.on&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;. &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/basics.html#using-sessions&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Session variables can be accessed with &amp;lt;tt&amp;gt;cherrypy.session&amp;lt;/tt&amp;gt;, which is a python dictionary object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        if 'number' not in cherrypy.session:&lt;br /&gt;
            cherrypy.session['number'] = 0&lt;br /&gt;
        else:&lt;br /&gt;
            cherrypy.session['number'] += 1&lt;br /&gt;
        return &amp;quot;Number = &amp;quot; + str(cherrypy.session['number'])&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'tools.sessions.on': True})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example shows a number that increments by 1 every time the user navigates to [http://localhost:8080 localhost:8080].&lt;br /&gt;
&lt;br /&gt;
=== Serve Static Content ===&lt;br /&gt;
Static contents like files, images, stylesheets etc. can be easily served by adding the following lines in the the application configuration file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[/images]&lt;br /&gt;
tools.staticdir.on = True&lt;br /&gt;
tools.staticdir.dir = &amp;quot;/site/public/images&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will allow the user to access some file &amp;quot;user.jpg&amp;quot; present in the folder &amp;quot;/site/public/images/user.jpg&amp;quot; using the url http://localhost:8080/images/user.jpg.&lt;br /&gt;
&lt;br /&gt;
=== Publish REST APIs ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can be used to expose the APIs as RESTful Web Services. This allows third party applications to easily communicate with the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class MyAppRestMode(object):&lt;br /&gt;
    exposed = True&lt;br /&gt;
&lt;br /&gt;
    def GET(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
conf = {&lt;br /&gt;
    '/': {&lt;br /&gt;
        'request.dispatch': cherrypy.dispatch.MethodDispatcher(),&lt;br /&gt;
        'tools.response_headers.on': True,&lt;br /&gt;
        'tools.response_headers.headers': [('Content-Type', 'text/plain')],&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
cherrypy.quickstart(MyAppRestMode(), '/', conf)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code exposes the GET API with url http://localhost:8080/. The API returns the string &amp;quot;Hello, CherryPy!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Multiple HTTP Servers ===&lt;br /&gt;
&lt;br /&gt;
The default HTTP server started by CherryPy can only be used to host the application on one port. But, it is also possible to host the application on multiple ports by starting additional servers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from cherrypy._cpserver import Server&lt;br /&gt;
&lt;br /&gt;
server = Server()&lt;br /&gt;
server.socket_port = 443&lt;br /&gt;
server.subscribe()&lt;br /&gt;
&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code hosts the application with one more server, which runs on port 443. It is possible to create any number of additional servers.&lt;br /&gt;
&lt;br /&gt;
=== Authentication ===&lt;br /&gt;
&lt;br /&gt;
CherryPy supports two authentication mechanisms: Simple and Digest. It follows the specification defined by [http://tools.ietf.org/html/rfc2617.html RFC 2617]&lt;br /&gt;
&lt;br /&gt;
=== WSGI Support ===&lt;br /&gt;
&lt;br /&gt;
CherryPy supports the WSGI (Web Server Gateway Interface) specification defined by [http://www.python.org/dev/peps/pep-0333 PEP 0333] and [http://www.python.org/dev/peps/pep-3333 PEP 3333]. &lt;br /&gt;
&lt;br /&gt;
This allows two things:&lt;br /&gt;
* Instead of using the default CherryPy server, a CherryPy application can be hosted on an external WSGI server.&lt;br /&gt;
* The CherryPy server can be used independently to host an external WSGI application.&lt;br /&gt;
&lt;br /&gt;
=== Test Suite ===&lt;br /&gt;
&lt;br /&gt;
CherryPy framework provides a class, named &amp;lt;tt&amp;gt;helper&amp;lt;/tt&amp;gt; which can be used as a base class for writing functional tests. &lt;br /&gt;
&lt;br /&gt;
Running a test will start the complete application and thus can be used to simulate the scenario when a user actually tries to access the server on web.&lt;br /&gt;
&lt;br /&gt;
The sample code to run a test can be found [http://docs.cherrypy.org/en/latest/advanced.html#testing-your-application here]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=86713</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=86713"/>
		<updated>2014-09-18T23:20:01Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a Python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
CherryPy is a lightweight web server framework written in Python.  It has an object-oriented design and provides a basic HTTP web server as defined in RFC 7321.  It includes built-in profiling, coverage, and testing tools to assist in development.  &lt;br /&gt;
&lt;br /&gt;
CherryPy does not have any built-in templating or database engines, and instead relies on external libraries and plugins. &amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;  Python comes with a rich library support, so this typically is not an issue.&lt;br /&gt;
&lt;br /&gt;
It is distributed under the BSD License&amp;lt;ref&amp;gt;https://bitbucket.org/cherrypy/cherrypy/src/697c7af588b8/cherrypy/LICENSE.txt&amp;lt;/ref&amp;gt;. The latest stable version is 3.6 as of August 19, 2014&amp;lt;ref&amp;gt;https://pypi.python.org/pypi/CherryPy&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some of the well known websites using CherryPy are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list can be found [http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy here].&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates the most basic webserver using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
'''WebApp.py'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Start the application by running the above python file &amp;quot;WebApp.py&amp;quot; and open your web browser to http://localhost:8080.  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
=== Query Strings ===&lt;br /&gt;
&lt;br /&gt;
CherryPy will automatically parse the query string of a URL.  Fields are passed as method arguments with matching names, and can take advantage of default argument values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def test(self, value=1):&lt;br /&gt;
        return &amp;quot;Value = &amp;quot; + str(value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A URL of http://localhost:8080/test?value=5 gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_06-37-27_PM.png]]&lt;br /&gt;
&lt;br /&gt;
=== Cookies ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can set browser cookies with &amp;lt;tt&amp;gt;cherrypy.response.cookie&amp;lt;/tt&amp;gt; and read browser cookies with &amp;lt;tt&amp;gt;cherrypy.request.cookie&amp;lt;/tt&amp;gt; by accessing these variables as python dictionary objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def set(self, value = &amp;quot;Test&amp;quot;):&lt;br /&gt;
        cookie = cherrypy.response.cookie&lt;br /&gt;
        cookie['Value'] = value&lt;br /&gt;
        return &amp;quot;Cookie set&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def get(self):&lt;br /&gt;
        cookie = cherrypy.request.cookie&lt;br /&gt;
        return &amp;quot;Cookie value = &amp;quot; + str(cookie['Value'].value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Navigating to http://localhost:8080/set?value=test followed by http://localhost:8080/get gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:CherryPyCookieTest.png]]&lt;br /&gt;
&lt;br /&gt;
=== Logging ===&lt;br /&gt;
&lt;br /&gt;
CherryPy provides the following method for application logging&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.log(&amp;quot;Hello, CherryPy!&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, all logging is written to the console.  The configuration keys &amp;lt;tt&amp;gt;log.access_file&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;log.error_file&amp;lt;/tt&amp;gt; are also available for writing logging and errors to a text file.&lt;br /&gt;
&lt;br /&gt;
=== In-built HTTP Server to host single or multiple applications ===&lt;br /&gt;
CherryPy comes with its own HTTP server which can be used to host web applications.&lt;br /&gt;
&lt;br /&gt;
==== Single application ====&lt;br /&gt;
The easiest way to do that is by calling the &amp;lt;tt&amp;gt;cherrypy.quickstart()&amp;lt;/tt&amp;gt; function. The function takes at least one argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application 'WebApp' at http://localhost:8080/.&lt;br /&gt;
&lt;br /&gt;
It can also take 2 more arguments.&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp(), '/hello', {'/': {'tools.gzip.on': True}})&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application 'WebApp' at http://localhost:8080/hello. &lt;br /&gt;
The third argument defines the configuration for our application. It can either be a dictionary object or a file.&lt;br /&gt;
&lt;br /&gt;
==== Multiple applications ====&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;tt&amp;gt;cherrypy.tree.mount&amp;lt;/tt&amp;gt; is used to host multiple applications.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.tree.mount(MyApp1(), '/app1', app1_conf)&lt;br /&gt;
cherrypy.tree.mount(MyApp2(), '/app2', app2_conf)&lt;br /&gt;
&lt;br /&gt;
cherrypy.engine.start()&lt;br /&gt;
cherrypy.engine.block()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will host two applications having paths http://localhost:8080/app1 and http://localhost:8080/app2.&lt;br /&gt;
&lt;br /&gt;
=== Server Configuration ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;cherrypy.config.update&amp;lt;/tt&amp;gt; function can be used to configure the HTTP server.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'server.socket_port': 9999})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will start the server on port 9999 instead of the default port 8080. The application can then be accessed at http://localhost:9999/.&lt;br /&gt;
&lt;br /&gt;
We can also pass a file (containing configuration) as an argument to this function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.config.update(&amp;quot;WebAppServer.conf&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''WebAppServer.conf'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[global]&lt;br /&gt;
server.socket_port: 9999&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sessions ===&lt;br /&gt;
&lt;br /&gt;
In CherryPy, sessions are disabled by default.  To enable sessions, set the configuration &amp;lt;tt&amp;gt;tools.sessions.on&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;. &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/basics.html#using-sessions&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Session variables can be accessed with &amp;lt;tt&amp;gt;cherrypy.session&amp;lt;/tt&amp;gt;, which is a python dictionary object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        if 'number' not in cherrypy.session:&lt;br /&gt;
            cherrypy.session['number'] = 0&lt;br /&gt;
        else:&lt;br /&gt;
            cherrypy.session['number'] += 1&lt;br /&gt;
        return &amp;quot;Number = &amp;quot; + str(cherrypy.session['number'])&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'tools.sessions.on': True})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example shows a number that increments by 1 every time the user navigates to [http://localhost:8080 localhost:8080].&lt;br /&gt;
&lt;br /&gt;
=== Serve Static Content ===&lt;br /&gt;
Static contents like files, images, stylesheets etc. can be easily served by adding the following lines in the the application configuration file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[/images]&lt;br /&gt;
tools.staticdir.on = True&lt;br /&gt;
tools.staticdir.dir = &amp;quot;/site/public/images&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will allow the user to access some file &amp;quot;user.jpg&amp;quot; present in the folder &amp;quot;/site/public/images/user.jpg&amp;quot; using the url http://localhost:8080/images/user.jpg.&lt;br /&gt;
&lt;br /&gt;
=== Publish REST APIs ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can be used to expose the APIs as RESTful Web Services. This allows third party applications to easily communicate with the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class MyAppRestMode(object):&lt;br /&gt;
    exposed = True&lt;br /&gt;
&lt;br /&gt;
    def GET(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
conf = {&lt;br /&gt;
    '/': {&lt;br /&gt;
        'request.dispatch': cherrypy.dispatch.MethodDispatcher(),&lt;br /&gt;
        'tools.response_headers.on': True,&lt;br /&gt;
        'tools.response_headers.headers': [('Content-Type', 'text/plain')],&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
cherrypy.quickstart(MyAppRestMode(), '/', conf)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code exposes the GET API with url http://localhost:8080/. The API returns the string &amp;quot;Hello, CherryPy!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Multiple HTTP Servers ===&lt;br /&gt;
&lt;br /&gt;
The default HTTP server started by CherryPy can only be used to host the application on one port. But, it is also possible to host the application on multiple ports by starting additional servers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from cherrypy._cpserver import Server&lt;br /&gt;
&lt;br /&gt;
server = Server()&lt;br /&gt;
server.socket_port = 443&lt;br /&gt;
server.subscribe()&lt;br /&gt;
&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code hosts the application with one more server, which runs on port 443. It is possible to create any number of additional servers.&lt;br /&gt;
&lt;br /&gt;
=== Authentication ===&lt;br /&gt;
&lt;br /&gt;
CherryPy supports two authentication mechanisms: Simple and Digest. It follows the specification defined by [http://tools.ietf.org/html/rfc2617.html RFC 2617]&lt;br /&gt;
&lt;br /&gt;
=== WSGI Support ===&lt;br /&gt;
&lt;br /&gt;
CherryPy supports the WSGI (Web Server Gateway Interface) specification defined by [http://www.python.org/dev/peps/pep-0333 PEP 0333] and [http://www.python.org/dev/peps/pep-3333 PEP 3333]. &lt;br /&gt;
&lt;br /&gt;
This allows two things:&lt;br /&gt;
* Instead of using the default CherryPy server, a CherryPy application can be hosted on an external WSGI server.&lt;br /&gt;
* The CherryPy server can be used independently to host an external WSGI application.&lt;br /&gt;
&lt;br /&gt;
=== Test Suite ===&lt;br /&gt;
&lt;br /&gt;
CherryPy framework provides a class, named &amp;lt;tt&amp;gt;helper&amp;lt;/tt&amp;gt; which can be used as a base class for writing functional tests. &lt;br /&gt;
&lt;br /&gt;
Running a test will start the complete application and thus can be used to simulate the scenario when a user actually tries to access the server on web.&lt;br /&gt;
&lt;br /&gt;
The sample code to run a test can be found [http://docs.cherrypy.org/en/latest/advanced.html#testing-your-application here]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=86712</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=86712"/>
		<updated>2014-09-18T23:19:50Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Background */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
CherryPy is a lightweight web server framework written in Python.  It has an object-oriented design and provides a basic HTTP web server as defined in RFC 7321.  It includes built-in profiling, coverage, and testing tools to assist in development.  &lt;br /&gt;
&lt;br /&gt;
CherryPy does not have any built-in templating or database engines, and instead relies on external libraries and plugins. &amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;  Python comes with a rich library support, so this typically is not an issue.&lt;br /&gt;
&lt;br /&gt;
It is distributed under the BSD License&amp;lt;ref&amp;gt;https://bitbucket.org/cherrypy/cherrypy/src/697c7af588b8/cherrypy/LICENSE.txt&amp;lt;/ref&amp;gt;. The latest stable version is 3.6 as of August 19, 2014&amp;lt;ref&amp;gt;https://pypi.python.org/pypi/CherryPy&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Some of the well known websites using CherryPy are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list can be found [http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy here].&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates the most basic webserver using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
'''WebApp.py'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Start the application by running the above python file &amp;quot;WebApp.py&amp;quot; and open your web browser to http://localhost:8080.  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
=== Query Strings ===&lt;br /&gt;
&lt;br /&gt;
CherryPy will automatically parse the query string of a URL.  Fields are passed as method arguments with matching names, and can take advantage of default argument values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def test(self, value=1):&lt;br /&gt;
        return &amp;quot;Value = &amp;quot; + str(value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A URL of http://localhost:8080/test?value=5 gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_06-37-27_PM.png]]&lt;br /&gt;
&lt;br /&gt;
=== Cookies ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can set browser cookies with &amp;lt;tt&amp;gt;cherrypy.response.cookie&amp;lt;/tt&amp;gt; and read browser cookies with &amp;lt;tt&amp;gt;cherrypy.request.cookie&amp;lt;/tt&amp;gt; by accessing these variables as python dictionary objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def set(self, value = &amp;quot;Test&amp;quot;):&lt;br /&gt;
        cookie = cherrypy.response.cookie&lt;br /&gt;
        cookie['Value'] = value&lt;br /&gt;
        return &amp;quot;Cookie set&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def get(self):&lt;br /&gt;
        cookie = cherrypy.request.cookie&lt;br /&gt;
        return &amp;quot;Cookie value = &amp;quot; + str(cookie['Value'].value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Navigating to http://localhost:8080/set?value=test followed by http://localhost:8080/get gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:CherryPyCookieTest.png]]&lt;br /&gt;
&lt;br /&gt;
=== Logging ===&lt;br /&gt;
&lt;br /&gt;
CherryPy provides the following method for application logging&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.log(&amp;quot;Hello, CherryPy!&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, all logging is written to the console.  The configuration keys &amp;lt;tt&amp;gt;log.access_file&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;log.error_file&amp;lt;/tt&amp;gt; are also available for writing logging and errors to a text file.&lt;br /&gt;
&lt;br /&gt;
=== In-built HTTP Server to host single or multiple applications ===&lt;br /&gt;
CherryPy comes with its own HTTP server which can be used to host web applications.&lt;br /&gt;
&lt;br /&gt;
==== Single application ====&lt;br /&gt;
The easiest way to do that is by calling the &amp;lt;tt&amp;gt;cherrypy.quickstart()&amp;lt;/tt&amp;gt; function. The function takes at least one argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application 'WebApp' at http://localhost:8080/.&lt;br /&gt;
&lt;br /&gt;
It can also take 2 more arguments.&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp(), '/hello', {'/': {'tools.gzip.on': True}})&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application 'WebApp' at http://localhost:8080/hello. &lt;br /&gt;
The third argument defines the configuration for our application. It can either be a dictionary object or a file.&lt;br /&gt;
&lt;br /&gt;
==== Multiple applications ====&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;tt&amp;gt;cherrypy.tree.mount&amp;lt;/tt&amp;gt; is used to host multiple applications.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.tree.mount(MyApp1(), '/app1', app1_conf)&lt;br /&gt;
cherrypy.tree.mount(MyApp2(), '/app2', app2_conf)&lt;br /&gt;
&lt;br /&gt;
cherrypy.engine.start()&lt;br /&gt;
cherrypy.engine.block()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will host two applications having paths http://localhost:8080/app1 and http://localhost:8080/app2.&lt;br /&gt;
&lt;br /&gt;
=== Server Configuration ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;cherrypy.config.update&amp;lt;/tt&amp;gt; function can be used to configure the HTTP server.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'server.socket_port': 9999})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will start the server on port 9999 instead of the default port 8080. The application can then be accessed at http://localhost:9999/.&lt;br /&gt;
&lt;br /&gt;
We can also pass a file (containing configuration) as an argument to this function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.config.update(&amp;quot;WebAppServer.conf&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''WebAppServer.conf'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[global]&lt;br /&gt;
server.socket_port: 9999&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Sessions ===&lt;br /&gt;
&lt;br /&gt;
In CherryPy, sessions are disabled by default.  To enable sessions, set the configuration &amp;lt;tt&amp;gt;tools.sessions.on&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;. &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/basics.html#using-sessions&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Session variables can be accessed with &amp;lt;tt&amp;gt;cherrypy.session&amp;lt;/tt&amp;gt;, which is a python dictionary object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        if 'number' not in cherrypy.session:&lt;br /&gt;
            cherrypy.session['number'] = 0&lt;br /&gt;
        else:&lt;br /&gt;
            cherrypy.session['number'] += 1&lt;br /&gt;
        return &amp;quot;Number = &amp;quot; + str(cherrypy.session['number'])&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'tools.sessions.on': True})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example shows a number that increments by 1 every time the user navigates to [http://localhost:8080 localhost:8080].&lt;br /&gt;
&lt;br /&gt;
=== Serve Static Content ===&lt;br /&gt;
Static contents like files, images, stylesheets etc. can be easily served by adding the following lines in the the application configuration file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[/images]&lt;br /&gt;
tools.staticdir.on = True&lt;br /&gt;
tools.staticdir.dir = &amp;quot;/site/public/images&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will allow the user to access some file &amp;quot;user.jpg&amp;quot; present in the folder &amp;quot;/site/public/images/user.jpg&amp;quot; using the url http://localhost:8080/images/user.jpg.&lt;br /&gt;
&lt;br /&gt;
=== Publish REST APIs ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can be used to expose the APIs as RESTful Web Services. This allows third party applications to easily communicate with the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class MyAppRestMode(object):&lt;br /&gt;
    exposed = True&lt;br /&gt;
&lt;br /&gt;
    def GET(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
conf = {&lt;br /&gt;
    '/': {&lt;br /&gt;
        'request.dispatch': cherrypy.dispatch.MethodDispatcher(),&lt;br /&gt;
        'tools.response_headers.on': True,&lt;br /&gt;
        'tools.response_headers.headers': [('Content-Type', 'text/plain')],&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
cherrypy.quickstart(MyAppRestMode(), '/', conf)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code exposes the GET API with url http://localhost:8080/. The API returns the string &amp;quot;Hello, CherryPy!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Multiple HTTP Servers ===&lt;br /&gt;
&lt;br /&gt;
The default HTTP server started by CherryPy can only be used to host the application on one port. But, it is also possible to host the application on multiple ports by starting additional servers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from cherrypy._cpserver import Server&lt;br /&gt;
&lt;br /&gt;
server = Server()&lt;br /&gt;
server.socket_port = 443&lt;br /&gt;
server.subscribe()&lt;br /&gt;
&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code hosts the application with one more server, which runs on port 443. It is possible to create any number of additional servers.&lt;br /&gt;
&lt;br /&gt;
=== Authentication ===&lt;br /&gt;
&lt;br /&gt;
CherryPy supports two authentication mechanisms: Simple and Digest. It follows the specification defined by [http://tools.ietf.org/html/rfc2617.html RFC 2617]&lt;br /&gt;
&lt;br /&gt;
=== WSGI Support ===&lt;br /&gt;
&lt;br /&gt;
CherryPy supports the WSGI (Web Server Gateway Interface) specification defined by [http://www.python.org/dev/peps/pep-0333 PEP 0333] and [http://www.python.org/dev/peps/pep-3333 PEP 3333]. &lt;br /&gt;
&lt;br /&gt;
This allows two things:&lt;br /&gt;
* Instead of using the default CherryPy server, a CherryPy application can be hosted on an external WSGI server.&lt;br /&gt;
* The CherryPy server can be used independently to host an external WSGI application.&lt;br /&gt;
&lt;br /&gt;
=== Test Suite ===&lt;br /&gt;
&lt;br /&gt;
CherryPy framework provides a class, named &amp;lt;tt&amp;gt;helper&amp;lt;/tt&amp;gt; which can be used as a base class for writing functional tests. &lt;br /&gt;
&lt;br /&gt;
Running a test will start the complete application and thus can be used to simulate the scenario when a user actually tries to access the server on web.&lt;br /&gt;
&lt;br /&gt;
The sample code to run a test can be found [http://docs.cherrypy.org/en/latest/advanced.html#testing-your-application here]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85548</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85548"/>
		<updated>2014-09-15T03:50:38Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Background */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some of the popular websites using it are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list of applications using it can be found here.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
CherryPy is a lightweight web server framework written in python.  It has an object-oriented design and provides only a basic HTTP web server as defined in RFC 7321.  It includes built-in profiling, coverage, and testing tools to assist in development.  CherryPy does not have any built-in templating or database engines, and instead relies on external libraries and plugins. &amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why, when, where and by whom was it developed ?&amp;lt;br&amp;gt;&lt;br /&gt;
Basic Philosophy Behind the project ?&amp;lt;br&amp;gt;&lt;br /&gt;
Which companies are using it ?&amp;lt;br&amp;gt;&lt;br /&gt;
Total number of active users, latest release version number etc.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates the most basic webserver using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the application, and open your web browser to [http://localhost:8080 localhost:8080].  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== In-built HTTP Server to host single or multiple applications ===&lt;br /&gt;
CherryPy comes with its own HTTP server which can be used to host web applications.&lt;br /&gt;
&lt;br /&gt;
==== Single application ====&lt;br /&gt;
The easiest way to do that is by calling the &amp;lt;code&amp;gt;cherrypy.quickstart()&amp;lt;/code&amp;gt; function. The function takes at least one argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application 'WebApp' at http://localhost:8080/.&lt;br /&gt;
&lt;br /&gt;
It can also take 2 more arguments.&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp(), '/hello', {'/': {'tools.gzip.on': True}})&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application 'WebApp' at http://localhost:8080/hello. &lt;br /&gt;
The third argument defines the configuration for our application. It can either be a dictionary object or a file.&lt;br /&gt;
&lt;br /&gt;
==== Multiple applications ====&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;cherrypy.tree.mount&amp;lt;/code&amp;gt; is used to host multiple applications.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.tree.mount(MyApp1(), '/app1', app1_conf)&lt;br /&gt;
cherrypy.tree.mount(MyApp2(), '/app2', app2_conf)&lt;br /&gt;
&lt;br /&gt;
cherrypy.engine.start()&lt;br /&gt;
cherrypy.engine.block()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will host two applications having paths http://localhost:8080/app1 and http://localhost:8080/app2.&lt;br /&gt;
&lt;br /&gt;
=== Logging ===&lt;br /&gt;
&lt;br /&gt;
CherryPy provides the following method for application logging&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.log(&amp;quot;Hello, CherryPy!&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, all logging is written to the console.  The configuration keys &amp;lt;tt&amp;gt;log.access_file&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;log.error_file&amp;lt;/tt&amp;gt; are also available for writing logging and errors to a text file.&lt;br /&gt;
&lt;br /&gt;
=== Query Strings ===&lt;br /&gt;
&lt;br /&gt;
CherryPy will automatically parse the query string of a URL.  Fields are passed as method arguments with matching names, and can take advantage of default argument values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def test(self, value=1):&lt;br /&gt;
        return &amp;quot;Value = &amp;quot; + str(value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A URL of [http://localhost:8080/test?value=5 localhost:8080/test?value=5] gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_06-37-27_PM.png]]&lt;br /&gt;
&lt;br /&gt;
=== Cookies ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can set browser cookies with &amp;lt;tt&amp;gt;cherrypy.response.cookie&amp;lt;/tt&amp;gt; and read browser cookies with &amp;lt;tt&amp;gt;cherrypy.request.cookie&amp;lt;/tt&amp;gt; by accessing these variables as python dictionary objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def set(self, value = &amp;quot;Test&amp;quot;):&lt;br /&gt;
        cookie = cherrypy.response.cookie&lt;br /&gt;
        cookie['Value'] = value&lt;br /&gt;
        return &amp;quot;Cookie set&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def get(self):&lt;br /&gt;
        cookie = cherrypy.request.cookie&lt;br /&gt;
        return &amp;quot;Cookie value = &amp;quot; + str(cookie['Value'].value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Navigating to [http://localhost:8080/set?value=test localhost:8080/set?value=test] followed by [http://localhost:8080/get localhost:8080/get] gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:CherryPyCookieTest.png]]&lt;br /&gt;
&lt;br /&gt;
=== Sessions ===&lt;br /&gt;
&lt;br /&gt;
In CherryPy, sessions are disabled by default.  To enable sessions, set the configuration &amp;lt;tt&amp;gt;tools.sessions.on&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;. &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/basics.html#using-sessions&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Session variables can be accessed with &amp;lt;tt&amp;gt;cherrypy.session&amp;lt;/tt&amp;gt;, which is a python dictionary object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        if 'number' not in cherrypy.session:&lt;br /&gt;
            cherrypy.session['number'] = 0&lt;br /&gt;
        else:&lt;br /&gt;
            cherrypy.session['number'] += 1&lt;br /&gt;
        return &amp;quot;Number = &amp;quot; + str(cherrypy.session['number'])&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'tools.sessions.on': True})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example shows a number that increments by 1 every time the user navigates to [http://localhost:8080 localhost:8080].&lt;br /&gt;
&lt;br /&gt;
=== Server Configuration ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;cherrypy.config.update&amp;lt;/code&amp;gt; function can be used to configure the HTTP server.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'server.socket_port': 9090})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will start the server on port 9999 instead of the default port 8080. The application can then be accessed at http://localhost:9999/.&lt;br /&gt;
&lt;br /&gt;
We can also pass a file (containing configuration) as an argument to this function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.config.update(&amp;quot;WebAppServer.conf&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''WebAppServer.conf'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[global]&lt;br /&gt;
server.socket_port: 9999&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Serve Static Content ===&lt;br /&gt;
Static contents like files, images, stylesheets etc. can be easily served by adding the following lines in the the application configuration file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[/images]&lt;br /&gt;
tools.staticdir.on = True&lt;br /&gt;
tools.staticdir.dir = &amp;quot;/site/public/images&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will allow us to access some file &amp;quot;user.jpg&amp;quot; present in the folder &amp;quot;/site/public/images/user.jpg&amp;quot; using the url http://localhost:8080/images/user.jpg.&lt;br /&gt;
&lt;br /&gt;
=== Publish REST APIs ===&lt;br /&gt;
&lt;br /&gt;
It allows to expose our APIs as Restful Web Services.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class MyAppRestMode(object):&lt;br /&gt;
    exposed = True&lt;br /&gt;
&lt;br /&gt;
    def GET(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
conf = {&lt;br /&gt;
    '/': {&lt;br /&gt;
        'request.dispatch': cherrypy.dispatch.MethodDispatcher(),&lt;br /&gt;
        'tools.response_headers.on': True,&lt;br /&gt;
        'tools.response_headers.headers': [('Content-Type', 'text/plain')],&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
cherrypy.quickstart(MyAppRestMode(), '/', conf)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This exposes the REST API &amp;quot;GET&amp;quot;: http://localhost:8080/. The API returns the string &amp;quot;Hello, CherryPy!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Multiple HTTP Servers ===&lt;br /&gt;
&lt;br /&gt;
It is possible to host the application with multiple servers, where each server runs on a different port.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from cherrypy._cpserver import Server&lt;br /&gt;
&lt;br /&gt;
server = Server()&lt;br /&gt;
server.socket_port = 443&lt;br /&gt;
server.subscribe()&lt;br /&gt;
&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code hosts our application with one more server which runs on port 443. We can create any number of additional servers.&lt;br /&gt;
&lt;br /&gt;
=== Test Suite ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85547</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85547"/>
		<updated>2014-09-15T03:50:04Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Background */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some of the popular websites using it are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list of applications using it can be found here.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
CherryPy is a lightweight web server written in python.  It has an object-oriented design and provides only a basic HTTP web server as defined in RFC 7321.  It includes built-in profiling, coverage, and testing tools to assist in development.  CherryPy does not have any built-in templating or database engines, and instead relies on external libraries and plugins. &amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why, when, where and by whom was it developed ?&amp;lt;br&amp;gt;&lt;br /&gt;
Basic Philosophy Behind the project ?&amp;lt;br&amp;gt;&lt;br /&gt;
Which companies are using it ?&amp;lt;br&amp;gt;&lt;br /&gt;
Total number of active users, latest release version number etc.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates the most basic webserver using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the application, and open your web browser to [http://localhost:8080 localhost:8080].  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== In-built HTTP Server to host single or multiple applications ===&lt;br /&gt;
CherryPy comes with its own HTTP server which can be used to host web applications.&lt;br /&gt;
&lt;br /&gt;
==== Single application ====&lt;br /&gt;
The easiest way to do that is by calling the &amp;lt;code&amp;gt;cherrypy.quickstart()&amp;lt;/code&amp;gt; function. The function takes at least one argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application 'WebApp' at http://localhost:8080/.&lt;br /&gt;
&lt;br /&gt;
It can also take 2 more arguments.&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp(), '/hello', {'/': {'tools.gzip.on': True}})&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application 'WebApp' at http://localhost:8080/hello. &lt;br /&gt;
The third argument defines the configuration for our application. It can either be a dictionary object or a file.&lt;br /&gt;
&lt;br /&gt;
==== Multiple applications ====&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;cherrypy.tree.mount&amp;lt;/code&amp;gt; is used to host multiple applications.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.tree.mount(MyApp1(), '/app1', app1_conf)&lt;br /&gt;
cherrypy.tree.mount(MyApp2(), '/app2', app2_conf)&lt;br /&gt;
&lt;br /&gt;
cherrypy.engine.start()&lt;br /&gt;
cherrypy.engine.block()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will host two applications having paths http://localhost:8080/app1 and http://localhost:8080/app2.&lt;br /&gt;
&lt;br /&gt;
=== Logging ===&lt;br /&gt;
&lt;br /&gt;
CherryPy provides the following method for application logging&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.log(&amp;quot;Hello, CherryPy!&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, all logging is written to the console.  The configuration keys &amp;lt;tt&amp;gt;log.access_file&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;log.error_file&amp;lt;/tt&amp;gt; are also available for writing logging and errors to a text file.&lt;br /&gt;
&lt;br /&gt;
=== Query Strings ===&lt;br /&gt;
&lt;br /&gt;
CherryPy will automatically parse the query string of a URL.  Fields are passed as method arguments with matching names, and can take advantage of default argument values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def test(self, value=1):&lt;br /&gt;
        return &amp;quot;Value = &amp;quot; + str(value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A URL of [http://localhost:8080/test?value=5 localhost:8080/test?value=5] gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_06-37-27_PM.png]]&lt;br /&gt;
&lt;br /&gt;
=== Cookies ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can set browser cookies with &amp;lt;tt&amp;gt;cherrypy.response.cookie&amp;lt;/tt&amp;gt; and read browser cookies with &amp;lt;tt&amp;gt;cherrypy.request.cookie&amp;lt;/tt&amp;gt; by accessing these variables as python dictionary objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def set(self, value = &amp;quot;Test&amp;quot;):&lt;br /&gt;
        cookie = cherrypy.response.cookie&lt;br /&gt;
        cookie['Value'] = value&lt;br /&gt;
        return &amp;quot;Cookie set&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def get(self):&lt;br /&gt;
        cookie = cherrypy.request.cookie&lt;br /&gt;
        return &amp;quot;Cookie value = &amp;quot; + str(cookie['Value'].value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Navigating to [http://localhost:8080/set?value=test localhost:8080/set?value=test] followed by [http://localhost:8080/get localhost:8080/get] gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:CherryPyCookieTest.png]]&lt;br /&gt;
&lt;br /&gt;
=== Sessions ===&lt;br /&gt;
&lt;br /&gt;
In CherryPy, sessions are disabled by default.  To enable sessions, set the configuration &amp;lt;tt&amp;gt;tools.sessions.on&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;. &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/basics.html#using-sessions&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Session variables can be accessed with &amp;lt;tt&amp;gt;cherrypy.session&amp;lt;/tt&amp;gt;, which is a python dictionary object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        if 'number' not in cherrypy.session:&lt;br /&gt;
            cherrypy.session['number'] = 0&lt;br /&gt;
        else:&lt;br /&gt;
            cherrypy.session['number'] += 1&lt;br /&gt;
        return &amp;quot;Number = &amp;quot; + str(cherrypy.session['number'])&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'tools.sessions.on': True})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example shows a number that increments by 1 every time the user navigates to [http://localhost:8080 localhost:8080].&lt;br /&gt;
&lt;br /&gt;
=== Server Configuration ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;cherrypy.config.update&amp;lt;/code&amp;gt; function can be used to configure the HTTP server.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'server.socket_port': 9090})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will start the server on port 9999 instead of the default port 8080. The application can then be accessed at http://localhost:9999/.&lt;br /&gt;
&lt;br /&gt;
We can also pass a file (containing configuration) as an argument to this function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.config.update(&amp;quot;WebAppServer.conf&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''WebAppServer.conf'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[global]&lt;br /&gt;
server.socket_port: 9999&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Serve Static Content ===&lt;br /&gt;
Static contents like files, images, stylesheets etc. can be easily served by adding the following lines in the the application configuration file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[/images]&lt;br /&gt;
tools.staticdir.on = True&lt;br /&gt;
tools.staticdir.dir = &amp;quot;/site/public/images&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will allow us to access some file &amp;quot;user.jpg&amp;quot; present in the folder &amp;quot;/site/public/images/user.jpg&amp;quot; using the url http://localhost:8080/images/user.jpg.&lt;br /&gt;
&lt;br /&gt;
=== Publish REST APIs ===&lt;br /&gt;
&lt;br /&gt;
It allows to expose our APIs as Restful Web Services.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class MyAppRestMode(object):&lt;br /&gt;
    exposed = True&lt;br /&gt;
&lt;br /&gt;
    def GET(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
conf = {&lt;br /&gt;
    '/': {&lt;br /&gt;
        'request.dispatch': cherrypy.dispatch.MethodDispatcher(),&lt;br /&gt;
        'tools.response_headers.on': True,&lt;br /&gt;
        'tools.response_headers.headers': [('Content-Type', 'text/plain')],&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
cherrypy.quickstart(MyAppRestMode(), '/', conf)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This exposes the REST API &amp;quot;GET&amp;quot;: http://localhost:8080/. The API returns the string &amp;quot;Hello, CherryPy!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Multiple HTTP Servers ===&lt;br /&gt;
&lt;br /&gt;
It is possible to host the application with multiple servers, where each server runs on a different port.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from cherrypy._cpserver import Server&lt;br /&gt;
&lt;br /&gt;
server = Server()&lt;br /&gt;
server.socket_port = 443&lt;br /&gt;
server.subscribe()&lt;br /&gt;
&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code hosts our application with one more server which runs on port 443. We can create any number of additional servers.&lt;br /&gt;
&lt;br /&gt;
=== Test Suite ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85528</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85528"/>
		<updated>2014-09-14T21:39:37Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Background */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some of the popular websites using it are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list of applications using it can be found here.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
Object-oriented, python based&amp;lt;br&amp;gt;&lt;br /&gt;
Basic RFC 7321 (HTTP)&amp;lt;br&amp;gt;&lt;br /&gt;
Built-in profiling&amp;lt;br&amp;gt;&lt;br /&gt;
complete test suite&amp;lt;br&amp;gt;&lt;br /&gt;
No built-in templating or database engines, use external tools&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Why, when, where and by whom was it developed ?&amp;lt;br&amp;gt;&lt;br /&gt;
Basic Philosophy Behind the project ?&amp;lt;br&amp;gt;&lt;br /&gt;
Which companies are using it ?&amp;lt;br&amp;gt;&lt;br /&gt;
Total number of active users, latest release version number etc.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates the most basic webserver using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the application, and open your web browser to [http://localhost:8080 localhost:8080].  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== In-built HTTP Server to host single or multiple applications ===&lt;br /&gt;
CherryPy comes with its own HTTP server which can be used to host web applications.&lt;br /&gt;
&lt;br /&gt;
==== Single application ====&lt;br /&gt;
The easiest way to do that is by calling the &amp;lt;code&amp;gt;cherrypy.quickstart()&amp;lt;/code&amp;gt; function. The function takes at least one argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application 'WebApp' at http://localhost:8080/.&lt;br /&gt;
&lt;br /&gt;
It can also take 2 more arguments.&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp(), '/hello', {'/': {'tools.gzip.on': True}})&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application 'WebApp' at http://localhost:8080/hello. &lt;br /&gt;
The third argument defines the configuration for our application. It can either be a dictionary object or a file.&lt;br /&gt;
&lt;br /&gt;
==== Multiple applications ====&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;cherrypy.tree.mount&amp;lt;/code&amp;gt; is used to host multiple applications.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.tree.mount(MyApp1(), '/app1', app1_conf)&lt;br /&gt;
cherrypy.tree.mount(MyApp2(), '/app2', app2_conf)&lt;br /&gt;
&lt;br /&gt;
cherrypy.engine.start()&lt;br /&gt;
cherrypy.engine.block()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will host two applications having paths http://localhost:8080/app1 and http://localhost:8080/app2.&lt;br /&gt;
&lt;br /&gt;
=== Logging ===&lt;br /&gt;
&lt;br /&gt;
CherryPy provides the following method for application logging&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.log(&amp;quot;Hello, CherryPy!&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, all logging is written to the console.  The configuration keys &amp;lt;tt&amp;gt;log.access_file&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;log.error_file&amp;lt;/tt&amp;gt; are also available for writing logging and errors to a text file.&lt;br /&gt;
&lt;br /&gt;
=== Query Strings ===&lt;br /&gt;
&lt;br /&gt;
CherryPy will automatically parse the query string of a URL.  Fields are passed as method arguments with matching names, and can take advantage of default argument values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def test(self, value=1):&lt;br /&gt;
        return &amp;quot;Value = &amp;quot; + str(value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A URL of [http://localhost:8080/test?value=5 localhost:8080/test?value=5] gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_06-37-27_PM.png]]&lt;br /&gt;
&lt;br /&gt;
=== Cookies ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can set browser cookies with &amp;lt;tt&amp;gt;cherrypy.response.cookie&amp;lt;/tt&amp;gt; and read browser cookies with &amp;lt;tt&amp;gt;cherrypy.request.cookie&amp;lt;/tt&amp;gt; by accessing these variables as python dictionary objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def set(self, value = &amp;quot;Test&amp;quot;):&lt;br /&gt;
        cookie = cherrypy.response.cookie&lt;br /&gt;
        cookie['Value'] = value&lt;br /&gt;
        return &amp;quot;Cookie set&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def get(self):&lt;br /&gt;
        cookie = cherrypy.request.cookie&lt;br /&gt;
        return &amp;quot;Cookie value = &amp;quot; + str(cookie['Value'].value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Navigating to [http://localhost:8080/set?value=test localhost:8080/set?value=test] followed by [http://localhost:8080/get localhost:8080/get] gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:CherryPyCookieTest.png]]&lt;br /&gt;
&lt;br /&gt;
=== Sessions ===&lt;br /&gt;
&lt;br /&gt;
In CherryPy, sessions are disabled by default.  To enable sessions, set the configuration &amp;lt;tt&amp;gt;tools.sessions.on&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;. &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/basics.html#using-sessions&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Session variables can be accessed with &amp;lt;tt&amp;gt;cherrypy.session&amp;lt;/tt&amp;gt;, which is a python dictionary object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        if 'number' not in cherrypy.session:&lt;br /&gt;
            cherrypy.session['number'] = 0&lt;br /&gt;
        else:&lt;br /&gt;
            cherrypy.session['number'] += 1&lt;br /&gt;
        return &amp;quot;Number = &amp;quot; + str(cherrypy.session['number'])&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'tools.sessions.on': True})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example shows a number that increments by 1 every time the user navigates to [http://localhost:8080 localhost:8080].&lt;br /&gt;
&lt;br /&gt;
=== Server Configuration ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;cherrypy.config.update&amp;lt;/code&amp;gt; function can be used to configure the HTTP server.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'server.socket_port': 9090})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will start the server on port 9999 instead of the default port 8080. The application can then be accessed at http://localhost:9999/.&lt;br /&gt;
&lt;br /&gt;
We can also pass a file (containing configuration) as an argument to this function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.config.update(&amp;quot;WebAppServer.conf&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''WebAppServer.conf'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[global]&lt;br /&gt;
server.socket_port: 9999&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Serve Static Content ===&lt;br /&gt;
Static contents like files, images, stylesheets etc. can be easily served by adding the following lines in the the application configuration file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[/images]&lt;br /&gt;
tools.staticdir.on = True&lt;br /&gt;
tools.staticdir.dir = &amp;quot;/site/public/images&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will allow us to access some file &amp;quot;user.jpg&amp;quot; present in the folder &amp;quot;/site/public/images/user.jpg&amp;quot; using the url http://localhost:8080/images/user.jpg.&lt;br /&gt;
&lt;br /&gt;
=== Publish REST APIs ===&lt;br /&gt;
&lt;br /&gt;
It allows to expose our APIs as Restful Web Services.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class MyAppRestMode(object):&lt;br /&gt;
    exposed = True&lt;br /&gt;
&lt;br /&gt;
    def GET(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
conf = {&lt;br /&gt;
    '/': {&lt;br /&gt;
        'request.dispatch': cherrypy.dispatch.MethodDispatcher(),&lt;br /&gt;
        'tools.response_headers.on': True,&lt;br /&gt;
        'tools.response_headers.headers': [('Content-Type', 'text/plain')],&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
cherrypy.quickstart(MyAppRestMode(), '/', conf)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This exposes the REST API &amp;quot;GET&amp;quot;: http://localhost:8080/. The API returns the string &amp;quot;Hello, CherryPy!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Multiple HTTP Servers ===&lt;br /&gt;
&lt;br /&gt;
It is possible to host the application with multiple servers, where each server runs on a different port.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from cherrypy._cpserver import Server&lt;br /&gt;
&lt;br /&gt;
server = Server()&lt;br /&gt;
server.socket_port = 443&lt;br /&gt;
server.subscribe()&lt;br /&gt;
&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code hosts our application with one more server which runs on port 443. We can create any number of additional servers.&lt;br /&gt;
&lt;br /&gt;
=== Test Suite ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85527</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85527"/>
		<updated>2014-09-14T21:35:25Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Sessions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some of the popular websites using it are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list of applications using it can be found here.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates the most basic webserver using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the application, and open your web browser to [http://localhost:8080 localhost:8080].  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== In-built HTTP Server to host single or multiple applications ===&lt;br /&gt;
CherryPy comes with its own HTTP server which can be used to host web applications.&lt;br /&gt;
&lt;br /&gt;
==== Single application ====&lt;br /&gt;
The easiest way to do that is by calling the &amp;lt;code&amp;gt;cherrypy.quickstart()&amp;lt;/code&amp;gt; function. The function takes at least one argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application 'WebApp' at http://localhost:8080/.&lt;br /&gt;
&lt;br /&gt;
It can also take 2 more arguments.&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp(), '/hello', {'/': {'tools.gzip.on': True}})&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application 'WebApp' at http://localhost:8080/hello. &lt;br /&gt;
The third argument defines the configuration for our application. It can either be a dictionary object or a file.&lt;br /&gt;
&lt;br /&gt;
==== Multiple applications ====&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;cherrypy.tree.mount&amp;lt;/code&amp;gt; is used to host multiple applications.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.tree.mount(MyApp1(), '/app1', app1_conf)&lt;br /&gt;
cherrypy.tree.mount(MyApp2(), '/app2', app2_conf)&lt;br /&gt;
&lt;br /&gt;
cherrypy.engine.start()&lt;br /&gt;
cherrypy.engine.block()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will host two applications having paths http://localhost:8080/app1 and http://localhost:8080/app2.&lt;br /&gt;
&lt;br /&gt;
=== Logging ===&lt;br /&gt;
&lt;br /&gt;
CherryPy provides the following method for application logging&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.log(&amp;quot;Hello, CherryPy!&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, all logging is written to the console.  The configuration keys &amp;lt;tt&amp;gt;log.access_file&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;log.error_file&amp;lt;/tt&amp;gt; are also available for writing logging and errors to a text file.&lt;br /&gt;
&lt;br /&gt;
=== Query Strings ===&lt;br /&gt;
&lt;br /&gt;
CherryPy will automatically parse the query string of a URL.  Fields are passed as method arguments with matching names, and can take advantage of default argument values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def test(self, value=1):&lt;br /&gt;
        return &amp;quot;Value = &amp;quot; + str(value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A URL of [http://localhost:8080/test?value=5 localhost:8080/test?value=5] gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_06-37-27_PM.png]]&lt;br /&gt;
&lt;br /&gt;
=== Cookies ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can set browser cookies with &amp;lt;tt&amp;gt;cherrypy.response.cookie&amp;lt;/tt&amp;gt; and read browser cookies with &amp;lt;tt&amp;gt;cherrypy.request.cookie&amp;lt;/tt&amp;gt; by accessing these variables as python dictionary objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def set(self, value = &amp;quot;Test&amp;quot;):&lt;br /&gt;
        cookie = cherrypy.response.cookie&lt;br /&gt;
        cookie['Value'] = value&lt;br /&gt;
        return &amp;quot;Cookie set&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def get(self):&lt;br /&gt;
        cookie = cherrypy.request.cookie&lt;br /&gt;
        return &amp;quot;Cookie value = &amp;quot; + str(cookie['Value'].value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Navigating to [http://localhost:8080/set?value=test localhost:8080/set?value=test] followed by [http://localhost:8080/get localhost:8080/get] gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:CherryPyCookieTest.png]]&lt;br /&gt;
&lt;br /&gt;
=== Sessions ===&lt;br /&gt;
&lt;br /&gt;
In CherryPy, sessions are disabled by default.  To enable sessions, set the configuration &amp;lt;tt&amp;gt;tools.sessions.on&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;. &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/basics.html#using-sessions&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Session variables can be accessed with &amp;lt;tt&amp;gt;cherrypy.session&amp;lt;/tt&amp;gt;, which is a python dictionary object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        if 'number' not in cherrypy.session:&lt;br /&gt;
            cherrypy.session['number'] = 0&lt;br /&gt;
        else:&lt;br /&gt;
            cherrypy.session['number'] += 1&lt;br /&gt;
        return &amp;quot;Number = &amp;quot; + str(cherrypy.session['number'])&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'tools.sessions.on': True})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example shows a number that increments by 1 every time the user navigates to [http://localhost:8080 localhost:8080].&lt;br /&gt;
&lt;br /&gt;
=== Server Configuration ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;cherrypy.config.update&amp;lt;/code&amp;gt; function can be used to configure the HTTP server.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'server.socket_port': 9090})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will start the server on port 9999 instead of the default port 8080. The application can then be accessed at http://localhost:9999/.&lt;br /&gt;
&lt;br /&gt;
We can also pass a file (containing configuration) as an argument to this function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.config.update(&amp;quot;WebAppServer.conf&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''WebAppServer.conf'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[global]&lt;br /&gt;
server.socket_port: 9999&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Serve Static Content ===&lt;br /&gt;
Static contents like files, images, stylesheets etc. can be easily served by adding the following lines in the the application configuration file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[/images]&lt;br /&gt;
tools.staticdir.on = True&lt;br /&gt;
tools.staticdir.dir = &amp;quot;/site/public/images&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will allow us to access some file &amp;quot;user.jpg&amp;quot; present in the folder &amp;quot;/site/public/images/user.jpg&amp;quot; using the url http://localhost:8080/images/user.jpg.&lt;br /&gt;
&lt;br /&gt;
=== Publish REST APIs ===&lt;br /&gt;
&lt;br /&gt;
It allows to expose our APIs as Restful Web Services.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class MyAppRestMode(object):&lt;br /&gt;
    exposed = True&lt;br /&gt;
&lt;br /&gt;
    def GET(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
conf = {&lt;br /&gt;
    '/': {&lt;br /&gt;
        'request.dispatch': cherrypy.dispatch.MethodDispatcher(),&lt;br /&gt;
        'tools.response_headers.on': True,&lt;br /&gt;
        'tools.response_headers.headers': [('Content-Type', 'text/plain')],&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
cherrypy.quickstart(MyAppRestMode(), '/', conf)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This exposes the REST API &amp;quot;GET&amp;quot;: http://localhost:8080/. The API returns the string &amp;quot;Hello, CherryPy!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Multiple HTTP Servers ===&lt;br /&gt;
&lt;br /&gt;
It is possible to host the application with multiple servers, where each server runs on a different port.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from cherrypy._cpserver import Server&lt;br /&gt;
&lt;br /&gt;
server = Server()&lt;br /&gt;
server.socket_port = 443&lt;br /&gt;
server.subscribe()&lt;br /&gt;
&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code hosts our application with one more server which runs on port 443. We can create any number of additional servers.&lt;br /&gt;
&lt;br /&gt;
=== Test Suite ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85526</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85526"/>
		<updated>2014-09-14T21:34:56Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Sessions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some of the popular websites using it are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list of applications using it can be found here.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates the most basic webserver using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the application, and open your web browser to [http://localhost:8080 localhost:8080].  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== In-built HTTP Server to host single or multiple applications ===&lt;br /&gt;
CherryPy comes with its own HTTP server which can be used to host web applications.&lt;br /&gt;
&lt;br /&gt;
==== Single application ====&lt;br /&gt;
The easiest way to do that is by calling the &amp;lt;code&amp;gt;cherrypy.quickstart()&amp;lt;/code&amp;gt; function. The function takes at least one argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application 'WebApp' at http://localhost:8080/.&lt;br /&gt;
&lt;br /&gt;
It can also take 2 more arguments.&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp(), '/hello', {'/': {'tools.gzip.on': True}})&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application 'WebApp' at http://localhost:8080/hello. &lt;br /&gt;
The third argument defines the configuration for our application. It can either be a dictionary object or a file.&lt;br /&gt;
&lt;br /&gt;
==== Multiple applications ====&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;cherrypy.tree.mount&amp;lt;/code&amp;gt; is used to host multiple applications.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.tree.mount(MyApp1(), '/app1', app1_conf)&lt;br /&gt;
cherrypy.tree.mount(MyApp2(), '/app2', app2_conf)&lt;br /&gt;
&lt;br /&gt;
cherrypy.engine.start()&lt;br /&gt;
cherrypy.engine.block()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will host two applications having paths http://localhost:8080/app1 and http://localhost:8080/app2.&lt;br /&gt;
&lt;br /&gt;
=== Logging ===&lt;br /&gt;
&lt;br /&gt;
CherryPy provides the following method for application logging&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.log(&amp;quot;Hello, CherryPy!&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, all logging is written to the console.  The configuration keys &amp;lt;tt&amp;gt;log.access_file&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;log.error_file&amp;lt;/tt&amp;gt; are also available for writing logging and errors to a text file.&lt;br /&gt;
&lt;br /&gt;
=== Query Strings ===&lt;br /&gt;
&lt;br /&gt;
CherryPy will automatically parse the query string of a URL.  Fields are passed as method arguments with matching names, and can take advantage of default argument values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def test(self, value=1):&lt;br /&gt;
        return &amp;quot;Value = &amp;quot; + str(value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A URL of [http://localhost:8080/test?value=5 localhost:8080/test?value=5] gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_06-37-27_PM.png]]&lt;br /&gt;
&lt;br /&gt;
=== Cookies ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can set browser cookies with &amp;lt;tt&amp;gt;cherrypy.response.cookie&amp;lt;/tt&amp;gt; and read browser cookies with &amp;lt;tt&amp;gt;cherrypy.request.cookie&amp;lt;/tt&amp;gt; by accessing these variables as python dictionary objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def set(self, value = &amp;quot;Test&amp;quot;):&lt;br /&gt;
        cookie = cherrypy.response.cookie&lt;br /&gt;
        cookie['Value'] = value&lt;br /&gt;
        return &amp;quot;Cookie set&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def get(self):&lt;br /&gt;
        cookie = cherrypy.request.cookie&lt;br /&gt;
        return &amp;quot;Cookie value = &amp;quot; + str(cookie['Value'].value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Navigating to [http://localhost:8080/set?value=test localhost:8080/set?value=test] followed by [http://localhost:8080/get localhost:8080/get] gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:CherryPyCookieTest.png]]&lt;br /&gt;
&lt;br /&gt;
=== Sessions ===&lt;br /&gt;
&lt;br /&gt;
In CherryPy, sessions are disabled by default.  To enable sessions, set the configuration &amp;lt;tt&amp;gt;tools.sessions.on&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;. &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/basics.html#using-sessions&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Session variables can be accessed with &amp;lt;tt&amp;gt;cherrypy.session&amp;lt;/tt&amp;gt;, which is accessed as a python dictionary object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        if 'number' not in cherrypy.session:&lt;br /&gt;
            cherrypy.session['number'] = 0&lt;br /&gt;
        else:&lt;br /&gt;
            cherrypy.session['number'] += 1&lt;br /&gt;
        return &amp;quot;Number = &amp;quot; + str(cherrypy.session['number'])&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'tools.sessions.on': True})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example shows a number that increments by 1 every time the user navigates to [http://localhost:8080 localhost:8080].&lt;br /&gt;
&lt;br /&gt;
=== Server Configuration ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;cherrypy.config.update&amp;lt;/code&amp;gt; function can be used to configure the HTTP server.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'server.socket_port': 9090})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will start the server on port 9999 instead of the default port 8080. The application can then be accessed at http://localhost:9999/.&lt;br /&gt;
&lt;br /&gt;
We can also pass a file (containing configuration) as an argument to this function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.config.update(&amp;quot;WebAppServer.conf&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''WebAppServer.conf'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[global]&lt;br /&gt;
server.socket_port: 9999&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Serve Static Content ===&lt;br /&gt;
Static contents like files, images, stylesheets etc. can be easily served by adding the following lines in the the application configuration file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[/images]&lt;br /&gt;
tools.staticdir.on = True&lt;br /&gt;
tools.staticdir.dir = &amp;quot;/site/public/images&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will allow us to access some file &amp;quot;user.jpg&amp;quot; present in the folder &amp;quot;/site/public/images/user.jpg&amp;quot; using the url http://localhost:8080/images/user.jpg.&lt;br /&gt;
&lt;br /&gt;
=== Publish REST APIs ===&lt;br /&gt;
&lt;br /&gt;
It allows to expose our APIs as Restful Web Services.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class MyAppRestMode(object):&lt;br /&gt;
    exposed = True&lt;br /&gt;
&lt;br /&gt;
    def GET(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
conf = {&lt;br /&gt;
    '/': {&lt;br /&gt;
        'request.dispatch': cherrypy.dispatch.MethodDispatcher(),&lt;br /&gt;
        'tools.response_headers.on': True,&lt;br /&gt;
        'tools.response_headers.headers': [('Content-Type', 'text/plain')],&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
cherrypy.quickstart(MyAppRestMode(), '/', conf)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This exposes the REST API &amp;quot;GET&amp;quot;: http://localhost:8080/. The API returns the string &amp;quot;Hello, CherryPy!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Multiple HTTP Servers ===&lt;br /&gt;
&lt;br /&gt;
It is possible to host the application with multiple servers, where each server runs on a different port.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from cherrypy._cpserver import Server&lt;br /&gt;
&lt;br /&gt;
server = Server()&lt;br /&gt;
server.socket_port = 443&lt;br /&gt;
server.subscribe()&lt;br /&gt;
&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code hosts our application with one more server which runs on port 443. We can create any number of additional servers.&lt;br /&gt;
&lt;br /&gt;
=== Test Suite ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85525</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85525"/>
		<updated>2014-09-14T21:34:19Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Sessions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some of the popular websites using it are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list of applications using it can be found here.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates the most basic webserver using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the application, and open your web browser to [http://localhost:8080 localhost:8080].  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== In-built HTTP Server to host single or multiple applications ===&lt;br /&gt;
CherryPy comes with its own HTTP server which can be used to host web applications.&lt;br /&gt;
&lt;br /&gt;
==== Single application ====&lt;br /&gt;
The easiest way to do that is by calling the &amp;lt;code&amp;gt;cherrypy.quickstart()&amp;lt;/code&amp;gt; function. The function takes at least one argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application 'WebApp' at http://localhost:8080/.&lt;br /&gt;
&lt;br /&gt;
It can also take 2 more arguments.&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp(), '/hello', {'/': {'tools.gzip.on': True}})&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application 'WebApp' at http://localhost:8080/hello. &lt;br /&gt;
The third argument defines the configuration for our application. It can either be a dictionary object or a file.&lt;br /&gt;
&lt;br /&gt;
==== Multiple applications ====&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;cherrypy.tree.mount&amp;lt;/code&amp;gt; is used to host multiple applications.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.tree.mount(MyApp1(), '/app1', app1_conf)&lt;br /&gt;
cherrypy.tree.mount(MyApp2(), '/app2', app2_conf)&lt;br /&gt;
&lt;br /&gt;
cherrypy.engine.start()&lt;br /&gt;
cherrypy.engine.block()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will host two applications having paths http://localhost:8080/app1 and http://localhost:8080/app2.&lt;br /&gt;
&lt;br /&gt;
=== Logging ===&lt;br /&gt;
&lt;br /&gt;
CherryPy provides the following method for application logging&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.log(&amp;quot;Hello, CherryPy!&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, all logging is written to the console.  The configuration keys &amp;lt;tt&amp;gt;log.access_file&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;log.error_file&amp;lt;/tt&amp;gt; are also available for writing logging and errors to a text file.&lt;br /&gt;
&lt;br /&gt;
=== Query Strings ===&lt;br /&gt;
&lt;br /&gt;
CherryPy will automatically parse the query string of a URL.  Fields are passed as method arguments with matching names, and can take advantage of default argument values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def test(self, value=1):&lt;br /&gt;
        return &amp;quot;Value = &amp;quot; + str(value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A URL of [http://localhost:8080/test?value=5 localhost:8080/test?value=5] gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_06-37-27_PM.png]]&lt;br /&gt;
&lt;br /&gt;
=== Cookies ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can set browser cookies with &amp;lt;tt&amp;gt;cherrypy.response.cookie&amp;lt;/tt&amp;gt; and read browser cookies with &amp;lt;tt&amp;gt;cherrypy.request.cookie&amp;lt;/tt&amp;gt; by accessing these variables as python dictionary objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def set(self, value = &amp;quot;Test&amp;quot;):&lt;br /&gt;
        cookie = cherrypy.response.cookie&lt;br /&gt;
        cookie['Value'] = value&lt;br /&gt;
        return &amp;quot;Cookie set&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def get(self):&lt;br /&gt;
        cookie = cherrypy.request.cookie&lt;br /&gt;
        return &amp;quot;Cookie value = &amp;quot; + str(cookie['Value'].value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Navigating to [http://localhost:8080/set?value=test localhost:8080/set?value=test] followed by [http://localhost:8080/get localhost:8080/get] gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:CherryPyCookieTest.png]]&lt;br /&gt;
&lt;br /&gt;
=== Sessions ===&lt;br /&gt;
&lt;br /&gt;
In CherryPy, sessions are disabled by default.  To enable sessions, set the configuration &amp;lt;tt&amp;gt;tools.sessions.on&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;. &amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/basics.html#using-sessions&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Session variables can be accessed with cherrypy.session, which is accessed as a python dictionary object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        if 'number' not in cherrypy.session:&lt;br /&gt;
            cherrypy.session['number'] = 0&lt;br /&gt;
        else:&lt;br /&gt;
            cherrypy.session['number'] += 1&lt;br /&gt;
        return &amp;quot;Number = &amp;quot; + str(cherrypy.session['number'])&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'tools.sessions.on': True})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This example shows a number that increments by 1 every time the user navigates to [http://localhost:8080 localhost:8080].&lt;br /&gt;
&lt;br /&gt;
=== Server Configuration ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;cherrypy.config.update&amp;lt;/code&amp;gt; function can be used to configure the HTTP server.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'server.socket_port': 9090})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will start the server on port 9999 instead of the default port 8080. The application can then be accessed at http://localhost:9999/.&lt;br /&gt;
&lt;br /&gt;
We can also pass a file (containing configuration) as an argument to this function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.config.update(&amp;quot;WebAppServer.conf&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''WebAppServer.conf'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[global]&lt;br /&gt;
server.socket_port: 9999&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Serve Static Content ===&lt;br /&gt;
Static contents like files, images, stylesheets etc. can be easily served by adding the following lines in the the application configuration file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[/images]&lt;br /&gt;
tools.staticdir.on = True&lt;br /&gt;
tools.staticdir.dir = &amp;quot;/site/public/images&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will allow us to access some file &amp;quot;user.jpg&amp;quot; present in the folder &amp;quot;/site/public/images/user.jpg&amp;quot; using the url http://localhost:8080/images/user.jpg.&lt;br /&gt;
&lt;br /&gt;
=== Publish REST APIs ===&lt;br /&gt;
&lt;br /&gt;
It allows to expose our APIs as Restful Web Services.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class MyAppRestMode(object):&lt;br /&gt;
    exposed = True&lt;br /&gt;
&lt;br /&gt;
    def GET(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
conf = {&lt;br /&gt;
    '/': {&lt;br /&gt;
        'request.dispatch': cherrypy.dispatch.MethodDispatcher(),&lt;br /&gt;
        'tools.response_headers.on': True,&lt;br /&gt;
        'tools.response_headers.headers': [('Content-Type', 'text/plain')],&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
cherrypy.quickstart(MyAppRestMode(), '/', conf)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This exposes the REST API &amp;quot;GET&amp;quot;: http://localhost:8080/. The API returns the string &amp;quot;Hello, CherryPy!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Multiple HTTP Servers ===&lt;br /&gt;
&lt;br /&gt;
It is possible to host the application with multiple servers, where each server runs on a different port.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from cherrypy._cpserver import Server&lt;br /&gt;
&lt;br /&gt;
server = Server()&lt;br /&gt;
server.socket_port = 443&lt;br /&gt;
server.subscribe()&lt;br /&gt;
&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code hosts our application with one more server which runs on port 443. We can create any number of additional servers.&lt;br /&gt;
&lt;br /&gt;
=== Test Suite ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85524</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85524"/>
		<updated>2014-09-14T21:05:04Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Sessions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some of the popular websites using it are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list of applications using it can be found here.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates the most basic webserver using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the application, and open your web browser to [http://localhost:8080 localhost:8080].  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== In-built HTTP Server to host single or multiple applications ===&lt;br /&gt;
CherryPy comes with its own HTTP server which can be used to host web applications.&lt;br /&gt;
&lt;br /&gt;
==== Single application ====&lt;br /&gt;
The easiest way to do that is by calling the &amp;lt;code&amp;gt;cherrypy.quickstart()&amp;lt;/code&amp;gt; function. The function takes at least one argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application 'WebApp' at http://localhost:8080/.&lt;br /&gt;
&lt;br /&gt;
It can also take 2 more arguments.&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp(), '/hello', {'/': {'tools.gzip.on': True}})&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application 'WebApp' at http://localhost:8080/hello. &lt;br /&gt;
The third argument defines the configuration for our application. It can either be a dictionary object or a file.&lt;br /&gt;
&lt;br /&gt;
==== Multiple applications ====&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;cherrypy.tree.mount&amp;lt;/code&amp;gt; is used to host multiple applications.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.tree.mount(MyApp1(), '/app1', app1_conf)&lt;br /&gt;
cherrypy.tree.mount(MyApp2(), '/app2', app2_conf)&lt;br /&gt;
&lt;br /&gt;
cherrypy.engine.start()&lt;br /&gt;
cherrypy.engine.block()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will host two applications having paths http://localhost:8080/app1 and http://localhost:8080/app2.&lt;br /&gt;
&lt;br /&gt;
=== Logging ===&lt;br /&gt;
&lt;br /&gt;
CherryPy provides the following method for application logging&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.log(&amp;quot;Hello, CherryPy!&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, all logging is written to the console.  The configuration keys &amp;lt;tt&amp;gt;log.access_file&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;log.error_file&amp;lt;/tt&amp;gt; are also available for writing logging and errors to a text file.&lt;br /&gt;
&lt;br /&gt;
=== Query Strings ===&lt;br /&gt;
&lt;br /&gt;
CherryPy will automatically parse the query string of a URL.  Fields are passed as method arguments with matching names, and can take advantage of default argument values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def test(self, value=1):&lt;br /&gt;
        return &amp;quot;Value = &amp;quot; + str(value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A URL of [http://localhost:8080/test?value=5 localhost:8080/test?value=5] gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_06-37-27_PM.png]]&lt;br /&gt;
&lt;br /&gt;
=== Cookies ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can set browser cookies with &amp;lt;tt&amp;gt;cherrypy.response.cookie&amp;lt;/tt&amp;gt; and read browser cookies with &amp;lt;tt&amp;gt;cherrypy.request.cookie&amp;lt;/tt&amp;gt; by accessing these variables as python dictionary objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def set(self, value = &amp;quot;Test&amp;quot;):&lt;br /&gt;
        cookie = cherrypy.response.cookie&lt;br /&gt;
        cookie['Value'] = value&lt;br /&gt;
        return &amp;quot;Cookie set&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def get(self):&lt;br /&gt;
        cookie = cherrypy.request.cookie&lt;br /&gt;
        return &amp;quot;Cookie value = &amp;quot; + str(cookie['Value'].value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Navigating to [http://localhost:8080/set?value=test localhost:8080/set?value=test] followed by [http://localhost:8080/get localhost:8080/get] gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:CherryPyCookieTest.png]]&lt;br /&gt;
&lt;br /&gt;
=== Sessions ===&lt;br /&gt;
&lt;br /&gt;
In CherryPy, sessions are disabled by default.  To enable sessions, set the configuration &amp;lt;tt&amp;gt;tools.sessions.on&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;True&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Server Configuration ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;cherrypy.config.update&amp;lt;/code&amp;gt; function can be used to configure the HTTP server.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'server.socket_port': 9090})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will start the server on port 9999 instead of the default port 8080. The application can then be accessed at http://localhost:9999/.&lt;br /&gt;
&lt;br /&gt;
We can also pass a file (containing configuration) as an argument to this function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.config.update(&amp;quot;WebAppServer.conf&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''WebAppServer.conf'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[global]&lt;br /&gt;
server.socket_port: 9999&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Serve Static Content ===&lt;br /&gt;
Static contents like files, images, stylesheets etc. can be easily served by adding the following lines in the the application configuration file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[/images]&lt;br /&gt;
tools.staticdir.on = True&lt;br /&gt;
tools.staticdir.dir = &amp;quot;/site/public/images&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will allow us to access some file &amp;quot;user.jpg&amp;quot; present in the folder &amp;quot;/site/public/images/user.jpg&amp;quot; using the url http://localhost:8080/images/user.jpg.&lt;br /&gt;
&lt;br /&gt;
=== Publish REST APIs ===&lt;br /&gt;
&lt;br /&gt;
It allows to expose our APIs as Restful Web Services.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class MyAppRestMode(object):&lt;br /&gt;
    exposed = True&lt;br /&gt;
&lt;br /&gt;
    def GET(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
conf = {&lt;br /&gt;
    '/': {&lt;br /&gt;
        'request.dispatch': cherrypy.dispatch.MethodDispatcher(),&lt;br /&gt;
        'tools.response_headers.on': True,&lt;br /&gt;
        'tools.response_headers.headers': [('Content-Type', 'text/plain')],&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
cherrypy.quickstart(MyAppRestMode(), '/', conf)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This exposes the REST API &amp;quot;GET&amp;quot;: http://localhost:8080/. The API returns the string &amp;quot;Hello, CherryPy!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Multiple HTTP Servers ===&lt;br /&gt;
&lt;br /&gt;
It is possible to host the application with multiple servers, where each server runs on a different port.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from cherrypy._cpserver import Server&lt;br /&gt;
&lt;br /&gt;
server = Server()&lt;br /&gt;
server.socket_port = 443&lt;br /&gt;
server.subscribe()&lt;br /&gt;
&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code hosts our application with one more server which runs on port 443. We can create any number of additional servers.&lt;br /&gt;
&lt;br /&gt;
=== Test Suite ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85520</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85520"/>
		<updated>2014-09-14T20:38:22Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Cookies */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some of the popular websites using it are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list of applications using it can be found here.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates the most basic webserver using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the application, and open your web browser to [http://localhost:8080 localhost:8080].  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== In-built HTTP Server to host single or multiple applications ===&lt;br /&gt;
CherryPy comes with its own HTTP server which can be used to host web applications.&lt;br /&gt;
&lt;br /&gt;
==== Single application ====&lt;br /&gt;
The easiest way to do that is by calling the &amp;lt;code&amp;gt;cherrypy.quickstart()&amp;lt;/code&amp;gt; function. The function takes at least one argument.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp())&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application 'WebApp' at http://localhost:8080/.&lt;br /&gt;
&lt;br /&gt;
It can also take 2 more arguments.&lt;br /&gt;
&amp;lt;pre&amp;gt;cherrypy.quickstart(WebApp(), '/hello', {'/': {'tools.gzip.on': True}})&amp;lt;/pre&amp;gt;&lt;br /&gt;
This starts the application 'WebApp' at http://localhost:8080/hello. &lt;br /&gt;
The third argument defines the configuration for our application. It can either be a dictionary object or a file.&lt;br /&gt;
&lt;br /&gt;
==== Multiple applications ====&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;cherrypy.tree.mount&amp;lt;/code&amp;gt; is used to host multiple applications.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.tree.mount(MyApp1(), '/app1', app1_conf)&lt;br /&gt;
cherrypy.tree.mount(MyApp2(), '/app2', app2_conf)&lt;br /&gt;
&lt;br /&gt;
cherrypy.engine.start()&lt;br /&gt;
cherrypy.engine.block()&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will host two applications having paths http://localhost:8080/app1 and http://localhost:8080/app2.&lt;br /&gt;
&lt;br /&gt;
=== Logging ===&lt;br /&gt;
&lt;br /&gt;
CherryPy provides the following method for application logging&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.log(&amp;quot;Hello, CherryPy!&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, all logging is written to the console.  The configuration keys &amp;lt;tt&amp;gt;log.access_file&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;log.error_file&amp;lt;/tt&amp;gt; are also available for writing logging and errors to a text file.&lt;br /&gt;
&lt;br /&gt;
=== Query Strings ===&lt;br /&gt;
&lt;br /&gt;
CherryPy will automatically parse the query string of a URL.  Fields are passed as method arguments with matching names, and can take advantage of default argument values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def test(self, value=1):&lt;br /&gt;
        return &amp;quot;Value = &amp;quot; + str(value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A URL of [http://localhost:8080/test?value=5 localhost:8080/test?value=5] gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_06-37-27_PM.png]]&lt;br /&gt;
&lt;br /&gt;
=== Cookies ===&lt;br /&gt;
&lt;br /&gt;
CherryPy can set browser cookies with &amp;lt;tt&amp;gt;cherrypy.response.cookie&amp;lt;/tt&amp;gt; and read browser cookies with &amp;lt;tt&amp;gt;cherrypy.request.cookie&amp;lt;/tt&amp;gt; by accessing these variables as python dictionary objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def set(self, value = &amp;quot;Test&amp;quot;):&lt;br /&gt;
        cookie = cherrypy.response.cookie&lt;br /&gt;
        cookie['Value'] = value&lt;br /&gt;
        return &amp;quot;Cookie set&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def get(self):&lt;br /&gt;
        cookie = cherrypy.request.cookie&lt;br /&gt;
        return &amp;quot;Cookie value = &amp;quot; + str(cookie['Value'].value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Navigating to [http://localhost:8080/set?value=test localhost:8080/set?value=test] followed by [http://localhost:8080/get localhost:8080/get] gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:CherryPyCookieTest.png]]&lt;br /&gt;
&lt;br /&gt;
=== Sessions ===&lt;br /&gt;
&lt;br /&gt;
=== Server Configuration ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;cherrypy.config.update&amp;lt;/code&amp;gt; function can be used to configure the HTTP server.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
cherrypy.config.update({'server.socket_port': 9090})&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will start the server on port 9999 instead of the default port 8080. The application can then be accessed at http://localhost:9999/.&lt;br /&gt;
&lt;br /&gt;
We can also pass a file (containing configuration) as an argument to this function.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.config.update(&amp;quot;WebAppServer.conf&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''WebAppServer.conf'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[global]&lt;br /&gt;
server.socket_port: 9999&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Serve Static Content ===&lt;br /&gt;
Static contents like files, images, stylesheets etc. can be easily served by adding the following lines in the the application configuration file.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[/images]&lt;br /&gt;
tools.staticdir.on = True&lt;br /&gt;
tools.staticdir.dir = &amp;quot;/site/public/images&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will allow us to access some file &amp;quot;user.jpg&amp;quot; present in the folder &amp;quot;/site/public/images/user.jpg&amp;quot; using the url http://localhost:8080/images/user.jpg.&lt;br /&gt;
&lt;br /&gt;
=== Publish REST APIs ===&lt;br /&gt;
&lt;br /&gt;
It allows to expose our APIs as Restful Web Services.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
class MyAppRestMode(object):&lt;br /&gt;
    exposed = True&lt;br /&gt;
&lt;br /&gt;
    def GET(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
conf = {&lt;br /&gt;
    '/': {&lt;br /&gt;
        'request.dispatch': cherrypy.dispatch.MethodDispatcher(),&lt;br /&gt;
        'tools.response_headers.on': True,&lt;br /&gt;
        'tools.response_headers.headers': [('Content-Type', 'text/plain')],&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
cherrypy.quickstart(MyAppRestMode(), '/', conf)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This exposes the REST API &amp;quot;GET&amp;quot;: http://localhost:8080/. The API returns the string &amp;quot;Hello, CherryPy!&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Multiple HTTP Servers ===&lt;br /&gt;
&lt;br /&gt;
It is possible to host the application with multiple servers, where each server runs on a different port.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
from cherrypy._cpserver import Server&lt;br /&gt;
&lt;br /&gt;
server = Server()&lt;br /&gt;
server.socket_port = 443&lt;br /&gt;
server.subscribe()&lt;br /&gt;
&lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above code hosts our application with one more server which runs on port 443. We can create any number of additional servers.&lt;br /&gt;
&lt;br /&gt;
=== Test Suite ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85165</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85165"/>
		<updated>2014-09-13T23:07:41Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Cookies */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some of the popular websites using it are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list of applications using it can be found here.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates the most basic webserver using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the application, and open your web browser to [http://localhost:8080 localhost:8080].  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Hosting one or multiple applications ===&lt;br /&gt;
&lt;br /&gt;
=== Logging ===&lt;br /&gt;
&lt;br /&gt;
CherryPy provides the following method for application logging&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.log(&amp;quot;Hello, CherryPy!&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, all logging is written to the console.  The configuration keys &amp;lt;tt&amp;gt;log.access_file&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;log.error_file&amp;lt;/tt&amp;gt; are also available for writing logging and errors to a text file.&lt;br /&gt;
&lt;br /&gt;
=== Query Strings ===&lt;br /&gt;
&lt;br /&gt;
CherryPy will automatically parse the query string of a URL.  Fields are passed as method arguments with matching names, and can take advantage of default argument values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def test(self, value=1):&lt;br /&gt;
        return &amp;quot;Value = &amp;quot; + str(value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A URL of [http://localhost:8080/test?value=5 localhost:8080/test?value=5] gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_06-37-27_PM.png]]&lt;br /&gt;
&lt;br /&gt;
=== Cookies ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def set(self, value = &amp;quot;Test&amp;quot;):&lt;br /&gt;
        cookie = cherrypy.response.cookie&lt;br /&gt;
        cookie['Value'] = value&lt;br /&gt;
        return &amp;quot;Cookie set&amp;quot;&lt;br /&gt;
    &lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def get(self):&lt;br /&gt;
        cookie = cherrypy.request.cookie&lt;br /&gt;
        return &amp;quot;Cookie value = &amp;quot; + str(cookie['Value'].value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:CherryPyCookieTest.png]]&lt;br /&gt;
&lt;br /&gt;
=== Sessions ===&lt;br /&gt;
&lt;br /&gt;
=== Serve Static Content ===&lt;br /&gt;
&lt;br /&gt;
=== Ajax Support ===&lt;br /&gt;
&lt;br /&gt;
=== Publish REST APIs ===&lt;br /&gt;
&lt;br /&gt;
=== Multiple HTTP Servers ===&lt;br /&gt;
&lt;br /&gt;
=== Test Suite ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:CherryPyCookieTest.png&amp;diff=85164</id>
		<title>File:CherryPyCookieTest.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:CherryPyCookieTest.png&amp;diff=85164"/>
		<updated>2014-09-13T23:07:11Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85155</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85155"/>
		<updated>2014-09-13T22:41:10Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Query Strings */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some of the popular websites using it are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list of applications using it can be found here.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates the most basic webserver using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the application, and open your web browser to [http://localhost:8080 localhost:8080].  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Logging ===&lt;br /&gt;
&lt;br /&gt;
CherryPy provides the following method for application logging&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.log(&amp;quot;Hello, CherryPy!&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, all logging is written to the console.  The configuration keys &amp;lt;tt&amp;gt;log.access_file&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;log.error_file&amp;lt;/tt&amp;gt; are also available for writing logging and errors to a text file.&lt;br /&gt;
&lt;br /&gt;
=== Query Strings ===&lt;br /&gt;
&lt;br /&gt;
CherryPy will automatically parse the query string of a URL.  Fields are passed as method arguments with matching names, and can take advantage of default argument values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def test(self, value=1):&lt;br /&gt;
        return &amp;quot;Value = &amp;quot; + str(value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A URL of [http://localhost:8080/test?value=5 localhost:8080/test?value=5] gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_06-37-27_PM.png]]&lt;br /&gt;
&lt;br /&gt;
=== Cookies ===&lt;br /&gt;
&lt;br /&gt;
=== Sessions ===&lt;br /&gt;
&lt;br /&gt;
=== Serve Static Content ===&lt;br /&gt;
&lt;br /&gt;
=== Ajax Support ===&lt;br /&gt;
&lt;br /&gt;
=== Publish REST APIs ===&lt;br /&gt;
&lt;br /&gt;
=== Multiple HTTP Servers ===&lt;br /&gt;
&lt;br /&gt;
=== Test Suite ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85154</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85154"/>
		<updated>2014-09-13T22:40:44Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Query Strings */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some of the popular websites using it are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list of applications using it can be found here.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates the most basic webserver using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the application, and open your web browser to [http://localhost:8080 localhost:8080].  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Logging ===&lt;br /&gt;
&lt;br /&gt;
CherryPy provides the following method for application logging&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.log(&amp;quot;Hello, CherryPy!&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, all logging is written to the console.  The configuration keys &amp;lt;tt&amp;gt;log.access_file&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;log.error_file&amp;lt;/tt&amp;gt; are also available for writing logging and errors to a text file.&lt;br /&gt;
&lt;br /&gt;
=== Query Strings ===&lt;br /&gt;
&lt;br /&gt;
CherryPy will automatically parse the query string of a URL.  Fields are passed as method arguments with matching names, and can take advantage of default argument values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def test(self, value=1):&lt;br /&gt;
        return &amp;quot;Value = &amp;quot; + str(value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A URL of [http://localhost:8080/test?value=10 localhost:8080/test?value=10] gives the following&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_06-37-27_PM.png]]&lt;br /&gt;
&lt;br /&gt;
=== Cookies ===&lt;br /&gt;
&lt;br /&gt;
=== Sessions ===&lt;br /&gt;
&lt;br /&gt;
=== Serve Static Content ===&lt;br /&gt;
&lt;br /&gt;
=== Ajax Support ===&lt;br /&gt;
&lt;br /&gt;
=== Publish REST APIs ===&lt;br /&gt;
&lt;br /&gt;
=== Multiple HTTP Servers ===&lt;br /&gt;
&lt;br /&gt;
=== Test Suite ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Screenshot_-_09132014_-_06-37-27_PM.png&amp;diff=85153</id>
		<title>File:Screenshot - 09132014 - 06-37-27 PM.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Screenshot_-_09132014_-_06-37-27_PM.png&amp;diff=85153"/>
		<updated>2014-09-13T22:40:26Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: uploaded a new version of &amp;amp;quot;File:Screenshot - 09132014 - 06-37-27 PM.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Result of CherryPy query string parsing&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Screenshot_-_09132014_-_06-37-27_PM.png&amp;diff=85151</id>
		<title>File:Screenshot - 09132014 - 06-37-27 PM.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Screenshot_-_09132014_-_06-37-27_PM.png&amp;diff=85151"/>
		<updated>2014-09-13T22:39:10Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: Result of CherryPy query string parsing&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Result of CherryPy query string parsing&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85150</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85150"/>
		<updated>2014-09-13T22:37:46Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Query Strings */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some of the popular websites using it are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list of applications using it can be found here.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates the most basic webserver using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the application, and open your web browser to [http://localhost:8080 localhost:8080].  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Logging ===&lt;br /&gt;
&lt;br /&gt;
CherryPy provides the following method for application logging&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.log(&amp;quot;Hello, CherryPy!&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, all logging is written to the console.  The configuration keys &amp;lt;tt&amp;gt;log.access_file&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;log.error_file&amp;lt;/tt&amp;gt; are also available for writing logging and errors to a text file.&lt;br /&gt;
&lt;br /&gt;
=== Query Strings ===&lt;br /&gt;
&lt;br /&gt;
CherryPy will automatically parse the query string of a URL.  Fields are passed as method arguments with matching names, and can take advantage of default argument values.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def test(self, value=1):&lt;br /&gt;
        return &amp;quot;Value = &amp;quot; + str(value)&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A URL of [http://localhost:8080/test?value=10 localhost:8080/test?value=10] gives the following&lt;br /&gt;
&lt;br /&gt;
=== Cookies ===&lt;br /&gt;
&lt;br /&gt;
=== Sessions ===&lt;br /&gt;
&lt;br /&gt;
=== Serve Static Content ===&lt;br /&gt;
&lt;br /&gt;
=== Ajax Support ===&lt;br /&gt;
&lt;br /&gt;
=== Publish REST APIs ===&lt;br /&gt;
&lt;br /&gt;
=== Multiple HTTP Servers ===&lt;br /&gt;
&lt;br /&gt;
=== Test Suite ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85148</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85148"/>
		<updated>2014-09-13T22:17:47Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Logging */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some of the popular websites using it are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list of applications using it can be found here.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates the most basic webserver using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the application, and open your web browser to [http://localhost:8080 localhost:8080].  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Logging ===&lt;br /&gt;
&lt;br /&gt;
CherryPy provides the following method for application logging&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
cherrypy.log(&amp;quot;Hello, CherryPy!&amp;quot;)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, all logging is written to the console.  The configuration keys &amp;lt;tt&amp;gt;log.access_file&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;log.error_file&amp;lt;/tt&amp;gt; are also available for writing logging and errors to a text file.&lt;br /&gt;
&lt;br /&gt;
=== Query Strings ===&lt;br /&gt;
&lt;br /&gt;
=== Cookies ===&lt;br /&gt;
&lt;br /&gt;
=== Sessions ===&lt;br /&gt;
&lt;br /&gt;
=== Serve Static Content ===&lt;br /&gt;
&lt;br /&gt;
=== Ajax Support ===&lt;br /&gt;
&lt;br /&gt;
=== Publish REST APIs ===&lt;br /&gt;
&lt;br /&gt;
=== Multiple HTTP Servers ===&lt;br /&gt;
&lt;br /&gt;
=== Test Suite ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85144</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85144"/>
		<updated>2014-09-13T21:21:24Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Features */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some of the popular websites using it are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list of applications using it can be found here.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates the most basic webserver using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the application, and open your web browser to [http://localhost:8080 localhost:8080].  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Logging ===&lt;br /&gt;
&lt;br /&gt;
=== Query Strings ===&lt;br /&gt;
&lt;br /&gt;
=== Cookies ===&lt;br /&gt;
&lt;br /&gt;
=== Sessions ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85143</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85143"/>
		<updated>2014-09-13T21:17:32Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Features */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some of the popular websites using it are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list of applications using it can be found here.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates the most basic webserver using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the application, and open your web browser to [http://localhost:8080 localhost:8080].  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
'''Logging'''&lt;br /&gt;
&lt;br /&gt;
'''Query Strings'''&lt;br /&gt;
&lt;br /&gt;
'''Cookies'''&lt;br /&gt;
&lt;br /&gt;
'''Sessions'''&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85142</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85142"/>
		<updated>2014-09-13T21:02:52Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Basic Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some of the popular websites using it are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list of applications using it can be found here.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates the most basic webserver using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the application, and open your web browser to [http://localhost:8080 localhost:8080].  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85141</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85141"/>
		<updated>2014-09-13T20:56:48Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Basic Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some of the popular websites using it are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list of applications using it can be found here.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates the most basic webserver using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run the application, and open your web browser to [http://localhost:8080].  The following page is displayed&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03-26-32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Screenshot_-_09132014_-_03-26-32_PM.png&amp;diff=85140</id>
		<title>File:Screenshot - 09132014 - 03-26-32 PM.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Screenshot_-_09132014_-_03-26-32_PM.png&amp;diff=85140"/>
		<updated>2014-09-13T20:51:48Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: Screenshot of Hello CherryPy output&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Screenshot of Hello CherryPy output&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85139</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85139"/>
		<updated>2014-09-13T20:51:19Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Basic Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some of the popular websites using it are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list of applications using it can be found here.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates the most basic webserver using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_-_09132014_-_03:26:32_PM.png]]&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85138</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85138"/>
		<updated>2014-09-13T20:34:46Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Basic Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some of the popular websites using it are Hulu&amp;lt;ref&amp;gt;http://tech.hulu.com/blog/2013/03/13/python-and-hulu/&amp;lt;/ref&amp;gt; and Netflix&amp;lt;ref&amp;gt;http://techblog.netflix.com/2013/03/python-at-netflix.html&amp;lt;/ref&amp;gt;. The full list of applications using it can be found here.&amp;lt;ref&amp;gt;http://docs.cherrypy.org/en/latest/intro.html#websites-running-atop-cherrypy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
The following code demonstrates the most basic webserver using the CherryPy framework.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85114</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85114"/>
		<updated>2014-09-13T19:31:54Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Basic Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import cherrypy&lt;br /&gt;
&lt;br /&gt;
class WebApp(object):&lt;br /&gt;
    @cherrypy.expose&lt;br /&gt;
    def index(self):&lt;br /&gt;
        return &amp;quot;Hello, CherryPy!&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
cherrypy.quickstart(WebApp())&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85081</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85081"/>
		<updated>2014-09-13T18:45:10Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a python based, object-oriented web framework that enables developers to quickly create lightweight and fast web applications.&amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;http://en.wikipedia.org/wiki/CherryPy&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85077</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85077"/>
		<updated>2014-09-13T18:34:26Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
CherryPy is a python based web framework that provides &amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85076</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85076"/>
		<updated>2014-09-13T18:33:49Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* Background */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
CherryPy is a python based web framework that provides &amp;lt;ref&amp;gt;http://www.cherrypy.org/&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85072</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85072"/>
		<updated>2014-09-13T18:31:21Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85066</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85066"/>
		<updated>2014-09-13T18:16:52Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''CherryPy Framework'''&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85065</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85065"/>
		<updated>2014-09-13T18:16:39Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;CherryPy Framework&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
== Basic Example ==&lt;br /&gt;
&lt;br /&gt;
== Features ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85063</id>
		<title>CSC/ECE 517 Fall 2014/ch1a 3 zq</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014/ch1a_3_zq&amp;diff=85063"/>
		<updated>2014-09-13T18:14:18Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: Created page with &amp;quot;== CherryPy Framework ==&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== CherryPy Framework ==&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2014&amp;diff=85061</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=85061"/>
		<updated>2014-09-13T18:12:51Z</updated>

		<summary type="html">&lt;p&gt;Jmkubasc: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*[[CSC/ECE_517_Fall_2014/sample_page]]&lt;br /&gt;
*[[CSC/ECE_517_Fall_2014/ch1a22as]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 19 mx]]&lt;br /&gt;
*[[CSC/ECE 517 Fall 2014/ch1a 3 zq]]&lt;/div&gt;</summary>
		<author><name>Jmkubasc</name></author>
	</entry>
</feed>