comparison emeraldtree/tree.py @ 95:5413661e5765

remove redundant code from tostring(list) functions, use new-style class, add method param to tostringlist function
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 23 Dec 2012 19:04:57 +0100
parents 08992651df1f
children c765f2440dad
comparison
equal deleted inserted replaced
94:08992651df1f 95:5413661e5765
666 # @param element An Element instance. 666 # @param element An Element instance.
667 # @return An encoded string containing the XML data. 667 # @return An encoded string containing the XML data.
668 # @defreturn string 668 # @defreturn string
669 669
670 def tostring(element, encoding=None, method=None): 670 def tostring(element, encoding=None, method=None):
671 class dummy: 671 data = tostringlist(element, encoding, method)
672 return "".join(data)
673
674 ##
675 # Generates a string representation of an XML element, including all
676 # subelements. The string is returned as a sequence of string fragments.
677 #
678 # @param element An Element instance.
679 # @return A sequence object containing the XML data.
680 # @defreturn sequence
681 # @since 1.3
682
683 def tostringlist(element, encoding=None, method=None):
684 class dummy(object):
672 pass 685 pass
673 data = [] 686 data = []
674 file = dummy() 687 file = dummy()
675 file.write = data.append 688 file.write = data.append
676 ElementTree(element).write(file, encoding, method=method) 689 ElementTree(element).write(file, encoding, method=method)
677 return "".join(data)
678
679 ##
680 # Generates a string representation of an XML element, including all
681 # subelements. The string is returned as a sequence of string fragments.
682 #
683 # @param element An Element instance.
684 # @return A sequence object containing the XML data.
685 # @defreturn sequence
686 # @since 1.3
687
688 def tostringlist(element, encoding=None):
689 class dummy:
690 pass
691 data = []
692 file = dummy()
693 file.write = data.append
694 ElementTree(element).write(file, encoding)
695 # FIXME: merge small fragments into larger parts 690 # FIXME: merge small fragments into larger parts
696 return data 691 return data
697 692
698 ## 693 ##
699 # Writes an element tree or element structure to sys.stdout. This 694 # Writes an element tree or element structure to sys.stdout. This