| 131 | | def _handle_text_a(self, tree): |
| | 135 | def _relatorio_statements(self, tree): |
| | 136 | # If this node href matches the relatorio URL it is kept. |
| | 137 | # If this node href matches a genshi directive it is kept for further |
| | 138 | # processing. |
| | 139 | r_statements, genshi_dir = [], [] |
| | 140 | xlink_href_attrib = '{%s}href' % self.namespaces['xlink'] |
| | 141 | text_a = '{%s}a' % self.namespaces['text'] |
| | 142 | placeholder = '{%s}placeholder' % self.namespaces['text'] |
| | 143 | |
| | 144 | s_xpath = "//text:a[starts-with(@xlink:href, 'relatorio://')]" \ |
| | 145 | "| //text:placeholder" |
| | 146 | for statement in tree.xpath(s_xpath, namespaces=self.namespaces): |
| | 147 | if statement.tag == placeholder: |
| | 148 | expr = statement.text[1:-1] |
| | 149 | elif statement.tag == text_a: |
| | 150 | expr = urllib.unquote(statement.attrib[xlink_href_attrib][12:]) |
| | 151 | |
| | 152 | if not expr: |
| | 153 | raise OOTemplateError("No expression in the tag", |
| | 154 | self.filepath) |
| | 155 | elif not statement.text: |
| | 156 | warnings.warn('No statement text in %s' % self.filepath) |
| | 157 | elif expr != statement.text and statement.tag == text_a: |
| | 158 | warnings.warn('url and text do not match in %s: %s != %s' |
| | 159 | % (self.filepath, expr, |
| | 160 | statement.text.encode('utf-8'))) |
| | 161 | |
| | 162 | match_obj = GENSHI_EXPR.match(expr) |
| | 163 | |
| | 164 | expr, closing, directive, _, attr, attr_val = match_obj.groups() |
| | 165 | if directive is not None: |
| | 166 | genshi_dir.append((statement, closing)) |
| | 167 | r_statements.append((statement, |
| | 168 | (expr, closing, directive, attr, attr_val))) |
| | 169 | |
| | 170 | return r_statements, genshi_dir |
| | 171 | |
| | 172 | def _handle_relatorio_tags(self, tree): |
| 141 | | genshi_name = '{%s}replace' % self.namespaces['py'] |
| 142 | | xlink_href_attrib = '{%s}href' % self.namespaces['xlink'] |
| 143 | | |
| 144 | | # First we create the list of all the text:a nodes. |
| 145 | | # If this node href matches the relatorio URL it is kept. |
| 146 | | # If this node href matches a genshi directive it is kept for further |
| 147 | | # processing. |
| 148 | | genshi_directives, text_a = [], [] |
| 149 | | xpath_expr = "//text:a[starts-with(@xlink:href, 'relatorio://')]" |
| 150 | | for statement in tree.xpath(xpath_expr, namespaces=self.namespaces): |
| 151 | | href = urllib.unquote(statement.attrib[xlink_href_attrib]) |
| 152 | | match_obj = GENSHI_TAGS.match(href) |
| 153 | | expr, closing, directive, _, attr, attr_val = match_obj.groups() |
| 154 | | if expr != statement.text: |
| 155 | | txt = statement.text or '' |
| 156 | | warnings.warn('url and text do not match in %s: %s != %s' |
| 157 | | % (self.filepath, expr, txt.encode('utf-8'))) |
| 158 | | if directive is not None: |
| 159 | | genshi_directives.append((statement, href)) |
| 160 | | text_a.append((statement, |
| 161 | | (expr, closing, directive, attr, attr_val))) |
| 162 | | |
| 163 | | # Then we match the opening and closing directives together |
| | 182 | genshi_replace = '{%s}replace' % self.namespaces['py'] |
| | 183 | |
| | 184 | r_statements, genshi_directives = self._relatorio_statements(tree) |
| | 185 | # We match the opening and closing directives together |