Mercurial > public > mercurial-scm > hg
comparison mercurial/extensions.py @ 50918:538c5a48e8f4
extension: access special module members using sysstr
These extensions variables and mapping are module attributes so they should be
dealt with unicode `str` in Python 3. We move the part that deal with reading
theses variable and checking their validity to use unicode `str` string.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 31 Aug 2023 01:47:07 +0200 |
parents | f75fd677cc05 |
children | 0e6cea0c3113 |
comparison
equal
deleted
inserted
replaced
50917:882687259181 | 50918:538c5a48e8f4 |
---|---|
153 for x in xs: | 153 for x in xs: |
154 _rejectunicode(name, x) | 154 _rejectunicode(name, x) |
155 elif isinstance(xs, dict): | 155 elif isinstance(xs, dict): |
156 for k, v in xs.items(): | 156 for k, v in xs.items(): |
157 _rejectunicode(name, k) | 157 _rejectunicode(name, k) |
158 _rejectunicode(b'%s.%s' % (name, stringutil.forcebytestr(k)), v) | 158 k = pycompat.sysstr(k) |
159 elif isinstance(xs, type(u'')): | 159 _rejectunicode('%s.%s' % (name, k), v) |
160 elif isinstance(xs, str): | |
160 raise error.ProgrammingError( | 161 raise error.ProgrammingError( |
161 b"unicode %r found in %s" % (xs, name), | 162 b"unicode %r found in %s" % (xs, stringutil.forcebytestr(name)), |
162 hint=b"use b'' to make it byte string", | 163 hint=b"use b'' to make it byte string", |
163 ) | 164 ) |
164 | 165 |
165 | 166 |
166 # attributes set by registrar.command | 167 # attributes set by registrar.command |
180 ) | 181 ) |
181 | 182 |
182 | 183 |
183 def _validatetables(ui, mod): | 184 def _validatetables(ui, mod): |
184 """Sanity check for loadable tables provided by extension module""" | 185 """Sanity check for loadable tables provided by extension module""" |
185 for t in [b'cmdtable', b'colortable', b'configtable']: | 186 for t in ['cmdtable', 'colortable', 'configtable']: |
186 _rejectunicode(t, getattr(mod, t, {})) | 187 _rejectunicode(t, getattr(mod, t, {})) |
187 for t in [ | 188 for t in [ |
188 b'filesetpredicate', | 189 'filesetpredicate', |
189 b'internalmerge', | 190 'internalmerge', |
190 b'revsetpredicate', | 191 'revsetpredicate', |
191 b'templatefilter', | 192 'templatefilter', |
192 b'templatefunc', | 193 'templatefunc', |
193 b'templatekeyword', | 194 'templatekeyword', |
194 ]: | 195 ]: |
195 o = getattr(mod, t, None) | 196 o = getattr(mod, t, None) |
196 if o: | 197 if o: |
197 _rejectunicode(t, o._table) | 198 _rejectunicode(t, o._table) |
198 _validatecmdtable(ui, getattr(mod, 'cmdtable', {})) | 199 _validatecmdtable(ui, getattr(mod, 'cmdtable', {})) |
347 # - loadername is the name of the function, | 348 # - loadername is the name of the function, |
348 # which takes (ui, extensionname, extraobj) arguments | 349 # which takes (ui, extensionname, extraobj) arguments |
349 # | 350 # |
350 # This one is for the list of item that must be run before running any setup | 351 # This one is for the list of item that must be run before running any setup |
351 earlyextraloaders = [ | 352 earlyextraloaders = [ |
352 (b'configtable', configitems, b'loadconfigtable'), | 353 ('configtable', configitems, 'loadconfigtable'), |
353 ] | 354 ] |
354 | 355 |
355 ui.log(b'extension', b'- loading configtable attributes\n') | 356 ui.log(b'extension', b'- loading configtable attributes\n') |
356 _loadextra(ui, newindex, earlyextraloaders) | 357 _loadextra(ui, newindex, earlyextraloaders) |
357 | 358 |
432 # - loadermod is the module where loader is placed | 433 # - loadermod is the module where loader is placed |
433 # - loadername is the name of the function, | 434 # - loadername is the name of the function, |
434 # which takes (ui, extensionname, extraobj) arguments | 435 # which takes (ui, extensionname, extraobj) arguments |
435 ui.log(b'extension', b'- loading extension registration objects\n') | 436 ui.log(b'extension', b'- loading extension registration objects\n') |
436 extraloaders = [ | 437 extraloaders = [ |
437 (b'cmdtable', commands, b'loadcmdtable'), | 438 ('cmdtable', commands, 'loadcmdtable'), |
438 (b'colortable', color, b'loadcolortable'), | 439 ('colortable', color, 'loadcolortable'), |
439 (b'filesetpredicate', fileset, b'loadpredicate'), | 440 ('filesetpredicate', fileset, 'loadpredicate'), |
440 (b'internalmerge', filemerge, b'loadinternalmerge'), | 441 ('internalmerge', filemerge, 'loadinternalmerge'), |
441 (b'revsetpredicate', revset, b'loadpredicate'), | 442 ('revsetpredicate', revset, 'loadpredicate'), |
442 (b'templatefilter', templatefilters, b'loadfilter'), | 443 ('templatefilter', templatefilters, 'loadfilter'), |
443 (b'templatefunc', templatefuncs, b'loadfunction'), | 444 ('templatefunc', templatefuncs, 'loadfunction'), |
444 (b'templatekeyword', templatekw, b'loadkeyword'), | 445 ('templatekeyword', templatekw, 'loadkeyword'), |
445 ] | 446 ] |
446 with util.timedcm('load registration objects') as stats: | 447 with util.timedcm('load registration objects') as stats: |
447 _loadextra(ui, newindex, extraloaders) | 448 _loadextra(ui, newindex, extraloaders) |
448 ui.log( | 449 ui.log( |
449 b'extension', | 450 b'extension', |