Merge branch 'master' into themes
This commit is contained in:
@@ -3,12 +3,14 @@ from __future__ import unicode_literals
|
||||
|
||||
import re
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import signal
|
||||
import inspect
|
||||
import weakref
|
||||
import logging
|
||||
import threading
|
||||
import webbrowser
|
||||
import curses
|
||||
import curses.ascii
|
||||
from contextlib import contextmanager
|
||||
@@ -23,6 +25,31 @@ from .packages import praw
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def patch_webbrowser():
|
||||
"""
|
||||
Patch webbrowser on macOS to support setting BROWSER=firefox,
|
||||
BROWSER=chrome, etc..
|
||||
|
||||
https://bugs.python.org/issue31348
|
||||
"""
|
||||
|
||||
if sys.platform != 'darwin' or 'BROWSER' not in os.environ:
|
||||
return
|
||||
|
||||
# This is a copy of what's at the end of webbrowser.py, except that
|
||||
# it adds MacOSXOSAScript entries instead of GenericBrowser entries.
|
||||
_userchoices = os.environ["BROWSER"].split(os.pathsep)
|
||||
for cmdline in reversed(_userchoices):
|
||||
if cmdline in ('safari', 'firefox', 'chrome', 'default'):
|
||||
browser = webbrowser.MacOSXOSAScript(cmdline)
|
||||
try:
|
||||
webbrowser.register(cmdline, None, browser, update_tryorder=-1)
|
||||
except TypeError:
|
||||
# 3.7 nightly build changed the method signature
|
||||
# pylint: disable=unexpected-keyword-arg
|
||||
webbrowser.register(cmdline, None, browser, preferred=True)
|
||||
|
||||
|
||||
@contextmanager
|
||||
def curses_session():
|
||||
"""
|
||||
@@ -605,14 +632,16 @@ class KeyMap(object):
|
||||
self.set_bindings(bindings)
|
||||
|
||||
def set_bindings(self, bindings):
|
||||
# Clear the keymap before applying the bindings to avoid confusion.
|
||||
# If a user defines custom bindings in their config file, they must
|
||||
# explicitly define ALL of the bindings.
|
||||
self._keymap = {}
|
||||
new_keymap = {}
|
||||
for command, keys in bindings.items():
|
||||
if not isinstance(command, Command):
|
||||
command = Command(command)
|
||||
self._keymap[command] = keys
|
||||
new_keymap[command] = keys
|
||||
|
||||
if not self._keymap:
|
||||
self._keymap = new_keymap
|
||||
else:
|
||||
self._keymap.update(new_keymap)
|
||||
|
||||
def get(self, command):
|
||||
if not isinstance(command, Command):
|
||||
@@ -656,4 +685,4 @@ class KeyMap(object):
|
||||
|
||||
except (AttributeError, ValueError, TypeError):
|
||||
raise exceptions.ConfigError('Invalid configuration! "%s" is not a '
|
||||
'valid key' % key)
|
||||
'valid key' % key)
|
||||
|
||||
Reference in New Issue
Block a user