Port os.getcwdu to python 3

This commit is contained in:
Kovid Goyal 2018-09-10 20:20:26 +05:30
parent 5234e43f0e
commit cc9a11fba0
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 11 additions and 3 deletions

View File

@ -23,6 +23,8 @@ sys.path.insert(0, SRC)
sys.resources_location = os.path.join(os.path.dirname(SRC), 'resources') sys.resources_location = os.path.join(os.path.dirname(SRC), 'resources')
sys.extensions_location = os.path.abspath(os.environ.get('CALIBRE_SETUP_EXTENSIONS_PATH', os.path.join(SRC, 'calibre', 'plugins'))) sys.extensions_location = os.path.abspath(os.environ.get('CALIBRE_SETUP_EXTENSIONS_PATH', os.path.join(SRC, 'calibre', 'plugins')))
sys.running_from_setup = True sys.running_from_setup = True
if not hasattr(os, 'getcwdu'):
os.getcwdu = os.getcwd
__version__ = __appname__ = modules = functions = basenames = scripts = None __version__ = __appname__ = modules = functions = basenames = scripts = None

View File

@ -12,6 +12,12 @@ if 'CALIBRE_SHOW_DEPRECATION_WARNINGS' not in os.environ:
warnings.simplefilter('ignore', DeprecationWarning) warnings.simplefilter('ignore', DeprecationWarning)
try: try:
os.getcwdu() os.getcwdu()
except AttributeError:
os.getcwdu = os.getcwd
try:
os.getcwd()
except EnvironmentError:
os.chdir(os.path.expanduser('~'))
except EnvironmentError: except EnvironmentError:
os.chdir(os.path.expanduser('~')) os.chdir(os.path.expanduser('~'))
@ -342,9 +348,9 @@ def get_parsed_proxy(typ='http', debug=True):
if proxy: if proxy:
pattern = re.compile(( pattern = re.compile((
'(?:ptype://)?' '(?:ptype://)?'
'(?:(?P<user>\w+):(?P<pass>.*)@)?' '(?:(?P<user>\\w+):(?P<pass>.*)@)?'
'(?P<host>[\w\-\.]+)' '(?P<host>[\\w\\-\\.]+)'
'(?::(?P<port>\d+))?').replace('ptype', typ) '(?::(?P<port>\\d+))?').replace('ptype', typ)
) )
match = pattern.match(proxies[typ]) match = pattern.match(proxies[typ])