Wrapper around `os.path.join` with handling for locale issues. Parameters ---------- path : str The first path to join. paths : varargs Subsequent path strings to join. Returns ------- joined_path : str The joined path string of the two path
(path, *paths)
| 1861 | |
| 1862 | |
| 1863 | def path_join_robust(path, *paths): |
| 1864 | """ |
| 1865 | Wrapper around `os.path.join` with handling for locale issues. |
| 1866 | |
| 1867 | Parameters |
| 1868 | ---------- |
| 1869 | path : str |
| 1870 | The first path to join. |
| 1871 | paths : varargs |
| 1872 | Subsequent path strings to join. |
| 1873 | |
| 1874 | Returns |
| 1875 | ------- |
| 1876 | joined_path : str |
| 1877 | The joined path string of the two path inputs. |
| 1878 | |
| 1879 | Raises |
| 1880 | ------ |
| 1881 | locale.Error : A locale issue was detected that prevents path joining. |
| 1882 | """ |
| 1883 | |
| 1884 | try: |
| 1885 | # gh-316: joining unicode and str can be saddening in Python 2.x |
| 1886 | path = str(path) |
| 1887 | paths = [str(another_path) for another_path in paths] |
| 1888 | |
| 1889 | return os.path.join(path, *paths) |
| 1890 | except UnicodeDecodeError as e: |
| 1891 | raise locale.Error( |
| 1892 | "Unable to construct path. This is likely a LOCALE issue:\n\n" + str(e) |
| 1893 | ) |
| 1894 | |
| 1895 | |
| 1896 | # Colors |
no outgoing calls