5 |
from backwards_compatibility import * |
from backwards_compatibility import * |
6 |
from utils import pack_list, XML |
from utils import pack_list, XML |
7 |
from core import Literal |
from core import Literal |
8 |
import types |
import types, sys, traceback |
9 |
|
|
10 |
class StopTransform(Exception): |
class StopTransform(Exception): |
11 |
def __init__(self, result=None, *args): |
def __init__(self, result=None, *args): |
55 |
result = pack_list(result) |
result = pack_list(result) |
56 |
except: |
except: |
57 |
# usually we're not interested in errors from pack |
# usually we're not interested in errors from pack |
58 |
|
traceback.print_exc() |
59 |
pass |
pass |
60 |
context.postprocess_remaining = processed |
context.postprocess_remaining = processed |
61 |
try: |
try: |
120 |
"Transforms something, and renders it to XML" |
"Transforms something, and renders it to XML" |
121 |
def transform(self, element, context): |
def transform(self, element, context): |
122 |
result = Engine.transform(self, element, context) |
result = Engine.transform(self, element, context) |
123 |
return XML(result, context.root_xmlns_map, context.encoding) |
if hasattr(result, 'children'): |
124 |
|
return XML(result, context.root_xmlns_map, context.encoding) |
125 |
|
elif type(result) in (types.ListType, types.TupleType): |
126 |
|
return ''.join([str(child) for child in result]) |
127 |
|
return result |
128 |
|
|
129 |
def transform_children(self,element,context): |
def transform_children(self,element,context): |
130 |
element = Engine.transform_children(self, element, context) |
element = Engine.transform_children(self, element, context) |
131 |
# except that the children will be strings |
# except that the children will be strings |
132 |
if hasattr(element, 'children'): |
if hasattr(element, 'children'): |
133 |
element.children = (Literal(''.join(element)),) |
element.children = (Literal(''.join([str(child) for child in element if child])),) |
|
elif type(element) in (types.ListType, types.TupleType): |
|
|
element = Literal(''.join(element)) |
|
134 |
return element |
return element |
135 |
|
|
136 |
|
|