+def tag_open_close(name_, classes_=None, **attrs):
+ u"""Creates tag beginning and end.
+
+ >>> tag_open_close("a", "klass", x=u"ą<")
+ (u'<a x="\\u0105<" class="klass">', u'</a>')
+
+ """
+ if classes_:
+ if isinstance(classes_, (tuple, list)):
+ classes_ = ' '.join(classes_)
+ attrs['class'] = classes_
+
+ e = etree.Element(name_)
+ e.text = " "
+ for k, v in attrs.items():
+ e.attrib[k] = v
+ pre, post = etree.tostring(e, encoding=unicode).split(u"> <")
+ return pre + u">", u"<" + post
+
+
+def tag(name_, classes_=None, **attrs):