Return a cleaned description text, removing extra leading whitespaces if needed. Some metadata formats padd each description line with 8 spaces. Some do not. We check first and cleanup if needed.
(description)
| 1903 | |
| 1904 | |
| 1905 | def clean_description(description): |
| 1906 | """ |
| 1907 | Return a cleaned description text, removing extra leading whitespaces if |
| 1908 | needed. Some metadata formats padd each description line with 8 spaces. Some |
| 1909 | do not. We check first and cleanup if needed. |
| 1910 | """ |
| 1911 | # TODO: verify what is the impact of Description-Content-Type: if any |
| 1912 | description = description or '' |
| 1913 | description = description.strip() |
| 1914 | lines = description.splitlines(False) |
| 1915 | |
| 1916 | space_padding = ' ' * 8 |
| 1917 | |
| 1918 | # we need cleaning if any of the first two lines starts with 8 spaces |
| 1919 | need_cleaning = any(l.startswith(space_padding) for l in lines[:2]) |
| 1920 | if not need_cleaning: |
| 1921 | return description |
| 1922 | |
| 1923 | cleaned_lines = [ |
| 1924 | line[8:] if line.startswith(space_padding) else line |
| 1925 | for line in lines |
| 1926 | ] |
| 1927 | |
| 1928 | return '\n'.join(cleaned_lines) |
| 1929 | |
| 1930 | |
| 1931 | def get_legacy_description(location): |