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

reset our umask on every request, should fix umask problems with twistd (ported from 1.5-797)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 30 Jan 2007 22:12:52 +0100
parents 66f2ea899da7
children 2668d470091f
comparison
equal deleted inserted replaced
1760:29595129bb5b 1761:9dc115f468e4
19 from MoinMoin import config, wikiutil, user, caching, error 19 from MoinMoin import config, wikiutil, user, caching, error
20 from MoinMoin.config import multiconfig 20 from MoinMoin.config import multiconfig
21 from MoinMoin.util import IsWin9x 21 from MoinMoin.util import IsWin9x
22 22
23 # umask setting -------------------------------------------------------- 23 # umask setting --------------------------------------------------------
24 # We do this once per Python process, when request is imported: 24 def set_umask(new_mask=0777^config.umask):
25 try: 25 """ Set the OS umask value (and ignore potential failures on OSes where
26 # we need to use a bitwise inverted value of config.umask 26 this is not supported).
27 os.umask(0777 ^ config.umask) 27 Default: the bitwise inverted value of config.umask
28 except: # we are on win32 28 """
29 pass 29 try:
30 old_mask = os.umask(new_mask)
31 except:
32 # maybe we are on win32?
33 pass
34
35 # We do this at least once per Python process, when request is imported.
36 # If other software parts (like twistd's daemonize() function) set an
37 # unwanted umask, we have to call this again to set the correct one:
38 set_umask()
30 39
31 # Exceptions ----------------------------------------------------------- 40 # Exceptions -----------------------------------------------------------
32 41
33 class MoinMoinFinish(Exception): 42 class MoinMoinFinish(Exception):
34 """ Raised to jump directly to end of run() function, where finish is called """ 43 """ Raised to jump directly to end of run() function, where finish is called """
120 # headers as lowercase. 129 # headers as lowercase.
121 moin_location = 'x-moin-location' 130 moin_location = 'x-moin-location'
122 proxy_host = 'x-forwarded-host' 131 proxy_host = 'x-forwarded-host'
123 132
124 def __init__(self, properties={}): 133 def __init__(self, properties={}):
134
135 # twistd's daemonize() overrides our umask, so we reset it here every
136 # request. we do it for all request types to avoid similar problems.
137 set_umask()
138
125 # Decode values collected by sub classes 139 # Decode values collected by sub classes
126 self.path_info = self.decodePagename(self.path_info) 140 self.path_info = self.decodePagename(self.path_info)
127 141
128 self.failed = 0 142 self.failed = 0
129 self._available_actions = None 143 self._available_actions = None