diff --git a/src/manage/pathutils.py b/src/manage/pathutils.py index f2798e8..2e4cea3 100644 --- a/src/manage/pathutils.py +++ b/src/manage/pathutils.py @@ -11,6 +11,17 @@ def _eq(x, y): return x == y or x.casefold() == y.casefold() +def _splitroot(path): + try: + return os.path.splitroot(path) + except AttributeError: + import ntpath + drive, rest = ntpath.splitdrive(path) + if rest.startswith('\\') or rest.startswith('/'): + return drive, rest[0], rest[1:] + return drive, '', rest + + class PurePath: def __init__(self, *parts): total = "" @@ -28,7 +39,7 @@ def __init__(self, *parts): total += "\\" + p else: total += p - drive, root, tail = os.path.splitroot(total) + drive, root, tail = _splitroot(total) parent, _, name = tail.rpartition("\\") self._parent = drive + root + parent self.name = name @@ -72,7 +83,7 @@ def parent(self): @property def parts(self): - drive, root, tail = os.path.splitroot(self._p) + drive, root, tail = _splitroot(self._p) bits = [] if drive or root: bits.append(drive + root) @@ -120,7 +131,7 @@ def relative_to(self, base): return type(self)("\\".join(parts[len(base):])) def as_uri(self): - drive, root, tail = os.path.splitroot(self._p) + drive, root, tail = _splitroot(self._p) if drive[1:2] == ":" and root: return "file:///" + self._p.replace("\\", "/") if drive[:2] == "\\\\": diff --git a/src/manage/urlutils.py b/src/manage/urlutils.py index e8a3808..1f0005e 100644 --- a/src/manage/urlutils.py +++ b/src/manage/urlutils.py @@ -294,7 +294,15 @@ def _powershell_urlretrieve(request): $url = $env:PYMANAGER_URL $outfile = $env:PYMANAGER_OUTFILE $method = $env:PYMANAGER_METHOD -$headers = ConvertFrom-Json $env:PYMANAGER_HEADERS +$headersObj = ConvertFrom-Json $env:PYMANAGER_HEADERS +$headers = @{} +if ($headersObj -ne $null) { + $headersObj.PSObject.Properties | ForEach-Object { + $name = $_.Name + $value = $_.Value + $headers[$name] = if ($value -eq $null) { "" } else { $value.ToString() } + } +} $r = Invoke-WebRequest -Uri $url -UseBasicParsing ` -Headers $headers ` -UseDefaultCredentials `