Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes
MoinMoin.parser.text_rst.MoinDirectives Class Reference

List of all members.

Public Member Functions

def __init__
def include
def macro

Public Attributes

 request
 num_includes
 max_includes

Detailed Description

    Class to handle all custom directive handling. This code is called as
    part of the parsing stage.

Definition at line 536 of file text_rst.py.


Constructor & Destructor Documentation

def MoinMoin.parser.text_rst.MoinDirectives.__init__ (   self,
  request 
)

Definition at line 542 of file text_rst.py.

00542 
00543     def __init__(self, request):
00544         self.request = request
00545 
00546         # include MoinMoin pages
00547         directives.register_directive('include', self.include)
00548 
00549         # used for MoinMoin macros
00550         directives.register_directive('macro', self.macro)
00551 
00552         # disallow a few directives in order to prevent XSS
00553         # for directive in ('meta', 'include', 'raw'):
00554         for directive in ('meta', 'raw'):
00555             directives.register_directive(directive, None)
00556 
00557         # disable the raw role
00558         roles._roles['raw'] = None
00559 
00560         # As a quick fix for infinite includes we only allow a fixed number of
00561         # includes per page
00562         self.num_includes = 0
00563         self.max_includes = 10


Member Function Documentation

def MoinMoin.parser.text_rst.MoinDirectives.include (   self,
  name,
  arguments,
  options,
  content,
  lineno,
  content_offset,
  block_text,
  state,
  state_machine 
)

Definition at line 568 of file text_rst.py.

00568 
00569                 content_offset, block_text, state, state_machine):
00570         # content contains the included file name
00571 
00572         _ = self.request.getText
00573 
00574         # Limit the number of documents that can be included
00575         if self.num_includes < self.max_includes:
00576             self.num_includes += 1
00577         else:
00578             lines = [_("**Maximum number of allowed includes exceeded**")]
00579             state_machine.insert_input(lines, 'MoinDirectives')
00580             return
00581 
00582         if len(content):
00583             pagename = content[0]
00584             page = Page(page_name=pagename, request=self.request)
00585             if not self.request.user.may.read(pagename):
00586                 lines = [_("**You are not allowed to read the page: %s**") % (pagename, )]
00587             else:
00588                 if page.exists():
00589                     text = page.get_raw_body()
00590                     lines = text.split('\n')
00591                     # Remove the "#format rst" line
00592                     if lines[0].startswith("#format"):
00593                         del lines[0]
00594                 else:
00595                     lines = [_("**Could not find the referenced page: %s**") % (pagename, )]
00596             # Insert the text from the included document and then continue parsing
00597             state_machine.insert_input(lines, 'MoinDirectives')
00598         return

Here is the call graph for this function:

def MoinMoin.parser.text_rst.MoinDirectives.macro (   self,
  name,
  arguments,
  options,
  content,
  lineno,
  content_offset,
  block_text,
  state,
  state_machine 
)

Definition at line 611 of file text_rst.py.

00611 
00612                 content_offset, block_text, state, state_machine):
00613         # content contains macro to be called
00614         if len(content):
00615             # Allow either with or without brackets
00616             if content[0].startswith('<<'):
00617                 macro = content[0]
00618             else:
00619                 macro = '<<%s>>' % content[0]
00620             ref = reference(macro, refuri=macro)
00621             ref['name'] = macro
00622             return [ref]
00623         return

Here is the caller graph for this function:


Member Data Documentation

Definition at line 562 of file text_rst.py.

Definition at line 561 of file text_rst.py.

Definition at line 543 of file text_rst.py.


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