Back to index

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

List of all members.

Classes

class  _proxy

Public Member Functions

def __getattr__
def read
def makeForbidden
def setHttpHeader
def disableHttpCaching
def http_redirect
def write
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__

Public Attributes

 write
 content_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)

Properties

 getText = property(getText)

Static Private Attributes

tuple _auth_redirected = EnvironProxy('old._auth_redirected', 0)

Detailed Description

Context that holds attributes and methods for manipulation of
incoming and outgoing HTTP data. 

Definition at line 190 of file contexts.py.


Member Function Documentation

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>')
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.HTTPContext.getQualifiedURL (   self,
  uri = '' 
)
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.HTTPContext.http_redirect (   self,
  url,
  code = 302 
)
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 
)

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 
)
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 
)
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 
)
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.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 
)
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

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.HTTPContext.write (   self,
  data 
)
Write to output stream. 

Reimplemented in MoinMoin.web.contexts.ScriptContext.

Definition at line 274 of file contexts.py.

00274 
00275     def write(self, *data):
00276         """ Write to output stream. """
00277         self.request.stream.writelines(data)

Here is the caller graph for this function:


Member Data Documentation

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

Definition at line 195 of file contexts.py.

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]

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 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.

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.

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

Definition at line 120 of file contexts.py.

Definition at line 82 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.

Definition at line 214 of file contexts.py.

Definition at line 215 of file contexts.py.

Definition at line 168 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]

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: