Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../lib64/python2....
File: macurl2path.py
"""Macintosh-specific module for conversion between pathnames and URLs.
[0] Fix | Delete
[1] Fix | Delete
Do not import directly; use urllib instead."""
[2] Fix | Delete
[3] Fix | Delete
import urllib
[4] Fix | Delete
import os
[5] Fix | Delete
[6] Fix | Delete
__all__ = ["url2pathname","pathname2url"]
[7] Fix | Delete
[8] Fix | Delete
def url2pathname(pathname):
[9] Fix | Delete
"""OS-specific conversion from a relative URL of the 'file' scheme
[10] Fix | Delete
to a file system path; not recommended for general use."""
[11] Fix | Delete
#
[12] Fix | Delete
# XXXX The .. handling should be fixed...
[13] Fix | Delete
#
[14] Fix | Delete
tp = urllib.splittype(pathname)[0]
[15] Fix | Delete
if tp and tp != 'file':
[16] Fix | Delete
raise RuntimeError, 'Cannot convert non-local URL to pathname'
[17] Fix | Delete
# Turn starting /// into /, an empty hostname means current host
[18] Fix | Delete
if pathname[:3] == '///':
[19] Fix | Delete
pathname = pathname[2:]
[20] Fix | Delete
elif pathname[:2] == '//':
[21] Fix | Delete
raise RuntimeError, 'Cannot convert non-local URL to pathname'
[22] Fix | Delete
components = pathname.split('/')
[23] Fix | Delete
# Remove . and embedded ..
[24] Fix | Delete
i = 0
[25] Fix | Delete
while i < len(components):
[26] Fix | Delete
if components[i] == '.':
[27] Fix | Delete
del components[i]
[28] Fix | Delete
elif components[i] == '..' and i > 0 and \
[29] Fix | Delete
components[i-1] not in ('', '..'):
[30] Fix | Delete
del components[i-1:i+1]
[31] Fix | Delete
i = i-1
[32] Fix | Delete
elif components[i] == '' and i > 0 and components[i-1] != '':
[33] Fix | Delete
del components[i]
[34] Fix | Delete
else:
[35] Fix | Delete
i = i+1
[36] Fix | Delete
if not components[0]:
[37] Fix | Delete
# Absolute unix path, don't start with colon
[38] Fix | Delete
rv = ':'.join(components[1:])
[39] Fix | Delete
else:
[40] Fix | Delete
# relative unix path, start with colon. First replace
[41] Fix | Delete
# leading .. by empty strings (giving ::file)
[42] Fix | Delete
i = 0
[43] Fix | Delete
while i < len(components) and components[i] == '..':
[44] Fix | Delete
components[i] = ''
[45] Fix | Delete
i = i + 1
[46] Fix | Delete
rv = ':' + ':'.join(components)
[47] Fix | Delete
# and finally unquote slashes and other funny characters
[48] Fix | Delete
return urllib.unquote(rv)
[49] Fix | Delete
[50] Fix | Delete
def pathname2url(pathname):
[51] Fix | Delete
"""OS-specific conversion from a file system path to a relative URL
[52] Fix | Delete
of the 'file' scheme; not recommended for general use."""
[53] Fix | Delete
if '/' in pathname:
[54] Fix | Delete
raise RuntimeError, "Cannot convert pathname containing slashes"
[55] Fix | Delete
components = pathname.split(':')
[56] Fix | Delete
# Remove empty first and/or last component
[57] Fix | Delete
if components[0] == '':
[58] Fix | Delete
del components[0]
[59] Fix | Delete
if components[-1] == '':
[60] Fix | Delete
del components[-1]
[61] Fix | Delete
# Replace empty string ('::') by .. (will result in '/../' later)
[62] Fix | Delete
for i in range(len(components)):
[63] Fix | Delete
if components[i] == '':
[64] Fix | Delete
components[i] = '..'
[65] Fix | Delete
# Truncate names longer than 31 bytes
[66] Fix | Delete
components = map(_pncomp2url, components)
[67] Fix | Delete
[68] Fix | Delete
if os.path.isabs(pathname):
[69] Fix | Delete
return '/' + '/'.join(components)
[70] Fix | Delete
else:
[71] Fix | Delete
return '/'.join(components)
[72] Fix | Delete
[73] Fix | Delete
def _pncomp2url(component):
[74] Fix | Delete
component = urllib.quote(component[:31], safe='') # We want to quote slashes
[75] Fix | Delete
return component
[76] Fix | Delete
[77] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function