MCPcopy
hub / github.com/StevenBlack/hosts / path_join_robust

Function path_join_robust

updateHostsFile.py:1863–1893  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1861
1862
1863def 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

Callers 15

test_basicMethod · 0.90
test_joinMethod · 0.90
test_join_unicodeMethod · 0.90
get_defaultsFunction · 0.85
mainFunction · 0.85
prompt_for_updateFunction · 0.85
update_sources_dataFunction · 0.85
update_all_sourcesFunction · 0.85
create_initial_fileFunction · 0.85
remove_dups_and_exclFunction · 0.85
write_opening_headerFunction · 0.85
update_readme_dataFunction · 0.85

Calls

no outgoing calls

Tested by 3

test_basicMethod · 0.72
test_joinMethod · 0.72
test_join_unicodeMethod · 0.72