[FIX] #1085 fix unicode handling

element.text  and  element.tail  are supposed to be unicode object. Everything should be handled with unicode objects inside the code, decoding should occur just after the inputs and encoding juste before outputs.

In the first fix, the `result` variable was already an encoded string, as it comes from a render output, while element.tail is still a unicode object. Thus element.tail must first be encoded to a string to be compatible with the pending output result.

In the second fix, `g_inner` is directly used to be returned to output a few lines later, so its content should already be encoded. (it may possibly be a little better to defer the encoding just before the return, but there are too many string handling before the return).