Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes
MoinMoin.web.utils.UniqueIDGenerator Class Reference

List of all members.

Public Member Functions

def __init__
def push
def pop
def begin
def end
def __call__

Public Attributes

 unique_stack
 include_stack
 include_id
 page_ids
 pagename

Detailed Description

Definition at line 151 of file utils.py.


Constructor & Destructor Documentation

def MoinMoin.web.utils.UniqueIDGenerator.__init__ (   self,
  pagename = None 
)

Definition at line 152 of file utils.py.

00152 
00153     def __init__(self, pagename=None):
00154         self.unique_stack = []
00155         self.include_stack = []
00156         self.include_id = None
00157         self.page_ids = {None: {}}
00158         self.pagename = pagename


Member Function Documentation

def MoinMoin.web.utils.UniqueIDGenerator.__call__ (   self,
  base,
  namespace = None 
)
Generates a unique ID using a given base name. Appends a running count to the base.

Needs to stay deterministic!

@param base: the base of the id
@type base: unicode
@param namespace: the namespace for the ID, used when including pages

@returns: a unique (relatively to the namespace) ID
@rtype: unicode

Definition at line 205 of file utils.py.

00205 
00206     def __call__(self, base, namespace=None):
00207         """
00208         Generates a unique ID using a given base name. Appends a running count to the base.
00209 
00210         Needs to stay deterministic!
00211 
00212         @param base: the base of the id
00213         @type base: unicode
00214         @param namespace: the namespace for the ID, used when including pages
00215 
00216         @returns: a unique (relatively to the namespace) ID
00217         @rtype: unicode
00218         """
00219         if not isinstance(base, unicode):
00220             base = unicode(str(base), 'ascii', 'ignore')
00221         if not namespace in self.page_ids:
00222             self.page_ids[namespace] = {}
00223         count = self.page_ids[namespace].get(base, -1) + 1
00224         self.page_ids[namespace][base] = count
00225         if not count:
00226             return base
00227         return u'%s-%d' % (base, count)

def MoinMoin.web.utils.UniqueIDGenerator.begin (   self,
  base 
)
Called by the formatter when a document begins, which means
that include causing nested documents gives us an include
stack in self.include_id_stack.

Definition at line 181 of file utils.py.

00181 
00182     def begin(self, base):
00183         """
00184         Called by the formatter when a document begins, which means
00185         that include causing nested documents gives us an include
00186         stack in self.include_id_stack.
00187         """
00188         pids = {}
00189         for namespace in self.page_ids:
00190             pids[namespace] = self.page_ids[namespace].copy()
00191         self.include_stack.append((self.include_id, pids))
00192         self.include_id = self(base)
00193         # if it's the page name then set it to None so we don't
00194         # prepend anything to IDs, but otherwise keep it.
00195         if self.pagename and self.pagename == self.include_id:
00196             self.include_id = None

Here is the call graph for this function:

Called by the formatter when a document ends, restores
the current include ID to the previous one and discards
the page IDs state we kept around for push().

Definition at line 197 of file utils.py.

00197 
00198     def end(self):
00199         """
00200         Called by the formatter when a document ends, restores
00201         the current include ID to the previous one and discards
00202         the page IDs state we kept around for push().
00203         """
00204         self.include_id, pids = self.include_stack.pop()

Used by the TOC macro to reset the ID namespaces after
having parsed the page for TOC generation and after
printing the TOC.

Definition at line 172 of file utils.py.

00172 
00173     def pop(self):
00174         """
00175         Used by the TOC macro to reset the ID namespaces after
00176         having parsed the page for TOC generation and after
00177         printing the TOC.
00178         """
00179         self.page_ids, self.include_id = self.unique_stack.pop()
00180         return self.page_ids, self.include_id

Here is the caller graph for this function:

Used by the TOC macro, this ensures that the ID namespaces
are reset to the status when the current include started.
This guarantees that doing the ID enumeration twice results
in the same results, on any level.

Definition at line 159 of file utils.py.

00159 
00160     def push(self):
00161         """
00162         Used by the TOC macro, this ensures that the ID namespaces
00163         are reset to the status when the current include started.
00164         This guarantees that doing the ID enumeration twice results
00165         in the same results, on any level.
00166         """
00167         self.unique_stack.append((self.page_ids, self.include_id))
00168         self.include_id, pids = self.include_stack[-1]
00169         self.page_ids = {}
00170         for namespace in pids:
00171             self.page_ids[namespace] = pids[namespace].copy()

Here is the call graph for this function:


Member Data Documentation

Definition at line 155 of file utils.py.

Definition at line 154 of file utils.py.

Definition at line 156 of file utils.py.

Definition at line 157 of file utils.py.

Definition at line 153 of file utils.py.


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