| | 239 | |
|---|
| | 240 | class Divorce: |
|---|
| | 241 | """HTTP Method handlers shouldn't collide with normal method names. |
|---|
| | 242 | For example, a GET-handler shouldn't collide with a method named 'get'. |
|---|
| | 243 | |
|---|
| | 244 | If you build HTTP method dispatching into CherryPy, rewrite this class |
|---|
| | 245 | to use your new dispatch mechanism and make sure that: |
|---|
| | 246 | "GET /divorce HTTP/1.1" maps to divorce.index() and |
|---|
| | 247 | "GET /divorce/get?ID=13 HTTP/1.1" maps to divorce.get() |
|---|
| | 248 | """ |
|---|
| | 249 | |
|---|
| | 250 | documents = {} |
|---|
| | 251 | |
|---|
| | 252 | def index(self): |
|---|
| | 253 | yield "<h1>Choose your document</h1>\n" |
|---|
| | 254 | yield "<ul>\n" |
|---|
| | 255 | for id, contents in self.documents: |
|---|
| | 256 | yield (" <li><a href='/divorce/get?ID=%s'>%s</a>: %s</li>\n" |
|---|
| | 257 | % (id, id, contents)) |
|---|
| | 258 | yield "</ul>" |
|---|
| | 259 | index.exposed = True |
|---|
| | 260 | |
|---|
| | 261 | def get(self, ID): |
|---|
| | 262 | return ("Divorce document %s: %s" % |
|---|
| | 263 | (ID, self.documents.get(ID, "empty"))) |
|---|
| | 264 | get.exposed = True |
|---|
| | 265 | |
|---|
| | 266 | cherrypy.root.divorce = Divorce() |
|---|
| | 267 | |
|---|
| | 697 | |
|---|
| | 698 | # For method dispatchers: make sure that an HTTP method doesn't |
|---|
| | 699 | # collide with a virtual path atom. If you build HTTP-method |
|---|
| | 700 | # dispatching into the core, rewrite these handlers to use |
|---|
| | 701 | # your dispatch idioms. |
|---|
| | 702 | self.getPage("/divorce/get?ID=13") |
|---|
| | 703 | self.assertBody('Divorce document 13: empty') |
|---|
| | 704 | self.assertStatus('200 OK') |
|---|
| | 705 | self.getPage("/divorce/", method="GET") |
|---|
| | 706 | self.assertBody('<h1>Choose your document</h1>\n<ul>\n</ul>') |
|---|
| | 707 | self.assertStatus('200 OK') |
|---|