home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- from odf.element import Node
- import odf.opendocument as odf
- from odf.text import S, LineBreak, Tab
-
- class WhitespaceText(object):
-
- def __init__(self):
- self.textBuffer = []
- self.spaceCount = 0
-
-
- def addTextToElement(self, odfElement, s):
- i = 0
- ch = ' '
- while i < len(s):
- ch = s[i]
- if ch == '\t':
- self._emitTextBuffer(odfElement)
- odfElement.addElement(Tab())
- i += 1
- continue
- if ch == '\n':
- self._emitTextBuffer(odfElement)
- odfElement.addElement(LineBreak())
- i += 1
- continue
- if ch == ' ':
- self.textBuffer.append(' ')
- i += 1
- self.spaceCount = 0
- while i < len(s) and s[i] == ' ':
- self.spaceCount += 1
- i += 1
- continue
- self
- if self.spaceCount > 0:
- self._emitTextBuffer(odfElement)
- self._emitSpaces(odfElement)
-
- self.spaceCount > 0
- self.textBuffer.append(ch)
- i += 1
- self._emitTextBuffer(odfElement)
-
-
- def _emitTextBuffer(self, odfElement):
- if len(self.textBuffer) > 0:
- odfElement.addText(''.join(self.textBuffer))
-
- self.textBuffer = []
-
-
- def _emitSpaces(self, odfElement):
- if self.spaceCount > 0:
- spaceElement = S(c = self.spaceCount)
- odfElement.addElement(spaceElement)
-
- self.spaceCount = 0
-
-
-
- def addTextToElement(odfElement, s):
- wst = WhitespaceText()
- wst.addTextToElement(odfElement, s)
-
-
- def extractText(odfElement):
- result = []
- if len(odfElement.childNodes) != 0:
- for child in odfElement.childNodes:
- if child.nodeType == Node.TEXT_NODE:
- result.append(child.data)
- continue
- if child.nodeType == Node.ELEMENT_NODE:
- subElement = child
- tagName = subElement.qname
- if tagName == (u'urn:oasis:names:tc:opendocument:xmlns:text:1.0', u'line-break'):
- result.append('\n')
- elif tagName == (u'urn:oasis:names:tc:opendocument:xmlns:text:1.0', u'tab'):
- result.append('\t')
- elif tagName == (u'urn:oasis:names:tc:opendocument:xmlns:text:1.0', u's'):
- c = subElement.getAttribute('c')
- if c:
- spaceCount = int(c)
- else:
- spaceCount = 1
- result.append(' ' * spaceCount)
- else:
- result.append(extractText(subElement))
- tagName == (u'urn:oasis:names:tc:opendocument:xmlns:text:1.0', u'line-break')
-
-
- return ''.join(result)
-
-