Expand $VARS and ~names in a string, like a shell :Examples: In [2]: os.environ['FOO']='test' In [3]: expand_path('variable FOO is $FOO') Out[3]: 'variable FOO is test'
(s: str)
| 235 | |
| 236 | |
| 237 | def expand_path(s: str) -> str: |
| 238 | """Expand $VARS and ~names in a string, like a shell |
| 239 | |
| 240 | :Examples: |
| 241 | |
| 242 | In [2]: os.environ['FOO']='test' |
| 243 | |
| 244 | In [3]: expand_path('variable FOO is $FOO') |
| 245 | Out[3]: 'variable FOO is test' |
| 246 | """ |
| 247 | # This is a pretty subtle hack. When expand user is given a UNC path |
| 248 | # on Windows (\\server\share$\%username%), os.path.expandvars, removes |
| 249 | # the $ to get (\\server\share\%username%). I think it considered $ |
| 250 | # alone an empty var. But, we need the $ to remains there (it indicates |
| 251 | # a hidden share). |
| 252 | if os.name=='nt': |
| 253 | s = s.replace('$\\', 'IPYTHON_TEMP') |
| 254 | s = os.path.expandvars(os.path.expanduser(s)) |
| 255 | if os.name=='nt': |
| 256 | s = s.replace('IPYTHON_TEMP', '$\\') |
| 257 | return s |
| 258 | |
| 259 | |
| 260 | def unescape_glob(string): |
no test coverage detected
searching dependent graphs…