Back to index

moin  1.9.0~rc2
Classes | Functions | Variables
MoinMoin.web.serving Namespace Reference

Classes

class  RequestHandler
class  ProxyTrust

Functions

def make_application
def switch_user
def run_server

Variables

tuple logging = log.getLogger(__name__)

Function Documentation

def MoinMoin.web.serving.make_application (   shared = None,
  trusted_proxies = None 
)
Make an instance of the MoinMoin WSGI application. This involves
wrapping it in middlewares as needed (static files, debugging, etc.).

@param shared: see MoinMoin.web.static.make_static_serving_app.
               If falsy, do not use static serving app.
@param trusted_proxies: list of trusted proxies. If None or empty, do not
                        use the ProxyTrust middleware.
@rtype: callable
@return: a WSGI callable

Definition at line 70 of file serving.py.

00070 
00071 def make_application(shared=None, trusted_proxies=None):
00072     """
00073     Make an instance of the MoinMoin WSGI application. This involves
00074     wrapping it in middlewares as needed (static files, debugging, etc.).
00075 
00076     @param shared: see MoinMoin.web.static.make_static_serving_app.
00077                    If falsy, do not use static serving app.
00078     @param trusted_proxies: list of trusted proxies. If None or empty, do not
00079                             use the ProxyTrust middleware.
00080     @rtype: callable
00081     @return: a WSGI callable
00082     """
00083     from MoinMoin.wsgiapp import application
00084 
00085     if trusted_proxies:
00086         application = ProxyTrust(application, trusted_proxies)
00087 
00088     if shared:
00089         from MoinMoin.web.static import make_static_serving_app
00090         application = make_static_serving_app(application, shared)
00091 
00092     return application

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.web.serving.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. 

Definition at line 136 of file serving.py.

00136 
00137                **kw):
00138     """ Run a standalone server on specified host/port. """
00139     application = make_application(shared=docs)
00140 
00141     if port < 1024 and os.getuid() != 0:
00142         raise RuntimeError('Must run as root to serve port number under 1024. '
00143                            'Run as root or change port setting.')
00144 
00145     if user:
00146         switch_user(user, group)
00147 
00148     if debug == 'external':
00149         # no threading is better for debugging, the main (and only)
00150         # thread then will just terminate when an exception happens
00151         threaded = False
00152 
00153     run_simple(hostname=hostname, port=port,
00154                application=application,
00155                threaded=threaded,
00156                use_debugger=(debug == 'web'),
00157                passthrough_errors=(debug == 'external'),
00158                request_handler=RequestHandler,
00159                **kw)
00160 

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.web.serving.switch_user (   uid,
  gid = None 
)
Switch identity to safe user and group

Does not support Windows, because the necessary calls are not available.
TODO: can we use win32api calls to achieve the same effect on Windows?

Raise RuntimeError if can't switch or trying to switch to root.

Definition at line 93 of file serving.py.

00093 
00094 def switch_user(uid, gid=None):
00095     """ Switch identity to safe user and group
00096 
00097     Does not support Windows, because the necessary calls are not available.
00098     TODO: can we use win32api calls to achieve the same effect on Windows?
00099 
00100     Raise RuntimeError if can't switch or trying to switch to root.
00101     """
00102     # no switch on windows
00103     if os.name == 'nt':
00104         return
00105 
00106     import pwd, grp
00107     if isinstance(uid, basestring):
00108         try:
00109             uid = pwd.getpwnam(uid)[2]
00110         except KeyError:
00111             raise RuntimeError("Unknown user: '%s', check user setting" % uid)
00112     if gid is not None and isinstance(gid, basestring):
00113         try:
00114             gid = grp.getgrnam(gid)[2]
00115         except KeyError:
00116             raise RuntimeError("Unknown group: '%s', check group setting" % gid)
00117 
00118     if uid == 0 or gid == 0:
00119         # We will not run as root. If you like to run a web
00120         # server as root, then hack this code.
00121         raise RuntimeError('will not run as root!')
00122     try:
00123         if gid:
00124             os.setgid(gid)
00125         os.setuid(uid)
00126     except (OSError, AttributeError):
00127         # Either we can't switch, or we are on windows, which does not have
00128         # those calls.
00129         raise RuntimeError("can't change uid/gid to %s/%s" % (uid, gid))
00130     logging.info("Running as uid/gid %d/%d" % (uid, gid))

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 15 of file serving.py.