| | 548 | def _set_tool(self, k, v): |
|---|
| | 549 | """Attach tools specified in config.""" |
|---|
| | 550 | toolname, arg = k.split(".", 1) |
|---|
| | 551 | bucket = self.toolmap.setdefault(toolname, {}) |
|---|
| | 552 | bucket[arg] = v |
|---|
| | 553 | |
|---|
| | 554 | def _set_hook(self, k, v): |
|---|
| | 555 | """Attach bare hooks declared in config.""" |
|---|
| | 556 | # Use split again to allow multiple hooks for a single |
|---|
| | 557 | # hookpoint per path (e.g. "hooks.before_main.1"). |
|---|
| | 558 | # Little-known fact you only get from reading source ;) |
|---|
| | 559 | hookpoint = k.split(".", 1)[0] |
|---|
| | 560 | if isinstance(v, basestring): |
|---|
| | 561 | v = cherrypy.lib.attributes(v) |
|---|
| | 562 | if not isinstance(v, Hook): |
|---|
| | 563 | v = Hook(v) |
|---|
| | 564 | self.hooks[hookpoint].append(v) |
|---|
| | 565 | |
|---|
| 549 | | if namespace == "tools": |
|---|
| 550 | | toolname, arg = atoms[1].split(".", 1) |
|---|
| 551 | | bucket = tm.setdefault(toolname, {}) |
|---|
| 552 | | bucket[arg] = reqconf[k] |
|---|
| 553 | | elif namespace == "hooks": |
|---|
| 554 | | # Attach bare hooks declared in config. |
|---|
| 555 | | # Use split again to allow multiple hooks for a single |
|---|
| 556 | | # hookpoint per path (e.g. "hooks.before_main.1"). |
|---|
| 557 | | # Little-known fact you only get from reading source ;) |
|---|
| 558 | | hookpoint = atoms[1].split(".", 1)[0] |
|---|
| 559 | | v = reqconf[k] |
|---|
| 560 | | if isinstance(v, basestring): |
|---|
| 561 | | v = cherrypy.lib.attributes(v) |
|---|
| 562 | | if not isinstance(v, Hook): |
|---|
| 563 | | v = Hook(v) |
|---|
| 564 | | self.hooks[hookpoint].append(v) |
|---|
| 565 | | elif namespace == "request": |
|---|
| 566 | | # Override properties of this request object. |
|---|
| 567 | | setattr(self, atoms[1], reqconf[k]) |
|---|
| 568 | | elif namespace == "response": |
|---|
| 569 | | # Override properties of the current response object. |
|---|
| 570 | | setattr(cherrypy.response, atoms[1], reqconf[k]) |
|---|
| 571 | | elif namespace == "error_page": |
|---|
| 572 | | self.error_page[int(atoms[1])] = reqconf[k] |
|---|
| | 574 | if namespace in self.namespaces: |
|---|
| | 575 | self.namespaces[namespace](atoms[1], reqconf[k]) |
|---|