Show More
@@ -19,6 +19,7 b' from mercurial import (' | |||||
19 | cmdutil, |
|
19 | cmdutil, | |
20 | commands, |
|
20 | commands, | |
21 | error, |
|
21 | error, | |
|
22 | pycompat, | |||
22 | registrar, |
|
23 | registrar, | |
23 | ) |
|
24 | ) | |
24 |
|
25 | |||
@@ -133,5 +134,5 b' def showbookmarks(ui, repo, fm):' | |||||
133 | # TODO make this more robust. |
|
134 | # TODO make this more robust. | |
134 | longest = max(map(len, showview._table.keys())) |
|
135 | longest = max(map(len, showview._table.keys())) | |
135 | for key in sorted(showview._table.keys()): |
|
136 | for key in sorted(showview._table.keys()): | |
136 | cmdtable['show'][0].__doc__ += ' %s %s\n' % ( |
|
137 | cmdtable['show'][0].__doc__ += pycompat.sysstr(' %s %s\n' % ( | |
137 | key.ljust(longest), showview._table[key]._origdoc) |
|
138 | key.ljust(longest), showview._table[key]._origdoc)) |
@@ -142,6 +142,14 b' if ispy3:' | |||||
142 | """Iterate bytes as if it were a str object of Python 2""" |
|
142 | """Iterate bytes as if it were a str object of Python 2""" | |
143 | return map(bytechr, s) |
|
143 | return map(bytechr, s) | |
144 |
|
144 | |||
|
145 | def sysbytes(s): | |||
|
146 | """Convert an internal str (e.g. keyword, __doc__) back to bytes | |||
|
147 | ||||
|
148 | This never raises UnicodeEncodeError, but only ASCII characters | |||
|
149 | can be round-trip by sysstr(sysbytes(s)). | |||
|
150 | """ | |||
|
151 | return s.encode(u'utf-8') | |||
|
152 | ||||
145 | def sysstr(s): |
|
153 | def sysstr(s): | |
146 | """Return a keyword str to be passed to Python functions such as |
|
154 | """Return a keyword str to be passed to Python functions such as | |
147 | getattr() and str.encode() |
|
155 | getattr() and str.encode() | |
@@ -210,6 +218,7 b' else:' | |||||
210 | bytechr = chr |
|
218 | bytechr = chr | |
211 | bytestr = str |
|
219 | bytestr = str | |
212 | iterbytestr = iter |
|
220 | iterbytestr = iter | |
|
221 | sysbytes = identity | |||
213 | sysstr = identity |
|
222 | sysstr = identity | |
214 |
|
223 | |||
215 | # Partial backport from os.py in Python 3, which only accepts bytes. |
|
224 | # Partial backport from os.py in Python 3, which only accepts bytes. |
@@ -56,9 +56,9 b' class _funcregistrarbase(object):' | |||||
56 | raise error.ProgrammingError(msg) |
|
56 | raise error.ProgrammingError(msg) | |
57 |
|
57 | |||
58 | if func.__doc__ and not util.safehasattr(func, '_origdoc'): |
|
58 | if func.__doc__ and not util.safehasattr(func, '_origdoc'): | |
59 | doc = func.__doc__.strip() |
|
59 | doc = pycompat.sysbytes(func.__doc__).strip() | |
60 | func._origdoc = doc |
|
60 | func._origdoc = doc | |
61 | func.__doc__ = self._formatdoc(decl, doc) |
|
61 | func.__doc__ = pycompat.sysstr(self._formatdoc(decl, doc)) | |
62 |
|
62 | |||
63 | self._table[name] = func |
|
63 | self._table[name] = func | |
64 | self._extrasetup(name, func, *args, **kwargs) |
|
64 | self._extrasetup(name, func, *args, **kwargs) | |
@@ -127,7 +127,7 b' class revsetpredicate(_funcregistrarbase' | |||||
127 | Otherwise, explicit 'revset.loadpredicate()' is needed. |
|
127 | Otherwise, explicit 'revset.loadpredicate()' is needed. | |
128 | """ |
|
128 | """ | |
129 | _getname = _funcregistrarbase._parsefuncdecl |
|
129 | _getname = _funcregistrarbase._parsefuncdecl | |
130 |
_docformat = |
|
130 | _docformat = "``%s``\n %s" | |
131 |
|
131 | |||
132 | def _extrasetup(self, name, func, safe=False, takeorder=False): |
|
132 | def _extrasetup(self, name, func, safe=False, takeorder=False): | |
133 | func._safe = safe |
|
133 | func._safe = safe | |
@@ -166,7 +166,7 b' class filesetpredicate(_funcregistrarbas' | |||||
166 | Otherwise, explicit 'fileset.loadpredicate()' is needed. |
|
166 | Otherwise, explicit 'fileset.loadpredicate()' is needed. | |
167 | """ |
|
167 | """ | |
168 | _getname = _funcregistrarbase._parsefuncdecl |
|
168 | _getname = _funcregistrarbase._parsefuncdecl | |
169 |
_docformat = |
|
169 | _docformat = "``%s``\n %s" | |
170 |
|
170 | |||
171 | def _extrasetup(self, name, func, callstatus=False, callexisting=False): |
|
171 | def _extrasetup(self, name, func, callstatus=False, callexisting=False): | |
172 | func._callstatus = callstatus |
|
172 | func._callstatus = callstatus | |
@@ -175,7 +175,7 b' class filesetpredicate(_funcregistrarbas' | |||||
175 | class _templateregistrarbase(_funcregistrarbase): |
|
175 | class _templateregistrarbase(_funcregistrarbase): | |
176 | """Base of decorator to register functions as template specific one |
|
176 | """Base of decorator to register functions as template specific one | |
177 | """ |
|
177 | """ | |
178 |
_docformat = |
|
178 | _docformat = ":%s: %s" | |
179 |
|
179 | |||
180 | class templatekeyword(_templateregistrarbase): |
|
180 | class templatekeyword(_templateregistrarbase): | |
181 | """Decorator to register template keyword |
|
181 | """Decorator to register template keyword |
General Comments 0
You need to be logged in to leave comments.
Login now