def create_multiline_string(text, maximum_line_length=120): def escape(t): return t.replace(u'"""', six.u(r'\"\"\"')) source_substring = u'"""\n{}"""'.format(u'\\\n'.join( chunkate_string(escape(text), maximum_line_length))) return Token(tokens.TYPE_MULTILINE_STRING, source_substring)
def test_chunkate_string(): text = """Lorem ipsum dolor sit amet, consectetur adipiscing elit. In et lectus nec erat condimentum scelerisque gravida sed ipsum. Mauris non orci tincidunt, viverra enim eget, tincidunt orci. Sed placerat nibh vitae ante maximus egestas maximus eu quam. Praesent vehicula mauris vestibulum, mattis turpis sollicitudin, aliquam felis. Pellentesque volutpat pharetra purus vel finibus. Vestibulum sed tempus dui. Maecenas auctor sit amet diam et porta. Morbi id libero at elit ultricies porta vel vitae nullam. """ chunks = chunkate_string(text, 50) assert ''.join(chunks) == text assert all(len(chunk) <= 50 for chunk in chunks)
def create_multiline_string(text, maximum_line_length=120): def escape(t): return t.replace(u'"""', six.u(r'\"\"\"')) source_substring = u'"""\n{}"""'.format(u'\\\n'.join(chunkate_string(escape(text), maximum_line_length))) return Token(tokens.TYPE_MULTILINE_STRING, source_substring)