Esempio n. 1
0
File: doc.py Progetto: wijjo/cmdo
 def _prepareNodes(self, forms, items, major, **props):
     ddd = forms == ['item']
     if type(items) is not list and type(items) is not tuple:
         items = [items]
     nodes = []
     for item in items:
         if isinstance(item, Node):
             node = item
             if len(forms) > 0 and node.getProp('form') != forms[0]:
                 node = Node(content = node, form = forms[0], **props)
             nodes.append(node)
             if props:
                 item.setProps(props)
             if major:
                 self._nodesPending.append(nodes[-1])
         else:
             props2 = copy.copy(props)
             if len(forms) > 1:
                 props2['content'] = self._prepareNodes(forms[1:], item, False)
             elif text_utility.isString(item) and 'text' not in props2:
                 props2['text'] = item
             else:
                 props2['content'] = item
             if len(forms) > 0:
                 props2['form'] = forms[0]
             nodes.append(Node(**props2))
             if major:
                 self._nodesPending.append(nodes[-1])
     return nodes
Esempio n. 2
0
File: doc.py Progetto: wijjo/cmdo
 def _getPublisherFileViewer(self, publisher, path):
     if text_utility.isString(publisher.types):
         viewer = sys_utility.getViewer(path, publisher.types)
     else:
         viewer = sys_utility.getViewer(path, *publisher.types)
     if not viewer:
         print 'No viewer found for types: %s' % str(publisher.types)
     return viewer
Esempio n. 3
0
File: doc.py Progetto: wijjo/cmdo
 def _dump(self, f = None, level = 0):
     if f is None:
         f = sys.stdout
     f.write('%s:%s: %s\n' % ('    ' * level, self.__class__.__name__, self.getProps()))
     for node in self.iterNodes():
         if text_utility.isString(node):
             f.write('%s\'\'\'%s\'\'\'\n' % ('    ' * (level+1), node))
         else:
             node._dump(f, level+1)
Esempio n. 4
0
File: doc.py Progetto: wijjo/cmdo
 def add(self, content):
     nStart = len(self._nodesChild)
     if isinstance(content, Node) or text_utility.isString(content):
         items = [content]
     else:
         # Allow, but strip out null items
         items = [item for item in content if item is not None]
     for item in items:
         if item:
             if isinstance(item, Node):
                 node = item
             # Naked lists/tuples become nodes
             elif type(item) is list or type(item) is tuple:
                 node = Node(content = item)
             # Naked strings become nodes with the text property set
             elif text_utility.isString(item):
                 # Parse structured text to produce nodes.
                 parserStrucText.parse(item)
                 node = parserStrucText.take()
             if node is not None:
                 node._nodeParent = self
                 self._nodesChild.append(node)
     # Simplify the structure by looking for special cases.
     self._optimize()
Esempio n. 5
0
File: doc.py Progetto: wijjo/cmdo
 def consolidateCacheText(self, name, sep):
     if len(self.levels) < 2:
         return False
     if name not in self.levels[-1].cache:
         return False
     text = self.levels[-1].cache[name]
     if not text or not text_utility.isString(text):
         return False
     if name in self.levels[-2].cache:
         textUp = self.levels[-2].cache[name]
     else:
         textUp = None
     if textUp:
         self.levels[-2].cache[name] = '%s%s%s' % (textUp.rstrip(), sep, text.lstrip())
     else:
         self.levels[-2].cache[name] = text
     del self.levels[-1].cache[name]
     return True
Esempio n. 6
0
 def abstractDict(d):
     s = ''
     keys = d.keys()
     keys.sort()
     sep = ''
     for key in keys:
         val = d[key]
         if val is not None:
             if text_utility.isString(val):
                 sVal = '"%s' % val[:20]
                 if len(sVal) < len(val):
                     sVal += '...(%d)' % len(val)
                 sVal += '"'
             else:
                 sVal = str(val)
             s += '%s%s=%s' % (sep, key, sVal)
             if not sep:
                 sep = ' '
     if not s:
         s = '(empty)'
     return s
Esempio n. 7
0
File: doc.py Progetto: wijjo/cmdo
 def list(self, style, *content):
     if style is not None:
         style = style.lower()
     if style and (not text_utility.isString(style) or style not in ('bullet', 'number')):
         raise ExcBase('Bad list style "%s"' % style)
     return self._wrapNodes(['list', 'item'], style = style, *content)