# HG changeset patch # User Paul Boddie # Date 1481762431 -3600 # Node ID 0c718cccf00fa9d34470bfa35546067763cf2bae # Parent 7a9dc5a0b86b885bade4e94e3e016e2abb42c312 Implemented the join method for Unicode objects, preserving encoding information if appropriate. diff -r 7a9dc5a0b86b -r 0c718cccf00f lib/__builtins__/unicode.py --- a/lib/__builtins__/unicode.py Thu Dec 15 01:39:45 2016 +0100 +++ b/lib/__builtins__/unicode.py Thu Dec 15 01:40:31 2016 +0100 @@ -130,6 +130,37 @@ finally: from_utf8.close() + def join(self, l): + + "Join the elements in 'l' with this string." + + # Empty strings just cause the list elements to be concatenated. + + nonempty = self.__bool__() + + # Non-empty strings join the elements together in a buffer. + + b = buffer() + first = True + encoding = self.encoding + + for s in l: + if first: + first = False + elif nonempty: + b.append(self) + + if _isinstance(s, utf8string): + encoding = None + + b.append(s) + + s = str(b) + if encoding: + s = utf8string(s) + s.encoding = encoding + return s + def unicode(s, encoding): "Convert 's' to a Unicode object, interpreting 's' as using 'encoding'."