Mercurial > hg
view hgext/pager.py @ 31361:8a17c541177f
py3: add "b" prefix to string literals related to module policy
String literals without explicit prefix in __init__.py and policy.py
are treated as unicode object on Python3, because these modules are
loaded before setup of our specific code transformation (the later
module is imported at the beginning of __init__.py).
BTW, "modulepolicy" in __init__.py is initialized by "policy.policy".
This causes issues below;
- checking "policy" value in other modules causes unintentional result
For example, "b'py' not in (u'c', u'py')" returns True
unintentionally on Python3.
- writing "policy" out fails at conversion from unicode to bytes
62939e0148f1 fixed this issue for default code path, but "policy"
can be overridden by HGMODULEPOLICY environment variable (it should
be rare case for developer using Python3, though).
This patch does:
- add "b" prefix to all string literals, which are related to module
policy, in modules above.
- check existence of HGMODULEPOLICY, and overwrite "policy" only if
it exists
For simplicity, this patch omits checking "supports_bytes_environ",
switching os.environ/os.environb, and so on (Yuya agreed this in
personal talking)
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Mon, 13 Mar 2017 04:06:36 +0900 |
parents | 53a60e95f154 |
children | e83302d43748 |
line wrap: on
line source
# pager.py - display output using a pager # # Copyright 2008 David Soria Parra <dsp@php.net> # # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. # # To load the extension, add it to your configuration file: # # [extension] # pager = # # Run 'hg help pager' to get info on configuration. '''browse command output with an external pager (DEPRECATED) Forcibly enable paging for individual commands that don't typically request pagination with the attend-<command> option. This setting takes precedence over ignore options and defaults:: [pager] attend-cat = false ''' from __future__ import absolute_import from mercurial import ( cmdutil, commands, dispatch, extensions, ) # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should # be specifying the version(s) of Mercurial they are tested with, or # leave the attribute unspecified. testedwith = 'ships-with-hg-core' def uisetup(ui): def pagecmd(orig, ui, options, cmd, cmdfunc): auto = options['pager'] == 'auto' if auto and not ui.pageractive: usepager = False attend = ui.configlist('pager', 'attend', attended) ignore = ui.configlist('pager', 'ignore') cmds, _ = cmdutil.findcmd(cmd, commands.table) for cmd in cmds: var = 'attend-%s' % cmd if ui.config('pager', var): usepager = ui.configbool('pager', var) break if (cmd in attend or (cmd not in ignore and not attend)): usepager = True break if usepager: # Slight hack: the attend list is supposed to override # the ignore list for the pager extension, but the # core code doesn't know about attend, so we have to # lobotomize the ignore list so that the extension's # behavior is preserved. ui.setconfig('pager', 'ignore', '', 'pager') ui.pager('extension-via-attend-' + cmd) return orig(ui, options, cmd, cmdfunc) extensions.wrapfunction(dispatch, '_runcommand', pagecmd) attended = [ 'the-default-attend-list-is-now-empty-but-that-breaks-the-extension', ]