From cc9a11fba0781b9f0d29f0b318965340a3881a2a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 10 Sep 2018 20:20:26 +0530 Subject: [PATCH] Port os.getcwdu to python 3 --- setup/__init__.py | 2 ++ src/calibre/__init__.py | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/setup/__init__.py b/setup/__init__.py index b71ff1c65c..922e8b7197 100644 --- a/setup/__init__.py +++ b/setup/__init__.py @@ -23,6 +23,8 @@ sys.path.insert(0, SRC) 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.running_from_setup = True +if not hasattr(os, 'getcwdu'): + os.getcwdu = os.getcwd __version__ = __appname__ = modules = functions = basenames = scripts = None diff --git a/src/calibre/__init__.py b/src/calibre/__init__.py index 39180615c3..d72b709f07 100644 --- a/src/calibre/__init__.py +++ b/src/calibre/__init__.py @@ -12,6 +12,12 @@ if 'CALIBRE_SHOW_DEPRECATION_WARNINGS' not in os.environ: warnings.simplefilter('ignore', DeprecationWarning) try: os.getcwdu() +except AttributeError: + os.getcwdu = os.getcwd + try: + os.getcwd() + except EnvironmentError: + os.chdir(os.path.expanduser('~')) except EnvironmentError: os.chdir(os.path.expanduser('~')) @@ -342,9 +348,9 @@ def get_parsed_proxy(typ='http', debug=True): if proxy: pattern = re.compile(( '(?:ptype://)?' - '(?:(?P\w+):(?P.*)@)?' - '(?P[\w\-\.]+)' - '(?::(?P\d+))?').replace('ptype', typ) + '(?:(?P\\w+):(?P.*)@)?' + '(?P[\\w\\-\\.]+)' + '(?::(?P\\d+))?').replace('ptype', typ) ) match = pattern.match(proxies[typ])