changeset 5038:6035cb0345db

merged moin/1.9
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Wed, 26 Aug 2009 14:05:42 +0200
parents 712677d7023c (current diff) 23654939130a (diff)
children 636ba2c195be
files
diffstat 7 files changed, 94 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/Page.py	Tue Aug 25 13:39:36 2009 +0200
+++ b/MoinMoin/Page.py	Wed Aug 26 14:05:42 2009 +0200
@@ -961,14 +961,15 @@
         pi['acl'] = security.AccessControlList(request.cfg, acl)
         return pi
 
-    def send_raw(self, content_disposition=None):
+    def send_raw(self, content_disposition=None, mimetype=None):
         """ Output the raw page data (action=raw).
             With no content_disposition, the browser usually just displays the
             data on the screen, with content_disposition='attachment', it will
             offer a dialogue to save it to disk (used by Save action).
+            Supplied mimetype overrides default text/plain.
         """
         request = self.request
-        request.mimetype = 'text/plain'
+        request.mimetype = mimetype or 'text/plain'
         if self.exists():
             # use the correct last-modified value from the on-disk file
             # to ensure cacheability where supported. Because we are sending
--- a/MoinMoin/action/__init__.py	Tue Aug 25 13:39:36 2009 +0200
+++ b/MoinMoin/action/__init__.py	Wed Aug 26 14:05:42 2009 +0200
@@ -27,6 +27,8 @@
     @license: GNU GPL, see COPYING for details.
 """
 
+import re
+
 from MoinMoin.util import pysupport
 from MoinMoin import config, wikiutil
 from MoinMoin.Page import Page
@@ -228,13 +230,18 @@
 
 # Builtin Actions ------------------------------------------------------------
 
+MIMETYPE_CRE = re.compile('[a-zA-Z0-9.+\-]{1,100}/[a-zA-Z0-9.+\-]{1,100}')
+
 def do_raw(pagename, request):
     """ send raw content of a page (e.g. wiki markup) """
     if not request.user.may.read(pagename):
         Page(request, pagename).send_page()
     else:
         rev = request.rev or 0
-        Page(request, pagename, rev=rev).send_raw()
+        mimetype = request.values.get('mimetype', None)
+        if mimetype and not MIMETYPE_CRE.match(mimetype):
+            mimetype = None
+        Page(request, pagename, rev=rev).send_raw(mimetype=mimetype)
 
 def do_show(pagename, request, content_only=0, count_hit=1, cacheable=1, print_mode=0, mimetype=u'text/html'):
     """ show a page, either current revision or the revision given by "rev=" value.
--- a/MoinMoin/filter/application_vnd_oasis_opendocument.py	Tue Aug 25 13:39:36 2009 +0200
+++ b/MoinMoin/filter/application_vnd_oasis_opendocument.py	Wed Aug 26 14:05:42 2009 +0200
@@ -21,8 +21,8 @@
         data = zf.read("content.xml")
         zf.close()
         data = " ".join(rx_stripxml.sub(" ", data).split())
-    except RuntimeError, err:
-        logging.error(str(err))
+    except (zipfile.BadZipfile, RuntimeError), err:
+        logging.error("%s [%s]" % (str(err), filename))
         data = ""
     return data.decode('utf-8')
 
--- a/MoinMoin/filter/application_vnd_sun_xml.py	Tue Aug 25 13:39:36 2009 +0200
+++ b/MoinMoin/filter/application_vnd_sun_xml.py	Wed Aug 26 14:05:42 2009 +0200
@@ -21,8 +21,8 @@
         data = zf.read("content.xml")
         zf.close()
         data = " ".join(rx_stripxml.sub(" ", data).split())
-    except RuntimeError, err:
-        logging.error(str(err))
+    except (zipfile.BadZipfile, RuntimeError), err:
+        logging.error("%s [%s]" % (str(err), filename))
         data = ""
     return data.decode('utf-8')
 
--- a/MoinMoin/script/server/standalone.py	Tue Aug 25 13:39:36 2009 +0200
+++ b/MoinMoin/script/server/standalone.py	Wed Aug 26 14:05:42 2009 +0200
@@ -34,8 +34,8 @@
             help="Set the port to listen on. Default: 8080"
         )
         self.parser.add_option(
-            "--interface", dest="interface",
-            help="Set the ip to listen on. Use \"\" for all interfaces. Default: localhost"
+            "--hostname", "--interface", dest="hostname",
+            help="Set the ip/hostname to listen on. Use \"\" for all interfaces. Default: localhost"
         )
         self.parser.add_option(
             "--start", dest="start", action="store_true",
@@ -88,33 +88,43 @@
                     raise
 
             # intialize some defaults if missing
-            for option in ('docs', 'user', 'group', 'port', 'interface', 'debug'):
-                if not hasattr(Config, option):
-                    value = getattr(DefaultConfig, option)
-                    setattr(Config, option, value)
+            kwargs = {}
+            for option in ('user', 'group',
+                           'hostname', 'port',
+                           'threaded', 'processes',
+                           'debug', 'use_evalex',
+                           'use_reloader', 'extra_files', 'reloader_interval',
+                           'docs', 'static_files', ):
+                if hasattr(Config, option):
+                    kwargs[option] = getattr(Config, option)
+                else:
+                    # usually inheriting from DefaultConfig should make this superfluous,
+                    # but who knows what users write into their config...
+                    kwargs[option] = getattr(DefaultConfig, option)
 
-            # override with cmdline options
+            # override config settings with cmdline options:
             if self.options.docs:
-                Config.docs = self.options.docs
+                kwargs['docs'] = self.options.docs
             if self.options.user:
-                Config.user = self.options.user
+                kwargs['user'] = self.options.user
             if self.options.group:
-                Config.group = self.options.group
+                kwargs['group'] = self.options.group
+            if self.options.debug:
+                kwargs['debug'] = self.options.debug
+
+            if self.options.hostname is not None: # needs to work for "" value also
+                kwargs['hostname'] = self.options.hostname
             if self.options.port:
-                Config.port = self.options.port
-            if self.options.interface is not None: # needs to work for "" value also
-                Config.interface = self.options.interface
-            if self.options.debug:
-                Config.debug = self.options.debug
+                kwargs['port'] = self.options.port
 
             if self.options.start:
-                daemon = Daemon('moin', pidfile, run_server, Config)
+                daemon = Daemon('moin', pidfile, run_server, **kwargs)
                 daemon.do_start()
             else:
-                run_server(Config.interface, Config.port, Config.docs,
-                           debug=Config.debug, user=Config.user, group=Config.group)
+                run_server(**kwargs)
 
-class DefaultConfig:
+
+class DefaultConfig(object):
     # where the static data is served from - you can either use:
     # docs = True  # serve the builtin static data from MoinMoin/web/static/htdocs/
     # docs = '/where/ever/you/like/to/keep/htdocs'  # serve it from the given path
@@ -122,9 +132,38 @@
     #               # you serve them in some other working way)
     docs = True
 
+    # user and group to run moin as:
     user = None
     group = None
-    port = 8080
-    interface = 'localhost'
+
+    # debugging options: 'off', 'web', 'external'
     debug = 'off'
 
+    # should the exception evaluation feature be enabled?
+    use_evalex = True
+
+    # Werkzeug run_simple arguments below here:
+
+    # hostname/ip and port the server listens on:
+    hostname = 'localhost'
+    port = 8080
+
+    # either multi-thread or multi-process (not both):
+    # threaded = True, processes = 1 is usually what you want
+    # threaded = False, processes = 10 (for example) can be rather slow
+    # thus, if you need a forking server, maybe rather use apache/mod-wsgi!
+    threaded = True
+    processes = 1
+
+    # automatic code reloader - needs testing!
+    use_reloader = False
+    extra_files = None
+    reloader_interval = 1
+
+    # we can't use static_files to replace our own middleware setup for moin's
+    # static files, because we also need the setup with other servers (like
+    # apache), not just when using werkzeug's run_simple server.
+    # But you can use it if you need to serve other static files you just need
+    # with the standalone wikiserver.
+    static_files = None
+
--- a/MoinMoin/web/serving.py	Tue Aug 25 13:39:36 2009 +0200
+++ b/MoinMoin/web/serving.py	Wed Aug 26 14:05:42 2009 +0200
@@ -128,8 +128,12 @@
         raise RuntimeError("can't change uid/gid to %s/%s" % (uid, gid))
     logging.info("Running as uid/gid %d/%d" % (uid, gid))
 
-def run_server(host='localhost', port=8080, docs=True,
-               threaded=True, debug='off', user=None, group=None):
+def run_server(hostname='localhost', port=8080,
+               docs=True,
+               debug='off',
+               user=None, group=None,
+               threaded=True,
+               **kw):
     """ Run a standalone server on specified host/port. """
     application = make_application(shared=docs)
 
@@ -145,8 +149,11 @@
         # thread then will just terminate when an exception happens
         threaded = False
 
-    run_simple(host, port, application, threaded=threaded,
+    run_simple(hostname=hostname, port=port,
+               application=application,
+               threaded=threaded, 
                use_debugger=(debug == 'web'),
                passthrough_errors=(debug == 'external'),
-               request_handler=RequestHandler)
+               request_handler=RequestHandler,
+               **kw)
 
--- a/wikiserverconfig.py	Tue Aug 25 13:39:36 2009 +0200
+++ b/wikiserverconfig.py	Wed Aug 26 14:05:42 2009 +0200
@@ -7,28 +7,19 @@
 from MoinMoin.script.server.standalone import DefaultConfig
 
 class LocalConfig(DefaultConfig):
-    port = 8080 # if you use port < 1024, you need to start as root
+    # hostname or IP the server listens on
+    # use '' for all interfaces
+    # or "1.2.3.4" for some specific IP
+    #hostname = 'localhost'
+
+    # if you use port < 1024, you need to start as root
+    #port = 8080
 
     # if you start the server as root, the standalone server can change
     # to this user and group, e.g. 'www-data'
     #user = ''
     #group = ''
 
-    # use '' for all interface or "1.2.3.4" for some specific IP
-    #interface = 'localhost'
-
-    # where the static data is served from - you can either use:
-    # docs = True  # serve the builtin static data from MoinMoin/web/static/htdocs
-    # docs = '/where/ever/you/like/to/keep/htdocs'  # serve it from the given path
-    # docs = False  # do not serve static files at all (will not work except
-    #               # you serve them in some other working way)
-    docs = True
-
-    # tuning options:
-    #serverClass = 'ThreadPoolServer'
-    #threadLimit = 10
-    #requestQueueSize = 50
-
     # How to debug? Your options:
     # debug = 'off' # for production wikis, exceptions are logged
     # debug = 'web' # show traceback in the browser, offer debug console,
@@ -41,6 +32,7 @@
     # environment variable MOIN_DEBUGGER. If not set, it means the same as 'off'.
     debug = os.environ.get('MOIN_DEBUGGER', 'off')
 
+
 # DEVELOPERS! Do not add your configuration items there,
 # you could accidentally commit them! Instead, create a
 # wikiserverconfig_local.py file containing this: