summaryrefslogtreecommitdiff
path: root/sphinx/source/tutorial/files/songs.py
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/source/tutorial/files/songs.py')
-rw-r--r--sphinx/source/tutorial/files/songs.py82
1 files changed, 0 insertions, 82 deletions
diff --git a/sphinx/source/tutorial/files/songs.py b/sphinx/source/tutorial/files/songs.py
deleted file mode 100644
index c8658b05..00000000
--- a/sphinx/source/tutorial/files/songs.py
+++ /dev/null
@@ -1,82 +0,0 @@
-import cherrypy
-
-songs = {
- '1': {
- 'title': 'Lumberjack Song',
- 'artist': 'Canadian Guard Choir'
- },
-
- '2': {
- 'title': 'Always Look On the Bright Side of Life',
- 'artist': 'Eric Idle'
- },
-
- '3': {
- 'title': 'Spam Spam Spam',
- 'artist': 'Monty Python'
- }
-}
-
-
-class Songs:
-
- exposed = True
-
- def GET(self, id=None):
-
- if id is None:
- return('Here are all the songs we have: %s' % songs)
- elif id in songs:
- song = songs[id]
-
- return(
- 'Song with the ID %s is called %s, and the artist is %s' % (
- id, song['title'], song['artist']))
- else:
- return('No song with the ID %s :-(' % id)
-
- def POST(self, title, artist):
-
- id = str(max([int(_) for _ in songs.keys()]) + 1)
-
- songs[id] = {
- 'title': title,
- 'artist': artist
- }
-
- return ('Create a new song with the ID: %s' % id)
-
- def PUT(self, id, title=None, artist=None):
- if id in songs:
- song = songs[id]
-
- song['title'] = title or song['title']
- song['artist'] = artist or song['artist']
-
- return(
- 'Song with the ID %s is now called %s, '
- 'and the artist is now %s' % (
- id, song['title'], song['artist'])
- )
- else:
- return('No song with the ID %s :-(' % id)
-
- def DELETE(self, id):
- if id in songs:
- songs.pop(id)
-
- return('Song with the ID %s has been deleted.' % id)
- else:
- return('No song with the ID %s :-(' % id)
-
-if __name__ == '__main__':
-
- cherrypy.tree.mount(
- Songs(), '/api/songs',
- {'/':
- {'request.dispatch': cherrypy.dispatch.MethodDispatcher()}
- }
- )
-
- cherrypy.engine.start()
- cherrypy.engine.block()