Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Static Public Attributes | Properties
MoinMoin.web.contexts.ScriptContext Class Reference
Inheritance diagram for MoinMoin.web.contexts.ScriptContext:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.web.contexts.ScriptContext:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def write
def __getattr__
def read
def makeForbidden
def setHttpHeader
def disableHttpCaching
def http_redirect
def redirectedOutput
def redirect
def send_file
def getScriptname
def getBaseURL
def getQualifiedURL
def cfg
def getText
def isSpiderAgent
def rootpage
def rev
def setContentLanguage
def initTheme
def become
def __repr__
def uid_generator
def dicts
def groups
def reset
def getPragma
def setPragma

Public Attributes

 write
 content_lang
 current_lang
 current_lang
 request
 environ
 personalities

Static Public Attributes

tuple session = EnvironProxy('session')
tuple cacheable = EnvironProxy('old.cacheable', 0)
tuple writestack = EnvironProxy('old.writestack', lambda o: list())
tuple content_type = _proxy('content_type')
tuple status = _proxy('status')
tuple status_code = _proxy('status_code')
tuple action = EnvironProxy('action', lambda o: o.request.values.get('action', 'show'))
tuple clock = EnvironProxy('clock', lambda o: Clock())
tuple user = EnvironProxy('user', lambda o: user.User(o, auth_method='request:invalid'))
tuple lang = EnvironProxy('lang')
tuple content_lang = EnvironProxy('content_lang', lambda o: o.cfg.language_default)
tuple current_lang = EnvironProxy('current_lang')
tuple html_formatter = EnvironProxy('html_formatter', lambda o: text_html.Formatter(o))
tuple formatter = EnvironProxy('formatter', lambda o: o.html_formatter)
tuple page = EnvironProxy('page', None)
tuple cfg = EnvironProxy(cfg)
tuple isSpiderAgent = EnvironProxy(isSpiderAgent)
tuple rootpage = EnvironProxy(rootpage)
tuple rev = EnvironProxy(rev)
tuple theme = EnvironProxy('theme', _theme)
tuple parsePageLinks_running = EnvironProxy('parsePageLinks_running', lambda o: {})
tuple mode_getpagelinks = EnvironProxy('mode_getpagelinks', 0)
tuple pragma = EnvironProxy('pragma', lambda o: {})
tuple pages = EnvironProxy('pages', lambda o: {})
tuple uid_generator = EnvironProxy(uid_generator)
tuple dicts = EnvironProxy(dicts)
tuple groups = EnvironProxy(groups)

Properties

 getText = property(getText)

Detailed Description

Context to act in scripting environments (e.g. former request_cli).

For input, sys.stdin is used as 'wsgi.input', output is written directly
to sys.stdout though.

Definition at line 411 of file contexts.py.


Constructor & Destructor Documentation

def MoinMoin.web.contexts.ScriptContext.__init__ (   self,
  url = None,
  pagename = '' 
)

Definition at line 417 of file contexts.py.

00417 
00418     def __init__(self, url=None, pagename=''):
00419         if url is None:
00420             url = 'http://localhost:0/' # just some somehow valid dummy URL
00421         environ = create_environ(base_url=url) # XXX not sure about base_url, but makes "make underlay" work
00422         environ['HTTP_USER_AGENT'] = 'CLI/Script'
00423         environ['wsgi.input'] = sys.stdin
00424         request = Request(environ)
00425         super(ScriptContext, self).__init__(request)
00426         from MoinMoin import wsgiapp
00427         wsgiapp.init(self)

Here is the call graph for this function:


Member Function Documentation

def MoinMoin.web.contexts.HTTPContext.__getattr__ (   self,
  name 
) [inherited]

Definition at line 220 of file contexts.py.

00220 
00221     def __getattr__(self, name):
00222         try:
00223             return getattr(self.request, name)
00224         except AttributeError, e:
00225             return super(HTTPContext, self).__getattribute__(name)

def MoinMoin.web.contexts.Context.__repr__ (   self) [inherited]

Definition at line 101 of file contexts.py.

00101 
00102     def __repr__(self):
00103         return "<%s %r>" % (self.__class__.__name__, self.personalities)

def MoinMoin.web.contexts.Context.become (   self,
  cls 
) [inherited]
Become another context, based on given class.

@param cls: class to change to, must be a sister class
@rtype: boolean
@return: wether a class change took place

Definition at line 87 of file contexts.py.

00087 
00088     def become(self, cls):
00089         """ Become another context, based on given class.
00090 
00091         @param cls: class to change to, must be a sister class
00092         @rtype: boolean
00093         @return: wether a class change took place
00094         """
00095         if self.__class__ is cls:
00096             return False
00097         else:
00098             self.personalities.append(cls)
00099             self.__class__ = cls
00100             return True

def MoinMoin.web.contexts.BaseContext.cfg (   self) [inherited]

Definition at line 123 of file contexts.py.

00123 
00124     def cfg(self):
00125         if self.request.given_config is not None:
00126             return self.request.given_config('MoinMoin._tests.wikiconfig')
00127         try:
00128             self.clock.start('load_multi_cfg')
00129             cfg = multiconfig.getConfig(self.request.url)
00130             self.clock.stop('load_multi_cfg')
00131             return cfg
00132         except error.NoConfigMatchedError:
            raise NotFound('<p>No wiki configuration matching the URL found!</p>')
def MoinMoin.web.contexts.AuxilaryMixin.dicts (   self) [inherited]
Lazy initialize the dicts on the first access 

Definition at line 372 of file contexts.py.

00372 
00373     def dicts(self):
00374         """ Lazy initialize the dicts on the first access """
00375         dicts = self.cfg.dicts(self)
        return dicts
def MoinMoin.web.contexts.HTTPContext.disableHttpCaching (   self,
  level = 1 
) [inherited]
Prevent caching of pages that should not be cached.

level == 1 means disabling caching when we have a cookie set
level == 2 means completely disabling caching (used by Page*Editor)

This is important to prevent caches break acl by providing one
user pages meant to be seen only by another user, when both users
share the same caching proxy.

AVOID using no-cache and no-store for attachments as it is completely broken on IE!

Details: http://support.microsoft.com/support/kb/articles/Q234/0/67.ASP

Definition at line 245 of file contexts.py.

00245 
00246     def disableHttpCaching(self, level=1):
00247         """ Prevent caching of pages that should not be cached.
00248 
00249         level == 1 means disabling caching when we have a cookie set
00250         level == 2 means completely disabling caching (used by Page*Editor)
00251 
00252         This is important to prevent caches break acl by providing one
00253         user pages meant to be seen only by another user, when both users
00254         share the same caching proxy.
00255 
00256         AVOID using no-cache and no-store for attachments as it is completely broken on IE!
00257 
00258         Details: http://support.microsoft.com/support/kb/articles/Q234/0/67.ASP
00259         """
00260         if level == 1 and self.headers.get('Pragma') == 'no-cache':
00261             return
00262 
00263         if level == 1:
00264             self.headers.set('Cache-Control', 'private, must-revalidate, max-age=10')
00265         elif level == 2:
00266             self.headers.set('Cache-Control', 'no-cache')
00267             self.headers.set('Pragma', 'no-cache')
00268         self.request.expires = time.time() - 3600 * 24 * 365

Definition at line 319 of file contexts.py.

00319 
00320     def getBaseURL(self):
00321         warnings.warn(
00322             "request.getBaseURL() is deprecated, please use the request's "
00323             "url_root property or the abs_href object if urls should be generated.",
00324             DeprecationWarning)
00325         return self.request.url_root

def MoinMoin.web.contexts.AuxilaryMixin.getPragma (   self,
  key,
  defval = None 
) [inherited]
Query a pragma value (#pragma processing instruction)

    Keys are not case-sensitive.

Definition at line 391 of file contexts.py.

00391 
00392     def getPragma(self, key, defval=None):
00393         """ Query a pragma value (#pragma processing instruction)
00394 
00395             Keys are not case-sensitive.
00396         """
00397         return self.pragma.get(key.lower(), defval)

def MoinMoin.web.contexts.HTTPContext.getQualifiedURL (   self,
  uri = '' 
) [inherited]
Return an absolute URL starting with schema and host.

Already qualified urls are returned unchanged.

@param uri: server rooted uri e.g /scriptname/pagename.
    It must start with a slash. Must be ascii and url encoded.

Definition at line 326 of file contexts.py.

00326 
00327     def getQualifiedURL(self, uri=''):
00328         """ Return an absolute URL starting with schema and host.
00329 
00330         Already qualified urls are returned unchanged.
00331 
00332         @param uri: server rooted uri e.g /scriptname/pagename.
00333                     It must start with a slash. Must be ascii and url encoded.
00334         """
00335         import urlparse
00336         scheme = urlparse.urlparse(uri)[0]
00337         if scheme:
00338             return uri
00339 
00340         host_url = self.request.host_url.rstrip('/')
00341         result = "%s%s" % (host_url, uri)
00342 
00343         # This might break qualified urls in redirects!
00344         # e.g. mapping 'http://netloc' -> '/'
00345         result = wikiutil.mapURL(self, result)
00346         return result

Definition at line 313 of file contexts.py.

00313 
00314     def getScriptname(self):
00315         warnings.warn(
00316             "request.getScriptname() is deprecated, please use the request's script_root property.",
00317             DeprecationWarning)
00318         return self.request.script_root

def MoinMoin.web.contexts.BaseContext.getText (   self) [inherited]

Definition at line 135 of file contexts.py.

00135 
00136     def getText(self):
00137         lang = self.lang
00138         def _(text, i18n=i18n, request=self, lang=lang, **kw):
00139             return i18n.getText(text, request, lang, **kw)
00140         return _

def MoinMoin.web.contexts.AuxilaryMixin.groups (   self) [inherited]
Lazy initialize the groups on the first access 

Definition at line 378 of file contexts.py.

00378 
00379     def groups(self):
00380         """ Lazy initialize the groups on the first access """
00381         groups = self.cfg.groups(self)
        return groups
def MoinMoin.web.contexts.HTTPContext.http_redirect (   self,
  url,
  code = 302 
) [inherited]
Raise a simple redirect exception. 

Definition at line 269 of file contexts.py.

00269 
00270     def http_redirect(self, url, code=302):
00271         """ Raise a simple redirect exception. """
00272         abort(redirect(url, code=code))

Here is the call graph for this function:

def MoinMoin.web.contexts.BaseContext.initTheme (   self) [inherited]
Set theme - forced theme, user theme or wiki default 

Definition at line 181 of file contexts.py.

00181 
00182     def initTheme(self):
00183         """ Set theme - forced theme, user theme or wiki default """
00184         if self.cfg.theme_force:
00185             theme_name = self.cfg.theme_default
00186         else:
00187             theme_name = self.user.theme_name
00188         load_theme_fallback(self, theme_name)
00189 

Here is the call graph for this function:

Here is the caller graph for this function:

Simple check if useragent is a spider bot. 

Definition at line 144 of file contexts.py.

00144 
00145     def isSpiderAgent(self):
00146         """ Simple check if useragent is a spider bot. """
00147         cfg = self.cfg
00148         user_agent = self.request.user_agent
00149         if user_agent and cfg.cache.ua_spiders:
00150             return cfg.cache.ua_spiders.search(user_agent.browser) is not None
        return False
def MoinMoin.web.contexts.HTTPContext.makeForbidden (   self,
  resultcode,
  msg 
) [inherited]

Definition at line 234 of file contexts.py.

00234 
00235     def makeForbidden(self, resultcode, msg):
00236         status = {401: Unauthorized,
00237                   403: Forbidden,
00238                   404: NotFound,
00239                   503: SurgeProtection}
00240         raise status[resultcode](msg)

def MoinMoin.web.contexts.HTTPContext.read (   self,
  n = None 
) [inherited]
Read n bytes (or everything) from input stream. 

Definition at line 227 of file contexts.py.

00227 
00228     def read(self, n=None):
00229         """ Read n bytes (or everything) from input stream. """
00230         if n is None:
00231             return self.request.in_data
00232         else:
00233             return self.request.in_stream.read(n)

def MoinMoin.web.contexts.HTTPContext.redirect (   self,
  file = None 
) [inherited]
Redirect output to file, or restore saved output 

Definition at line 290 of file contexts.py.

00290 
00291     def redirect(self, file=None):
00292         """ Redirect output to file, or restore saved output """
00293         if file:
00294             self.writestack.append(self.write)
00295             self.write = file.write
00296         else:
00297             self.write = self.writestack.pop()

Here is the caller graph for this function:

def MoinMoin.web.contexts.HTTPContext.redirectedOutput (   self,
  function,
  args,
  kw 
) [inherited]
Redirect output during function, return redirected output 

Definition at line 278 of file contexts.py.

00278 
00279     def redirectedOutput(self, function, *args, **kw):
00280         """ Redirect output during function, return redirected output """
00281         buf = StringIO.StringIO()
00282         self.redirect(buf)
00283         try:
00284             function(*args, **kw)
00285         finally:
00286             self.redirect()
00287         text = buf.getvalue()
00288         buf.close()
00289         return text

Here is the call graph for this function:

def MoinMoin.web.contexts.AuxilaryMixin.reset (   self) [inherited]

Definition at line 384 of file contexts.py.

00384 
00385     def reset(self):
00386         self.current_lang = self.cfg.language_default
00387         if hasattr(self, '_fmt_hd_counters'):
00388             del self._fmt_hd_counters
00389         if hasattr(self, 'uid_generator'):
00390             del self.uid_generator

def MoinMoin.web.contexts.BaseContext.rev (   self) [inherited]

Definition at line 158 of file contexts.py.

00158 
00159     def rev(self):
00160         try:
00161             return int(self.values['rev'])
00162         except:
            return None

Here is the call graph for this function:

def MoinMoin.web.contexts.BaseContext.rootpage (   self) [inherited]

Definition at line 153 of file contexts.py.

00153 
00154     def rootpage(self):
00155         from MoinMoin.Page import RootPage
        return RootPage(self)
def MoinMoin.web.contexts.HTTPContext.send_file (   self,
  fileobj,
  bufsize = 8192,
  do_flush = None 
) [inherited]
Send a file to the output stream.

@param fileobj: a file-like object (supporting read, close)
@param bufsize: size of chunks to read/write
@param do_flush: call flush after writing?

Definition at line 298 of file contexts.py.

00298 
00299     def send_file(self, fileobj, bufsize=8192, do_flush=None):
00300         """ Send a file to the output stream.
00301 
00302         @param fileobj: a file-like object (supporting read, close)
00303         @param bufsize: size of chunks to read/write
00304         @param do_flush: call flush after writing?
00305         """
00306         def simple_wrapper(fileobj, bufsize):
00307             return iter(lambda: fileobj.read(bufsize), '')
00308         file_wrapper = self.environ.get('wsgi.file_wrapper', simple_wrapper)
00309         self.request.direct_passthrough = True
00310         self.request.response = file_wrapper(fileobj, bufsize)
00311         raise MoinMoinFinish('sent file')

def MoinMoin.web.contexts.BaseContext.setContentLanguage (   self,
  lang 
) [inherited]
Set the content language, used for the content div

Actions that generate content in the user language, like search,
should set the content direction to the user language before they
call send_title!

Definition at line 171 of file contexts.py.

00171 
00172     def setContentLanguage(self, lang):
00173         """ Set the content language, used for the content div
00174 
00175         Actions that generate content in the user language, like search,
00176         should set the content direction to the user language before they
00177         call send_title!
00178         """
00179         self.content_lang = lang
00180         self.current_lang = lang

def MoinMoin.web.contexts.HTTPContext.setHttpHeader (   self,
  header 
) [inherited]

Definition at line 241 of file contexts.py.

00241 
00242     def setHttpHeader(self, header):
00243         header, value = header.split(':', 1)
00244         self.headers.add(header, value)

def MoinMoin.web.contexts.AuxilaryMixin.setPragma (   self,
  key,
  value 
) [inherited]
Set a pragma value (#pragma processing instruction)

    Keys are not case-sensitive.

Definition at line 398 of file contexts.py.

00398 
00399     def setPragma(self, key, value):
00400         """ Set a pragma value (#pragma processing instruction)
00401 
00402             Keys are not case-sensitive.
00403         """
00404         self.pragma[key.lower()] = value

Definition at line 365 of file contexts.py.

00365 
00366     def uid_generator(self):
00367         pagename = None
00368         if hasattr(self, 'page') and hasattr(self.page, 'page_name'):
00369             pagename = self.page.page_name
        return UniqueIDGenerator(pagename=pagename)
def MoinMoin.web.contexts.ScriptContext.write (   self,
  data 
)
Write to output stream. 

Reimplemented from MoinMoin.web.contexts.HTTPContext.

Definition at line 428 of file contexts.py.

00428 
00429     def write(self, *data):
00430         for d in data:
00431             if isinstance(d, unicode):
00432                 d = d.encode(config.charset)
00433             else:
00434                 d = str(d)
00435             sys.stdout.write(d)

Here is the caller graph for this function:


Member Data Documentation

tuple MoinMoin.web.contexts.BaseContext.action = EnvironProxy('action', lambda o: o.request.values.get('action', 'show')) [static, inherited]

Definition at line 109 of file contexts.py.

tuple MoinMoin.web.contexts.HTTPContext.cacheable = EnvironProxy('old.cacheable', 0) [static, inherited]

Definition at line 196 of file contexts.py.

Definition at line 133 of file contexts.py.

tuple MoinMoin.web.contexts.BaseContext.clock = EnvironProxy('clock', lambda o: Clock()) [static, inherited]

Definition at line 110 of file contexts.py.

tuple MoinMoin.web.contexts.BaseContext.content_lang = EnvironProxy('content_lang', lambda o: o.cfg.language_default) [static, inherited]

Definition at line 114 of file contexts.py.

Definition at line 178 of file contexts.py.

Definition at line 213 of file contexts.py.

Definition at line 115 of file contexts.py.

Definition at line 179 of file contexts.py.

Definition at line 385 of file contexts.py.

Definition at line 376 of file contexts.py.

Definition at line 81 of file contexts.py.

tuple MoinMoin.web.contexts.BaseContext.formatter = EnvironProxy('formatter', lambda o: o.html_formatter) [static, inherited]

Definition at line 118 of file contexts.py.

Definition at line 382 of file contexts.py.

tuple MoinMoin.web.contexts.BaseContext.html_formatter = EnvironProxy('html_formatter', lambda o: text_html.Formatter(o)) [static, inherited]

Definition at line 117 of file contexts.py.

Definition at line 151 of file contexts.py.

Definition at line 113 of file contexts.py.

Definition at line 356 of file contexts.py.

tuple MoinMoin.web.contexts.BaseContext.page = EnvironProxy('page', None) [static, inherited]

Definition at line 120 of file contexts.py.

tuple MoinMoin.web.contexts.AuxilaryMixin.pages = EnvironProxy('pages', lambda o: {}) [static, inherited]

Definition at line 363 of file contexts.py.

Definition at line 355 of file contexts.py.

Definition at line 82 of file contexts.py.

tuple MoinMoin.web.contexts.AuxilaryMixin.pragma = EnvironProxy('pragma', lambda o: {}) [static, inherited]

Definition at line 358 of file contexts.py.

Definition at line 80 of file contexts.py.

Definition at line 163 of file contexts.py.

Definition at line 156 of file contexts.py.

Definition at line 194 of file contexts.py.

tuple MoinMoin.web.contexts.HTTPContext.status = _proxy('status') [static, inherited]

Definition at line 214 of file contexts.py.

Definition at line 215 of file contexts.py.

Definition at line 168 of file contexts.py.

Definition at line 370 of file contexts.py.

tuple MoinMoin.web.contexts.BaseContext.user = EnvironProxy('user', lambda o: user.User(o, auth_method='request:invalid')) [static, inherited]

Definition at line 111 of file contexts.py.

Definition at line 294 of file contexts.py.

tuple MoinMoin.web.contexts.HTTPContext.writestack = EnvironProxy('old.writestack', lambda o: list()) [static, inherited]

Definition at line 197 of file contexts.py.


Property Documentation

MoinMoin.web.contexts.BaseContext.getText = property(getText) [static, inherited]

Definition at line 141 of file contexts.py.


The documentation for this class was generated from the following file: