annotate MoinMoin/request/__init__.py @ 2894:f009ead62bfd

PEP8 fixes
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sun, 21 Oct 2007 10:14:47 +0200
parents 408b301a5e44
children 4be125bafc8a
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
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1870
diff changeset
5 @copyright: 2001-2003 Juergen Hermann <jh@web.de>,
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
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
1931
7f87f9d0159e move cookie parsing to request and pass the cookie object (or None) to the
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1918
diff changeset
12 import Cookie
1148
301575ccf95f added set import for py 2.3 compatibility
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1132
diff changeset
13
1071
64e513264aed cleanup, less header logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1070
diff changeset
14 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
15 from MoinMoin.config import multiconfig
2595
5e7b45489430 moved python2.3/2.4 compatibility code to MoinMoin.support.python_compatibility (thanks to Heinrich Wendel)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2574
diff changeset
16 from MoinMoin.support.python_compatibility import set
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
17 from MoinMoin.util import IsWin9x
2025
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
18 from MoinMoin import auth
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
19 from urllib import quote, quote_plus
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
20
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
21 # 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
22 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
23 """ 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
24 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
25 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
26 """
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 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
28 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
29 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
30 # 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
31 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
32
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 # 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
34 # 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
35 # 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
36 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
37
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
38 # 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
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 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
41 """ 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
42
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
43
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 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
45 """ 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
46
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
47
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
48 # Timing ---------------------------------------------------------------
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 class Clock:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
51 """ 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
52 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
53 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
54 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
55 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
56 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
57
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
58 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
59 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
60 self.states = {}
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
61
1144
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
62 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
63 if generation == 0:
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
64 return timer
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
65 else:
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
66 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
67 _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
68
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
69 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
70 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
71 new_level = state + 1
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
72 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
73 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
74 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
75
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
76 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
77 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
78 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
79 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
80 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
81 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
82
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
83 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
84 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
85 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
86 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
87 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
88 elif state is None:
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
89 result = "- (%s)" % state
1b5093cfc607 Streamlined Request.Clock, added support for recursive calls.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1132
diff changeset
90 else:
1147
637d90f1209d Oops, removed a debug print.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1144
diff changeset
91 #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
92 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
93 return result
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
94
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
95 def dump(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
96 outlist = []
1870
9406e02388cf reduce usage of .keys()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
97 for timer in self.timings:
1130
787e963c9bfd fix Clock code, add more timers (ported from 1.5)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1116
diff changeset
98 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
99 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
100 outlist.sort()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
101 return outlist
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
102
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
103
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
104 # Utilities
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 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
107 """ Return CGI meta variable for header name
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
108
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
109 e.g 'User-Agent' -> 'HTTP_USER_AGENT'
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
110 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
111 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
112 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
113 return var.upper().replace('-', '_')
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
114
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
115
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
116 # Request Base ----------------------------------------------------------
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 class RequestBase(object):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
119 """ 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
120
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
121 # 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
122 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
123 server_name = 'localhost'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
124 server_port = '80'
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
125
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
126 # 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
127 # headers as lowercase.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
128 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
129 proxy_host = 'x-forwarded-host'
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
130
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
131 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
132
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
133 # 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
134 # 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
135 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
136
2007
6cc2e0544657 add finish handlers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1988
diff changeset
137 self._finishers = []
6cc2e0544657 add finish handlers
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1988
diff changeset
138
2025
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
139 self._auth_redirected = False
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
140
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
141 # 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
142 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
143
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
144 self.failed = 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
145 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
146 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
147
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
148 # 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
149 self.pages = {}
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
150
2892
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2844
diff changeset
151 self.sent_headers = False
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
152 self.user_headers = []
15
5a2a8201bb6f make moin friendlier to proxies, thanks to ASF
Thomas Waldmann <tw@waldmann-edv.de>
parents: 9
diff changeset
153 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
154 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
155 self.page = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
156 self._dicts = None
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
157
1933
19e3af7cabcd change the set user functionality to use the session storage and keep track
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1932
diff changeset
158 # setuid handling requires an attribute in the request
19e3af7cabcd change the set user functionality to use the session storage and keep track
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1932
diff changeset
159 # that stores the real user
19e3af7cabcd change the set user functionality to use the session storage and keep track
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1932
diff changeset
160 self._setuid_real_user = None
19e3af7cabcd change the set user functionality to use the session storage and keep track
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1932
diff changeset
161
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
162 # 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
163 # 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
164 # 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
165 self.forbidden = False
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
166 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
167 self.makeForbidden403()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
168
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
169 # Init
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
170 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
171 self.writestack = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
172 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
173 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
174 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
175 # order is important here!
397
1a7f4e1f3e4d Fixed MoinMoinBugs/ RewritingAndCookieUrl/
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 393
diff changeset
176 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
177 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
178 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
179 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
180 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
181 return
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
182
447
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
183 self.isSpiderAgent = self.check_spider()
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
184
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
185 # 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
186 # 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
187 # 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
188 self.decode_charsets = [config.charset]
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
189
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
190 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
191 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
192 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
193 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
194 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
195 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
196 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
197 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
198 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
199 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
200 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
201 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
202
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
203 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
204 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
205
1857
659070e5e4d3 introduce request.editlog and use it for ItemCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1816
diff changeset
206 from MoinMoin.logfile import editlog
659070e5e4d3 introduce request.editlog and use it for ItemCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1816
diff changeset
207 self.editlog = editlog.EditLog(self)
659070e5e4d3 introduce request.editlog and use it for ItemCache
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1816
diff changeset
208
688
15c55ecd7ccb fix some i18n bugs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 684
diff changeset
209 from MoinMoin import i18n
15c55ecd7ccb fix some i18n bugs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 684
diff changeset
210 self.i18n = i18n
15c55ecd7ccb fix some i18n bugs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 684
diff changeset
211 i18n.i18n_init(self)
15c55ecd7ccb fix some i18n bugs
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 684
diff changeset
212
2008
52c474b8c02f allow translating things early
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2007
diff changeset
213 # authentication might require translated forms, so
52c474b8c02f allow translating things early
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2007
diff changeset
214 # have a try at guessing the language from the browser
52c474b8c02f allow translating things early
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2007
diff changeset
215 lang = i18n.requestLanguage(self, try_user=False)
52c474b8c02f allow translating things early
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2007
diff changeset
216 self.getText = lambda text, i18n=self.i18n, request=self, lang=lang, **kv: i18n.getText(text, request, lang, kv.get('formatted', True))
52c474b8c02f allow translating things early
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2007
diff changeset
217
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
218 # session handler start, auth
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
219 self.parse_cookie()
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
220 user_obj = self.cfg.session_handler.start(self, self._cookie)
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
221 shfinisher = lambda request: self.cfg.session_handler.finish(request, self._cookie, request.user)
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
222 self.add_finisher(shfinisher)
2026
5aa49f81db45 finishers: execute only once and make sure request.user is set
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2025
diff changeset
223 # set self.user even if _handle_auth_form raises an Exception
5aa49f81db45 finishers: execute only once and make sure request.user is set
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2025
diff changeset
224 self.user = None
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
225 self.user = self._handle_auth_form(user_obj)
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
226 del user_obj
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
227 self.cfg.session_handler.after_auth(self, self._cookie, self.user)
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
228 if not self.user:
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
229 self.user = user.User(self, auth_method='request:invalid')
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
230
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
231 # setuid handling, check isSuperUser() because the user
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
232 # might have lost the permission between requests
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
233 if 'setuid' in self.session and self.user.isSuperUser():
1933
19e3af7cabcd change the set user functionality to use the session storage and keep track
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1932
diff changeset
234 self._setuid_real_user = self.user
19e3af7cabcd change the set user functionality to use the session storage and keep track
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1932
diff changeset
235 uid = self.session['setuid']
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
236 self.user = user.User(self, uid, auth_method='setuid')
2369
ccf996479233 fix a suid bug: force switched-to user valid
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2299
diff changeset
237 # set valid to True so superusers can even switch
ccf996479233 fix a suid bug: force switched-to user valid
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2299
diff changeset
238 # to disable accounts
ccf996479233 fix a suid bug: force switched-to user valid
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2299
diff changeset
239 self.user.valid = True
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
240
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 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
242 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
243 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
244 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
245 self.makeUnavailable503()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
246
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
247 self.pragma = {}
1595
3a63c9b31d7e avoid infinite recursion in parsePageLinks
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1590
diff changeset
248 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
249 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
250
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
251 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
252 # 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
253 # 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
254 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
255 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
256
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
257 self.reset()
2217
f8dcc3232e8b move html_formatter creation to RequestBase.__init__ so it also works for CLI requests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2208
diff changeset
258
f8dcc3232e8b move html_formatter creation to RequestBase.__init__ so it also works for CLI requests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2208
diff changeset
259 from MoinMoin.formatter.text_html import Formatter
f8dcc3232e8b move html_formatter creation to RequestBase.__init__ so it also works for CLI requests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2208
diff changeset
260 self.html_formatter = Formatter(self)
f8dcc3232e8b move html_formatter creation to RequestBase.__init__ so it also works for CLI requests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2208
diff changeset
261 self.formatter = self.html_formatter
f8dcc3232e8b move html_formatter creation to RequestBase.__init__ so it also works for CLI requests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2208
diff changeset
262
1131
67044a2a0224 add some more timers, fix wrong path in i18n_init
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1130
diff changeset
263 self.clock.stop('base__init__')
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
264
1553
24ef62e7013f add kick_me option to surge_protect
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1550
diff changeset
265 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
266 """ 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
267 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
268 """
1245
5b6031179fef allow disabling surge protection by surge_action_limits = None
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1183
diff changeset
269 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
270 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
271 return False
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
272
411
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
273 validuser = self.user.valid
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
274 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
275 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
276 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
277 current_action = self.action
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
278
420
b4ff26eb2c43 adjusting some surge protection limits
Thomas Waldmann <tw@waldmann-edv.de>
parents: 412
diff changeset
279 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
280
411
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
281 now = int(time.time())
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
282 surgedict = {}
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
283 surge_detected = False
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
284
411
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
285 try:
682
1314fdb74689 refactor CacheEntry usage to use scope param
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 640
diff changeset
286 # if we have common farm users, we could also use scope='farm':
2239
0232aa023881 fixed encoding/decoding for surge-log data, fixes leftoever surge-logXXXXX.tmp files in data/cache/surgeprotect (ported from 1.5 changeset 817: 4b9425f89248)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2217
diff changeset
287 cache = caching.CacheEntry(self, 'surgeprotect', 'surge-log', scope='wiki', use_encode=True)
445
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
288 if cache.exists():
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
289 data = cache.content()
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
290 data = data.split("\n")
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
291 for line in data:
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
292 try:
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
293 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
294 t = int(t)
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
295 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
296 if t >= now - dt:
2438
609ef7393a14 remove bogus copy statements
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2369
diff changeset
297 events = surgedict.setdefault(id, {})
609ef7393a14 remove bogus copy statements
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2369
diff changeset
298 timestamps = events.setdefault(action, [])
445
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
299 timestamps.append((t, surge_indicator))
1805
ebcebba1afb3 removed some unused attributes, used 'dummy' for dummies
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1801
diff changeset
300 except StandardError:
445
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
301 pass
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
302
411
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
303 maxnum, dt = limits.get(current_action, default_limit)
2438
609ef7393a14 remove bogus copy statements
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2369
diff changeset
304 events = surgedict.setdefault(current_id, {})
609ef7393a14 remove bogus copy statements
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2369
diff changeset
305 timestamps = events.setdefault(current_action, [])
411
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
306 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
307
a858267f7dea improved surge protection: dont sleep, add total requests rate
Thomas Waldmann <tw@waldmann-edv.de>
parents: 440
diff changeset
308 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
309 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
310 if surge_detected:
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
311 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
312 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
313
445
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
314 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
315 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
316 maxnum, dt = limits.get(current_action, default_limit)
2438
609ef7393a14 remove bogus copy statements
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2369
diff changeset
317 events = surgedict.setdefault(current_id, {})
609ef7393a14 remove bogus copy statements
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2369
diff changeset
318 timestamps = events.setdefault(current_action, [])
1553
24ef62e7013f add kick_me option to surge_protect
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1550
diff changeset
319
24ef62e7013f add kick_me option to surge_protect
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1550
diff changeset
320 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
321 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
322
445
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
323 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
324
445
a71176d858be surge protection: specialcase AttachFile, fix no cache exists case
Thomas Waldmann <tw@waldmann-edv.de>
parents: 441
diff changeset
325 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
326 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
327 if surge_detected:
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
328 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
329 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
330
411
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
331 data = []
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
332 for id, events in surgedict.items():
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
333 for action, timestamps in events.items():
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
334 for t, surge_indicator in timestamps:
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
335 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
336 data = "\n".join(data)
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
337 cache.update(data)
1805
ebcebba1afb3 removed some unused attributes, used 'dummy' for dummies
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1801
diff changeset
338 except StandardError:
411
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
339 pass
6e2114f8e942 fixed version, surge protection configuration, merged CHANGES
Thomas Waldmann <tw@waldmann-edv.de>
parents: 406
diff changeset
340
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
341 return surge_detected
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
342
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
343 def getDicts(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
344 """ 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
345 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
346 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
347 dicts = wikidicts.GroupDict(self)
2254
564dee5eb254 use event system to trigger wikidicts cache update
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2239
diff changeset
348 dicts.load_dicts()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
349 self._dicts = dicts
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
350 return self._dicts
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
351
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
352 def delDicts(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
353 """ 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
354 del self._dicts
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
355 self._dicts = None
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
356
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
357 dicts = property(getDicts, None, delDicts)
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
358
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
359 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
360 # 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
361 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
362 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
363 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
364 self.clock.stop('load_multi_cfg')
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
365
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
366 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
367 """ 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
368
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
369 Set self.accepted_charsets to an ordered list based on http_accept_charset.
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
370
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
371 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
372
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
373 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
374
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
375 @param accept_charset: accept-charset header
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
376 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
377 charsets = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
378 if accept_charset:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
379 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
380 # 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
381 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
382 '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
383 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
384
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
385 # Make a list, sorted by quality value, using Schwartzian Transform
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
386 # Create list of tuples (value, name) , sort, extract names
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
387 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
388 if ';' in item:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
389 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
390 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
391 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
392 name, qval = item, 0
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
393 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
394 charsets.sort()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
395 # 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
396 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
397
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
398 self.accepted_charsets = charsets
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
399
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
400 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
401 """ Set common request variables from CGI environment
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
402
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
403 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
404 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
405
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
406 @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
407 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
408 # 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
409 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
410 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
411 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
412 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
413 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
414 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
415 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
416 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
417 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
418 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
419 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
420 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
421 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
422
298
6c74345f4d55 cleaned up and moved moin's cookie stuff to auth.moin_cookie
Thomas Waldmann <tw@waldmann-edv.de>
parents: 295
diff changeset
423 # 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
424 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
425
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
426 # 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
427 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
428 self.setIsSSL(env)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
429 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
430 self.fixURI(env)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
431 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
432 #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
433
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
434 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
435 """ Set http_referer, making sure its ascii
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
436
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
437 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
438 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
439 value = ''
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
440 if referer:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
441 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
442 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
443 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
444
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
445 def setIsSSL(self, env):
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
446 """ Set is_ssl
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
447
0
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
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
449 """
149
c5b967d9d1e6 fixed MoinMoinBugs/TypeErrorOnHttpsPageChangeEmail
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 131
diff changeset
450 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
451 env.get('SSL_PROTOCOL_VERSION') or
c5b967d9d1e6 fixed MoinMoinBugs/TypeErrorOnHttpsPageChangeEmail
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 131
diff changeset
452 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
453
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
454 def setHost(self, host=None):
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
455 """ Set http_host
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
456
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
457 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
458 default to localhost.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
459 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
460 if not host:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
461 port = ''
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
462 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
463 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
464 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
465 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
466 self.http_host = host
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
467
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
468 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
469 """ Fix problems with script_name and path_info
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
470
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
471 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
472 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
473 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
474 most webservers choke.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
475
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
476 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
477 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
478 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
479 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
480 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
481 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
482 - := Hopefully not.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
483
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
484 @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
485 """
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
486 # 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
487 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
488 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
489 # 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
490 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
491 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
492
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
493 # Fix path_info
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
494 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
495 # 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
496 import urlparse
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
497 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
498 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
499 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
500 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
501 # 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
502 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
503 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
504
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
505 # 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
506 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
507 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
508
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
509 def setURL(self, env):
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
510 """ Set url, used to locate wiki config
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
511
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
512 This is the place to manipulate url parts as needed.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
513
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
514 @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
515 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
516 # 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
517 # 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
518 # 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
519 self.rewriteHost(env)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
520 self.rewriteURI(env)
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
521
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
522 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
523 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
524 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
525
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
526 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
527 """ Rewrite http_host transparently
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
528
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
529 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
530 Apache 2 and other proxy software.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
531
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
532 TODO: Will not work for Apache 1 or others that don't add this header.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
533
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
534 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
535 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
536 loaded at this point, and must be loaded after url is set.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
537
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
538 @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
539 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
540 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
541 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
542 if proxy_host:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
543 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
544
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
545 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
546 """ Rewrite request_uri, script_name and path_info transparently
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
547
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
548 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
549 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
550
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
551 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
552 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
553 <location> directive::
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
554
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
555 <Location /my/wiki/>
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
556 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
557 </location>
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
558
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
559 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
560 setting custom headers per request.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
561
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
562 @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
563 """
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
564 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
565 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
566 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
567 return
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
568
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
569 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
570 location = location.rstrip('/')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
571 self.script_name = location
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
572
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
573 # 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
574 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
575 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
576
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
577 # 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
578 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
579 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
580
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
581 def makeURI(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
582 """ Return uri created from uri parts """
101
2202f548cbb0 use own urllib wrapper, see wikiutil
Thomas Waldmann <tw@waldmann-edv.de>
parents: 85
diff changeset
583 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
584 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
585 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
586 return uri
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
587
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
588 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
589 """ Return path and query splited from uri
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
590
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
591 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
592 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
593 if '?' in uri:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
594 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
595 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
596 path, query = uri, ''
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
597 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
598
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
599 def _handle_auth_form(self, user_obj):
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
600 username = self.form.get('name', [None])[0]
295
91d47ebee530 make posted UserPreferences form values easily available for auth methods
Thomas Waldmann <tw@waldmann-edv.de>
parents: 290
diff changeset
601 password = self.form.get('password', [None])[0]
2299
39d11cf4af6c OpenID relying party (client) support
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
602 oid = self.form.get('openid_identifier', [None])[0]
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1857
diff changeset
603 login = 'login' in self.form
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1857
diff changeset
604 logout = 'logout' in self.form
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
605 stage = self.form.get('stage', [None])[0]
2030
00f52826b5df allow unattended login (for xmlrpc)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2029
diff changeset
606 return self.handle_auth(user_obj, attended=True, username=username,
00f52826b5df allow unattended login (for xmlrpc)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2029
diff changeset
607 password=password, login=login, logout=logout,
2299
39d11cf4af6c OpenID relying party (client) support
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
608 stage=stage, openid_identifier=oid)
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
609
2030
00f52826b5df allow unattended login (for xmlrpc)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2029
diff changeset
610 def handle_auth(self, user_obj, attended=False, **kw):
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
611 username = kw.get('username')
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
612 password = kw.get('password')
2299
39d11cf4af6c OpenID relying party (client) support
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
613 oid = kw.get('openid_identifier')
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
614 login = kw.get('login')
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
615 logout = kw.get('logout')
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
616 stage = kw.get('stage')
2040
68e302934c77 add cookie back to auth keyword arguments
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2030
diff changeset
617 extra = {
68e302934c77 add cookie back to auth keyword arguments
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2030
diff changeset
618 'cookie': self._cookie,
68e302934c77 add cookie back to auth keyword arguments
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2030
diff changeset
619 }
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
620 if login:
2030
00f52826b5df allow unattended login (for xmlrpc)
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2029
diff changeset
621 extra['attended'] = attended
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
622 extra['username'] = username
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
623 extra['password'] = password
2299
39d11cf4af6c OpenID relying party (client) support
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2286
diff changeset
624 extra['openid_identifier'] = oid
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
625 if stage:
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
626 extra['multistage'] = True
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
627 login_msgs = []
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
628 self._login_multistage = None
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
629
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
630 if logout and 'setuid' in self.session:
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
631 del self.session['setuid']
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
632 return user_obj
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
633
2025
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
634 for authmethod in self.cfg.auth:
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
635 if logout:
2025
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
636 user_obj, cont = authmethod.logout(self, user_obj, **extra)
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
637 elif login:
2025
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
638 if stage and authmethod.name != stage:
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
639 continue
2025
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
640 ret = authmethod.login(self, user_obj, **extra)
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
641 user_obj = ret.user_obj
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
642 cont = ret.continue_flag
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
643 if stage:
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
644 stage = None
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
645 del extra['multistage']
2025
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
646 if ret.multistage:
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
647 self._login_multistage = ret.multistage
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
648 self._login_multistage_name = authmethod.name
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
649 return user_obj
2025
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
650 if ret.redirect_to:
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
651 nextstage = auth.get_multistage_continuation_url(self, authmethod.name)
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
652 url = ret.redirect_to
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
653 url = url.replace('%return_form', quote_plus(nextstage))
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
654 url = url.replace('%return', quote(nextstage))
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
655 self._auth_redirected = True
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
656 self.http_redirect(url)
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
657 return user_obj
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
658 msg = ret.message
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
659 if msg and not msg in login_msgs:
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
660 login_msgs.append(msg)
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
661 else:
2025
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
662 user_obj, cont = authmethod.request(self, user_obj, **extra)
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
663 if not cont:
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
664 break
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
665
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
666 self._login_messages = login_msgs
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
667 return user_obj
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
668
2122
69412724ce93 Make it possible to get an auth token using jid and shared secret.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2040
diff changeset
669 def handle_jid_auth(self, jid):
69412724ce93 Make it possible to get an auth token using jid and shared secret.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2040
diff changeset
670 return user.get_by_jabber_id(self, jid)
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
671
1931
7f87f9d0159e move cookie parsing to request and pass the cookie object (or None) to the
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1918
diff changeset
672 def parse_cookie(self):
7f87f9d0159e move cookie parsing to request and pass the cookie object (or None) to the
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1918
diff changeset
673 try:
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
674 self._cookie = Cookie.SimpleCookie(self.saved_cookie)
1931
7f87f9d0159e move cookie parsing to request and pass the cookie object (or None) to the
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 1918
diff changeset
675 except Cookie.CookieError:
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
676 self._cookie = None
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
677
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
678 def reset(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
679 """ Reset request state.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
680
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
681 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
682 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
683 modified during saving.
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 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
686 # 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
687 # 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
688 # 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
689 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
690
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
691 # caches unique ids
2572
ce0787373150 introduce ID cache in request, make everybody generate valid IDs even inside includes
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2566
diff changeset
692 self.init_unique_ids()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
693
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
694 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
695 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
696
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
697 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
698 """ 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
699
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
700 @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
701 @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
702 @rtype: int
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
703 @return: success code
490
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 483
diff changeset
704 0 on success
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 483
diff changeset
705 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
706 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
707 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
708 fallback = 0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
709 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
710 theme_name = self.cfg.theme_default
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
711
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
712 try:
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
713 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
714 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
715 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
716 try:
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
717 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
718 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
719 fallback = 2
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
720 from MoinMoin.theme.modern import Theme
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
721
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
722 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
723 return fallback
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
724
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
725 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
726 """ 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
727
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
728 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
729 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
730 call send_title!
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 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
733 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
734
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
735 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
736 """ 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
737
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
738 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
739 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
740 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
741
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
742 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
743 """ 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
744
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
745 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
746 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
747 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
748
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
749 def getPathinfo(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
750 """ 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
751 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
752
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
753 def getScriptname(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
754 """ 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
755 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
756 return ''
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
757 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
758
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
759 def getKnownActions(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
760 """ 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
761
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
762 Return cached version if avaiable.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
763
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
764 @rtype: dict
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
765 @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
766 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
767 try:
1550
a4f0632414da using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1549
diff changeset
768 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
769 except AttributeError:
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 623
diff changeset
770 from MoinMoin import action
1550
a4f0632414da using request.cfg.cache more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1549
diff changeset
771 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
772
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
773 # 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
774 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
775
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
776 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
777 """ 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
778
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
779 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
780 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
781
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
782 @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
783 @rtype: dict
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
784 @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
785 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
786 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
787 # 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
788 # Fix *OnNonExistingPage bugs.
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
789 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
790 return []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
791
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
792 # 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
793 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
794 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
795
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
796 # 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
797 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
798
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
799 # 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
800 excluded = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
801 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
802 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
803 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
804 # 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
805 # 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
806 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
807 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
808
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
809 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
810
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
811 # 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
812 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
813
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
814 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
815 """ Redirect output during function, return redirected output """
1986
3475126f78c6 fix some builtin names used as attribute names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
816 buf = StringIO.StringIO()
3475126f78c6 fix some builtin names used as attribute names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
817 self.redirect(buf)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
818 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
819 function(*args, **kw)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
820 finally:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
821 self.redirect()
1986
3475126f78c6 fix some builtin names used as attribute names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
822 text = buf.getvalue()
3475126f78c6 fix some builtin names used as attribute names
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1940
diff changeset
823 buf.close()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
824 return text
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
825
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
826 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
827 """ 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
828 if file:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
829 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
830 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
831 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
832 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
833
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
834 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
835 """ 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
836 destroy output stack
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
837 (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
838 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
839 if self.writestack:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
840 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
841 self.writestack = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
842
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
843 def log(self, msg):
1585
a843bc5793fb introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1580
diff changeset
844 """ 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
845 msg = msg.strip()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
846 # Encode unicode msg
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
847 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
848 msg = msg.encode(config.charset)
1585
a843bc5793fb introduce stdlib's logging module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1580
diff changeset
849 logging.info(msg)
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
850
2208
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
851 def timing_log(self, start, action):
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
852 """ Log to timing log (for performance analysis) """
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
853 indicator = ''
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
854 if start:
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
855 total = "vvv"
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
856 else:
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
857 self.clock.stop('total') # make sure it is stopped
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
858 total_secs = self.clock.timings['total']
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
859 # we add some stuff that is easy to grep when searching for peformance problems:
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
860 if total_secs > 50:
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
861 indicator += '!4!'
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
862 elif total_secs > 20:
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
863 indicator += '!3!'
2208
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
864 elif total_secs > 10:
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
865 indicator += '!2!'
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
866 elif total_secs > 2:
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
867 indicator += '!1!'
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
868 total = self.clock.value('total')
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
869 # use + for existing pages, - for non-existing pages
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
870 indicator += self.page.exists() and '+' or '-'
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
871 if self.isSpiderAgent:
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
872 indicator += "B"
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
873
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
874 # Add time stamp and process ID
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
875 pid = os.getpid()
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
876 t = time.time()
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
877 timestr = time.strftime("%Y%m%d %H%M%S", time.gmtime(t))
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
878 msg = '%s %5d %-6s %4s %-10s %s\n' % (timestr, pid, total, indicator, action, self.url)
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
879 self.log(msg)
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
880
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
881 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
882 """ 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
883 raise NotImplementedError
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
884
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
885 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
886 """ 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
887 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
888 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
889 wd = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
890 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
891 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
892 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
893 # 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
894 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
895 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
896 continue
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
897 wd.append(d)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
898 except UnicodeError:
910
1730c8e75ade use self.log instead stderr in request
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 909
diff changeset
899 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
900 return ''.join(wd)
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
901
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
902 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
903 """ 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
904
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
905 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
906
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
907 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
908 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
909 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
910 an existing page.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
911
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
912 See http://www.w3.org/TR/REC-html40/appendix/notes.html#h-B.2.1
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
913
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
914 @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
915 @rtype: unicode
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
916 @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
917 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
918 # 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
919 pages = name.split('/')
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
920 decoded = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
921 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
922 # 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
923 # 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
924 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
925 try:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
926 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
927 # 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
928 # 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
929 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
930 except UnicodeError:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
931 pass
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
932
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
933 # 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
934 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
935 decoded.append(page)
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
936
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
937 # Assemble decoded parts
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
938 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
939 return name
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
940
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
941 def normalizePagename(self, name):
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
942 """ Normalize page name
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 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
945 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
946 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
947
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
948 Restrict even more group pages, so they can be used inside acl lines.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
949
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
950 @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
951 @rtype: unicode
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
952 @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
953 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
954 # Strip invalid characters
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
955 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
956
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
957 # 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
958 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
959 normalized = []
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
960 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
961 # 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
962 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
963 continue
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 # Cleanup group pages.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
966 # 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
967 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
968 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
969 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
970
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
971 # Normalize white space. Each name can contain multiple
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
972 # 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
973 # 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
974 page = u' '.join(page.split())
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
975
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
976 normalized.append(page)
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
977
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
978 # 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
979 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
980 return name
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
981
1988
dbf2b7426385 fixed some pylint warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1986
diff changeset
982 def read(self, n=None):
616
3b08d9413589 move send_title/footer from wikiutil to theme.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 615
diff changeset
983 """ 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
984 raise NotImplementedError
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
985
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
986 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
987 """ 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
988 raise NotImplementedError
447
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
989
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
990 def check_spider(self):
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
991 """ 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
992 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
993 ua = self.getUserAgent()
1557
60067807cf9a Allow empty strings for ua_spiders.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1553
diff changeset
994 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
995 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
996 return isSpider
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
997
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
998 def isForbidden(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
999 """ 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
1000 forbidden = 0
447
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
1001 # 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
1002 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
1003 action = self.action
447
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
1004 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
1005 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
1006 # 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
1007 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
1008 action != 'show' and
debeeba5cce6 allow sitemap action for spiders
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1657
diff changeset
1009 action != 'sitemap'
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1010 ):
447
e0e016a553bd only check once for spiders
Thomas Waldmann <tw@waldmann-edv.de>
parents: 445
diff changeset
1011 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
1012
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1013 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
1014 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
1015 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
1016 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
1017 forbidden = 1
441
a858267f7dea improved surge protection: dont sleep, add total requests rate
Thomas Waldmann <tw@waldmann-edv.de>
parents: 440
diff changeset
1018 #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
1019 break
a858267f7dea improved surge protection: dont sleep, add total requests rate
Thomas Waldmann <tw@waldmann-edv.de>
parents: 440
diff changeset
1020 if ip == host:
a858267f7dea improved surge protection: dont sleep, add total requests rate
Thomas Waldmann <tw@waldmann-edv.de>
parents: 440
diff changeset
1021 forbidden = 1
a858267f7dea improved surge protection: dont sleep, add total requests rate
Thomas Waldmann <tw@waldmann-edv.de>
parents: 440
diff changeset
1022 #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
1023 break
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1024 return forbidden
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1025
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
1026 def setup_args(self):
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
1027 """ 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
1028 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
1029 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
1030 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
1031 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
1032 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
1033 """
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
1034 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
1035 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
1036 # 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
1037 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
1038 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
1039 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
1040 return args
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1041
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1042 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
1043 """ 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
1044
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
1045 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
1046 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
1047 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
1048
490
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 483
diff changeset
1049 @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
1050 @rtype: dict
490
ca35d9e6d63e eypdoc comments: fixed some warnings/errors
Thomas Waldmann <tw@waldmann-edv.de>
parents: 483
diff changeset
1051 @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
1052 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1053 args = {}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1054 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
1055 values = form[key]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1056 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
1057 values = [values]
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1058 fixedResult = []
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1059 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
1060 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
1061 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
1062 # 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
1063 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
1064 args[key] = fixedResult
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 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
1067
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1068 def decodeArgs(self, args):
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
1069 """ Decode args dict
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
1070
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1071 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
1072 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
1073 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1074 decode = wikiutil.decodeUserInput
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1075 result = {}
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1076 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
1077 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
1078 # 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
1079 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
1080 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
1081 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
1082 else:
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
1083 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
1084 return result
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1085
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1086 def getBaseURL(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1087 """ 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
1088 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
1089
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1090 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
1091 """ 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
1092
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1093 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
1094
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
1095 @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
1096 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
1097 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1098 import urlparse
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1099 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
1100 if scheme:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1101 return uri
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1102
481
285b42d58a45 minor change: fixed some typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 462
diff changeset
1103 scheme = ('http', 'https')[self.is_ssl]
285b42d58a45 minor change: fixed some typos
Thomas Waldmann <tw@waldmann-edv.de>
parents: 462
diff changeset
1104 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
1105
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1106 # 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
1107 # 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
1108 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
1109
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1110 def getUserAgent(self):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1111 """ 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
1112 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
1113
403
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1114 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
1115 statusmsg = {
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
1116 401: 'Authorization required',
403
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1117 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
1118 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
1119 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
1120 }
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
1121 headers = [
403
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1122 '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
1123 '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
1124 ]
311492a91530 add a Retry-After header for 503 result code (surge protection)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 944
diff changeset
1125 # 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
1126 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
1127 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
1128 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
1129 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
1130 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
1131
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1132 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
1133 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
1134
689396849b0a added surge protection code (TODO: configurability), added voyager to bot list
Thomas Waldmann <tw@waldmann-edv.de>
parents: 401
diff changeset
1135 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
1136 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
1137 "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
1138 "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
1139 "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
1140
763d15fbcdfc fixed moin_dump
Thomas Waldmann <tw@waldmann-edv.de>
parents: 236
diff changeset
1141 def initTheme(self):
763d15fbcdfc fixed moin_dump
Thomas Waldmann <tw@waldmann-edv.de>
parents: 236
diff changeset
1142 """ Set theme - forced theme, user theme or wiki default """
763d15fbcdfc fixed moin_dump
Thomas Waldmann <tw@waldmann-edv.de>
parents: 236
diff changeset
1143 if self.cfg.theme_force:
763d15fbcdfc fixed moin_dump
Thomas Waldmann <tw@waldmann-edv.de>
parents: 236
diff changeset
1144 theme_name = self.cfg.theme_default
763d15fbcdfc fixed moin_dump
Thomas Waldmann <tw@waldmann-edv.de>
parents: 236
diff changeset
1145 else:
763d15fbcdfc fixed moin_dump
Thomas Waldmann <tw@waldmann-edv.de>
parents: 236
diff changeset
1146 theme_name = self.user.theme_name
763d15fbcdfc fixed moin_dump
Thomas Waldmann <tw@waldmann-edv.de>
parents: 236
diff changeset
1147 self.loadTheme(theme_name)
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
1148
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1149 def run(self):
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents: 47
diff changeset
1150 # Exit now if __init__ failed or request is forbidden
2025
d919b7b7b3e9 auth framework: login() methods return an object now
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2009
diff changeset
1151 if self.failed or self.forbidden or self._auth_redirected:
612
6a5fa8276bde request.py: only comments and whitespace changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 567
diff changeset
1152 # 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
1153 return self.finish()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1154
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1155 _ = self.getText
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1156 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
1157
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1158 from MoinMoin.Page import Page
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1159
2124
005938143378 Initialize theme eariler, so that it works with xmlrpc getPageHTML
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2122
diff changeset
1160 self.initTheme()
005938143378 Initialize theme eariler, so that it works with xmlrpc getPageHTML
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2122
diff changeset
1161
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
1162 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
1163 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
1164 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
1165 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
1166 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
1167 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
1168 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
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 # parse request data
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1172 try:
2208
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
1173 if self.cfg.log_timing:
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
1174 self.timing_log(True, action)
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
1175
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1176 # 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
1177 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
1178
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
1179 # 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
1180 # 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
1181 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
1182 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
1183 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
1184 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
1185 # 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
1186 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
1187 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
1188 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
1189
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1190 if path.startswith('/'):
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1191 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
1192 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1193 pagename = None
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents: 47
diff changeset
1194
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
1195 # 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
1196 # * 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
1197 # * 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
1198 # * 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
1199 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
1200 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
1201 else:
944
7c8e8d370740 use comma-separated Vary header items
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 942
diff changeset
1202 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
1203
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1204 # Handle request. We have these options:
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
1205 # 1. jump to page where user left off
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
1206 if 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
1207 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
1208 if pagetrail:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1209 # Redirect to last page visited
2728
59b3d8b8971f remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2595
diff changeset
1210 last_visited = pagetrail[-1]
59b3d8b8971f remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2595
diff changeset
1211 wikiname, pagename = wikiutik.split_interwiki(last_visited)
59b3d8b8971f remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2595
diff changeset
1212 if wikiname != 'Self':
59b3d8b8971f remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2595
diff changeset
1213 wikitag, wikiurl, wikitail, error = wikiutil.resolve_interwiki(self, wikiname, pagename)
57
546541209681 fix remember_last_visit(ed page) root url redirect
Thomas Waldmann <tw@waldmann-edv.de>
parents: 53
diff changeset
1214 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
1215 else:
2728
59b3d8b8971f remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2595
diff changeset
1216 url = Page(self, pagename).url(self, relative=False)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1217 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1218 # Or to localized FrontPage
1816
4a31739bc6e1 Page.url(): removed escaping support
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1805
diff changeset
1219 url = wikiutil.getFrontPage(self).url(self, relative=False)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1220 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
1221 return self.finish()
908
75df9c6c20bc removed some trailing whitespace
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 888
diff changeset
1222
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
1223 # 2. 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
1224 else:
95fb435b72aa refactor: use show action when no action is given
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 613
diff changeset
1225 # 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
1226 # 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
1227 if not pagename:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1228 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
1229 else:
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1230 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
1231
1013
289254f32ab2 refactored action error msg output
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1012
diff changeset
1232 msg = None
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1233 # 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
1234 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
1235 msg = _("Unknown action %(action_name)s.") % {
289254f32ab2 refactored action error msg output
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1012
diff changeset
1236 '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
1237
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1238 # 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
1239 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
1240 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
1241 '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
1242 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
1243 # 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
1244 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
1245
289254f32ab2 refactored action error msg output
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1012
diff changeset
1246 if msg:
1789
8da1d5df4b90 send_page: remove some more call's request param (see cs 1777)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1784
diff changeset
1247 self.page.send_page(msg=msg)
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1248
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1249 # Try action
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1250 else:
636
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 623
diff changeset
1251 from MoinMoin import action
b77ab6ea0c18 move wikiaction.py to action/__init__.py
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 623
diff changeset
1252 handler = action.getHandler(self, action_name)
1541
b54e89c69227 handle exluded lowercase action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1398
diff changeset
1253 if handler is None:
b54e89c69227 handle exluded lowercase action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1398
diff changeset
1254 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
1255 'action_name': wikiutil.escape(action_name), }
b54e89c69227 handle exluded lowercase action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1398
diff changeset
1256 if not self.user.valid:
b54e89c69227 handle exluded lowercase action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1398
diff changeset
1257 # Suggest non valid user to login
b54e89c69227 handle exluded lowercase action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1398
diff changeset
1258 msg += " " + _("Login and try again.", formatted=0)
1789
8da1d5df4b90 send_page: remove some more call's request param (see cs 1777)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1784
diff changeset
1259 self.page.send_page(msg=msg)
1541
b54e89c69227 handle exluded lowercase action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1398
diff changeset
1260 else:
b54e89c69227 handle exluded lowercase action
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1398
diff changeset
1261 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
1262
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
1263 # every action that didn't use to raise MoinMoinFinish must call this now:
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
1264 # 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
1265
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
1266 except MoinMoinFinish:
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1267 pass
49
cf52f97a5857 merge moin--main--1.3--patch-928
Nir Soffer <nirs@freeshell.org>
parents: 47
diff changeset
1268 except Exception, err:
2573
fd896a933d58 fcgi completely stops output at request.finish()
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2572
diff changeset
1269 self.fail(err)
2009
1b14cc05a54a refactor authentication and split out session handling
Johannes Berg <johannes AT sipsolutions DOT net>
parents: 2008
diff changeset
1270 self.finish()
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1271
2208
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
1272 if self.cfg.log_timing:
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
1273 self.timing_log(False, action)
2f7f195f4dd2 log timing (using std logging)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2124
diff changeset
1274
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1275 return self.finish()
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1276
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1277 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
1278 """ Redirect to a fully qualified, or server-rooted URL
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
1279
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1280 @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
1281 """
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1282 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
1283 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
1284
2892
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2844
diff changeset
1285 def emit_http_headers(self, more_headers=[], testing=False):
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
1286 """ 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
1287
1103
fe874e9e72c7 fix comments in emit_http_headers
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1102
diff changeset
1288 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
1289 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
1290 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
1291 Make sure Status header string begins with a integer number.
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2254
diff changeset
1292
2892
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2844
diff changeset
1293 For emitting (testing == False), it calls the server specific
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2844
diff changeset
1294 _emit_http_headers method. For testing, it returns the result.
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
1295
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
1296 @param more_headers: list of additional header strings
2894
f009ead62bfd PEP8 fixes
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 2893
diff changeset
1297 @param testing: set to True by test code
1061
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1298 """
2892
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2844
diff changeset
1299 user_headers = self.user_headers
1071
64e513264aed cleanup, less header logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1070
diff changeset
1300 self.user_headers = []
1073
a6bb4df3888d fix http headers bug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1071
diff changeset
1301 all_headers = more_headers + user_headers
1071
64e513264aed cleanup, less header logging
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1070
diff changeset
1302
2892
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2844
diff changeset
1303 if self.sent_headers:
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2844
diff changeset
1304 # Send headers only once
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2844
diff changeset
1305 raise HeadersAlreadySentException("emit_http_headers has already been called before! Headers: %r" % all_headers)
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2844
diff changeset
1306 else:
863060b2cfc5 cleanup http header emission, support list-type headers, add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2844
diff changeset
1307 self.sent_headers = True
1061
0f18462344f8 refactored http header emitting code, CGI works, others untested
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1049
diff changeset
1308
2844
34632d44f50f Fix: do not emit duplicate keys in http headers, log warning
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728