Adding patch for webbrowser on macOS

This commit is contained in:
Michael Lazar
2017-09-06 00:22:05 -04:00
parent d7bb75d065
commit 5499aadffb
4 changed files with 82 additions and 30 deletions

View File

@@ -26,6 +26,7 @@ except ImportError:
# If we want to override the $BROWSER variable that the python webbrowser
# references, it needs to be done before the webbrowser module is imported
# for the first time.
webbrowser_import_warning = ('webbrowser' in sys.modules)
RTV_BROWSER, BROWSER = os.environ.get('RTV_BROWSER'), os.environ.get('BROWSER')
if RTV_BROWSER:
os.environ['BROWSER'] = RTV_BROWSER
@@ -36,7 +37,7 @@ from .packages import praw
from .config import Config, copy_default_config, copy_default_mailcap
from .oauth import OAuthHelper
from .terminal import Terminal
from .objects import curses_session, Color
from .objects import curses_session, Color, patch_webbrowser
from .subreddit_page import SubredditPage
from .exceptions import ConfigError
from .__version__ import __version__
@@ -156,6 +157,12 @@ def main():
_logger.info('Packaged PRAW not found, falling back to system '
'installed version %s', praw.__version__)
# Update the webbrowser module's default behavior
patch_webbrowser()
if webbrowser_import_warning:
_logger.warning('webbrowser module was unexpectedly imported before'
'$BROWSER could be overwritten')
# Construct the reddit user agent
user_agent = docs.AGENT.format(version=__version__)