annotate MoinMoin/request/__init__.py @ 1761:9dc115f468e4

reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 30 Jan 2007 22:12:52 +0100
parents 66f2ea899da7
children 2668d470091f
rev   line source
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
2 """
640
80d0ad85a2d8 splitted request.py into request/*, please help fixing/testing, see CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 637
diff changeset
3 MoinMoin - RequestBase Implementation
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
4
640
80d0ad85a2d8 splitted request.py into request/*, please help fixing/testing, see CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 637
diff changeset
5 @copyright: 2001-2003 by Jürgen Hermann <jh@web.de>,
80d0ad85a2d8 splitted request.py into request/*, please help fixing/testing, see CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 637
diff changeset
6 2003-2006 MoinMoin:ThomasWaldmann
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
7 @license: GNU GPL, see COPYING for details.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
8 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
9
447
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
10 import os, re, time, sys, cgi, StringIO
1590
56bf38d79ba8 added missing logging import
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1586
diff changeset
11 import logging
403
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
12 import copy
1148
301575ccf95f added set import for py 2.3 compatibility
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1132
diff changeset
13
301575ccf95f added set import for py 2.3 compatibility
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1132
diff changeset
14 try:
301575ccf95f added set import for py 2.3 compatibility
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1132
diff changeset
15 set
301575ccf95f added set import for py 2.3 compatibility
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1132
diff changeset
16 except:
301575ccf95f added set import for py 2.3 compatibility
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1132
diff changeset
17 from sets import Set as set
301575ccf95f added set import for py 2.3 compatibility
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1132
diff changeset
18
1071
64e513264aed cleanup, less header logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1070
diff changeset
19 from MoinMoin import config, wikiutil, user, caching, error
1567
2e1aff91a0a5 use 404 instead of ConfigurationError when no config is matched for some URL
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1557
diff changeset
20 from MoinMoin.config import multiconfig
618
e0cbf33ff15c remove MoinMoinNoFooter (not needed and more), please call theme.send_closing_html() for closing what send_title() opened
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
21 from MoinMoin.util import IsWin9x
e0cbf33ff15c remove MoinMoinNoFooter (not needed and more), please call theme.send_closing_html() for closing what send_title() opened
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
22
1317
76a76def8687 remove most chmod calls, use 1 os.umask() call in request module instead (port from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1245
diff changeset
23 # umask setting --------------------------------------------------------
1761
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
24 def set_umask(new_mask=0777^config.umask):
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
25 """ Set the OS umask value (and ignore potential failures on OSes where
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
26 this is not supported).
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
27 Default: the bitwise inverted value of config.umask
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
28 """
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
29 try:
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
30 old_mask = os.umask(new_mask)
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
31 except:
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
32 # maybe we are on win32?
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
33 pass
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
34
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
35 # We do this at least once per Python process, when request is imported.
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
36 # If other software parts (like twistd's daemonize() function) set an
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
37 # unwanted umask, we have to call this again to set the correct one:
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
38 set_umask()
618
e0cbf33ff15c remove MoinMoinNoFooter (not needed and more), please call theme.send_closing_html() for closing what send_title() opened
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
39
e0cbf33ff15c remove MoinMoinNoFooter (not needed and more), please call theme.send_closing_html() for closing what send_title() opened
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
40 # Exceptions -----------------------------------------------------------
e0cbf33ff15c remove MoinMoinNoFooter (not needed and more), please call theme.send_closing_html() for closing what send_title() opened
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
41
e0cbf33ff15c remove MoinMoinNoFooter (not needed and more), please call theme.send_closing_html() for closing what send_title() opened
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
42 class MoinMoinFinish(Exception):
e0cbf33ff15c remove MoinMoinNoFooter (not needed and more), please call theme.send_closing_html() for closing what send_title() opened
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
43 """ Raised to jump directly to end of run() function, where finish is called """
1086
db7863d7a45e Fixed bug in request.py that avoided showing a traceback if there was a fault after the first headers were sent.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1071
diff changeset
44
db7863d7a45e Fixed bug in request.py that avoided showing a traceback if there was a fault after the first headers were sent.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1071
diff changeset
45
db7863d7a45e Fixed bug in request.py that avoided showing a traceback if there was a fault after the first headers were sent.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1071
diff changeset
46 class HeadersAlreadySentException(Exception):
db7863d7a45e Fixed bug in request.py that avoided showing a traceback if there was a fault after the first headers were sent.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1071
diff changeset
47 """ Is raised if the headers were already sent when emit_http_headers is called."""
db7863d7a45e Fixed bug in request.py that avoided showing a traceback if there was a fault after the first headers were sent.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1071
diff changeset
48
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
49
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
50 # Timing ---------------------------------------------------------------
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
51
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
52 class Clock:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
53 """ Helper class for code profiling
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
54 we do not use time.clock() as this does not work across threads
1144
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
55 This is not thread-safe when it comes to multiple starts for one timer.
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
56 It is possible to recursively call the start and stop methods, you
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
57 should just ensure that you call them often enough :)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
58 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
59
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
60 def __init__(self):
1130
787e963c9bfd fix Clock code, add more timers (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1116
diff changeset
61 self.timings = {}
787e963c9bfd fix Clock code, add more timers (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1116
diff changeset
62 self.states = {}
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
63
1144
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
64 def _get_name(timer, generation):
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
65 if generation == 0:
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
66 return timer
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
67 else:
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
68 return "%s|%i" % (timer, generation)
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
69 _get_name = staticmethod(_get_name)
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
70
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
71 def start(self, timer):
1144
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
72 state = self.states.setdefault(timer, -1)
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
73 new_level = state + 1
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
74 name = Clock._get_name(timer, new_level)
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
75 self.timings[name] = time.time() - self.timings.get(name, 0)
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
76 self.states[timer] = new_level
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
77
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
78 def stop(self, timer):
1144
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
79 state = self.states.setdefault(timer, -1)
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
80 if state >= 0: # timer is active
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
81 name = Clock._get_name(timer, state)
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
82 self.timings[name] = time.time() - self.timings[name]
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
83 self.states[timer] = state - 1
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
84
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
85 def value(self, timer):
1144
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
86 base_timer = timer.split("|")[0]
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
87 state = self.states.get(base_timer, None)
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
88 if state == -1:
1130
787e963c9bfd fix Clock code, add more timers (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1116
diff changeset
89 result = "%.3fs" % self.timings[timer]
1144
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
90 elif state is None:
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
91 result = "- (%s)" % state
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
92 else:
1147
637d90f1209d Oops, removed a debug print.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1144
diff changeset
93 #print "Got state %r" % state
1130
787e963c9bfd fix Clock code, add more timers (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1116
diff changeset
94 result = "%.3fs (still running)" % (time.time() - self.timings[timer])
787e963c9bfd fix Clock code, add more timers (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1116
diff changeset
95 return result
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
96
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
97 def dump(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
98 outlist = []
1130
787e963c9bfd fix Clock code, add more timers (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1116
diff changeset
99 for timer in self.timings.keys():
787e963c9bfd fix Clock code, add more timers (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1116
diff changeset
100 value = self.value(timer)
787e963c9bfd fix Clock code, add more timers (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1116
diff changeset
101 outlist.append("%s = %s" % (timer, value))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
102 outlist.sort()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
103 return outlist
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
104
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
105
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
106 # Utilities
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
107
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
108 def cgiMetaVariable(header, scheme='http'):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
109 """ Return CGI meta variable for header name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
110
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
111 e.g 'User-Agent' -> 'HTTP_USER_AGENT'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
112 See http://www.faqs.org/rfcs/rfc3875.html section 4.1.18
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
113 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
114 var = '%s_%s' % (scheme, header)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
115 return var.upper().replace('-', '_')
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
116
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
117
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
118 # Request Base ----------------------------------------------------------
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
119
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
120 class RequestBase(object):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
121 """ A collection for all data associated with ONE request. """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
122
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
123 # Defaults (used by sub classes)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
124 http_accept_language = 'en'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
125 server_name = 'localhost'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
126 server_port = '80'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
127
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
128 # Extra headers we support. Both standalone and twisted store
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
129 # headers as lowercase.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
130 moin_location = 'x-moin-location'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
131 proxy_host = 'x-forwarded-host'
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
132
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
133 def __init__(self, properties={}):
1761
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
134
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
135 # twistd's daemonize() overrides our umask, so we reset it here every
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
136 # request. we do it for all request types to avoid similar problems.
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
137 set_umask()
9dc115f468e4 reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1699
diff changeset
138
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
139 # Decode values collected by sub classes
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
140 self.path_info = self.decodePagename(self.path_info)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
141
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
142 self.failed = 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
143 self._available_actions = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
144 self._known_actions = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
145
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
146 # Pages meta data that we collect in one request
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
147 self.pages = {}
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
148
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
149 self.user_headers = []
15
5a2a8201bb6f make moin friendlier to proxies, thanks to ASF
Thomas Waldmann <tw@waldmann-edv.de>
parents: 9
diff changeset
150 self.cacheable = 0 # may this output get cached by http proxies/caches?
1580
1393f9e111f4 cleanup disabling of http caching, avoid usage of no-cache because it breaks attachment download on IE6
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1567
diff changeset
151 self.http_caching_disabled = 0 # see disableHttpCaching()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
152 self.page = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
153 self._dicts = None
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
154
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
155 # Fix dircaching problems on Windows 9x
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
156 if IsWin9x():
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
157 import dircache
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
158 dircache.reset()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
159
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
160 # Check for dumb proxy requests
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
161 # TODO relying on request_uri will not work on all servers, especially
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
162 # not on external non-Apache servers
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
163 self.forbidden = False
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
164 if self.request_uri.startswith('http://'):
403
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
165 self.makeForbidden403()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
166
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
167 # Init
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
168 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
169 self.writestack = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
170 self.clock = Clock()
1130
787e963c9bfd fix Clock code, add more timers (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1116
diff changeset
171 self.clock.start('total')
1131
67044a2a0224 add some more timers, fix wrong path in i18n_init
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1130
diff changeset
172 self.clock.start('base__init__')
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
173 # order is important here!
397
1a7f4e1f3e4d Fixed MoinMoinBugs/ RewritingAndCookieUrl/
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 393
diff changeset
174 self.__dict__.update(properties)
1567
2e1aff91a0a5 use 404 instead of ConfigurationError when no config is matched for some URL
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1557
diff changeset
175 try:
2e1aff91a0a5 use 404 instead of ConfigurationError when no config is matched for some URL
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1557
diff changeset
176 self._load_multi_cfg()
2e1aff91a0a5 use 404 instead of ConfigurationError when no config is matched for some URL
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1557
diff changeset
177 except error.NoConfigMatchedError:
2e1aff91a0a5 use 404 instead of ConfigurationError when no config is matched for some URL
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1557
diff changeset
178 self.makeForbidden(404, 'No wiki configuration matching the URL found!\r\n')
2e1aff91a0a5 use 404 instead of ConfigurationError when no config is matched for some URL
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1557
diff changeset
179 return
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
180
447
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
181 self.isSpiderAgent = self.check_spider()
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
182
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
183 # Set decode charsets. Input from the user is always in
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
184 # config.charset, which is the page charsets. Except
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
185 # path_info, which may use utf-8, and handled by decodePagename.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
186 self.decode_charsets = [config.charset]
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
187
1007
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
188 if self.query_string.startswith('action=xmlrpc'):
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
189 self.args = {}
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
190 self.form = {}
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
191 self.action = 'xmlrpc'
1682
30116d7d098a request.rev is either revision integer (when given in form) or None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1666
diff changeset
192 self.rev = None
1007
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
193 else:
305
5ed08461ab7d trying to fix xmlrpc not working on cgi due to setup_args call eating POST data
Thomas Waldmann <tw@waldmann-edv.de>
parents: 298
diff changeset
194 self.args = self.form = self.setup_args()
1007
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
195 self.action = self.form.get('action', ['show'])[0]
1682
30116d7d098a request.rev is either revision integer (when given in form) or None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1666
diff changeset
196 try:
30116d7d098a request.rev is either revision integer (when given in form) or None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1666
diff changeset
197 self.rev = int(self.form['rev'][0])
30116d7d098a request.rev is either revision integer (when given in form) or None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1666
diff changeset
198 except:
30116d7d098a request.rev is either revision integer (when given in form) or None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1666
diff changeset
199 self.rev = None
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
200
1618
e682a1ea7a68 remove hierarchical page storage support, split new RootPage class off from Page class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1595
diff changeset
201 from MoinMoin.Page import RootPage
e682a1ea7a68 remove hierarchical page storage support, split new RootPage class off from Page class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1595
diff changeset
202 self.rootpage = RootPage(self)
e682a1ea7a68 remove hierarchical page storage support, split new RootPage class off from Page class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1595
diff changeset
203
688
15c55ecd7ccb fix some i18n bugs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 684
diff changeset
204 from MoinMoin import i18n
15c55ecd7ccb fix some i18n bugs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 684
diff changeset
205 self.i18n = i18n
15c55ecd7ccb fix some i18n bugs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 684
diff changeset
206 i18n.i18n_init(self)
15c55ecd7ccb fix some i18n bugs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 684
diff changeset
207
456
12b6367214e3 feed current user_obj to auth methods, continue auth list in most cases, moved cookie code to auth module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 451
diff changeset
208 self.user = self.get_user_from_form()
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
209
1007
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
210 if self.action != 'xmlrpc':
440
0f07dcad6614 reorderer 1. bot 2. surge protection, add sleep time for forbidden requests, add surge prot. value for recall action
Thomas Waldmann <tw@waldmann-edv.de>
parents: 434
diff changeset
211 if not self.forbidden and self.isForbidden():
0f07dcad6614 reorderer 1. bot 2. surge protection, add sleep time for forbidden requests, add surge prot. value for recall action
Thomas Waldmann <tw@waldmann-edv.de>
parents: 434
diff changeset
212 self.makeForbidden403()
0f07dcad6614 reorderer 1. bot 2. surge protection, add sleep time for forbidden requests, add surge prot. value for recall action
Thomas Waldmann <tw@waldmann-edv.de>
parents: 434
diff changeset
213 if not self.forbidden and self.surge_protect():
406
0ff631c36afb surge protection: use userid of logged in users, reorder surge-log entry format, fix error handling
Thomas Waldmann <tw@waldmann-edv.de>
parents: 405
diff changeset
214 self.makeUnavailable503()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
215
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
216 self.pragma = {}
1595
3a63c9b31d7e avoid infinite recursion in parsePageLinks
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1590
diff changeset
217 self.mode_getpagelinks = 0 # is > 0 as long as we are in a getPageLinks call
3a63c9b31d7e avoid infinite recursion in parsePageLinks
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1590
diff changeset
218 self.parsePageLinks_running = {} # avoid infinite recursion by remembering what we are already running
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
219
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
220 self.lang = i18n.requestLanguage(self)
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
221 # Language for content. Page content should use the wiki default lang,
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
222 # but generated content like search results should use the user language.
131
1738cbba372c new cfg settings: language_ignore_browser and language_default (was: default_lang)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
223 self.content_lang = self.cfg.language_default
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
224 self.getText = lambda text, i18n=self.i18n, request=self, lang=self.lang, **kv: i18n.getText(text, request, lang, kv.get('formatted', True))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
225
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
226 self.reset()
1131
67044a2a0224 add some more timers, fix wrong path in i18n_init
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1130
diff changeset
227 self.clock.stop('base__init__')
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
228
1553
24ef62e7013f add kick_me option to surge_protect
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1550
diff changeset
229 def surge_protect(self, kick_him=False):
24ef62e7013f add kick_me option to surge_protect
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1550
diff changeset
230 """ check if someone requesting too much from us,
24ef62e7013f add kick_me option to surge_protect
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1550
diff changeset
231 if kick_him is True, we unconditionally blacklist the current user/ip
24ef62e7013f add kick_me option to surge_protect
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1550
diff changeset
232 """
1245
5b6031179fef allow disabling surge protection by surge_action_limits = None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1183
diff changeset
233 limits = self.cfg.surge_action_limits
5b6031179fef allow disabling surge protection by surge_action_limits = None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1183
diff changeset
234 if not limits:
5b6031179fef allow disabling surge protection by surge_action_limits = None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1183
diff changeset
235 return False
5b6031179fef allow disabling surge protection by surge_action_limits = None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1183
diff changeset
236
411
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
237 validuser = self.user.valid
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
238 current_id = validuser and self.user.name or self.remote_addr
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
239 if not validuser and current_id.startswith('127.'): # localnet
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
240 return False
1007
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
241 current_action = self.action
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
242
420
b4ff26eb2c43 adjusting some surge protection limits
Thomas Waldmann <tw@waldmann-edv.de>
parents: 412
diff changeset
243 default_limit = self.cfg.surge_action_limits.get('default', (30, 60))
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
244
411
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
245 now = int(time.time())
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
246 surgedict = {}
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
247 surge_detected = False
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
248
411
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
249 try:
682
1314fdb74689 refactor CacheEntry usage to use scope param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 640
diff changeset
250 # if we have common farm users, we could also use scope='farm':
1314fdb74689 refactor CacheEntry usage to use scope param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 640
diff changeset
251 cache = caching.CacheEntry(self, 'surgeprotect', 'surge-log', scope='wiki')
445
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
252 if cache.exists():
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
253 data = cache.content()
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
254 data = data.split("\n")
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
255 for line in data:
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
256 try:
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
257 id, t, action, surge_indicator = line.split("\t")
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
258 t = int(t)
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
259 maxnum, dt = limits.get(action, default_limit)
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
260 if t >= now - dt:
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
261 events = surgedict.setdefault(id, copy.copy({}))
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
262 timestamps = events.setdefault(action, copy.copy([]))
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
263 timestamps.append((t, surge_indicator))
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
264 except StandardError, err:
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
265 pass
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
266
411
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
267 maxnum, dt = limits.get(current_action, default_limit)
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
268 events = surgedict.setdefault(current_id, copy.copy({}))
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
269 timestamps = events.setdefault(current_action, copy.copy([]))
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
270 surge_detected = len(timestamps) > maxnum
441
a858267f7dea improved surge protection: dont sleep, add total requests rate
Thomas Waldmann <tw@waldmann-edv.de>
parents: 440
diff changeset
271
a858267f7dea improved surge protection: dont sleep, add total requests rate
Thomas Waldmann <tw@waldmann-edv.de>
parents: 440
diff changeset
272 surge_indicator = surge_detected and "!" or ""
a858267f7dea improved surge protection: dont sleep, add total requests rate
Thomas Waldmann <tw@waldmann-edv.de>
parents: 440
diff changeset
273 timestamps.append((now, surge_indicator))
a858267f7dea improved surge protection: dont sleep, add total requests rate
Thomas Waldmann <tw@waldmann-edv.de>
parents: 440
diff changeset
274 if surge_detected:
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
275 if len(timestamps) < maxnum * 2:
441
a858267f7dea improved surge protection: dont sleep, add total requests rate
Thomas Waldmann <tw@waldmann-edv.de>
parents: 440
diff changeset
276 timestamps.append((now + self.cfg.surge_lockout_time, surge_indicator)) # continue like that and get locked out
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
277
445
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
278 if current_action != 'AttachFile': # don't add AttachFile accesses to all or picture galleries will trigger SP
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
279 current_action = 'all' # put a total limit on user's requests
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
280 maxnum, dt = limits.get(current_action, default_limit)
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
281 events = surgedict.setdefault(current_id, copy.copy({}))
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
282 timestamps = events.setdefault(current_action, copy.copy([]))
1553
24ef62e7013f add kick_me option to surge_protect
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1550
diff changeset
283
24ef62e7013f add kick_me option to surge_protect
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1550
diff changeset
284 if kick_him: # ban this guy, NOW
24ef62e7013f add kick_me option to surge_protect
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1550
diff changeset
285 timestamps.extend([(now + self.cfg.surge_lockout_time, "!")] * (2*maxnum))
24ef62e7013f add kick_me option to surge_protect
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1550
diff changeset
286
445
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
287 surge_detected = surge_detected or len(timestamps) > maxnum
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
288
445
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
289 surge_indicator = surge_detected and "!" or ""
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
290 timestamps.append((now, surge_indicator))
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
291 if surge_detected:
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
292 if len(timestamps) < maxnum * 2:
445
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
293 timestamps.append((now + self.cfg.surge_lockout_time, surge_indicator)) # continue like that and get locked out
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
294
411
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
295 data = []
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
296 for id, events in surgedict.items():
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
297 for action, timestamps in events.items():
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
298 for t, surge_indicator in timestamps:
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
299 data.append("%s\t%d\t%s\t%s" % (id, t, action, surge_indicator))
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
300 data = "\n".join(data)
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
301 cache.update(data)
412
481c432b3d11 fix some error handlers, logging for caching lock failures
Thomas Waldmann <tw@waldmann-edv.de>
parents: 411
diff changeset
302 except StandardError, err:
411
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
303 pass
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
304
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
305 return surge_detected
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
306
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
307 def getDicts(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
308 """ Lazy initialize the dicts on the first access """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
309 if self._dicts is None:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
310 from MoinMoin import wikidicts
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
311 dicts = wikidicts.GroupDict(self)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
312 dicts.scandicts()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
313 self._dicts = dicts
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
314 return self._dicts
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
315
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
316 def delDicts(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
317 """ Delete the dicts, used by some tests """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
318 del self._dicts
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
319 self._dicts = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
320
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
321 dicts = property(getDicts, None, delDicts)
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
322
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
323 def _load_multi_cfg(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
324 # protect against calling multiple times
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
325 if not hasattr(self, 'cfg'):
1130
787e963c9bfd fix Clock code, add more timers (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1116
diff changeset
326 self.clock.start('load_multi_cfg')
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
327 self.cfg = multiconfig.getConfig(self.url)
1130
787e963c9bfd fix Clock code, add more timers (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1116
diff changeset
328 self.clock.stop('load_multi_cfg')
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
329
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
330 def setAcceptedCharsets(self, accept_charset):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
331 """ Set accepted_charsets by parsing accept-charset header
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
332
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
333 Set self.accepted_charsets to an ordered list based on http_accept_charset.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
334
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
335 Reference: http://www.w3.org/Protocols/rfc2616/rfc2616.txt
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
336
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
337 TODO: currently no code use this value.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
338
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
339 @param accept_charset: accept-charset header
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
340 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
341 charsets = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
342 if accept_charset:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
343 accept_charset = accept_charset.lower()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
344 # Add iso-8859-1 if needed
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
345 if (not '*' in accept_charset and
1183
bc84eae93f8c replace usage of find by 'in' operator
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1149
diff changeset
346 'iso-8859-1' not in accept_charset):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
347 accept_charset += ',iso-8859-1'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
348
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
349 # Make a list, sorted by quality value, using Schwartzian Transform
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
350 # Create list of tuples (value, name) , sort, extract names
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
351 for item in accept_charset.split(','):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
352 if ';' in item:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
353 name, qval = item.split(';')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
354 qval = 1.0 - float(qval.split('=')[1])
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
355 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
356 name, qval = item, 0
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
357 charsets.append((qval, name))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
358 charsets.sort()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
359 # Remove *, its not clear what we should do with it later
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
360 charsets = [name for qval, name in charsets if name != '*']
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
361
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
362 self.accepted_charsets = charsets
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
363
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
364 def _setup_vars_from_std_env(self, env):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
365 """ Set common request variables from CGI environment
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
366
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
367 Parse a standard CGI environment as created by common web servers.
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
368 Reference: http://www.faqs.org/rfcs/rfc3875.html
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
369
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
370 @param env: dict like object containing cgi meta variables
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
371 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
372 # Values we can just copy
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
373 self.env = env
1116
4aae51ce0172 support if-modified-since and if-none-match for Twisted, Standalone and CLI, cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1113
diff changeset
374 self.http_accept_language = env.get('HTTP_ACCEPT_LANGUAGE', self.http_accept_language)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
375 self.server_name = env.get('SERVER_NAME', self.server_name)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
376 self.server_port = env.get('SERVER_PORT', self.server_port)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
377 self.saved_cookie = env.get('HTTP_COOKIE', '')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
378 self.script_name = env.get('SCRIPT_NAME', '')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
379 self.path_info = env.get('PATH_INFO', '')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
380 self.query_string = env.get('QUERY_STRING', '')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
381 self.request_method = env.get('REQUEST_METHOD', None)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
382 self.remote_addr = env.get('REMOTE_ADDR', '')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
383 self.http_user_agent = env.get('HTTP_USER_AGENT', '')
1116
4aae51ce0172 support if-modified-since and if-none-match for Twisted, Standalone and CLI, cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1113
diff changeset
384 self.if_modified_since = env.get('If-modified-since') or env.get(cgiMetaVariable('If-modified-since'))
4aae51ce0172 support if-modified-since and if-none-match for Twisted, Standalone and CLI, cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1113
diff changeset
385 self.if_none_match = env.get('If-none-match') or env.get(cgiMetaVariable('If-none-match'))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
386
298
6c74345f4d55 cleaned up and moved moin's cookie stuff to auth.moin_cookie
Thomas Waldmann <tw@waldmann-edv.de>
parents: 295
diff changeset
387 # REQUEST_URI is not part of CGI spec, but an addition of Apache.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
388 self.request_uri = env.get('REQUEST_URI', '')
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
389
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
390 # Values that need more work
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
391 self.setHttpReferer(env.get('HTTP_REFERER'))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
392 self.setIsSSL(env)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
393 self.setHost(env.get('HTTP_HOST'))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
394 self.fixURI(env)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
395 self.setURL(env)
1113
9485500daadf read if-modified-since and if-none-match headers, first use for rss_rc action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1103
diff changeset
396 #self.debugEnvironment(env)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
397
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
398 def setHttpReferer(self, referer):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
399 """ Set http_referer, making sure its ascii
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
400
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
401 IE might send non-ascii value.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
402 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
403 value = ''
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
404 if referer:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
405 value = unicode(referer, 'ascii', 'replace')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
406 value = value.encode('ascii', 'replace')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
407 self.http_referer = value
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
408
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
409 def setIsSSL(self, env):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
410 """ Set is_ssl
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
411
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
412 @param env: dict like object containing cgi meta variables
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
413 """
149
c5b967d9d1e6 fixed MoinMoinBugs/TypeErrorOnHttpsPageChangeEmail
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 131
diff changeset
414 self.is_ssl = bool(env.get('SSL_PROTOCOL') or
c5b967d9d1e6 fixed MoinMoinBugs/TypeErrorOnHttpsPageChangeEmail
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 131
diff changeset
415 env.get('SSL_PROTOCOL_VERSION') or
c5b967d9d1e6 fixed MoinMoinBugs/TypeErrorOnHttpsPageChangeEmail
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 131
diff changeset
416 env.get('HTTPS') == 'on')
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
417
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
418 def setHost(self, host=None):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
419 """ Set http_host
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
420
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
421 Create from server name and port if missing. Previous code
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
422 default to localhost.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
423 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
424 if not host:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
425 port = ''
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
426 standardPort = ('80', '443')[self.is_ssl]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
427 if self.server_port != standardPort:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
428 port = ':' + self.server_port
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
429 host = self.server_name + port
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
430 self.http_host = host
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
431
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
432 def fixURI(self, env):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
433 """ Fix problems with script_name and path_info
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
434
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
435 Handle the strange charset semantics on Windows and other non
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
436 posix systems. path_info is transformed into the system code
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
437 page by the web server. Additionally, paths containing dots let
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
438 most webservers choke.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
439
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
440 Broken environment variables in different environments:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
441 path_info script_name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
442 Apache1 X X PI does not contain dots
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
443 Apache2 X X PI is not encoded correctly
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
444 IIS X X path_info include script_name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
445 Other ? - ? := Possible and even RFC-compatible.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
446 - := Hopefully not.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
447
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
448 @param env: dict like object containing cgi meta variables
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
449 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
450 # Fix the script_name when using Apache on Windows.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
451 server_software = env.get('SERVER_SOFTWARE', '')
1183
bc84eae93f8c replace usage of find by 'in' operator
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1149
diff changeset
452 if os.name == 'nt' and 'Apache/' in server_software:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
453 # Removes elements ending in '.' from the path.
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
454 self.script_name = '/'.join([x for x in self.script_name.split('/')
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
455 if not x.endswith('.')])
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
456
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
457 # Fix path_info
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
458 if os.name != 'posix' and self.request_uri != '':
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
459 # Try to recreate path_info from request_uri.
101
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 85
diff changeset
460 import urlparse
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
461 scriptAndPath = urlparse.urlparse(self.request_uri)[2]
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
462 path = scriptAndPath.replace(self.script_name, '', 1)
101
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 85
diff changeset
463 self.path_info = wikiutil.url_unquote(path, want_unicode=False)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
464 elif os.name == 'nt':
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
465 # Recode path_info to utf-8
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
466 path = wikiutil.decodeWindowsPath(self.path_info)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
467 self.path_info = path.encode("utf-8")
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
468
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
469 # Fix bug in IIS/4.0 when path_info contain script_name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
470 if self.path_info.startswith(self.script_name):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
471 self.path_info = self.path_info[len(self.script_name):]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
472
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
473 def setURL(self, env):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
474 """ Set url, used to locate wiki config
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
475
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
476 This is the place to manipulate url parts as needed.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
477
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
478 @param env: dict like object containing cgi meta variables or http headers.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
479 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
480 # If we serve on localhost:8000 and use a proxy on
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
481 # example.com/wiki, our urls will be example.com/wiki/pagename
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
482 # Same for the wiki config - they must use the proxy url.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
483 self.rewriteHost(env)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
484 self.rewriteURI(env)
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
485
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
486 if not self.request_uri:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
487 self.request_uri = self.makeURI()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
488 self.url = self.http_host + self.request_uri
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
489
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
490 def rewriteHost(self, env):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
491 """ Rewrite http_host transparently
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
492
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
493 Get the proxy host using 'X-Forwarded-Host' header, added by
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
494 Apache 2 and other proxy software.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
495
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
496 TODO: Will not work for Apache 1 or others that don't add this header.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
497
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
498 TODO: If we want to add an option to disable this feature it
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
499 should be in the server script, because the config is not
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
500 loaded at this point, and must be loaded after url is set.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
501
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
502 @param env: dict like object containing cgi meta variables or http headers.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
503 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
504 proxy_host = (env.get(self.proxy_host) or
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
505 env.get(cgiMetaVariable(self.proxy_host)))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
506 if proxy_host:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
507 self.http_host = proxy_host
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
508
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
509 def rewriteURI(self, env):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
510 """ Rewrite request_uri, script_name and path_info transparently
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
511
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
512 Useful when running mod python or when running behind a proxy,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
513 e.g run on localhost:8000/ and serve as example.com/wiki/.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
514
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
515 Uses private 'X-Moin-Location' header to set the script name.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
516 This allow setting the script name when using Apache 2
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
517 <location> directive::
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
518
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
519 <Location /my/wiki/>
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
520 RequestHeader set X-Moin-Location /my/wiki/
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
521 </location>
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
522
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
523 TODO: does not work for Apache 1 and others that do not allow
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
524 setting custom headers per request.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
525
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
526 @param env: dict like object containing cgi meta variables or http headers.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
527 """
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
528 location = (env.get(self.moin_location) or
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
529 env.get(cgiMetaVariable(self.moin_location)))
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
530 if location is None:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
531 return
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
532
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
533 scriptAndPath = self.script_name + self.path_info
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
534 location = location.rstrip('/')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
535 self.script_name = location
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
536
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
537 # This may happen when using mod_python
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
538 if scriptAndPath.startswith(location):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
539 self.path_info = scriptAndPath[len(location):]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
540
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
541 # Recreate the URI from the modified parts
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
542 if self.request_uri:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
543 self.request_uri = self.makeURI()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
544
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
545 def makeURI(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
546 """ Return uri created from uri parts """
101
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 85
diff changeset
547 uri = self.script_name + wikiutil.url_quote(self.path_info)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
548 if self.query_string:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
549 uri += '?' + self.query_string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
550 return uri
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
551
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
552 def splitURI(self, uri):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
553 """ Return path and query splited from uri
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
554
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
555 Just like CGI environment, the path is unquoted, the query is not.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
556 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
557 if '?' in uri:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
558 path, query = uri.split('?', 1)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
559 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
560 path, query = uri, ''
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
561 return wikiutil.url_unquote(path, want_unicode=False), query
456
12b6367214e3 feed current user_obj to auth methods, continue auth list in most cases, moved cookie code to auth module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 451
diff changeset
562
12b6367214e3 feed current user_obj to auth methods, continue auth list in most cases, moved cookie code to auth module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 451
diff changeset
563 def get_user_from_form(self):
12b6367214e3 feed current user_obj to auth methods, continue auth list in most cases, moved cookie code to auth module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 451
diff changeset
564 """ read the maybe present UserPreferences form and call get_user with the values """
295
91d47ebee530 make posted UserPreferences form values easily available for auth methods
Thomas Waldmann <tw@waldmann-edv.de>
parents: 290
diff changeset
565 name = self.form.get('name', [None])[0]
91d47ebee530 make posted UserPreferences form values easily available for auth methods
Thomas Waldmann <tw@waldmann-edv.de>
parents: 290
diff changeset
566 password = self.form.get('password', [None])[0]
91d47ebee530 make posted UserPreferences form values easily available for auth methods
Thomas Waldmann <tw@waldmann-edv.de>
parents: 290
diff changeset
567 login = self.form.has_key('login')
91d47ebee530 make posted UserPreferences form values easily available for auth methods
Thomas Waldmann <tw@waldmann-edv.de>
parents: 290
diff changeset
568 logout = self.form.has_key('logout')
461
c296f00ca63e redirect to base url after successful login
Thomas Waldmann <tw@waldmann-edv.de>
parents: 456
diff changeset
569 u = self.get_user_default_unknown(name=name, password=password,
c296f00ca63e redirect to base url after successful login
Thomas Waldmann <tw@waldmann-edv.de>
parents: 456
diff changeset
570 login=login, logout=logout,
c296f00ca63e redirect to base url after successful login
Thomas Waldmann <tw@waldmann-edv.de>
parents: 456
diff changeset
571 user_obj=None)
c296f00ca63e redirect to base url after successful login
Thomas Waldmann <tw@waldmann-edv.de>
parents: 456
diff changeset
572 return u
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
573
456
12b6367214e3 feed current user_obj to auth methods, continue auth list in most cases, moved cookie code to auth module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 451
diff changeset
574 def get_user_default_unknown(self, **kw):
12b6367214e3 feed current user_obj to auth methods, continue auth list in most cases, moved cookie code to auth module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 451
diff changeset
575 """ call do_auth and if it doesnt return a user object, make some "Unknown User" """
12b6367214e3 feed current user_obj to auth methods, continue auth list in most cases, moved cookie code to auth module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 451
diff changeset
576 user_obj = self.get_user_default_None(**kw)
268
130bd0403e21 auth methods now return tuple (user_obj, continue_flag)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 265
diff changeset
577 if user_obj is None:
130bd0403e21 auth methods now return tuple (user_obj, continue_flag)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 265
diff changeset
578 user_obj = user.User(self, auth_method="request:427")
130bd0403e21 auth methods now return tuple (user_obj, continue_flag)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 265
diff changeset
579 return user_obj
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
580
456
12b6367214e3 feed current user_obj to auth methods, continue auth list in most cases, moved cookie code to auth module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 451
diff changeset
581 def get_user_default_None(self, **kw):
12b6367214e3 feed current user_obj to auth methods, continue auth list in most cases, moved cookie code to auth module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 451
diff changeset
582 """ loop over auth handlers, return a user obj or None """
12b6367214e3 feed current user_obj to auth methods, continue auth list in most cases, moved cookie code to auth module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 451
diff changeset
583 name = kw.get('name')
12b6367214e3 feed current user_obj to auth methods, continue auth list in most cases, moved cookie code to auth module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 451
diff changeset
584 password = kw.get('password')
12b6367214e3 feed current user_obj to auth methods, continue auth list in most cases, moved cookie code to auth module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 451
diff changeset
585 login = kw.get('login')
12b6367214e3 feed current user_obj to auth methods, continue auth list in most cases, moved cookie code to auth module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 451
diff changeset
586 logout = kw.get('logout')
12b6367214e3 feed current user_obj to auth methods, continue auth list in most cases, moved cookie code to auth module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 451
diff changeset
587 user_obj = kw.get('user_obj')
12b6367214e3 feed current user_obj to auth methods, continue auth list in most cases, moved cookie code to auth module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 451
diff changeset
588 for auth in self.cfg.auth:
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
589 user_obj, continue_flag = auth(self, name=name, password=password,
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
590 login=login, logout=logout, user_obj=user_obj)
456
12b6367214e3 feed current user_obj to auth methods, continue auth list in most cases, moved cookie code to auth module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 451
diff changeset
591 if not continue_flag:
12b6367214e3 feed current user_obj to auth methods, continue auth list in most cases, moved cookie code to auth module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 451
diff changeset
592 break
12b6367214e3 feed current user_obj to auth methods, continue auth list in most cases, moved cookie code to auth module
Thomas Waldmann <tw@waldmann-edv.de>
parents: 451
diff changeset
593 return user_obj
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
594
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
595 def reset(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
596 """ Reset request state.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
597
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
598 Called after saving a page, before serving the updated
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
599 page. Solves some practical problems with request state
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
600 modified during saving.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
601
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
602 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
603 # This is the content language and has nothing to do with
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
604 # The user interface language. The content language can change
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
605 # during the rendering of a page by lang macros
131
1738cbba372c new cfg settings: language_ignore_browser and language_default (was: default_lang)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 101
diff changeset
606 self.current_lang = self.cfg.language_default
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
607
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
608 # caches unique ids
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
609 self._page_ids = {}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
610 # keeps track of pagename/heading combinations
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
611 # parsers should use this dict and not a local one, so that
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
612 # macros like TableOfContents in combination with Include can work
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
613 self._page_headings = {}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
614
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
615 if hasattr(self, "_fmt_hd_counters"):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
616 del self._fmt_hd_counters
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
617
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
618 def loadTheme(self, theme_name):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
619 """ Load the Theme to use for this request.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
620
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
621 @param theme_name: the name of the theme
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
622 @type theme_name: str
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
623 @rtype: int
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
624 @return: success code
490
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 483
diff changeset
625 0 on success
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 483
diff changeset
626 1 if user theme could not be loaded,
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 483
diff changeset
627 2 if a hard fallback to modern theme was required.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
628 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
629 fallback = 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
630 if theme_name == "<default>":
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
631 theme_name = self.cfg.theme_default
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
632
51
54d5932d5a03 merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents: 49
diff changeset
633 try:
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
634 Theme = wikiutil.importPlugin(self.cfg, 'theme', theme_name, 'Theme')
53
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
635 except wikiutil.PluginMissingError:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
636 fallback = 1
51
54d5932d5a03 merge moin--main--1.3--patch-930: fix error handling in plugins, fix broken chart action
Nir Soffer <nirs@freeshell.org>
parents: 49
diff changeset
637 try:
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
638 Theme = wikiutil.importPlugin(self.cfg, 'theme', self.cfg.theme_default, 'Theme')
53
699811601bed merge moin--main--1.3--patch-934,935: detect correctly missing plguins and missing names in plugins
Nir Soffer <nirs@freeshell.org>
parents: 51
diff changeset
639 except wikiutil.PluginMissingError:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
640 fallback = 2
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
641 from MoinMoin.theme.modern import Theme
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
642
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
643 self.theme = Theme(self)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
644 return fallback
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
645
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
646 def setContentLanguage(self, lang):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
647 """ Set the content language, used for the content div
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
648
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
649 Actions that generate content in the user language, like search,
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
650 should set the content direction to the user language before they
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
651 call send_title!
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
652 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
653 self.content_lang = lang
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
654 self.current_lang = lang
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
655
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
656 def getPragma(self, key, defval=None):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
657 """ Query a pragma value (#pragma processing instruction)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
658
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
659 Keys are not case-sensitive.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
660 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
661 return self.pragma.get(key.lower(), defval)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
662
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
663 def setPragma(self, key, value):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
664 """ Set a pragma value (#pragma processing instruction)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
665
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
666 Keys are not case-sensitive.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
667 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
668 self.pragma[key.lower()] = value
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
669
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
670 def getPathinfo(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
671 """ Return the remaining part of the URL. """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
672 return self.path_info
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
673
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
674 def getScriptname(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
675 """ Return the scriptname part of the URL ('/path/to/my.cgi'). """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
676 if self.script_name == '/':
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
677 return ''
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
678 return self.script_name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
679
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
680 def getKnownActions(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
681 """ Create a dict of avaiable actions
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
682
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
683 Return cached version if avaiable.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
684
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
685 @rtype: dict
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
686 @return: dict of all known actions
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
687 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
688 try:
1550
a4f0632414da using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1549
diff changeset
689 self.cfg.cache.known_actions # check
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
690 except AttributeError:
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 623
diff changeset
691 from MoinMoin import action
1550
a4f0632414da using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1549
diff changeset
692 self.cfg.cache.known_actions = set(action.getNames(self.cfg))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
693
1132
f9d8b80f5afb implement list of known actions similar to list of known macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1131
diff changeset
694 # Return a copy, so clients will not change the set.
1550
a4f0632414da using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1549
diff changeset
695 return self.cfg.cache.known_actions.copy()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
696
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
697 def getAvailableActions(self, page):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
698 """ Get list of avaiable actions for this request
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
699
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
700 The dict does not contain actions that starts with lower case.
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
701 Themes use this dict to display the actions to the user.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
702
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
703 @param page: current page, Page object
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
704 @rtype: dict
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
705 @return: dict of avaiable actions
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
706 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
707 if self._available_actions is None:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
708 # Add actions for existing pages only, including deleted pages.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
709 # Fix *OnNonExistingPage bugs.
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
710 if not (page.exists(includeDeleted=1) and self.user.may.read(page.page_name)):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
711 return []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
712
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
713 # Filter non ui actions (starts with lower case letter)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
714 actions = self.getKnownActions()
1132
f9d8b80f5afb implement list of known actions similar to list of known macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1131
diff changeset
715 actions = [action for action in actions if not action[0].islower()]
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
716
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
717 # Filter wiki excluded actions
1132
f9d8b80f5afb implement list of known actions similar to list of known macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1131
diff changeset
718 actions = [action for action in actions if not action in self.cfg.actions_excluded]
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
719
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
720 # Filter actions by page type, acl and user state
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
721 excluded = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
722 if ((page.isUnderlayPage() and not page.isStandardPage()) or
236
81620fd76cac fix minor UI bug: DeletePage/RenamePage was shown active in menu although user missed delete rights. We also stop checking for user.valid as this should be driven by ACLs only.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 158
diff changeset
723 not self.user.may.write(page.page_name) or
81620fd76cac fix minor UI bug: DeletePage/RenamePage was shown active in menu although user missed delete rights. We also stop checking for user.valid as this should be driven by ACLs only.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 158
diff changeset
724 not self.user.may.delete(page.page_name)):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
725 # Prevent modification of underlay only pages, or pages
236
81620fd76cac fix minor UI bug: DeletePage/RenamePage was shown active in menu although user missed delete rights. We also stop checking for user.valid as this should be driven by ACLs only.
Thomas Waldmann <tw@waldmann-edv.de>
parents: 158
diff changeset
726 # the user can't write and can't delete
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
727 excluded = [u'RenamePage', u'DeletePage', ] # AttachFile must NOT be here!
1132
f9d8b80f5afb implement list of known actions similar to list of known macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1131
diff changeset
728 actions = [action for action in actions if not action in excluded]
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
729
1132
f9d8b80f5afb implement list of known actions similar to list of known macros
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1131
diff changeset
730 self._available_actions = set(actions)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
731
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
732 # Return a copy, so clients will not change the dict.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
733 return self._available_actions.copy()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
734
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
735 def redirectedOutput(self, function, *args, **kw):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
736 """ Redirect output during function, return redirected output """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
737 buffer = StringIO.StringIO()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
738 self.redirect(buffer)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
739 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
740 function(*args, **kw)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
741 finally:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
742 self.redirect()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
743 text = buffer.getvalue()
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
744 buffer.close()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
745 return text
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
746
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
747 def redirect(self, file=None):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
748 """ Redirect output to file, or restore saved output """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
749 if file:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
750 self.writestack.append(self.write)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
751 self.write = file.write
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
752 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
753 self.write = self.writestack.pop()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
754
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
755 def reset_output(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
756 """ restore default output method
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
757 destroy output stack
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
758 (useful for error messages)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
759 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
760 if self.writestack:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
761 self.write = self.writestack[0]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
762 self.writestack = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
763
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
764 def log(self, msg):
1585
a843bc5793fb introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1580
diff changeset
765 """ Log msg to logging framework """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
766 msg = msg.strip()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
767 # Encode unicode msg
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
768 if isinstance(msg, unicode):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
769 msg = msg.encode(config.charset)
1585
a843bc5793fb introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1580
diff changeset
770 logging.info(msg)
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
771
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
772 def write(self, *data):
616
3b08d9413589 move send_title/footer from wikiutil to theme.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 615
diff changeset
773 """ Write to output stream. """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
774 raise NotImplementedError
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
775
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
776 def encode(self, data):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
777 """ encode data (can be both unicode strings and strings),
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
778 preparing for a single write()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
779 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
780 wd = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
781 for d in data:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
782 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
783 if isinstance(d, unicode):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
784 # if we are REALLY sure, we can use "strict"
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
785 d = d.encode(config.charset, 'replace')
1398
fe8facfcb439 avoid trouble when write data contains None, just skip it - thanks to Juergen Hermann for patch
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1339
diff changeset
786 elif d is None:
fe8facfcb439 avoid trouble when write data contains None, just skip it - thanks to Juergen Hermann for patch
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1339
diff changeset
787 continue
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
788 wd.append(d)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
789 except UnicodeError:
910
1730c8e75ade use self.log instead stderr in request
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 909
diff changeset
790 self.log("Unicode error on: %s" % repr(d))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
791 return ''.join(wd)
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
792
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
793 def decodePagename(self, name):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
794 """ Decode path, possibly using non ascii characters
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
795
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
796 Does not change the name, only decode to Unicode.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
797
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
798 First split the path to pages, then decode each one. This enables
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
799 us to decode one page using config.charset and another using
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
800 utf-8. This situation happens when you try to add to a name of
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
801 an existing page.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
802
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
803 See http://www.w3.org/TR/REC-html40/appendix/notes.html#h-B.2.1
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
804
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
805 @param name: page name, string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
806 @rtype: unicode
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
807 @return decoded page name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
808 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
809 # Split to pages and decode each one
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
810 pages = name.split('/')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
811 decoded = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
812 for page in pages:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
813 # Recode from utf-8 into config charset. If the path
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
814 # contains user typed parts, they are encoded using 'utf-8'.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
815 if config.charset != 'utf-8':
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
816 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
817 page = unicode(page, 'utf-8', 'strict')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
818 # Fit data into config.charset, replacing what won't
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
819 # fit. Better have few "?" in the name than crash.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
820 page = page.encode(config.charset, 'replace')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
821 except UnicodeError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
822 pass
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
823
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
824 # Decode from config.charset, replacing what can't be decoded.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
825 page = unicode(page, config.charset, 'replace')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
826 decoded.append(page)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
827
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
828 # Assemble decoded parts
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
829 name = u'/'.join(decoded)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
830 return name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
831
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
832 def normalizePagename(self, name):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
833 """ Normalize page name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
834
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
835 Prevent creating page names with invisible characters or funny
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
836 whitespace that might confuse the users or abuse the wiki, or
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
837 just does not make sense.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
838
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
839 Restrict even more group pages, so they can be used inside acl lines.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
840
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
841 @param name: page name, unicode
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
842 @rtype: unicode
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
843 @return: decoded and sanitized page name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
844 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
845 # Strip invalid characters
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
846 name = config.page_invalid_chars_regex.sub(u'', name)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
847
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
848 # Split to pages and normalize each one
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
849 pages = name.split(u'/')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
850 normalized = []
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
851 for page in pages:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
852 # Ignore empty or whitespace only pages
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
853 if not page or page.isspace():
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
854 continue
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
855
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
856 # Cleanup group pages.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
857 # Strip non alpha numeric characters, keep white space
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
858 if wikiutil.isGroupPage(self, page):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
859 page = u''.join([c for c in page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
860 if c.isalnum() or c.isspace()])
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
861
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
862 # Normalize white space. Each name can contain multiple
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
863 # words separated with only one space. Split handle all
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
864 # 30 unicode spaces (isspace() == True)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
865 page = u' '.join(page.split())
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
866
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
867 normalized.append(page)
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
868
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
869 # Assemble components into full pagename
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
870 name = u'/'.join(normalized)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
871 return name
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
872
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
873 def read(self, n):
616
3b08d9413589 move send_title/footer from wikiutil to theme.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 615
diff changeset
874 """ Read n bytes from input stream. """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
875 raise NotImplementedError
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
876
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
877 def flush(self):
616
3b08d9413589 move send_title/footer from wikiutil to theme.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 615
diff changeset
878 """ Flush output stream. """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
879 raise NotImplementedError
447
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
880
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
881 def check_spider(self):
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
882 """ check if the user agent for current request is a spider/bot """
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
883 isSpider = False
1549
e36313297589 introduce request.cfg.cache object, start using it for some precompiled regexes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1541
diff changeset
884 ua = self.getUserAgent()
1557
60067807cf9a Allow empty strings for ua_spiders.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1553
diff changeset
885 if ua and self.cfg.cache.ua_spiders:
1549
e36313297589 introduce request.cfg.cache object, start using it for some precompiled regexes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1541
diff changeset
886 isSpider = self.cfg.cache.ua_spiders.search(ua) is not None
447
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
887 return isSpider
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
888
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
889 def isForbidden(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
890 """ check for web spiders and refuse anything except viewing """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
891 forbidden = 0
447
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
892 # we do not have a parsed query string here, so we can just do simple matching
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
893 qs = self.query_string
1007
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
894 action = self.action
447
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
895 if ((qs != '' or self.request_method != 'GET') and
1007
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
896 action != 'rss_rc' and
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
897 # allow spiders to get attachments and do 'show'
1007
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
898 not (action == 'AttachFile' and 'do=get' in qs) and
1666
debeeba5cce6 allow sitemap action for spiders
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1657
diff changeset
899 action != 'show' and
debeeba5cce6 allow sitemap action for spiders
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1657
diff changeset
900 action != 'sitemap'
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
901 ):
447
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
902 forbidden = self.isSpiderAgent
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
903
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
904 if not forbidden and self.cfg.hosts_deny:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
905 ip = self.remote_addr
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
906 for host in self.cfg.hosts_deny:
441
a858267f7dea improved surge protection: dont sleep, add total requests rate
Thomas Waldmann <tw@waldmann-edv.de>
parents: 440
diff changeset
907 if host[-1] == '.' and ip.startswith(host):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
908 forbidden = 1
441
a858267f7dea improved surge protection: dont sleep, add total requests rate
Thomas Waldmann <tw@waldmann-edv.de>
parents: 440
diff changeset
909 #self.log("hosts_deny (net): %s" % str(forbidden))
a858267f7dea improved surge protection: dont sleep, add total requests rate
Thomas Waldmann <tw@waldmann-edv.de>
parents: 440
diff changeset
910 break
a858267f7dea improved surge protection: dont sleep, add total requests rate
Thomas Waldmann <tw@waldmann-edv.de>
parents: 440
diff changeset
911 if ip == host:
a858267f7dea improved surge protection: dont sleep, add total requests rate
Thomas Waldmann <tw@waldmann-edv.de>
parents: 440
diff changeset
912 forbidden = 1
a858267f7dea improved surge protection: dont sleep, add total requests rate
Thomas Waldmann <tw@waldmann-edv.de>
parents: 440
diff changeset
913 #self.log("hosts_deny (ip): %s" % str(forbidden))
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
914 break
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
915 return forbidden
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
916
1012
882a8e99e0e8 removed form param from most setup_args* methods, fixed missing cgi import for WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1011
diff changeset
917 def setup_args(self):
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
918 """ Return args dict
623
088282ae5cf3 move twikidraw saving stuff from request to AttachFile, ok for CGI, needs tests for Twisted and WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
919 First, we parse the query string (usually this is used in GET methods,
088282ae5cf3 move twikidraw saving stuff from request to AttachFile, ok for CGI, needs tests for Twisted and WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
920 but TwikiDraw uses ?action=AttachFile&do=savedrawing plus posted stuff).
088282ae5cf3 move twikidraw saving stuff from request to AttachFile, ok for CGI, needs tests for Twisted and WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
921 Second, we update what we got in first step by the stuff we get from
088282ae5cf3 move twikidraw saving stuff from request to AttachFile, ok for CGI, needs tests for Twisted and WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
922 the form (or by a POST). We invoke _setup_args_from_cgi_form to handle
088282ae5cf3 move twikidraw saving stuff from request to AttachFile, ok for CGI, needs tests for Twisted and WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
923 possible file uploads.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
924 """
623
088282ae5cf3 move twikidraw saving stuff from request to AttachFile, ok for CGI, needs tests for Twisted and WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
925 args = cgi.parse_qs(self.query_string, keep_blank_values=1)
088282ae5cf3 move twikidraw saving stuff from request to AttachFile, ok for CGI, needs tests for Twisted and WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
926 args = self.decodeArgs(args)
1012
882a8e99e0e8 removed form param from most setup_args* methods, fixed missing cgi import for WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1011
diff changeset
927 # if we have form data (in a POST), those override the stuff we already have:
882a8e99e0e8 removed form param from most setup_args* methods, fixed missing cgi import for WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1011
diff changeset
928 if self.request_method == 'POST':
882a8e99e0e8 removed form param from most setup_args* methods, fixed missing cgi import for WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1011
diff changeset
929 postargs = self._setup_args_from_cgi_form()
623
088282ae5cf3 move twikidraw saving stuff from request to AttachFile, ok for CGI, needs tests for Twisted and WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
930 args.update(postargs)
088282ae5cf3 move twikidraw saving stuff from request to AttachFile, ok for CGI, needs tests for Twisted and WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
931 return args
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
932
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
933 def _setup_args_from_cgi_form(self, form=None):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
934 """ Return args dict from a FieldStorage
1012
882a8e99e0e8 removed form param from most setup_args* methods, fixed missing cgi import for WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1011
diff changeset
935
882a8e99e0e8 removed form param from most setup_args* methods, fixed missing cgi import for WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1011
diff changeset
936 Create the args from a given form. Each key contain a list of values.
882a8e99e0e8 removed form param from most setup_args* methods, fixed missing cgi import for WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1011
diff changeset
937 This method usually gets overridden in classes derived from this - it
882a8e99e0e8 removed form param from most setup_args* methods, fixed missing cgi import for WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1011
diff changeset
938 is their task to call this method with an appropriate form parameter.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
939
490
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 483
diff changeset
940 @param form: a cgi.FieldStorage
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
941 @rtype: dict
490
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 483
diff changeset
942 @return: dict with form keys, each contains a list of values
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
943 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
944 args = {}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
945 for key in form:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
946 values = form[key]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
947 if not isinstance(values, list):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
948 values = [values]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
949 fixedResult = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
950 for item in values:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
951 fixedResult.append(item.value)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
952 if isinstance(item, cgi.FieldStorage) and item.filename:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
953 # Save upload file name in a separate key
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
954 args[key + '__filename__'] = item.filename
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
955 args[key] = fixedResult
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
956
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
957 return self.decodeArgs(args)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
958
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
959 def decodeArgs(self, args):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
960 """ Decode args dict
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
961
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
962 Decoding is done in a separate path because it is reused by
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
963 other methods and sub classes.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
964 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
965 decode = wikiutil.decodeUserInput
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
966 result = {}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
967 for key in args:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
968 if key + '__filename__' in args:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
969 # Copy file data as is
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
970 result[key] = args[key]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
971 elif key.endswith('__filename__'):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
972 result[key] = decode(args[key], self.decode_charsets)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
973 else:
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
974 result[key] = [decode(value, self.decode_charsets) for value in args[key]]
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
975 return result
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
976
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
977 def getBaseURL(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
978 """ Return a fully qualified URL to this script. """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
979 return self.getQualifiedURL(self.getScriptname())
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
980
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
981 def getQualifiedURL(self, uri=''):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
982 """ Return an absolute URL starting with schema and host.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
983
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
984 Already qualified urls are returned unchanged.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
985
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
986 @param uri: server rooted uri e.g /scriptname/pagename.
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
987 It must start with a slash. Must be ascii and url encoded.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
988 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
989 import urlparse
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
990 scheme = urlparse.urlparse(uri)[0]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
991 if scheme:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
992 return uri
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
993
481
285b42d58a45 minor change: fixed some typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 462
diff changeset
994 scheme = ('http', 'https')[self.is_ssl]
285b42d58a45 minor change: fixed some typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 462
diff changeset
995 result = "%s://%s%s" % (scheme, self.http_host, uri)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
996
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
997 # This might break qualified urls in redirects!
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
998 # e.g. mapping 'http://netloc' -> '/'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
999 return wikiutil.mapURL(self, result)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1000
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1001 def getUserAgent(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1002 """ Get the user agent. """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1003 return self.http_user_agent
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1004
403
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1005 def makeForbidden(self, resultcode, msg):
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1006 statusmsg = {
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1007 403: 'FORBIDDEN',
1567
2e1aff91a0a5 use 404 instead of ConfigurationError when no config is matched for some URL
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1557
diff changeset
1008 404: 'Not found',
403
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1009 503: 'Service unavailable',
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1010 }
984
311492a91530 add a Retry-After header for 503 result code (surge protection)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 944
diff changeset
1011 headers = [
403
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1012 'Status: %d %s' % (resultcode, statusmsg[resultcode]),
1067
5bf357a720e7 deprecated setResponseCode method, replaced by emit_http_headers
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1064
diff changeset
1013 'Content-Type: text/plain; charset=utf-8'
984
311492a91530 add a Retry-After header for 503 result code (surge protection)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 944
diff changeset
1014 ]
311492a91530 add a Retry-After header for 503 result code (surge protection)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 944
diff changeset
1015 # when surge protection triggered, tell bots to come back later...
311492a91530 add a Retry-After header for 503 result code (surge protection)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 944
diff changeset
1016 if resultcode == 503:
311492a91530 add a Retry-After header for 503 result code (surge protection)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 944
diff changeset
1017 headers.append('Retry-After: %d' % self.cfg.surge_lockout_time)
1061
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1018 self.emit_http_headers(headers)
403
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1019 self.write(msg)
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1020 self.forbidden = True
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1021
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1022 def makeForbidden403(self):
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1023 self.makeForbidden(403, 'You are not allowed to access this!\r\n')
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1024
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1025 def makeUnavailable503(self):
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1026 self.makeForbidden(503, "Warning:\r\n"
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1027 "You triggered the wiki's surge protection by doing too many requests in a short time.\r\n"
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1028 "Please make a short break reading the stuff you already got.\r\n"
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1029 "When you restart doing requests AFTER that, slow down or you might get locked out for a longer time!\r\n")
250
763d15fbcdfc fixed moin_dump
Thomas Waldmann <tw@waldmann-edv.de>
parents: 236
diff changeset
1030
763d15fbcdfc fixed moin_dump
Thomas Waldmann <tw@waldmann-edv.de>
parents: 236
diff changeset
1031 def initTheme(self):
763d15fbcdfc fixed moin_dump
Thomas Waldmann <tw@waldmann-edv.de>
parents: 236
diff changeset
1032 """ Set theme - forced theme, user theme or wiki default """
763d15fbcdfc fixed moin_dump
Thomas Waldmann <tw@waldmann-edv.de>
parents: 236
diff changeset
1033 if self.cfg.theme_force:
763d15fbcdfc fixed moin_dump
Thomas Waldmann <tw@waldmann-edv.de>
parents: 236
diff changeset
1034 theme_name = self.cfg.theme_default
763d15fbcdfc fixed moin_dump
Thomas Waldmann <tw@waldmann-edv.de>
parents: 236
diff changeset
1035 else:
763d15fbcdfc fixed moin_dump
Thomas Waldmann <tw@waldmann-edv.de>
parents: 236
diff changeset
1036 theme_name = self.user.theme_name
763d15fbcdfc fixed moin_dump
Thomas Waldmann <tw@waldmann-edv.de>
parents: 236
diff changeset
1037 self.loadTheme(theme_name)
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
1038
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1039 def run(self):
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents: 47
diff changeset
1040 # Exit now if __init__ failed or request is forbidden
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1041 if self.failed or self.forbidden:
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
1042 # Don't sleep() here, it binds too much of our resources!
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1043 return self.finish()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1044
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1045 _ = self.getText
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1046 self.clock.start('run')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1047
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1048 from MoinMoin.Page import Page
622
8fba6d15a2f5 make request.(html_)formatter available early and use it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
1049 from MoinMoin.formatter.text_html import Formatter
8fba6d15a2f5 make request.(html_)formatter available early and use it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
1050 self.html_formatter = Formatter(self)
8fba6d15a2f5 make request.(html_)formatter available early and use it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 618
diff changeset
1051 self.formatter = self.html_formatter
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1052
1007
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
1053 action_name = self.action
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
1054 if action_name == 'xmlrpc':
637
35f0f8584a57 move wikirpc.py to xmlrpc/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 636
diff changeset
1055 from MoinMoin import xmlrpc
1007
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
1056 if self.query_string == 'action=xmlrpc':
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
1057 xmlrpc.xmlrpc(self)
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
1058 elif self.query_string == 'action=xmlrpc2':
8cc609b746de request.action now has the action for the current request, default 'show'
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 984
diff changeset
1059 xmlrpc.xmlrpc2(self)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1060 return self.finish()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1061
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1062 # parse request data
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1063 try:
250
763d15fbcdfc fixed moin_dump
Thomas Waldmann <tw@waldmann-edv.de>
parents: 236
diff changeset
1064 self.initTheme()
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
1065
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1066 # The last component in path_info is the page name, if any
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1067 path = self.getPathinfo()
1339
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1317
diff changeset
1068
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1317
diff changeset
1069 # we can have all action URLs like this: /action/ActionName/PageName?action=ActionName&...
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1317
diff changeset
1070 # this is just for robots.txt being able to forbid them for crawlers
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1317
diff changeset
1071 prefix = self.cfg.url_prefix_action
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1317
diff changeset
1072 if prefix is not None:
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1317
diff changeset
1073 prefix = '/%s/' % prefix # e.g. '/action/'
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1317
diff changeset
1074 if path.startswith(prefix):
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1317
diff changeset
1075 # remove prefix and action name
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1317
diff changeset
1076 path = path[len(prefix):]
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1317
diff changeset
1077 action, path = path.split('/', 1)
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1317
diff changeset
1078 path = '/' + path
544b931cd965 new setting url_prefix_action, cleanup page.url/link_to, wikiutil.link_tag
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1317
diff changeset
1079
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1080 if path.startswith('/'):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1081 pagename = self.normalizePagename(path)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1082 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1083 pagename = None
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents: 47
diff changeset
1084
941
16f7b6728b4e move vary: header code to request module and fix it (multiple headers of same type don't work!)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 910
diff changeset
1085 # need to inform caches that content changes based on:
16f7b6728b4e move vary: header code to request module and fix it (multiple headers of same type don't work!)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 910
diff changeset
1086 # * cookie (even if we aren't sending one now)
16f7b6728b4e move vary: header code to request module and fix it (multiple headers of same type don't work!)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 910
diff changeset
1087 # * User-Agent (because a bot might be denied and get no content)
16f7b6728b4e move vary: header code to request module and fix it (multiple headers of same type don't work!)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 910
diff changeset
1088 # * Accept-Language (except if moin is told to ignore browser language)
16f7b6728b4e move vary: header code to request module and fix it (multiple headers of same type don't work!)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 910
diff changeset
1089 if self.cfg.language_ignore_browser:
944
7c8e8d370740 use comma-separated Vary header items
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 942
diff changeset
1090 self.setHttpHeader("Vary: Cookie,User-Agent")
941
16f7b6728b4e move vary: header code to request module and fix it (multiple headers of same type don't work!)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 910
diff changeset
1091 else:
944
7c8e8d370740 use comma-separated Vary header items
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 942
diff changeset
1092 self.setHttpHeader("Vary: Cookie,User-Agent,Accept-Language")
941
16f7b6728b4e move vary: header code to request module and fix it (multiple headers of same type don't work!)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 910
diff changeset
1093
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1094 # Handle request. We have these options:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1095 # 1. If user has a bad user name, delete its bad cookie and
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1096 # send him to UserPreferences to make a new account.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1097 if not user.isValidName(self, self.user.name):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1098 msg = _("""Invalid user name {{{'%s'}}}.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1099 Name may contain any Unicode alpha numeric character, with optional one
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1100 space between words. Group page name is not allowed.""") % self.user.name
495
36fe4eebb72b fix wrong object reference in request.py
Thomas Waldmann <tw@waldmann-edv.de>
parents: 490
diff changeset
1101 self.user = self.get_user_default_unknown(name=self.user.name, logout=True)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1102 page = wikiutil.getSysPage(self, 'UserPreferences')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1103 page.send_page(self, msg=msg)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1104
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1105 # 2. Or jump to page where user left off
909
3680f8b5066f show is default action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 908
diff changeset
1106 elif not pagename and self.user.remember_last_visit:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1107 pagetrail = self.user.getTrail()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1108 if pagetrail:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1109 # Redirect to last page visited
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1110 if ":" in pagetrail[-1]:
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
1111 wikitag, wikiurl, wikitail, error = wikiutil.resolve_wiki(self, pagetrail[-1])
57
546541209681 fix remember_last_visit(ed page) root url redirect
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
1112 url = wikiurl + wikiutil.quoteWikinameURL(wikitail)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1113 else:
1657
e8b3d979dff3 remember_last_visit fixed to use absolute url
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1618
diff changeset
1114 url = Page(self, pagetrail[-1]).url(self, escape=0, relative=False)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1115 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1116 # Or to localized FrontPage
1657
e8b3d979dff3 remember_last_visit fixed to use absolute url
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1618
diff changeset
1117 url = wikiutil.getFrontPage(self).url(self, escape=0, relative=False)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1118 self.http_redirect(url)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1119 return self.finish()
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
1120
623
088282ae5cf3 move twikidraw saving stuff from request to AttachFile, ok for CGI, needs tests for Twisted and WSGI
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 622
diff changeset
1121 # 3. Or handle action
614
95fb435b72aa refactor: use show action when no action is given
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 613
diff changeset
1122 else:
95fb435b72aa refactor: use show action when no action is given
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 613
diff changeset
1123 # pagename could be empty after normalization e.g. '///' -> ''
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1124 # Use localized FrontPage if pagename is empty
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1125 if not pagename:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1126 self.page = wikiutil.getFrontPage(self)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1127 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1128 self.page = Page(self, pagename)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1129
1013
289254f32ab2 refactored action error msg output
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1012
diff changeset
1130 msg = None
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1131 # Complain about unknown actions
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 623
diff changeset
1132 if not action_name in self.getKnownActions():
1013
289254f32ab2 refactored action error msg output
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1012
diff changeset
1133 msg = _("Unknown action %(action_name)s.") % {
289254f32ab2 refactored action error msg output
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1012
diff changeset
1134 'action_name': wikiutil.escape(action_name), }
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1135
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1136 # Disallow non available actions
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 623
diff changeset
1137 elif action_name[0].isupper() and not action_name in self.getAvailableActions(self.page):
1013
289254f32ab2 refactored action error msg output
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1012
diff changeset
1138 msg = _("You are not allowed to do %(action_name)s on this page.") % {
289254f32ab2 refactored action error msg output
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1012
diff changeset
1139 'action_name': wikiutil.escape(action_name), }
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1140 if not self.user.valid:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1141 # Suggest non valid user to login
613
1ba2c3686e98 more comment and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 612
diff changeset
1142 msg += " " + _("Login and try again.", formatted=0)
1013
289254f32ab2 refactored action error msg output
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1012
diff changeset
1143
289254f32ab2 refactored action error msg output
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1012
diff changeset
1144 if msg:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1145 self.page.send_page(self, msg=msg)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1146
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1147 # Try action
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1148 else:
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 623
diff changeset
1149 from MoinMoin import action
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 623
diff changeset
1150 handler = action.getHandler(self, action_name)
1541
b54e89c69227 handle exluded lowercase action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1398
diff changeset
1151 if handler is None:
b54e89c69227 handle exluded lowercase action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1398
diff changeset
1152 msg = _("You are not allowed to do %(action_name)s on this page.") % {
b54e89c69227 handle exluded lowercase action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1398
diff changeset
1153 'action_name': wikiutil.escape(action_name), }
b54e89c69227 handle exluded lowercase action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1398
diff changeset
1154 if not self.user.valid:
b54e89c69227 handle exluded lowercase action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1398
diff changeset
1155 # Suggest non valid user to login
b54e89c69227 handle exluded lowercase action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1398
diff changeset
1156 msg += " " + _("Login and try again.", formatted=0)
b54e89c69227 handle exluded lowercase action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1398
diff changeset
1157 self.page.send_page(self, msg=msg)
b54e89c69227 handle exluded lowercase action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1398
diff changeset
1158 else:
b54e89c69227 handle exluded lowercase action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1398
diff changeset
1159 handler(self.page.page_name, self)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1160
617
cf420addd95c removed MoinMoinNoFooter at many places, added call to theme.send_closing_html() where needed
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 616
diff changeset
1161 # every action that didn't use to raise MoinMoinNoFooter must call this now:
cf420addd95c removed MoinMoinNoFooter at many places, added call to theme.send_closing_html() where needed
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 616
diff changeset
1162 # self.theme.send_closing_html()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1163
618
e0cbf33ff15c remove MoinMoinNoFooter (not needed and more), please call theme.send_closing_html() for closing what send_title() opened
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 617
diff changeset
1164 except MoinMoinFinish:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1165 pass
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents: 47
diff changeset
1166 except Exception, err:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1167 self.fail(err)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1168
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1169 return self.finish()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1170
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1171 def http_redirect(self, url):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1172 """ Redirect to a fully qualified, or server-rooted URL
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1173
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1174 @param url: relative or absolute url, ascii using url encoding.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1175 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1176 url = self.getQualifiedURL(url)
1061
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1177 self.emit_http_headers(["Status: 302 Found", "Location: %s" % url])
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1178
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1179 def http_headers(self, more_headers=[]):
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1180 """ wrapper for old, deprecated http_headers call,
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1181 new code only calls emit_http_headers.
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1182 Remove in moin 1.7.
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1183 """
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1184 self.emit_http_headers(more_headers)
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1185
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1186 def emit_http_headers(self, more_headers=[]):
1064
a8ea94a0cbe8 emit_http_headers: better docs, _emit_http_headers raises NotImplementedError in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1061
diff changeset
1187 """ emit http headers after some preprocessing / checking
a8ea94a0cbe8 emit_http_headers: better docs, _emit_http_headers raises NotImplementedError in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1061
diff changeset
1188
1103
fe874e9e72c7 fix comments in emit_http_headers
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1102
diff changeset
1189 Makes sure we only emit headers once.
1064
a8ea94a0cbe8 emit_http_headers: better docs, _emit_http_headers raises NotImplementedError in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1061
diff changeset
1190 Encodes to ASCII if it gets unicode headers.
a8ea94a0cbe8 emit_http_headers: better docs, _emit_http_headers raises NotImplementedError in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1061
diff changeset
1191 Make sure we have exactly one Content-Type and one Status header.
a8ea94a0cbe8 emit_http_headers: better docs, _emit_http_headers raises NotImplementedError in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1061
diff changeset
1192 Make sure Status header string begins with a integer number.
a8ea94a0cbe8 emit_http_headers: better docs, _emit_http_headers raises NotImplementedError in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1061
diff changeset
1193
a8ea94a0cbe8 emit_http_headers: better docs, _emit_http_headers raises NotImplementedError in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1061
diff changeset
1194 For emitting, it calls the server specific _emit_http_headers
a8ea94a0cbe8 emit_http_headers: better docs, _emit_http_headers raises NotImplementedError in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1061
diff changeset
1195 method.
a8ea94a0cbe8 emit_http_headers: better docs, _emit_http_headers raises NotImplementedError in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1061
diff changeset
1196
a8ea94a0cbe8 emit_http_headers: better docs, _emit_http_headers raises NotImplementedError in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1061
diff changeset
1197 @param more_headers: list of additional header strings
1061
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1198 """
1073
a6bb4df3888d fix http headers bug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1071
diff changeset
1199 user_headers = getattr(self, 'user_headers', [])
1071
64e513264aed cleanup, less header logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1070
diff changeset
1200 self.user_headers = []
1073
a6bb4df3888d fix http headers bug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1071
diff changeset
1201 all_headers = more_headers + user_headers
1071
64e513264aed cleanup, less header logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1070
diff changeset
1202
1061
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1203 # Send headers only once
1070
054a3d3d8dfe fix http headers for edit, RenamePage, DeletePage action, raise exception when http_headers is called multiple times
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1067
diff changeset
1204 sent_headers = getattr(self, 'sent_headers', 0)
1699
66f2ea899da7 fckdialog action: don't call emit_http_headers twice, fix wrong attribute name in emit_http_headers
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
1205 sent_headers += 1
66f2ea899da7 fckdialog action: don't call emit_http_headers twice, fix wrong attribute name in emit_http_headers
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
1206 self.sent_headers = sent_headers
66f2ea899da7 fckdialog action: don't call emit_http_headers twice, fix wrong attribute name in emit_http_headers
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
1207 if sent_headers > 1:
66f2ea899da7 fckdialog action: don't call emit_http_headers twice, fix wrong attribute name in emit_http_headers
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1682
diff changeset
1208 raise HeadersAlreadySentException("emit_http_headers called multiple (%d) times! Headers: %r" % (sent_headers, all_headers))
1071
64e513264aed cleanup, less header logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1070
diff changeset
1209 #else:
1073
a6bb4df3888d fix http headers bug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1071
diff changeset
1210 # self.log("Notice: emit_http_headers called first time. Headers: %r" % all_headers)
1061
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1211
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1212 content_type = None
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1213 status = None
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1214 headers = []
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1215 # assemble complete list of http headers
1073
a6bb4df3888d fix http headers bug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1071
diff changeset
1216 for header in all_headers:
1061
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1217 if isinstance(header, unicode):
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1218 header = header.encode('ascii')
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1219 key, value = header.split(':', 1)
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1220 lkey = key.lower()
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1221 value = value.lstrip()
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1222 if content_type is None and lkey == "content-type":
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1223 content_type = value
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1224 elif status is None and lkey == "status":
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1225 status = value
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1226 else:
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1227 headers.append(header)
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1228
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1229 if content_type is None:
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1230 content_type = "text/html; charset=%s" % config.charset
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1231 ct_header = "Content-type: %s" % content_type
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1232
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1233 if status is None:
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1234 status = "200 OK"
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1235 try:
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1236 int(status.split(" ", 1)[0])
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1237 except:
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1238 self.log("emit_http_headers called with invalid header Status: %s" % status)
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1239 status = "500 Server Error - invalid status header"
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1240 st_header = "Status: %s" % status
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1241
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1242 headers = [st_header, ct_header] + headers # do NOT change order!
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1243 self._emit_http_headers(headers)
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1244
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1245 #from pprint import pformat
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1246 #sys.stderr.write(pformat(headers))
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1247
1064
a8ea94a0cbe8 emit_http_headers: better docs, _emit_http_headers raises NotImplementedError in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1061
diff changeset
1248 def _emit_http_headers(self, headers):
a8ea94a0cbe8 emit_http_headers: better docs, _emit_http_headers raises NotImplementedError in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1061
diff changeset
1249 """ server specific method to emit http headers.
a8ea94a0cbe8 emit_http_headers: better docs, _emit_http_headers raises NotImplementedError in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1061
diff changeset
1250
a8ea94a0cbe8 emit_http_headers: better docs, _emit_http_headers raises NotImplementedError in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1061
diff changeset
1251 @param headers: a list of http header strings in this FIXED order:
a8ea94a0cbe8 emit_http_headers: better docs, _emit_http_headers raises NotImplementedError in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1061
diff changeset
1252 1. status header (always present and valid, e.g. "200 OK")
a8ea94a0cbe8 emit_http_headers: better docs, _emit_http_headers raises NotImplementedError in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1061
diff changeset
1253 2. content type header (always present)
a8ea94a0cbe8 emit_http_headers: better docs, _emit_http_headers raises NotImplementedError in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1061
diff changeset
1254 3. other headers (optional)
a8ea94a0cbe8 emit_http_headers: better docs, _emit_http_headers raises NotImplementedError in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1061
diff changeset
1255 """
a8ea94a0cbe8 emit_http_headers: better docs, _emit_http_headers raises NotImplementedError in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1061
diff changeset
1256 raise NotImplementedError
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1257
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1258 def setHttpHeader(self, header):
942
86ea8f868030 use only one setHttpHeader call for one header type, add warning to docstring in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 941
diff changeset
1259 """ Save header for later send.
86ea8f868030 use only one setHttpHeader call for one header type, add warning to docstring in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 941
diff changeset
1260
86ea8f868030 use only one setHttpHeader call for one header type, add warning to docstring in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 941
diff changeset
1261 Attention: although we use a list here, some implementations use a dict,
86ea8f868030 use only one setHttpHeader call for one header type, add warning to docstring in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 941
diff changeset
1262 thus multiple calls with the same header type do NOT work in the end!
86ea8f868030 use only one setHttpHeader call for one header type, add warning to docstring in base class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 941
diff changeset
1263 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1264 self.user_headers.append(header)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1265
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1266 def setResponseCode(self, code, message=None):
1067
5bf357a720e7 deprecated setResponseCode method, replaced by emit_http_headers
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1064
diff changeset
1267 """ DEPRECATED, will vanish in moin 1.7,
5bf357a720e7 deprecated setResponseCode method, replaced by emit_http_headers
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1064
diff changeset
1268 just use a Status: <code> <message> header and emit_http_headers.
5bf357a720e7 deprecated setResponseCode method, replaced by emit_http_headers
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1064
diff changeset
1269 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1270 pass
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1271
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1272 def fail(self, err):
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents: 47
diff changeset
1273 """ Fail when we can't continue
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1274
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents: 47
diff changeset
1275 Send 500 status code with the error name. Reference:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1276 http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6.1.1
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1277
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents: 47
diff changeset
1278 Log the error, then let failure module handle it.
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents: 47
diff changeset
1279
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents: 47
diff changeset
1280 @param err: Exception instance or subclass.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1281 """
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents: 47
diff changeset
1282 self.failed = 1 # save state for self.run()
1086
db7863d7a45e Fixed bug in request.py that avoided showing a traceback if there was a fault after the first headers were sent.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1071
diff changeset
1283 # we should not generate the headers two times
db7863d7a45e Fixed bug in request.py that avoided showing a traceback if there was a fault after the first headers were sent.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1071
diff changeset
1284 if not getattr(self, 'sent_headers', 0):
db7863d7a45e Fixed bug in request.py that avoided showing a traceback if there was a fault after the first headers were sent.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1071
diff changeset
1285 self.emit_http_headers(['Status: 500 MoinMoin Internal Error'])
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents: 47
diff changeset
1286 from MoinMoin import failure
1586
cae5575b07fa log tracebacks
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1585
diff changeset
1287 failure.handle(self, err)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1288
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1289 def makeUniqueID(self, base):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1290 """
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
1291 Generates a unique ID using a given base name. Appends a running count to the base.
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1292
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1293 @param base: the base of the id
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1294 @type base: unicode
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1295
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1296 @returns: an unique id
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1297 @rtype: unicode
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1298 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1299 if not isinstance(base, unicode):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1300 base = unicode(str(base), 'ascii', 'ignore')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1301 count = self._page_ids.get(base, -1) + 1
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1302 self._page_ids[base] = count
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1303 if count == 0:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1304 return base
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1305 return u'%s_%04d' % (base, count)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1306
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1307 def httpDate(self, when=None, rfc='1123'):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1308 """ Returns http date string, according to rfc2068
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1309
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1310 See http://www.cse.ohio-state.edu/cgi-bin/rfc/rfc2068.html#sec-3.3
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1311
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1312 A http 1.1 server should use only rfc1123 date, but cookie's
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1313 "expires" field should use the older obsolete rfc850 date.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1314
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1315 Note: we can not use strftime() because that honors the locale
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1316 and rfc2822 requires english day and month names.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1317
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1318 We can not use email.Utils.formatdate because it formats the
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1319 zone as '-0000' instead of 'GMT', and creates only rfc1123
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1320 dates. This is a modified version of email.Utils.formatdate
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1321 from Python 2.4.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1322
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1323 @param when: seconds from epoch, as returned by time.time()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1324 @param rfc: conform to rfc ('1123' or '850')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1325 @rtype: string
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1326 @return: http date conforming to rfc1123 or rfc850
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1327 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1328 if when is None:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1329 when = time.time()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1330 now = time.gmtime(when)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1331 month = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul',
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1332 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][now.tm_mon - 1]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1333 if rfc == '1123':
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1334 day = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'][now.tm_wday]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1335 date = '%02d %s %04d' % (now.tm_mday, month, now.tm_year)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1336 elif rfc == '850':
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1337 day = ["Monday", "Tuesday", "Wednesday", "Thursday",
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1338 "Friday", "Saturday", "Sunday"][now.tm_wday]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1339 date = '%02d-%s-%s' % (now.tm_mday, month, str(now.tm_year)[-2:])
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1340 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1341 raise ValueError("Invalid rfc value: %s" % rfc)
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
1342