Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes
MoinMoin.formatter.text_python.Formatter Class Reference

List of all members.

Public Member Functions

def __init__
def assemble_code
def __getattr__
def pagelink
def attachment_link
def attachment_image
def attachment_drawing
def attachment_inlined
def heading
def icon
def span
def div
def macro
def parser
def startContent
def endContent
def anchorlink
def line_anchorlink
def code_area
def line_anchordef
def anchordef

Public Attributes

 formatter
 static
 code_fragments
 request
 text_cmd_begin
 text_cmd_end

Static Public Attributes

list defaultDependencies = ["time"]
 smiley = icon

Private Member Functions

def __cache_if_no_id
def __insert_code
def __insert_fmt_call
def __is_static
def __adjust_language_state
def __adjust_formatter_state

Private Attributes

 __formatter
 __parser
 __lang
 __in_p
 __in_pre

Detailed Description

    Inserts '<<<>>>' into the page and adds python code to
    self.code_fragments for dynamic parts of the page
    (as macros, wikinames...).
    Static parts are formatted with an external formatter.
    Page must be assembled after the parsing to get working python code.

Definition at line 15 of file text_python.py.


Constructor & Destructor Documentation

def MoinMoin.formatter.text_python.Formatter.__init__ (   self,
  request,
  static = [],
  formatter = None,
  kw 
)

Definition at line 26 of file text_python.py.

00026 
00027     def __init__(self, request, static=[], formatter=None, **kw):
00028         if formatter:
00029             self.formatter = formatter
00030         else:
00031             from MoinMoin.formatter.text_html import Formatter
00032             self.formatter = Formatter(request, store_pagelinks=1)
00033         self.static = static
00034         self.code_fragments = []
00035         self.__formatter = "formatter"
00036         self.__parser = "parser"
00037         self.request = request
00038         self.__lang = request.current_lang
00039         self.__in_p = 0
00040         self.__in_pre = 0
00041         self.text_cmd_begin = '\nrequest.write('
00042         self.text_cmd_end = ')\n'


Member Function Documentation

Definition at line 121 of file text_python.py.

00121 
00122     def __adjust_formatter_state(self):
00123         result = self.__adjust_language_state()
00124         if self.__in_p != self.formatter.in_p:
00125             result = "%s%s.in_p = %r\n" % (result, self.__formatter,
00126                                            self.formatter.in_p)
00127             self.__in_p = self.formatter.in_p
00128         if self.__in_pre != self.formatter.in_pre:
00129             result = "%s%s.in_pre = %r\n" % (result, self.__formatter,
00130                                            self.formatter.in_pre)
00131             self.__in_pre = self.formatter.in_pre
00132         return result

Here is the call graph for this function:

Here is the caller graph for this function:

Add current language state changing code to the cache 

Definition at line 114 of file text_python.py.

00114 
00115     def __adjust_language_state(self):
00116         """ Add current language state changing code to the cache """
00117         if self.__lang != self.request.current_lang:
00118             self.__lang = self.request.current_lang
00119             return 'request.current_lang = %r\n' % self.__lang
00120         return ''

Here is the caller graph for this function:

def MoinMoin.formatter.text_python.Formatter.__cache_if_no_id (   self,
  name,
  args,
  kw 
) [private]

Definition at line 80 of file text_python.py.

00080 
00081     def __cache_if_no_id(self, name, *args, **kw):
00082         if not 'id' in kw:
00083             return getattr(self.formatter, name)(*args, **kw)
00084         else:
00085             return self.__insert_code('request.write(%s.%s(*%r, **%r))' %
00086                 (self.__formatter, name, args, kw))

Here is the call graph for this function:

Here is the caller graph for this function:

For every thing we have no method/attribute use the formatter
unless there's an ID in the keywords.

Definition at line 87 of file text_python.py.

00087 
00088     def __getattr__(self, name):
00089         """
00090         For every thing we have no method/attribute use the formatter
00091         unless there's an ID in the keywords.
00092         """
00093         attr = getattr(self.formatter, name)
00094         if callable(attr):
00095             return lambda *args, **kw: self.__cache_if_no_id(name, *args, **kw)
00096         else:
00097             return attr

Here is the call graph for this function:

def MoinMoin.formatter.text_python.Formatter.__insert_code (   self,
  call 
) [private]
returns the python code

Definition at line 98 of file text_python.py.

00098 
00099     def __insert_code(self, call):
00100         """ returns the python code
00101         """
00102         self.code_fragments.append(call)
00103         return '<<<>>>'

Here is the caller graph for this function:

def MoinMoin.formatter.text_python.Formatter.__insert_fmt_call (   self,
  function,
  args,
  kw 
) [private]

Definition at line 104 of file text_python.py.

00104 
00105     def __insert_fmt_call(self, function, *args, **kw):
00106         return self.__insert_code('request.write(%s.%s(*%r, **%r))' % (
00107             self.__formatter, function, args, kw))

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.formatter.text_python.Formatter.__is_static (   self,
  dependencies 
) [private]

Definition at line 108 of file text_python.py.

00108 
00109     def __is_static(self, dependencies):
00110         for dep in dependencies:
00111             if dep not in self.static:
00112                 return False
00113         return True

Here is the caller graph for this function:

Definition at line 252 of file text_python.py.

00252 
00253     def anchordef(self, id):
00254         return self.__insert_fmt_call('anchordef', id)

Here is the call graph for this function:

def MoinMoin.formatter.text_python.Formatter.anchorlink (   self,
  on,
  name = '',
  kw 
)

Definition at line 224 of file text_python.py.

00224 
00225     def anchorlink(self, on, name='', **kw):
00226         # anchorlink depends on state now, namely the include ID in the request.
00227         if on:
00228             return self.__insert_fmt_call('anchorlink', on, name, **kw)
00229         else:
00230             return self.formatter.anchorlink(on, name=name, **kw)

Here is the call graph for this function:

inserts the code into the generated text

Definition at line 43 of file text_python.py.

00043 
00044     def assemble_code(self, text):
00045         """inserts the code into the generated text
00046         """
00047         # Automatic invalidation due to moin code changes:
00048         # we are called from Page.py, so moincode_timestamp is
00049         # mtime of MoinMoin directory. If we detect, that the
00050         # saved rendering code is older than the MoinMoin directory
00051         # we invalidate it by raising an exception. This avoids
00052         # calling functions that have changed by a code update.
00053         # Hint: we don't check the mtime of the directories within
00054         # MoinMoin, so better do a touch if you only modified stuff
00055         # in a subdirectory.
00056         waspcode_timestamp = int(time.time())
00057         source = ["""
00058 moincode_timestamp = int(os.path.getmtime(os.path.dirname(__file__)))
00059 cfg_mtime = getattr(request.cfg, "cfg_mtime", None)
00060 if moincode_timestamp > %d or cfg_mtime is None or cfg_mtime > %d:
00061     raise Exception("CacheNeedsUpdate")
00062 """ % (waspcode_timestamp, waspcode_timestamp)]
00063 
00064 
00065         text = text.split('<<<>>>', len(self.code_fragments))
00066         source.extend([self.text_cmd_begin, repr(text[0])])
00067         i = 0
00068         for t in text[1:]:
00069             source.extend([self.text_cmd_end,
00070                            self.code_fragments[i],
00071                            self.text_cmd_begin,
00072                            repr(text[i+1])])
00073             i += 1
00074         source.append(self.text_cmd_end)
00075         source.append(self.__adjust_formatter_state())
00076 
00077         self.code_fragments = [] # clear code fragments to make
00078                                  # this object reusable
00079         return "".join(source)

Here is the call graph for this function:

def MoinMoin.formatter.text_python.Formatter.attachment_drawing (   self,
  url,
  text,
  kw 
)

Definition at line 151 of file text_python.py.

00151 
00152     def attachment_drawing(self, url, text, **kw):
00153         return self.__insert_fmt_call('attachment_drawing', url, text, **kw)

Here is the call graph for this function:

Definition at line 148 of file text_python.py.

00148 
00149     def attachment_image(self, url, **kw):
00150         return self.__insert_fmt_call('attachment_image', url, **kw)

Here is the call graph for this function:

def MoinMoin.formatter.text_python.Formatter.attachment_inlined (   self,
  url,
  text,
  kw 
)

Definition at line 154 of file text_python.py.

00154 
00155     def attachment_inlined(self, url, text, **kw):
00156         return self.__insert_fmt_call('attachment_inlined', url, text, **kw)

Here is the call graph for this function:

def MoinMoin.formatter.text_python.Formatter.attachment_link (   self,
  on,
  url = None,
  kw 
)

Definition at line 145 of file text_python.py.

00145 
00146     def attachment_link(self, on, url=None, **kw):
00147         return self.__insert_fmt_call('attachment_link', on, url, **kw)

Here is the call graph for this function:

def MoinMoin.formatter.text_python.Formatter.code_area (   self,
  on,
  code_id,
  code_type = 'code',
  show = 0,
  start = -1,
  step = -1,
  msg = None 
)

Definition at line 238 of file text_python.py.

00238 
00239     def code_area(self, on, code_id, code_type='code', show=0, start=-1, step=-1, msg=None):
00240         if on:
00241             # update state of the HTML formatter
00242             self.formatter._in_code_area = 1
00243             self.formatter._in_code_line = 0
00244             self.formatter._code_area_state = [None, show, start, step, start]
00245             return self.__insert_fmt_call('code_area', on, code_id, code_type, show,
00246                                           start, step)
00247         else:
00248             return self.formatter.code_area(False, code_id, code_type, show, start, step)

Here is the call graph for this function:

def MoinMoin.formatter.text_python.Formatter.div (   self,
  on,
  kw 
)

Definition at line 182 of file text_python.py.

00182 
00183     def div(self, on, **kw):
00184         if on and 'comment' in kw.get('css_class', '').split():
00185             return self.__insert_fmt_call('div', on, **kw)
00186         else:
00187             return self.formatter.div(on, **kw)

Here is the call graph for this function:

def MoinMoin.formatter.text_python.Formatter.endContent (   self,
  newline = True 
)

Definition at line 220 of file text_python.py.

00220 
00221     def endContent(self, newline=True):
00222         # we need to tell the request about the end of the content
00223         return self.__insert_fmt_call('endContent', newline)

Here is the call graph for this function:

def MoinMoin.formatter.text_python.Formatter.heading (   self,
  on,
  depth,
  kw 
)

Definition at line 157 of file text_python.py.

00157 
00158     def heading(self, on, depth, **kw):
00159         if on:
00160             code = [
00161                 self.__adjust_language_state(),
00162                 'request.write(%s.heading(%r, %r, **%r))' % (self.__formatter,
00163                                                              on, depth, kw),
00164                 ]
00165             return self.__insert_code(''.join(code))
00166         else:
00167             return self.formatter.heading(on, depth, **kw)

Here is the call graph for this function:

Definition at line 168 of file text_python.py.

00168 
00169     def icon(self, type):
00170         if self.__is_static(['user']):
00171             return self.formatter.icon(type)
00172         else:
00173             return self.__insert_fmt_call('icon', type)

Here is the call graph for this function:

Definition at line 249 of file text_python.py.

00249 
00250     def line_anchordef(self, lineno):
00251         return self.__insert_fmt_call('line_anchordef', lineno)

Here is the call graph for this function:

def MoinMoin.formatter.text_python.Formatter.line_anchorlink (   self,
  on,
  lineno = 0 
)

Definition at line 231 of file text_python.py.

00231 
00232     def line_anchorlink(self, on, lineno=0):
00233         # anchorlink depends on state now, namely the include ID in the request.
00234         if on:
00235             return self.__insert_fmt_call('line_anchorlink', on, lineno)
00236         else:
00237             return self.formatter.line_anchorlink(on, lineno)

Here is the call graph for this function:

def MoinMoin.formatter.text_python.Formatter.macro (   self,
  macro_obj,
  name,
  args,
  markup = None 
)

Definition at line 188 of file text_python.py.

00188 
00189     def macro(self, macro_obj, name, args, markup=None):
00190         if self.__is_static(macro_obj.get_dependencies(name)):
00191             # XXX: why is this necessary??
00192             macro_obj.formatter = self
00193             return macro_obj.execute(name, args)
00194         else:
00195             return self.__insert_code(
00196                 '%srequest.write(%s.macro(macro_obj, %r, %r, %r))' %
00197                 (self.__adjust_formatter_state(),
00198                  self.__formatter, name, args, markup))

Here is the call graph for this function:

def MoinMoin.formatter.text_python.Formatter.pagelink (   self,
  on,
  pagename = '',
  page = None,
  kw 
)

Definition at line 135 of file text_python.py.

00135 
00136     def pagelink(self, on, pagename='', page=None, **kw):
00137         if on:
00138             return self.__insert_code('page=Page(request, %r, formatter=%s);'
00139                                       'request.write(%s.pagelink(%r, page=page, **%r))' %
00140                                       (pagename, self.__formatter,
00141                                        self.__formatter, on, kw))
00142         else:
00143             return self.__insert_code('request.write(%s.pagelink(%r, page=page, **%r))' %
00144                                       (self.__formatter, on, kw))

Here is the call graph for this function:

def MoinMoin.formatter.text_python.Formatter.parser (   self,
  parser_name,
  lines 
)
parser_name MUST be valid!
    prints out the result instead of returning it!

Definition at line 199 of file text_python.py.

00199 
00200     def parser(self, parser_name, lines):
00201         """ parser_name MUST be valid!
00202             prints out the result instead of returning it!
00203         """
00204         try:
00205             Dependencies = wikiutil.searchAndImportPlugin(self.request.cfg, "parser", parser_name, "Dependencies")
00206         except (wikiutil.PluginMissingError, wikiutil.PluginAttributeError):
00207             Dependencies = self.defaultDependencies
00208 
00209         if self.__is_static(Dependencies):
00210             return self.formatter.parser(parser_name, lines)
00211         else:
00212             return self.__insert_code('%s%s.parser(%r, %r)' %
00213                                       (self.__adjust_formatter_state(),
00214                                        self.__formatter,
00215                                        parser_name, lines))

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.formatter.text_python.Formatter.span (   self,
  on,
  kw 
)

Definition at line 176 of file text_python.py.

00176 
00177     def span(self, on, **kw):
00178         if on and 'comment' in kw.get('css_class', '').split():
00179             return self.__insert_fmt_call('span', on, **kw)
00180         else:
00181             return self.formatter.span(on, **kw)

Here is the call graph for this function:

def MoinMoin.formatter.text_python.Formatter.startContent (   self,
  content_id = 'content',
  newline = True,
  kw 
)

Definition at line 216 of file text_python.py.

00216 
00217     def startContent(self, content_id='content', newline=True, **kw):
00218         # we need to tell the request about the start of the content
00219         return self.__insert_fmt_call('startContent', content_id, newline, **kw)

Here is the call graph for this function:


Member Data Documentation

Definition at line 34 of file text_python.py.

Definition at line 38 of file text_python.py.

Definition at line 39 of file text_python.py.

Definition at line 37 of file text_python.py.

Definition at line 35 of file text_python.py.

Definition at line 33 of file text_python.py.

Definition at line 24 of file text_python.py.

Definition at line 28 of file text_python.py.

Definition at line 36 of file text_python.py.

Definition at line 174 of file text_python.py.

Definition at line 32 of file text_python.py.

Definition at line 40 of file text_python.py.

Definition at line 41 of file text_python.py.


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