Back to index

plone3  3.1.7
Public Member Functions | Private Attributes
makepox.XMLParser Class Reference

List of all members.

Public Member Functions

def __init__
def parse_file
def extract_text
def next_node

Private Attributes

 _current

Detailed Description

scans XML files (or well-formed HTML files, obviously) for i18 attrs

Definition at line 56 of file makepox.py.


Constructor & Destructor Documentation

def makepox.XMLParser.__init__ (   self,
  files,
  pox 
)

Definition at line 58 of file makepox.py.

00058 
00059     def __init__(self, files, pox):
00060         self._current = None
00061         for file in files:
00062             self.parse_file(file, pox)


Member Function Documentation

def makepox.XMLParser.extract_text (   self,
  node 
)

Definition at line 99 of file makepox.py.

00099 
00100     def extract_text(self, node):
00101         xml = ''
00102         for child in node.childNodes:
00103             xml += child.toxml().strip().replace('\n', ' ').replace('\t', ' ')
00104         while xml.find('  ') > -1:
00105             xml = xml.replace('  ', ' ')
00106         return xml

Here is the call graph for this function:

Here is the caller graph for this function:

def makepox.XMLParser.next_node (   self,
  dom 
)

Definition at line 107 of file makepox.py.

00107 
00108     def next_node(self, dom):
00109         if not self._current or self._current.ownerDocument != dom:
00110             self._current = dom.documentElement
00111         else:
00112             cur = self._current
00113             if cur.hasChildNodes():
00114                 self._current = cur.childNodes[0]
00115             elif cur != cur.parentNode.lastChild:
00116                 self._current = cur.nextSibling
00117             else:
00118                 self._current = cur.parentNode.nextSibling
00119         return self._current

Here is the caller graph for this function:

def makepox.XMLParser.parse_file (   self,
  filename,
  pox 
)

Definition at line 63 of file makepox.py.

00063 
00064     def parse_file(self, filename, pox):
00065         fp = open(filename)
00066         try:
00067             dom = parseString(fp.read())
00068         except:
00069             exc, e, tb = sys.exc_info()
00070             del tb
00071             if warn_on_broken_xml:
00072                 print >>stderr, 'Error parsing %s: %s - %s' % (filename, exc, e)
00073             return
00074         # walk through all the nodes and scan for i18n: stuff
00075         while 1:
00076             node = self.next_node(dom)
00077             if not node:
00078                 break
00079             if node.nodeType == 1:
00080                 attrs = node.attributes
00081                 translate = attrs.getNamedItem('i18n:translate')
00082                 if translate:
00083                     msgid = translate.value
00084                     if not msgid.strip():
00085                         msgid = self.extract_text(node)
00086                     pox.add(msgid, filename)
00087                 attributes = attrs.getNamedItem('i18n:attributes')
00088                 if attributes:
00089                     attributes = [a.strip() for a in 
00090                                         attributes.value.split(';')]
00091                     for attr in attributes:
00092                         attritem = attrs.getNamedItem(attr)
00093                         if not attritem:
00094                             raise AttributeError, \
00095                                 'No %s on %s in %s' % (
00096                                     attr, node.nodeName, filename)
00097                         msgid = attritem.value;
00098                         pox.add(msgid, filename)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 59 of file makepox.py.


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