##// END OF EJS Templates
stringutil: bulk-replace call sites to point to new module...
Yuya Nishihara -
r37102:f0b6fbea default
parent child Browse files
Show More
@@ -307,6 +307,9 from mercurial import (
307 307 url,
308 308 util,
309 309 )
310 from mercurial.utils import (
311 stringutil,
312 )
310 313
311 314 xmlrpclib = util.xmlrpclib
312 315
@@ -1099,7 +1102,8 class bugzilla(object):
1099 1102 root=self.repo.root,
1100 1103 webroot=webroot(self.repo.root))
1101 1104 data = self.ui.popbuffer()
1102 self.bzdriver.updatebug(bugid, newstate, data, util.email(ctx.user()))
1105 self.bzdriver.updatebug(bugid, newstate, data,
1106 stringutil.email(ctx.user()))
1103 1107
1104 1108 def notify(self, bugs, committer):
1105 1109 '''ensure Bugzilla users are notified of bug change.'''
@@ -1119,6 +1123,6 def hook(ui, repo, hooktype, node=None,
1119 1123 if bugs:
1120 1124 for bug in bugs:
1121 1125 bz.update(bug, bugs[bug], ctx)
1122 bz.notify(bugs, util.email(ctx.user()))
1126 bz.notify(bugs, stringutil.email(ctx.user()))
1123 1127 except Exception as e:
1124 1128 raise error.Abort(_('Bugzilla error: %s') % e)
@@ -17,7 +17,10 from mercurial import (
17 17 pycompat,
18 18 util,
19 19 )
20 from mercurial.utils import dateutil
20 from mercurial.utils import (
21 dateutil,
22 stringutil,
23 )
21 24
22 25 pickle = util.pickle
23 26
@@ -452,7 +455,8 def createlog(ui, directory=None, root="
452 455 rcsmap[e.rcs.replace('/Attic/', '/')] = e.rcs
453 456
454 457 if len(log) % 100 == 0:
455 ui.status(util.ellipsis('%d %s' % (len(log), e.file), 80)+'\n')
458 ui.status(stringutil.ellipsis('%d %s' % (len(log), e.file), 80)
459 + '\n')
456 460
457 461 log.sort(key=lambda x: (x.rcs, x.revision))
458 462
@@ -608,7 +612,7 def createchangeset(ui, log, fuzz=60, me
608 612 files = set()
609 613 if len(changesets) % 100 == 0:
610 614 t = '%d %s' % (len(changesets), repr(e.comment)[1:-1])
611 ui.status(util.ellipsis(t, 80) + '\n')
615 ui.status(stringutil.ellipsis(t, 80) + '\n')
612 616
613 617 c.entries.append(e)
614 618 files.add(e.file)
@@ -14,7 +14,10 from mercurial import (
14 14 error,
15 15 util,
16 16 )
17 from mercurial.utils import dateutil
17 from mercurial.utils import (
18 dateutil,
19 stringutil,
20 )
18 21
19 22 from . import common
20 23
@@ -169,7 +172,7 class p4_source(common.converter_source)
169 172 shortdesc = '**empty changelist description**'
170 173
171 174 t = '%s %s' % (c.rev, repr(shortdesc)[1:-1])
172 ui.status(util.ellipsis(t, 80) + '\n')
175 ui.status(stringutil.ellipsis(t, 80) + '\n')
173 176
174 177 files = []
175 178 copies = {}
@@ -16,7 +16,10 from mercurial import (
16 16 util,
17 17 vfs as vfsmod,
18 18 )
19 from mercurial.utils import dateutil
19 from mercurial.utils import (
20 dateutil,
21 stringutil,
22 )
20 23
21 24 from . import common
22 25
@@ -147,7 +150,7 def get_log_child(fp, url, paths, start,
147 150 # Caller may interrupt the iteration
148 151 pickle.dump(None, fp, protocol)
149 152 except Exception as inst:
150 pickle.dump(util.forcebytestr(inst), fp, protocol)
153 pickle.dump(stringutil.forcebytestr(inst), fp, protocol)
151 154 else:
152 155 pickle.dump(None, fp, protocol)
153 156 fp.flush()
@@ -1315,7 +1318,7 class svn_sink(converter_sink, commandli
1315 1318 fp.close()
1316 1319 try:
1317 1320 output = self.run0('commit',
1318 username=util.shortuser(commit.author),
1321 username=stringutil.shortuser(commit.author),
1319 1322 file=messagefile,
1320 1323 encoding='utf-8')
1321 1324 try:
@@ -105,6 +105,9 from mercurial import (
105 105 registrar,
106 106 util,
107 107 )
108 from mercurial.utils import (
109 stringutil,
110 )
108 111
109 112 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
110 113 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
@@ -133,7 +136,7 def inconsistenteol(data):
133 136
134 137 def tolf(s, params, ui, **kwargs):
135 138 """Filter to convert to LF EOLs."""
136 if util.binary(s):
139 if stringutil.binary(s):
137 140 return s
138 141 if ui.configbool('eol', 'only-consistent') and inconsistenteol(s):
139 142 return s
@@ -144,7 +147,7 def tolf(s, params, ui, **kwargs):
144 147
145 148 def tocrlf(s, params, ui, **kwargs):
146 149 """Filter to convert to CRLF EOLs."""
147 if util.binary(s):
150 if stringutil.binary(s):
148 151 return s
149 152 if ui.configbool('eol', 'only-consistent') and inconsistenteol(s):
150 153 return s
@@ -403,7 +406,7 def reposetup(ui, repo):
403 406 if fctx is None:
404 407 continue
405 408 data = fctx.data()
406 if util.binary(data):
409 if stringutil.binary(data):
407 410 # We should not abort here, since the user should
408 411 # be able to say "** = native" to automatically
409 412 # have all non-binary files taken care of.
@@ -82,6 +82,9 from mercurial import (
82 82 scmutil,
83 83 util,
84 84 )
85 from mercurial.utils import (
86 stringutil,
87 )
85 88
86 89 cmdtable = {}
87 90 command = registrar.command(cmdtable)
@@ -367,8 +370,8 class savedcmd(object):
367 370 def __init__(self, path, cmdline):
368 371 # We can't pass non-ASCII through docstrings (and path is
369 372 # in an unknown encoding anyway)
370 docpath = util.escapestr(path)
371 self.__doc__ %= {r'path': pycompat.sysstr(util.uirepr(docpath))}
373 docpath = stringutil.escapestr(path)
374 self.__doc__ %= {r'path': pycompat.sysstr(stringutil.uirepr(docpath))}
372 375 self._cmdline = cmdline
373 376
374 377 def __call__(self, ui, repo, *pats, **opts):
@@ -15,7 +15,10 demandimport.ignore.extend(['pkgutil', '
15 15
16 16 from mercurial import (
17 17 encoding,
18 util,
18 )
19
20 from mercurial.utils import (
21 stringutil,
19 22 )
20 23
21 24 with demandimport.deactivated():
@@ -47,7 +50,7 def pygmentize(field, fctx, style, tmpl,
47 50 tmpl.cache['header'] = new_header
48 51
49 52 text = fctx.data()
50 if util.binary(text):
53 if stringutil.binary(text):
51 54 return
52 55
53 56 # str.splitlines() != unicode.splitlines() because "reasons"
@@ -209,6 +209,9 from mercurial import (
209 209 scmutil,
210 210 util,
211 211 )
212 from mercurial.utils import (
213 stringutil,
214 )
212 215
213 216 pickle = util.pickle
214 217 release = lock.release
@@ -465,7 +468,7 class histeditaction(object):
465 468 # (the 5 more are left for verb)
466 469 maxlen = self.repo.ui.configint('histedit', 'linelen')
467 470 maxlen = max(maxlen, 22) # avoid truncating hash
468 return util.ellipsis(line, maxlen)
471 return stringutil.ellipsis(line, maxlen)
469 472
470 473 def tostate(self):
471 474 """Print an action in format used by histedit state files
@@ -36,7 +36,10 from mercurial import (
36 36 registrar,
37 37 util,
38 38 )
39 from mercurial.utils import dateutil
39 from mercurial.utils import (
40 dateutil,
41 stringutil,
42 )
40 43
41 44 cmdtable = {}
42 45 command = registrar.command(cmdtable)
@@ -376,9 +379,9 class journalstorage(object):
376 379
377 380 """
378 381 if namespace is not None:
379 namespace = util.stringmatcher(namespace)[-1]
382 namespace = stringutil.stringmatcher(namespace)[-1]
380 383 if name is not None:
381 name = util.stringmatcher(name)[-1]
384 name = stringutil.stringmatcher(name)[-1]
382 385 for entry in self:
383 386 if namespace is not None and not namespace(entry.namespace):
384 387 continue
@@ -111,7 +111,10 from mercurial import (
111 111 templatefilters,
112 112 util,
113 113 )
114 from mercurial.utils import dateutil
114 from mercurial.utils import (
115 dateutil,
116 stringutil,
117 )
115 118
116 119 cmdtable = {}
117 120 command = registrar.command(cmdtable)
@@ -272,7 +275,8 class kwtemplater(object):
272 275
273 276 def expand(self, path, node, data):
274 277 '''Returns data with keywords expanded.'''
275 if not self.restrict and self.match(path) and not util.binary(data):
278 if (not self.restrict and self.match(path)
279 and not stringutil.binary(data)):
276 280 ctx = self.linkctx(path, node)
277 281 return self.substitute(data, path, ctx, self.rekw.sub)
278 282 return data
@@ -304,7 +308,7 class kwtemplater(object):
304 308 data = self.repo.file(f).read(mf[f])
305 309 else:
306 310 data = self.repo.wread(f)
307 if util.binary(data):
311 if stringutil.binary(data):
308 312 continue
309 313 if expand:
310 314 parents = ctx.parents()
@@ -335,7 +339,7 class kwtemplater(object):
335 339
336 340 def shrink(self, fname, text):
337 341 '''Returns text with all keyword substitutions removed.'''
338 if self.match(fname) and not util.binary(text):
342 if self.match(fname) and not stringutil.binary(text):
339 343 return _shrinktext(text, self.rekwexp.sub)
340 344 return text
341 345
@@ -343,7 +347,7 class kwtemplater(object):
343 347 '''Returns lines with keyword substitutions removed.'''
344 348 if self.match(fname):
345 349 text = ''.join(lines)
346 if not util.binary(text):
350 if not stringutil.binary(text):
347 351 return _shrinktext(text, self.rekwexp.sub).splitlines(True)
348 352 return lines
349 353
@@ -14,6 +14,10 from mercurial import (
14 14 util,
15 15 )
16 16
17 from mercurial.utils import (
18 stringutil,
19 )
20
17 21 from . import (
18 22 basestore,
19 23 lfutil,
@@ -52,7 +56,7 class remotestore(basestore.basestore):
52 56 except IOError as e:
53 57 raise error.Abort(
54 58 _('remotestore: could not open file %s: %s')
55 % (filename, util.forcebytestr(e)))
59 % (filename, stringutil.forcebytestr(e)))
56 60
57 61 def _getfile(self, tmpfile, filename, hash):
58 62 try:
@@ -61,7 +65,7 class remotestore(basestore.basestore):
61 65 # 401s get converted to error.Aborts; everything else is fine being
62 66 # turned into a StoreError
63 67 raise basestore.StoreError(filename, hash, self.url,
64 util.forcebytestr(e))
68 stringutil.forcebytestr(e))
65 69 except urlerr.urlerror as e:
66 70 # This usually indicates a connection problem, so don't
67 71 # keep trying with the other files... they will probably
@@ -70,7 +74,7 class remotestore(basestore.basestore):
70 74 (util.hidepassword(self.url), e.reason))
71 75 except IOError as e:
72 76 raise basestore.StoreError(filename, hash, self.url,
73 util.forcebytestr(e))
77 stringutil.forcebytestr(e))
74 78
75 79 return lfutil.copyandhash(chunks, tmpfile)
76 80
@@ -19,6 +19,10 from mercurial import (
19 19 util,
20 20 )
21 21
22 from mercurial.utils import (
23 stringutil,
24 )
25
22 26 from ..largefiles import lfutil
23 27
24 28 from . import (
@@ -95,7 +99,7 def writetostore(self, text):
95 99 # by default, we expect the content to be binary. however, LFS could also
96 100 # be used for non-binary content. add a special entry for non-binary data.
97 101 # this will be used by filectx.isbinary().
98 if not util.binary(text):
102 if not stringutil.binary(text):
99 103 # not hg filelog metadata (affecting commit hash), no "x-hg-" prefix
100 104 metadata['x-is-binary'] = '0'
101 105
@@ -98,7 +98,10 from mercurial import (
98 98 util,
99 99 vfs as vfsmod,
100 100 )
101 from mercurial.utils import dateutil
101 from mercurial.utils import (
102 dateutil,
103 stringutil,
104 )
102 105
103 106 release = lockmod.release
104 107 seriesopts = [('s', 'summary', None, _('print first line of patch header'))]
@@ -469,7 +472,7 class queue(object):
469 472 self.guardsdirty = False
470 473 # Handle mq.git as a bool with extended values
471 474 gitmode = ui.config('mq', 'git').lower()
472 boolmode = util.parsebool(gitmode)
475 boolmode = stringutil.parsebool(gitmode)
473 476 if boolmode is not None:
474 477 if boolmode:
475 478 gitmode = 'yes'
@@ -724,7 +727,7 class queue(object):
724 727 os.unlink(undo)
725 728 except OSError as inst:
726 729 self.ui.warn(_('error removing undo: %s\n') %
727 util.forcebytestr(inst))
730 stringutil.forcebytestr(inst))
728 731
729 732 def backup(self, repo, files, copy=False):
730 733 # backup local changes in --force case
@@ -857,7 +860,7 class queue(object):
857 860 files=files, eolmode=None)
858 861 return (True, list(files), fuzz)
859 862 except Exception as inst:
860 self.ui.note(util.forcebytestr(inst) + '\n')
863 self.ui.note(stringutil.forcebytestr(inst) + '\n')
861 864 if not self.ui.verbose:
862 865 self.ui.warn(_("patch failed, unable to continue (try -v)\n"))
863 866 self.ui.traceback()
@@ -1917,7 +1920,7 class queue(object):
1917 1920 if self.ui.formatted():
1918 1921 width = self.ui.termwidth() - len(pfx) - len(patchname) - 2
1919 1922 if width > 0:
1920 msg = util.ellipsis(msg, width)
1923 msg = stringutil.ellipsis(msg, width)
1921 1924 else:
1922 1925 msg = ''
1923 1926 self.ui.write(patchname, label='qseries.' + state)
@@ -29,6 +29,9 from mercurial import (
29 29 util,
30 30 wireproto,
31 31 )
32 from mercurial.utils import (
33 stringutil,
34 )
32 35
33 36 NARROWCAP = 'narrow'
34 37 _NARROWACL_SECTION = 'narrowhgacl'
@@ -449,7 +452,7 def handlechangegroup_widen(op, inpart):
449 452 except OSError as e:
450 453 if e.errno != errno.ENOENT:
451 454 ui.warn(_('error removing %s: %s\n') %
452 (undovfs.join(undofile), util.forcebytestr(e)))
455 (undovfs.join(undofile), stringutil.forcebytestr(e)))
453 456
454 457 # Remove partial backup only if there were no exceptions
455 458 vfs.unlink(chgrpfile)
@@ -149,7 +149,10 from mercurial import (
149 149 registrar,
150 150 util,
151 151 )
152 from mercurial.utils import dateutil
152 from mercurial.utils import (
153 dateutil,
154 stringutil,
155 )
153 156
154 157 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
155 158 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
@@ -277,7 +280,7 class notifier(object):
277 280 def fixmail(self, addr):
278 281 '''try to clean up email addresses.'''
279 282
280 addr = util.email(addr.strip())
283 addr = stringutil.email(addr.strip())
281 284 if self.domain:
282 285 a = addr.find('@localhost')
283 286 if a != -1:
@@ -372,7 +375,7 class notifier(object):
372 375 subject = '%s: %s' % (self.root, s)
373 376 maxsubject = int(self.ui.config('notify', 'maxsubject'))
374 377 if maxsubject:
375 subject = util.ellipsis(subject, maxsubject)
378 subject = stringutil.ellipsis(subject, maxsubject)
376 379 msg['Subject'] = mail.headencode(self.ui, subject,
377 380 self.charsets, self.test)
378 381
@@ -399,7 +402,7 class notifier(object):
399 402 else:
400 403 self.ui.status(_('notify: sending %d subscribers %d changes\n') %
401 404 (len(subs), count))
402 mail.sendmail(self.ui, util.email(msg['From']),
405 mail.sendmail(self.ui, stringutil.email(msg['From']),
403 406 subs, msgtext, mbox=self.mbox)
404 407
405 408 def diff(self, ctx, ref=None):
@@ -18,6 +18,9 from mercurial import (
18 18 registrar,
19 19 util,
20 20 )
21 from mercurial.utils import (
22 stringutil,
23 )
21 24
22 25 cmdtable = {}
23 26 command = registrar.command(cmdtable)
@@ -187,7 +190,7 def do_relink(src, dst, files, ui):
187 190 relinked += 1
188 191 savedbytes += sz
189 192 except OSError as inst:
190 ui.warn('%s: %s\n' % (tgt, util.forcebytestr(inst)))
193 ui.warn('%s: %s\n' % (tgt, stringutil.forcebytestr(inst)))
191 194
192 195 ui.progress(_('relinking'), None)
193 196
@@ -56,7 +56,10 from mercurial import (
56 56 from . import (
57 57 rebase,
58 58 )
59 from mercurial.utils import dateutil
59 from mercurial.utils import (
60 dateutil,
61 stringutil,
62 )
60 63
61 64 cmdtable = {}
62 65 command = registrar.command(cmdtable)
@@ -477,7 +480,7 def _docreatecmd(ui, repo, pats, opts):
477 480 _shelvecreatedcommit(repo, node, name)
478 481
479 482 if ui.formatted():
480 desc = util.ellipsis(desc, ui.termwidth())
483 desc = stringutil.ellipsis(desc, ui.termwidth())
481 484 ui.status(_('shelved as %s\n') % name)
482 485 hg.update(repo, parent.node())
483 486 if origbranch != repo['.'].branch() and not _isbareshelve(pats, opts):
@@ -578,7 +581,7 def listcmd(ui, repo, pats, opts):
578 581 if not line.startswith('#'):
579 582 desc = line.rstrip()
580 583 if ui.formatted():
581 desc = util.ellipsis(desc, width - used)
584 desc = stringutil.ellipsis(desc, width - used)
582 585 ui.write(desc)
583 586 break
584 587 ui.write('\n')
@@ -38,6 +38,9 from mercurial import (
38 38 util,
39 39 vfs as vfsmod,
40 40 )
41 from mercurial.utils import (
42 stringutil,
43 )
41 44
42 45 class TransplantError(error.Abort):
43 46 pass
@@ -311,7 +314,7 class transplanter(object):
311 314 p1 = repo.dirstate.p1()
312 315 p2 = node
313 316 self.log(user, date, message, p1, p2, merge=merge)
314 self.ui.write(util.forcebytestr(inst) + '\n')
317 self.ui.write(stringutil.forcebytestr(inst) + '\n')
315 318 raise TransplantError(_('fix up the working directory and run '
316 319 'hg transplant --continue'))
317 320 else:
@@ -50,7 +50,9 from mercurial.node import (
50 50 )
51 51 from mercurial import (
52 52 registrar,
53 util,
53 )
54 from mercurial.utils import (
55 stringutil,
54 56 )
55 57
56 58 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for
@@ -100,22 +102,22 def macdumbencode(s, cmd):
100 102 return s.replace('\r', '\n')
101 103
102 104 def cleverdecode(s, cmd, **kwargs):
103 if not util.binary(s):
105 if not stringutil.binary(s):
104 106 return dumbdecode(s, cmd, **kwargs)
105 107 return s
106 108
107 109 def cleverencode(s, cmd):
108 if not util.binary(s):
110 if not stringutil.binary(s):
109 111 return dumbencode(s, cmd)
110 112 return s
111 113
112 114 def macdecode(s, cmd, **kwargs):
113 if not util.binary(s):
115 if not stringutil.binary(s):
114 116 return macdumbdecode(s, cmd, **kwargs)
115 117 return s
116 118
117 119 def macencode(s, cmd):
118 if not util.binary(s):
120 if not stringutil.binary(s):
119 121 return macdumbencode(s, cmd)
120 122 return s
121 123
@@ -146,7 +148,7 def forbidnewline(ui, repo, hooktype, no
146 148 continue
147 149 seen.add(f)
148 150 data = c[f].data()
149 if not util.binary(data) and newline in data:
151 if not stringutil.binary(data) and newline in data:
150 152 if not halt:
151 153 ui.warn(_('attempt to commit or push text file(s) '
152 154 'using %s line endings\n') %
@@ -22,6 +22,9 from . import (
22 22 scmutil,
23 23 util,
24 24 )
25 from .utils import (
26 stringutil,
27 )
25 28
26 29 calcsize = struct.calcsize
27 30 pack_into = struct.pack_into
@@ -256,7 +259,7 class branchcache(dict):
256 259 except (IOError, OSError, error.Abort) as inst:
257 260 # Abort may be raised by read only opener, so log and continue
258 261 repo.ui.debug("couldn't write branch cache: %s\n" %
259 util.forcebytestr(inst))
262 stringutil.forcebytestr(inst))
260 263
261 264 def update(self, repo, revgen):
262 265 """Given a branchhead cache, self, that may have extra nodes or be
@@ -378,7 +381,7 class revbranchcache(object):
378 381 self._rbcrevs[:] = data
379 382 except (IOError, OSError) as inst:
380 383 repo.ui.debug("couldn't read revision branch cache: %s\n" %
381 util.forcebytestr(inst))
384 stringutil.forcebytestr(inst))
382 385 # remember number of good records on disk
383 386 self._rbcrevslen = min(len(self._rbcrevs) // _rbcrecsize,
384 387 len(repo.changelog))
@@ -540,7 +543,7 class revbranchcache(object):
540 543 self._rbcrevslen = revs
541 544 except (IOError, OSError, error.Abort, error.LockError) as inst:
542 545 repo.ui.debug("couldn't write revision branch cache%s: %s\n"
543 % (step, util.forcebytestr(inst)))
546 % (step, stringutil.forcebytestr(inst)))
544 547 finally:
545 548 if wlock is not None:
546 549 wlock.release()
@@ -171,6 +171,9 from . import (
171 171 url,
172 172 util,
173 173 )
174 from .utils import (
175 stringutil,
176 )
174 177
175 178 urlerr = util.urlerr
176 179 urlreq = util.urlreq
@@ -1091,7 +1094,7 class bundlepart(object):
1091 1094 ui.debug('bundle2-generatorexit\n')
1092 1095 raise
1093 1096 except BaseException as exc:
1094 bexc = util.forcebytestr(exc)
1097 bexc = stringutil.forcebytestr(exc)
1095 1098 # backup exception data for later
1096 1099 ui.debug('bundle2-input-stream-interrupt: encoding exception %s'
1097 1100 % bexc)
@@ -28,6 +28,10 from . import (
28 28 util,
29 29 )
30 30
31 from .utils import (
32 stringutil,
33 )
34
31 35 _CHANGEGROUPV1_DELTA_HEADER = "20s20s20s20s"
32 36 _CHANGEGROUPV2_DELTA_HEADER = "20s20s20s20s20s"
33 37 _CHANGEGROUPV3_DELTA_HEADER = ">20s20s20s20s20sH"
@@ -514,7 +518,7 class cg1packer(object):
514 518 if reorder == 'auto':
515 519 reorder = None
516 520 else:
517 reorder = util.parsebool(reorder)
521 reorder = stringutil.parsebool(reorder)
518 522 self._repo = repo
519 523 self._reorder = reorder
520 524 self._progress = repo.ui.progress
@@ -24,7 +24,10 from . import (
24 24 revlog,
25 25 util,
26 26 )
27 from .utils import dateutil
27 from .utils import (
28 dateutil,
29 stringutil,
30 )
28 31
29 32 _defaultextra = {'branch': 'default'}
30 33
@@ -36,7 +39,7 def _string_escape(text):
36 39 >>> s
37 40 'ab\\ncd\\\\\\\\n\\x00ab\\rcd\\\\\\n'
38 41 >>> res = _string_escape(s)
39 >>> s == util.unescapestr(res)
42 >>> s == stringutil.unescapestr(res)
40 43 True
41 44 """
42 45 # subset of the string_escape codec
@@ -62,7 +65,7 def decodeextra(text):
62 65 l = l.replace('\\\\', '\\\\\n')
63 66 l = l.replace('\\0', '\0')
64 67 l = l.replace('\n', '')
65 k, v = util.unescapestr(l).split(':', 1)
68 k, v = stringutil.unescapestr(l).split(':', 1)
66 69 extra[k] = v
67 70 return extra
68 71
@@ -48,7 +48,12 from . import (
48 48 util,
49 49 vfs as vfsmod,
50 50 )
51 from .utils import dateutil
51
52 from .utils import (
53 dateutil,
54 stringutil,
55 )
56
52 57 stringio = util.stringio
53 58
54 59 # templates of common command options
@@ -962,9 +967,9 def _buildfntemplate(pat, total=None, se
962 967 while i < end:
963 968 n = pat.find(b'%', i, end)
964 969 if n < 0:
965 newname.append(util.escapestr(pat[i:end]))
970 newname.append(stringutil.escapestr(pat[i:end]))
966 971 break
967 newname.append(util.escapestr(pat[i:n]))
972 newname.append(stringutil.escapestr(pat[i:n]))
968 973 if n + 2 > end:
969 974 raise error.Abort(_("incomplete format spec in output "
970 975 "filename"))
@@ -1479,7 +1484,7 def tryimportone(ui, repo, hunk, parents
1479 1484 patch.patchrepo(ui, repo, p1, store, tmpname, strip, prefix,
1480 1485 files, eolmode=None)
1481 1486 except error.PatchError as e:
1482 raise error.Abort(util.forcebytestr(e))
1487 raise error.Abort(stringutil.forcebytestr(e))
1483 1488 if opts.get('exact'):
1484 1489 editor = None
1485 1490 else:
@@ -14,7 +14,10 from .i18n import _
14 14 from . import (
15 15 encoding,
16 16 pycompat,
17 util
17 )
18
19 from .utils import (
20 stringutil,
18 21 )
19 22
20 23 try:
@@ -200,7 +203,7 def _modesetup(ui):
200 203
201 204 auto = (config == 'auto')
202 205 always = False
203 if not auto and util.parsebool(config):
206 if not auto and stringutil.parsebool(config):
204 207 # We want the config to behave like a boolean, "on" is actually auto,
205 208 # but "always" value is treated as a special case to reduce confusion.
206 209 if ui.configsource('ui', 'color') == '--color' or config == 'always':
@@ -61,7 +61,10 from . import (
61 61 util,
62 62 wireprotoserver,
63 63 )
64 from .utils import dateutil
64 from .utils import (
65 dateutil,
66 stringutil,
67 )
65 68
66 69 release = lockmod.release
67 70
@@ -2469,7 +2472,7 def grep(ui, repo, pattern, *pats, **opt
2469 2472 @util.cachefunc
2470 2473 def binary():
2471 2474 flog = getfile(fn)
2472 return util.binary(flog.read(ctx.filenode(fn)))
2475 return stringutil.binary(flog.read(ctx.filenode(fn)))
2473 2476
2474 2477 fieldnamemap = {'filename': 'file', 'linenumber': 'line_number'}
2475 2478 if opts.get('all'):
@@ -3914,7 +3917,7 def postincoming(ui, repo, modheads, opt
3914 3917 try:
3915 3918 return hg.updatetotally(ui, repo, checkout, brev)
3916 3919 except error.UpdateAbort as inst:
3917 msg = _("not updating: %s") % util.forcebytestr(inst)
3920 msg = _("not updating: %s") % stringutil.forcebytestr(inst)
3918 3921 hint = inst.hint
3919 3922 raise error.UpdateAbort(msg, hint=hint)
3920 3923 if modheads > 1:
@@ -46,7 +46,10 from . import (
46 46 subrepoutil,
47 47 util,
48 48 )
49 from .utils import dateutil
49 from .utils import (
50 dateutil,
51 stringutil,
52 )
50 53
51 54 propertycache = util.propertycache
52 55
@@ -818,7 +821,7 class basefilectx(object):
818 821
819 822 def isbinary(self):
820 823 try:
821 return util.binary(self.data())
824 return stringutil.binary(self.data())
822 825 except IOError:
823 826 return False
824 827 def isexec(self):
@@ -1500,7 +1503,8 class workingctx(committablectx):
1500 1503 for f in files:
1501 1504 if self.flags(f) == 'l':
1502 1505 d = self[f].data()
1503 if d == '' or len(d) >= 1024 or '\n' in d or util.binary(d):
1506 if (d == '' or len(d) >= 1024 or '\n' in d
1507 or stringutil.binary(d)):
1504 1508 self._repo.ui.debug('ignoring suspect symlink placeholder'
1505 1509 ' "%s"\n' % f)
1506 1510 continue
@@ -23,6 +23,9 from . import (
23 23 scmutil,
24 24 util,
25 25 )
26 from .utils import (
27 stringutil,
28 )
26 29 stringio = util.stringio
27 30
28 31 # This is required for ncurses to display non-ASCII characters in default user
@@ -585,7 +588,7 class curseschunkselector(object):
585 588 # long as not explicitly set to a falsy value - especially,
586 589 # when not set at all. This is to stay most compatible with
587 590 # previous (color only) behaviour.
588 uicolor = util.parsebool(self.ui.config('ui', 'color'))
591 uicolor = stringutil.parsebool(self.ui.config('ui', 'color'))
589 592 self.usecolor = uicolor is not False
590 593
591 594 # the currently selected header, hunk, or hunk-line
@@ -1058,7 +1061,7 class curseschunkselector(object):
1058 1061 if len(lines) != self.numstatuslines:
1059 1062 self.numstatuslines = len(lines)
1060 1063 self.statuswin.resize(self.numstatuslines, self.xscreensize)
1061 return [util.ellipsis(l, self.xscreensize - 1) for l in lines]
1064 return [stringutil.ellipsis(l, self.xscreensize - 1) for l in lines]
1062 1065
1063 1066 def updatescreen(self):
1064 1067 self.statuswin.erase()
@@ -14,7 +14,9 from .i18n import _
14 14 from . import (
15 15 error,
16 16 pycompat,
17 util,
17 )
18 from .utils import (
19 stringutil,
18 20 )
19 21
20 22 def parsedag(desc):
@@ -372,8 +374,8 def dagtextlines(events,
372 374 else:
373 375 raise error.Abort(_("invalid event type in dag: "
374 376 "('%s', '%s')")
375 % (util.escapestr(kind),
376 util.escapestr(data)))
377 % (stringutil.escapestr(kind),
378 stringutil.escapestr(data)))
377 379 if run:
378 380 yield '+%d' % run
379 381
@@ -81,7 +81,10 from . import (
81 81 wireprotoframing,
82 82 wireprotoserver,
83 83 )
84 from .utils import dateutil
84 from .utils import (
85 dateutil,
86 stringutil,
87 )
85 88
86 89 release = lockmod.release
87 90
@@ -1141,7 +1144,7 def debuginstall(ui, **opts):
1141 1144 try:
1142 1145 codecs.lookup(pycompat.sysstr(encoding.encoding))
1143 1146 except LookupError as inst:
1144 err = util.forcebytestr(inst)
1147 err = stringutil.forcebytestr(inst)
1145 1148 problems += 1
1146 1149 fm.condwrite(err, 'encodingerror', _(" %s\n"
1147 1150 " (check that your locale is properly set)\n"), err)
@@ -1197,7 +1200,7 def debuginstall(ui, **opts):
1197 1200 )
1198 1201 dir(bdiff), dir(mpatch), dir(base85), dir(osutil) # quiet pyflakes
1199 1202 except Exception as inst:
1200 err = util.forcebytestr(inst)
1203 err = stringutil.forcebytestr(inst)
1201 1204 problems += 1
1202 1205 fm.condwrite(err, 'extensionserror', " %s\n", err)
1203 1206
@@ -1234,7 +1237,7 def debuginstall(ui, **opts):
1234 1237 try:
1235 1238 templater.templater.frommapfile(m)
1236 1239 except Exception as inst:
1237 err = util.forcebytestr(inst)
1240 err = stringutil.forcebytestr(inst)
1238 1241 p = None
1239 1242 fm.condwrite(err, 'defaulttemplateerror', " %s\n", err)
1240 1243 else:
@@ -1271,7 +1274,7 def debuginstall(ui, **opts):
1271 1274 try:
1272 1275 username = ui.username()
1273 1276 except error.Abort as e:
1274 err = util.forcebytestr(e)
1277 err = stringutil.forcebytestr(e)
1275 1278 problems += 1
1276 1279
1277 1280 fm.condwrite(username, 'username', _("checking username (%s)\n"), username)
@@ -1822,8 +1825,8 def debugpushkey(ui, repopath, namespace
1822 1825 return not r
1823 1826 else:
1824 1827 for k, v in sorted(target.listkeys(namespace).iteritems()):
1825 ui.write("%s\t%s\n" % (util.escapestr(k),
1826 util.escapestr(v)))
1828 ui.write("%s\t%s\n" % (stringutil.escapestr(k),
1829 stringutil.escapestr(v)))
1827 1830
1828 1831 @command('debugpvec', [], _('A B'))
1829 1832 def debugpvec(ui, repo, a, b=None):
@@ -2909,7 +2912,7 def debugwireproto(ui, repo, path=None,
2909 2912
2910 2913 # Concatenate the data together.
2911 2914 data = ''.join(l.lstrip() for l in lines)
2912 data = util.unescapestr(data)
2915 data = stringutil.unescapestr(data)
2913 2916 stdin.write(data)
2914 2917
2915 2918 if action == 'raw+':
@@ -2935,7 +2938,7 def debugwireproto(ui, repo, path=None,
2935 2938 else:
2936 2939 key, value = fields
2937 2940
2938 args[key] = util.unescapestr(value)
2941 args[key] = stringutil.unescapestr(value)
2939 2942
2940 2943 if batchedcommands is not None:
2941 2944 batchedcommands.append((command, args))
@@ -2948,12 +2951,12 def debugwireproto(ui, repo, path=None,
2948 2951 del args['PUSHFILE']
2949 2952 res, output = peer._callpush(command, fh,
2950 2953 **pycompat.strkwargs(args))
2951 ui.status(_('result: %s\n') % util.escapedata(res))
2954 ui.status(_('result: %s\n') % stringutil.escapedata(res))
2952 2955 ui.status(_('remote output: %s\n') %
2953 util.escapedata(output))
2956 stringutil.escapedata(output))
2954 2957 else:
2955 2958 res = peer._call(command, **pycompat.strkwargs(args))
2956 ui.status(_('response: %s\n') % util.escapedata(res))
2959 ui.status(_('response: %s\n') % stringutil.escapedata(res))
2957 2960
2958 2961 elif action == 'batchbegin':
2959 2962 if batchedcommands is not None:
@@ -2967,7 +2970,8 def debugwireproto(ui, repo, path=None,
2967 2970 ui.status(_('sending batch with %d sub-commands\n') %
2968 2971 len(batchedcommands))
2969 2972 for i, chunk in enumerate(peer._submitbatch(batchedcommands)):
2970 ui.status(_('response #%d: %s\n') % (i, util.escapedata(chunk)))
2973 ui.status(_('response #%d: %s\n') %
2974 (i, stringutil.escapedata(chunk)))
2971 2975
2972 2976 batchedcommands = None
2973 2977
@@ -41,6 +41,10 from . import (
41 41 util,
42 42 )
43 43
44 from .utils import (
45 stringutil,
46 )
47
44 48 unrecoverablewrite = registrar.command.unrecoverablewrite
45 49
46 50 class request(object):
@@ -496,7 +500,7 class cmdalias(object):
496 500 args = pycompat.shlexsplit(self.definition)
497 501 except ValueError as inst:
498 502 self.badalias = (_("error in definition for alias '%s': %s")
499 % (self.name, util.forcebytestr(inst)))
503 % (self.name, stringutil.forcebytestr(inst)))
500 504 return
501 505 earlyopts, args = _earlysplitopts(args)
502 506 if earlyopts:
@@ -623,7 +627,7 def _parse(ui, args):
623 627 try:
624 628 args = fancyopts.fancyopts(args, commands.globalopts, options)
625 629 except getopt.GetoptError as inst:
626 raise error.CommandError(None, util.forcebytestr(inst))
630 raise error.CommandError(None, stringutil.forcebytestr(inst))
627 631
628 632 if args:
629 633 cmd, args = args[0], args[1:]
@@ -647,7 +651,7 def _parse(ui, args):
647 651 try:
648 652 args = fancyopts.fancyopts(args, c, cmdoptions, gnu=True)
649 653 except getopt.GetoptError as inst:
650 raise error.CommandError(cmd, util.forcebytestr(inst))
654 raise error.CommandError(cmd, stringutil.forcebytestr(inst))
651 655
652 656 # separate global options back out
653 657 for o in commands.globalopts:
@@ -872,7 +876,7 def _dispatch(req):
872 876 ui_.setconfig('ui', 'color', coloropt, '--color')
873 877 color.setup(ui_)
874 878
875 if util.parsebool(options['pager']):
879 if stringutil.parsebool(options['pager']):
876 880 # ui.pager() expects 'internal-always-' prefix in this case
877 881 ui.pager('internal-always-' + cmd)
878 882 elif options['pager'] != 'auto':
@@ -968,7 +972,7 def _exceptionwarning(ui):
968 972 for name, mod in extensions.extensions():
969 973 # 'testedwith' should be bytes, but not all extensions are ported
970 974 # to py3 and we don't want UnicodeException because of that.
971 testedwith = util.forcebytestr(getattr(mod, 'testedwith', ''))
975 testedwith = stringutil.forcebytestr(getattr(mod, 'testedwith', ''))
972 976 report = getattr(mod, 'buglink', _('the extension author.'))
973 977 if not testedwith.strip():
974 978 # We found an untested extension. It's likely the culprit.
@@ -990,7 +994,8 def _exceptionwarning(ui):
990 994 if worst[0] is not None:
991 995 name, testedwith, report = worst
992 996 if not isinstance(testedwith, (bytes, str)):
993 testedwith = '.'.join([util.forcebytestr(c) for c in testedwith])
997 testedwith = '.'.join([stringutil.forcebytestr(c)
998 for c in testedwith])
994 999 warning = (_('** Unknown exception encountered with '
995 1000 'possibly-broken third-party extension %s\n'
996 1001 '** which supports versions %s of Mercurial.\n'
@@ -35,6 +35,9 from . import (
35 35 url as urlmod,
36 36 util,
37 37 )
38 from .utils import (
39 stringutil,
40 )
38 41
39 42 urlerr = util.urlerr
40 43 urlreq = util.urlreq
@@ -2180,7 +2183,7 def filterclonebundleentries(repo, entri
2180 2183 except error.UnsupportedBundleSpecification as e:
2181 2184 repo.ui.debug('filtering %s because unsupported bundle '
2182 2185 'spec: %s\n' % (
2183 entry['URL'], util.forcebytestr(e)))
2186 entry['URL'], stringutil.forcebytestr(e)))
2184 2187 continue
2185 2188 # If we don't have a spec and requested a stream clone, we don't know
2186 2189 # what the entry is so don't attempt to apply it.
@@ -2286,9 +2289,9 def trypullbundlefromurl(ui, repo, url):
2286 2289 return True
2287 2290 except urlerr.httperror as e:
2288 2291 ui.warn(_('HTTP error fetching bundle: %s\n') %
2289 util.forcebytestr(e))
2292 stringutil.forcebytestr(e))
2290 2293 except urlerr.urlerror as e:
2291 2294 ui.warn(_('error fetching bundle: %s\n') %
2292 util.forcebytestr(e.reason))
2295 stringutil.forcebytestr(e.reason))
2293 2296
2294 2297 return False
@@ -25,6 +25,10 from . import (
25 25 util,
26 26 )
27 27
28 from .utils import (
29 stringutil,
30 )
31
28 32 _extensions = {}
29 33 _disabledextensions = {}
30 34 _aftercallbacks = {}
@@ -118,7 +122,7 def _reportimporterror(ui, err, failed,
118 122 # note: this ui.debug happens before --debug is processed,
119 123 # Use --config ui.debug=1 to see them.
120 124 ui.debug('could not import %s (%s): trying %s\n'
121 % (failed, util.forcebytestr(err), next))
125 % (failed, stringutil.forcebytestr(err), next))
122 126 if ui.debugflag:
123 127 ui.traceback()
124 128
@@ -129,7 +133,7 def _rejectunicode(name, xs):
129 133 elif isinstance(xs, dict):
130 134 for k, v in xs.items():
131 135 _rejectunicode(name, k)
132 _rejectunicode(b'%s.%s' % (name, util.forcebytestr(k)), v)
136 _rejectunicode(b'%s.%s' % (name, stringutil.forcebytestr(k)), v)
133 137 elif isinstance(xs, type(u'')):
134 138 raise error.ProgrammingError(b"unicode %r found in %s" % (xs, name),
135 139 hint="use b'' to make it byte string")
@@ -198,7 +202,7 def _runuisetup(name, ui):
198 202 uisetup(ui)
199 203 except Exception as inst:
200 204 ui.traceback(force=True)
201 msg = util.forcebytestr(inst)
205 msg = stringutil.forcebytestr(inst)
202 206 ui.warn(_("*** failed to set up extension %s: %s\n") % (name, msg))
203 207 return False
204 208 return True
@@ -215,7 +219,7 def _runextsetup(name, ui):
215 219 extsetup() # old extsetup with no ui argument
216 220 except Exception as inst:
217 221 ui.traceback(force=True)
218 msg = util.forcebytestr(inst)
222 msg = stringutil.forcebytestr(inst)
219 223 ui.warn(_("*** failed to set up extension %s: %s\n") % (name, msg))
220 224 return False
221 225 return True
@@ -233,7 +237,7 def loadall(ui, whitelist=None):
233 237 try:
234 238 load(ui, name, path)
235 239 except Exception as inst:
236 msg = util.forcebytestr(inst)
240 msg = stringutil.forcebytestr(inst)
237 241 if path:
238 242 ui.warn(_("*** failed to import extension %s from %s: %s\n")
239 243 % (name, path, msg))
@@ -31,6 +31,10 from . import (
31 31 util,
32 32 )
33 33
34 from .utils import (
35 stringutil,
36 )
37
34 38 def _toolstr(ui, tool, part, *args):
35 39 return ui.config("merge-tools", tool + "." + part, *args)
36 40
@@ -573,7 +577,7 def _formatconflictmarker(ctx, template,
573 577 mark = mark.splitlines()[0] # split for safety
574 578
575 579 # 8 for the prefix of conflict marker lines (e.g. '<<<<<<< ')
576 return util.ellipsis(mark, 80 - 8)
580 return stringutil.ellipsis(mark, 80 - 8)
577 581
578 582 _defaultconflictlabels = ['local', 'other']
579 583
@@ -20,6 +20,9 from . import (
20 20 scmutil,
21 21 util,
22 22 )
23 from .utils import (
24 stringutil,
25 )
23 26
24 27 elements = {
25 28 # token-type: binding-strength, primary, prefix, infix, suffix
@@ -445,7 +448,7 def eol(mctx, x):
445 448 s = []
446 449 for f in mctx.existing():
447 450 d = mctx.ctx[f].data()
448 if util.binary(d):
451 if stringutil.binary(d):
449 452 continue
450 453 if (enc == 'dos' or enc == 'win') and '\r\n' in d:
451 454 s.append(f)
@@ -48,6 +48,10 from . import (
48 48 vfs as vfsmod,
49 49 )
50 50
51 from .utils import (
52 stringutil,
53 )
54
51 55 release = lock.release
52 56
53 57 # shared features
@@ -270,7 +274,7 def share(ui, source, dest=None, update=
270 274 # ValueError is raised on Windows if the drive letters differ on
271 275 # each path
272 276 raise error.Abort(_('cannot calculate relative path'),
273 hint=util.forcebytestr(e))
277 hint=stringutil.forcebytestr(e))
274 278 else:
275 279 requirements += 'shared\n'
276 280
@@ -36,7 +36,10 from .. import (
36 36 scmutil,
37 37 smartset,
38 38 templater,
39 util,
39 )
40
41 from ..utils import (
42 stringutil,
40 43 )
41 44
42 45 from . import (
@@ -121,7 +124,7 def rawfile(web):
121 124 if guessmime:
122 125 mt = mimetypes.guess_type(path)[0]
123 126 if mt is None:
124 if util.binary(text):
127 if stringutil.binary(text):
125 128 mt = 'application/binary'
126 129 else:
127 130 mt = 'text/plain'
@@ -141,7 +144,7 def _filerevision(web, fctx):
141 144 parity = paritygen(web.stripecount)
142 145 ishead = fctx.filerev() in fctx.filelog().headrevs()
143 146
144 if util.binary(text):
147 if stringutil.binary(text):
145 148 mt = mimetypes.guess_type(f)[0] or 'application/octet-stream'
146 149 text = '(binary:%s)' % mt
147 150
@@ -38,6 +38,10 from .. import (
38 38 util,
39 39 )
40 40
41 from ..utils import (
42 stringutil,
43 )
44
41 45 def up(p):
42 46 if p[0:1] != "/":
43 47 p = "/" + p
@@ -180,7 +184,7 def difffeatureopts(req, ui, section):
180 184 for k in ('ignorews', 'ignorewsamount', 'ignorewseol', 'ignoreblanklines'):
181 185 v = req.qsparams.get(k)
182 186 if v is not None:
183 v = util.parsebool(v)
187 v = stringutil.parsebool(v)
184 188 setattr(diffopts, k, v if v is not None else True)
185 189
186 190 return diffopts
@@ -64,6 +64,9 from . import (
64 64 util,
65 65 vfs as vfsmod,
66 66 )
67 from .utils import (
68 stringutil,
69 )
67 70
68 71 release = lockmod.release
69 72 urlerr = util.urlerr
@@ -263,7 +266,7 class localpeer(repository.peer):
263 266 raise
264 267 except error.PushRaced as exc:
265 268 raise error.ResponseError(_('push failed:'),
266 util.forcebytestr(exc))
269 stringutil.forcebytestr(exc))
267 270
268 271 # End of _basewirecommands interface.
269 272
@@ -35,7 +35,10 from . import (
35 35 templater,
36 36 util,
37 37 )
38 from .utils import dateutil
38 from .utils import (
39 dateutil,
40 stringutil,
41 )
39 42
40 43 def getlimit(opts):
41 44 """get the log limit according to option -l/--limit"""
@@ -260,7 +263,8 class changesetprinter(object):
260 263 extra = ctx.extra()
261 264 if extra and self.ui.debugflag:
262 265 for key, value in sorted(extra.items()):
263 self.ui.write(columns['extra'] % (key, util.escapestr(value)),
266 self.ui.write(columns['extra']
267 % (key, stringutil.escapestr(value)),
264 268 label='ui.debug log.extra')
265 269
266 270 description = ctx.description().strip()
@@ -24,6 +24,9 from . import (
24 24 sslutil,
25 25 util,
26 26 )
27 from .utils import (
28 stringutil,
29 )
27 30
28 31 class STARTTLS(smtplib.SMTP):
29 32 '''Derived class to verify the peer certificate for STARTTLS.
@@ -81,7 +84,7 def _smtp(ui):
81 84 local_hostname = ui.config('smtp', 'local_hostname')
82 85 tls = ui.config('smtp', 'tls')
83 86 # backward compatible: when tls = true, we use starttls.
84 starttls = tls == 'starttls' or util.parsebool(tls)
87 starttls = tls == 'starttls' or stringutil.parsebool(tls)
85 88 smtps = tls == 'smtps'
86 89 if (starttls or smtps) and not util.safehasattr(socket, 'ssl'):
87 90 raise error.Abort(_("can't use TLS: Python SSL support not installed"))
@@ -137,8 +140,8 def _smtp(ui):
137 140 def _sendmail(ui, sender, recipients, msg):
138 141 '''send mail using sendmail.'''
139 142 program = ui.config('email', 'method')
140 cmdline = '%s -f %s %s' % (program, util.email(sender),
141 ' '.join(map(util.email, recipients)))
143 cmdline = '%s -f %s %s' % (program, stringutil.email(sender),
144 ' '.join(map(stringutil.email, recipients)))
142 145 ui.note(_('sending mail: %s\n') % cmdline)
143 146 fp = util.popen(cmdline, 'w')
144 147 fp.write(msg)
@@ -19,6 +19,9 from . import (
19 19 pycompat,
20 20 util,
21 21 )
22 from .utils import (
23 stringutil,
24 )
22 25
23 26 allpatternkinds = ('re', 'glob', 'path', 'relglob', 'relpath', 'relre',
24 27 'listfile', 'listfile0', 'set', 'include', 'subinclude',
@@ -227,7 +230,7 def _donormalize(patterns, default, root
227 230 except IOError as inst:
228 231 if warn:
229 232 warn(_("skipping unreadable pattern file '%s': %s\n") %
230 (pat, util.forcebytestr(inst.strerror)))
233 (pat, stringutil.forcebytestr(inst.strerror)))
231 234 continue
232 235 # else: re or relre - which cannot be normalized
233 236 kindpats.append((kind, pat, ''))
@@ -27,7 +27,9 from . import (
27 27 encoding,
28 28 pycompat,
29 29 url,
30 util,
30 )
31 from .utils import (
32 stringutil,
31 33 )
32 34
33 35 def section(s):
@@ -459,7 +461,7 def formatoption(block, width):
459 461 hanging = block['optstrwidth']
460 462 initindent = '%s%s ' % (block['optstr'], ' ' * ((hanging - colwidth)))
461 463 hangindent = ' ' * (encoding.colwidth(initindent) + 1)
462 return ' %s\n' % (util.wrap(desc, usablewidth,
464 return ' %s\n' % (stringutil.wrap(desc, usablewidth,
463 465 initindent=initindent,
464 466 hangindent=hangindent))
465 467
@@ -477,7 +479,7 def formatblock(block, width):
477 479 defindent = indent + hang * ' '
478 480 text = ' '.join(map(bytes.strip, block['lines']))
479 481 return '%s\n%s\n' % (indent + admonition,
480 util.wrap(text, width=width,
482 stringutil.wrap(text, width=width,
481 483 initindent=defindent,
482 484 hangindent=defindent))
483 485 if block['type'] == 'margin':
@@ -503,7 +505,9 def formatblock(block, width):
503 505 pad = ' ' * (w - encoding.colwidth(v))
504 506 l.append(v + pad)
505 507 l = ' '.join(l)
506 l = util.wrap(l, width=width, initindent=indent, hangindent=hang)
508 l = stringutil.wrap(l, width=width,
509 initindent=indent,
510 hangindent=hang)
507 511 if not text and block['header']:
508 512 text = l + '\n' + indent + '-' * (min(width, span)) + '\n'
509 513 else:
@@ -514,7 +518,7 def formatblock(block, width):
514 518 hang = len(block['lines'][-1]) - len(block['lines'][-1].lstrip())
515 519 defindent = indent + hang * ' '
516 520 text = ' '.join(map(bytes.strip, block['lines'][1:]))
517 return '%s\n%s\n' % (term, util.wrap(text, width=width,
521 return '%s\n%s\n' % (term, stringutil.wrap(text, width=width,
518 522 initindent=defindent,
519 523 hangindent=defindent))
520 524 subindent = indent
@@ -540,7 +544,7 def formatblock(block, width):
540 544 return formatoption(block, width)
541 545
542 546 text = ' '.join(map(bytes.strip, block['lines']))
543 return util.wrap(text, width=width,
547 return stringutil.wrap(text, width=width,
544 548 initindent=indent,
545 549 hangindent=subindent) + '\n'
546 550
@@ -25,6 +25,9 from . import (
25 25 pycompat,
26 26 util,
27 27 )
28 from .utils import (
29 stringutil,
30 )
28 31
29 32 class parser(object):
30 33 def __init__(self, elements, methods=None):
@@ -190,14 +193,14 def buildargsdict(trees, funcname, argsp
190 193
191 194 def unescapestr(s):
192 195 try:
193 return util.unescapestr(s)
196 return stringutil.unescapestr(s)
194 197 except ValueError as e:
195 198 # mangle Python's exception into our format
196 199 raise error.ParseError(pycompat.bytestr(e).lower())
197 200
198 201 def _brepr(obj):
199 202 if isinstance(obj, bytes):
200 return b"'%s'" % util.escapestr(obj)
203 return b"'%s'" % stringutil.escapestr(obj)
201 204 return encoding.strtolocal(repr(obj))
202 205
203 206 def _prettyformat(tree, leafnodes, level, lines):
@@ -40,7 +40,10 from . import (
40 40 util,
41 41 vfs as vfsmod,
42 42 )
43 from .utils import dateutil
43 from .utils import (
44 dateutil,
45 stringutil,
46 )
44 47
45 48 diffhelpers = policy.importmod(r'diffhelpers')
46 49 stringio = util.stringio
@@ -1461,7 +1464,7 class binhunk(object):
1461 1464 dec.append(util.b85decode(line[1:])[:l])
1462 1465 except ValueError as e:
1463 1466 raise PatchError(_('could not decode "%s" binary patch: %s')
1464 % (self._fname, util.forcebytestr(e)))
1467 % (self._fname, stringutil.forcebytestr(e)))
1465 1468 line = getline(lr, self.hunk)
1466 1469 text = zlib.decompress(''.join(dec))
1467 1470 if len(text) != size:
@@ -26,6 +26,9 from . import (
26 26 obsutil,
27 27 util,
28 28 )
29 from .utils import (
30 stringutil,
31 )
29 32
30 33 def backupbundle(repo, bases, heads, node, suffix, compress=True,
31 34 obsolescence=True):
@@ -236,7 +239,8 def strip(ui, repo, nodelist, backup=Tru
236 239 except OSError as e:
237 240 if e.errno != errno.ENOENT:
238 241 ui.warn(_('error removing %s: %s\n') %
239 (undovfs.join(undofile), util.forcebytestr(e)))
242 (undovfs.join(undofile),
243 stringutil.forcebytestr(e)))
240 244
241 245 except: # re-raises
242 246 if backupfile:
@@ -45,6 +45,9 from . import (
45 45 templatefilters,
46 46 util,
47 47 )
48 from .utils import (
49 stringutil,
50 )
48 51
49 52 parsers = policy.importmod(r'parsers')
50 53
@@ -2017,7 +2020,7 class revlog(object):
2017 2020 return _zlibdecompress(data)
2018 2021 except zlib.error as e:
2019 2022 raise RevlogError(_('revlog decompress error: %s') %
2020 util.forcebytestr(e))
2023 stringutil.forcebytestr(e))
2021 2024 # '\0' is more common than 'u' so it goes first.
2022 2025 elif t == '\0':
2023 2026 return data
@@ -31,7 +31,10 from . import (
31 31 stack,
32 32 util,
33 33 )
34 from .utils import dateutil
34 from .utils import (
35 dateutil,
36 stringutil,
37 )
35 38
36 39 # helpers for processing parsed tree
37 40 getsymbol = revsetlang.getsymbol
@@ -447,7 +450,7 def bookmark(repo, subset, x):
447 450 bm = getstring(args[0],
448 451 # i18n: "bookmark" is a keyword
449 452 _('the argument to bookmark must be a string'))
450 kind, pattern, matcher = util.stringmatcher(bm)
453 kind, pattern, matcher = stringutil.stringmatcher(bm)
451 454 bms = set()
452 455 if kind == 'literal':
453 456 bmrev = repo._bookmarks.get(pattern, None)
@@ -492,7 +495,7 def branch(repo, subset, x):
492 495 # not a string, but another revspec, e.g. tip()
493 496 pass
494 497 else:
495 kind, pattern, matcher = util.stringmatcher(b)
498 kind, pattern, matcher = stringutil.stringmatcher(b)
496 499 if kind == 'literal':
497 500 # note: falls through to the revspec case if no branch with
498 501 # this name exists and pattern kind is not specified explicitly
@@ -819,7 +822,7 def extra(repo, subset, x):
819 822 # i18n: "extra" is a keyword
820 823 value = getstring(args['value'], _('second argument to extra must be '
821 824 'a string'))
822 kind, value, matcher = util.stringmatcher(value)
825 kind, value, matcher = stringutil.stringmatcher(value)
823 826
824 827 def _matchvalue(r):
825 828 extra = repo[r].extra()
@@ -1014,7 +1017,7 def grep(repo, subset, x):
1014 1017 gr = re.compile(getstring(x, _("grep requires a string")))
1015 1018 except re.error as e:
1016 1019 raise error.ParseError(
1017 _('invalid match pattern: %s') % util.forcebytestr(e))
1020 _('invalid match pattern: %s') % stringutil.forcebytestr(e))
1018 1021
1019 1022 def matches(x):
1020 1023 c = repo[x]
@@ -1286,7 +1289,7 def named(repo, subset, x):
1286 1289 ns = getstring(args[0],
1287 1290 # i18n: "named" is a keyword
1288 1291 _('the argument to named must be a string'))
1289 kind, pattern, matcher = util.stringmatcher(ns)
1292 kind, pattern, matcher = stringutil.stringmatcher(ns)
1290 1293 namespaces = set()
1291 1294 if kind == 'literal':
1292 1295 if pattern not in repo.names:
@@ -1942,7 +1945,7 def subrepo(repo, subset, x):
1942 1945 m = matchmod.exact(repo.root, repo.root, ['.hgsubstate'])
1943 1946
1944 1947 def submatches(names):
1945 k, p, m = util.stringmatcher(pat)
1948 k, p, m = stringutil.stringmatcher(pat)
1946 1949 for name in names:
1947 1950 if m(name):
1948 1951 yield name
@@ -1995,8 +1998,8 def successors(repo, subset, x):
1995 1998 return subset & d
1996 1999
1997 2000 def _substringmatcher(pattern, casesensitive=True):
1998 kind, pattern, matcher = util.stringmatcher(pattern,
1999 casesensitive=casesensitive)
2001 kind, pattern, matcher = stringutil.stringmatcher(
2002 pattern, casesensitive=casesensitive)
2000 2003 if kind == 'literal':
2001 2004 if not casesensitive:
2002 2005 pattern = encoding.lower(pattern)
@@ -2019,7 +2022,7 def tag(repo, subset, x):
2019 2022 pattern = getstring(args[0],
2020 2023 # i18n: "tag" is a keyword
2021 2024 _('the argument to tag must be a string'))
2022 kind, pattern, matcher = util.stringmatcher(pattern)
2025 kind, pattern, matcher = stringutil.stringmatcher(pattern)
2023 2026 if kind == 'literal':
2024 2027 # avoid resolving all tags
2025 2028 tn = repo._tagscache.tags.get(pattern, None)
@@ -17,6 +17,9 from . import (
17 17 pycompat,
18 18 util,
19 19 )
20 from .utils import (
21 stringutil,
22 )
20 23
21 24 elements = {
22 25 # token-type: binding-strength, primary, prefix, infix, suffix
@@ -207,7 +210,7 def getinteger(x, err, default=_notset):
207 210 raise error.ParseError(err)
208 211
209 212 def getboolean(x, err):
210 value = util.parsebool(getsymbol(x))
213 value = stringutil.parsebool(getsymbol(x))
211 214 if value is not None:
212 215 return value
213 216 raise error.ParseError(err)
@@ -565,7 +568,7 def _quote(s):
565 568 >>> _quote(1)
566 569 "'1'"
567 570 """
568 return "'%s'" % util.escapestr(pycompat.bytestr(s))
571 return "'%s'" % stringutil.escapestr(pycompat.bytestr(s))
569 572
570 573 def _formatargtype(c, arg):
571 574 if c == 'd':
@@ -41,6 +41,10 from . import (
41 41 vfs,
42 42 )
43 43
44 from .utils import (
45 stringutil,
46 )
47
44 48 if pycompat.iswindows:
45 49 from . import scmwindows as scmplatform
46 50 else:
@@ -163,12 +167,12 def callcatch(ui, func):
163 167 else:
164 168 reason = _('lock held by %r') % inst.locker
165 169 ui.warn(_("abort: %s: %s\n")
166 % (inst.desc or util.forcebytestr(inst.filename), reason))
170 % (inst.desc or stringutil.forcebytestr(inst.filename), reason))
167 171 if not inst.locker:
168 172 ui.warn(_("(lock might be very busy)\n"))
169 173 except error.LockUnavailable as inst:
170 174 ui.warn(_("abort: could not lock %s: %s\n") %
171 (inst.desc or util.forcebytestr(inst.filename),
175 (inst.desc or stringutil.forcebytestr(inst.filename),
172 176 encoding.strtolocal(inst.strerror)))
173 177 except error.OutOfBandError as inst:
174 178 if inst.args:
@@ -194,7 +198,7 def callcatch(ui, func):
194 198 elif not msg:
195 199 ui.warn(_(" empty string\n"))
196 200 else:
197 ui.warn("\n%r\n" % util.ellipsis(msg))
201 ui.warn("\n%r\n" % stringutil.ellipsis(msg))
198 202 except error.CensoredNodeError as inst:
199 203 ui.warn(_("abort: file censored %s!\n") % inst)
200 204 except error.RevlogError as inst:
@@ -211,15 +215,15 def callcatch(ui, func):
211 215 if inst.hint:
212 216 ui.warn(_("(%s)\n") % inst.hint)
213 217 except ImportError as inst:
214 ui.warn(_("abort: %s!\n") % util.forcebytestr(inst))
215 m = util.forcebytestr(inst).split()[-1]
218 ui.warn(_("abort: %s!\n") % stringutil.forcebytestr(inst))
219 m = stringutil.forcebytestr(inst).split()[-1]
216 220 if m in "mpatch bdiff".split():
217 221 ui.warn(_("(did you forget to compile extensions?)\n"))
218 222 elif m in "zlib".split():
219 223 ui.warn(_("(is your Python install correct?)\n"))
220 224 except IOError as inst:
221 225 if util.safehasattr(inst, "code"):
222 ui.warn(_("abort: %s\n") % util.forcebytestr(inst))
226 ui.warn(_("abort: %s\n") % stringutil.forcebytestr(inst))
223 227 elif util.safehasattr(inst, "reason"):
224 228 try: # usually it is in the form (errno, strerror)
225 229 reason = inst.reason.args[1]
@@ -237,7 +241,7 def callcatch(ui, func):
237 241 if getattr(inst, "filename", None):
238 242 ui.warn(_("abort: %s: %s\n") % (
239 243 encoding.strtolocal(inst.strerror),
240 util.forcebytestr(inst.filename)))
244 stringutil.forcebytestr(inst.filename)))
241 245 else:
242 246 ui.warn(_("abort: %s\n") % encoding.strtolocal(inst.strerror))
243 247 else:
@@ -246,7 +250,7 def callcatch(ui, func):
246 250 if getattr(inst, "filename", None) is not None:
247 251 ui.warn(_("abort: %s: '%s'\n") % (
248 252 encoding.strtolocal(inst.strerror),
249 util.forcebytestr(inst.filename)))
253 stringutil.forcebytestr(inst.filename)))
250 254 else:
251 255 ui.warn(_("abort: %s\n") % encoding.strtolocal(inst.strerror))
252 256 except MemoryError:
@@ -256,7 +260,7 def callcatch(ui, func):
256 260 # Just in case catch this and and pass exit code to caller.
257 261 return inst.code
258 262 except socket.error as inst:
259 ui.warn(_("abort: %s\n") % util.forcebytestr(inst.args[-1]))
263 ui.warn(_("abort: %s\n") % stringutil.forcebytestr(inst.args[-1]))
260 264
261 265 return -1
262 266
@@ -299,7 +303,7 def checkportabilityalert(ui):
299 303 non-portable filenames'''
300 304 val = ui.config('ui', 'portablefilenames')
301 305 lval = val.lower()
302 bval = util.parsebool(val)
306 bval = stringutil.parsebool(val)
303 307 abort = pycompat.iswindows or lval == 'abort'
304 308 warn = bval or lval == 'warn'
305 309 if bval is None and not (warn or abort or lval == 'ignore'):
@@ -23,7 +23,9 from . import (
23 23 error,
24 24 mdiff,
25 25 pycompat,
26 util,
26 )
27 from .utils import (
28 stringutil,
27 29 )
28 30
29 31 class CantReprocessAndShowBase(Exception):
@@ -397,7 +399,7 class Merge3Text(object):
397 399 def _verifytext(text, path, ui, opts):
398 400 """verifies that text is non-binary (unless opts[text] is passed,
399 401 then we just warn)"""
400 if util.binary(text):
402 if stringutil.binary(text):
401 403 msg = _("%s looks like a binary file.") % path
402 404 if not opts.get('quiet'):
403 405 ui.warn(_('warning: %s\n') % msg)
@@ -21,6 +21,9 from . import (
21 21 pycompat,
22 22 util,
23 23 )
24 from .utils import (
25 stringutil,
26 )
24 27
25 28 # Python 2.7.9+ overhauled the built-in SSL/TLS features of Python. It added
26 29 # support for TLS 1.1, TLS 1.2, SNI, system CA stores, etc. These features are
@@ -374,7 +377,8 def wrapsocket(sock, keyfile, certfile,
374 377 sslcontext.set_ciphers(pycompat.sysstr(settings['ciphers']))
375 378 except ssl.SSLError as e:
376 379 raise error.Abort(
377 _('could not set ciphers: %s') % util.forcebytestr(e.args[0]),
380 _('could not set ciphers: %s')
381 % stringutil.forcebytestr(e.args[0]),
378 382 hint=_('change cipher string (%s) in config') %
379 383 settings['ciphers'])
380 384
@@ -393,7 +397,7 def wrapsocket(sock, keyfile, certfile,
393 397 else:
394 398 msg = e.args[1]
395 399 raise error.Abort(_('error loading CA file %s: %s') % (
396 settings['cafile'], util.forcebytestr(msg)),
400 settings['cafile'], stringutil.forcebytestr(msg)),
397 401 hint=_('file is empty or malformed?'))
398 402 caloaded = True
399 403 elif settings['allowloaddefaultcerts']:
@@ -642,7 +646,7 def _verifycert(cert, hostname):
642 646 if _dnsnamematch(value, hostname):
643 647 return
644 648 except wildcarderror as e:
645 return util.forcebytestr(e.args[0])
649 return stringutil.forcebytestr(e.args[0])
646 650
647 651 dnsnames.append(value)
648 652
@@ -663,7 +667,7 def _verifycert(cert, hostname):
663 667 if _dnsnamematch(value, hostname):
664 668 return
665 669 except wildcarderror as e:
666 return util.forcebytestr(e.args[0])
670 return stringutil.forcebytestr(e.args[0])
667 671
668 672 dnsnames.append(value)
669 673
@@ -36,7 +36,10 from . import (
36 36 util,
37 37 vfs as vfsmod,
38 38 )
39 from .utils import dateutil
39 from .utils import (
40 dateutil,
41 stringutil,
42 )
40 43
41 44 hg = None
42 45 reporelpath = subrepoutil.reporelpath
@@ -74,7 +77,7 def annotatesubrepoerror(func):
74 77 raise ex
75 78 except error.Abort as ex:
76 79 subrepo = subrelpath(self)
77 errormsg = (util.forcebytestr(ex) + ' '
80 errormsg = (stringutil.forcebytestr(ex) + ' '
78 81 + _('(in subrepository "%s")') % subrepo)
79 82 # avoid handling this exception by raising a SubrepoAbort exception
80 83 raise SubrepoAbort(errormsg, hint=ex.hint, subrepo=subrepo,
@@ -21,6 +21,9 from . import (
21 21 phases,
22 22 util,
23 23 )
24 from .utils import (
25 stringutil,
26 )
24 27
25 28 nullstate = ('', '', 'empty')
26 29
@@ -74,7 +77,7 def state(ctx, ui):
74 77 for pattern, repl in p.items('subpaths'):
75 78 # Turn r'C:\foo\bar' into r'C:\\foo\\bar' since re.sub
76 79 # does a string decode.
77 repl = util.escapestr(repl)
80 repl = stringutil.escapestr(repl)
78 81 # However, we still want to allow back references to go
79 82 # through unharmed, so we turn r'\\1' into r'\1'. Again,
80 83 # extra escapes are needed because re.sub string decodes.
@@ -28,6 +28,9 from . import (
28 28 scmutil,
29 29 util,
30 30 )
31 from .utils import (
32 stringutil,
33 )
31 34
32 35 # Tags computation can be expensive and caches exist to make it fast in
33 36 # the common case.
@@ -783,6 +786,6 class hgtagsfnodescache(object):
783 786 except (IOError, OSError) as inst:
784 787 repo.ui.log('tagscache',
785 788 "couldn't write cache/%s: %s\n" % (
786 _fnodescachefile, util.forcebytestr(inst)))
789 _fnodescachefile, stringutil.forcebytestr(inst)))
787 790 finally:
788 791 lock.release()
@@ -21,7 +21,10 from . import (
21 21 url,
22 22 util,
23 23 )
24 from .utils import dateutil
24 from .utils import (
25 dateutil,
26 stringutil,
27 )
25 28
26 29 urlerr = util.urlerr
27 30 urlreq = util.urlreq
@@ -128,7 +131,7 def email(text):
128 131 address. Example: ``User <user@example.com>`` becomes
129 132 ``user@example.com``.
130 133 """
131 return util.email(text)
134 return stringutil.email(text)
132 135
133 136 @templatefilter('escape')
134 137 def escape(text):
@@ -162,7 +165,8 def fill(text, width, initindent='', han
162 165 yield text[start:m.start(0)], m.group(1)
163 166 start = m.end(1)
164 167
165 return "".join([util.wrap(space_re.sub(' ', util.wrap(para, width)),
168 return "".join([stringutil.wrap(space_re.sub(' ',
169 stringutil.wrap(para, width)),
166 170 width, initindent, hangindent) + rest
167 171 for para, rest in findparas()])
168 172
@@ -369,7 +373,7 def splitlines(text):
369 373
370 374 @templatefilter('stringescape')
371 375 def stringescape(text):
372 return util.escapestr(text)
376 return stringutil.escapestr(text)
373 377
374 378 @templatefilter('stringify')
375 379 def stringify(thing):
@@ -412,12 +416,12 def urlescape(text):
412 416 def userfilter(text):
413 417 """Any text. Returns a short representation of a user name or email
414 418 address."""
415 return util.shortuser(text)
419 return stringutil.shortuser(text)
416 420
417 421 @templatefilter('emailuser')
418 422 def emailuser(text):
419 423 """Any text. Returns the user portion of an email address."""
420 return util.emailuser(text)
424 return stringutil.emailuser(text)
421 425
422 426 @templatefilter('utf8')
423 427 def utf8(text):
@@ -26,6 +26,9 from . import (
26 26 templateutil,
27 27 util,
28 28 )
29 from .utils import (
30 stringutil,
31 )
29 32
30 33 _hybrid = templateutil.hybrid
31 34 _mappable = templateutil.mappable
@@ -72,7 +75,7 def getlatesttags(context, mapping, patt
72 75 cachename = 'latesttags'
73 76 if pattern is not None:
74 77 cachename += '-' + pattern
75 match = util.stringmatcher(pattern)[2]
78 match = stringutil.stringmatcher(pattern)[2]
76 79 else:
77 80 match = util.always
78 81
@@ -307,7 +310,7 def showextras(context, mapping):
307 310 c = [makemap(k) for k in extras]
308 311 f = _showcompatlist(context, mapping, 'extra', c, plural='extras')
309 312 return _hybrid(f, extras, makemap,
310 lambda k: '%s=%s' % (k, util.escapestr(extras[k])))
313 lambda k: '%s=%s' % (k, stringutil.escapestr(extras[k])))
311 314
312 315 def _showfilesbystat(context, mapping, name, index):
313 316 repo = context.resource(mapping, 'repo')
@@ -63,6 +63,9 from . import (
63 63 templateutil,
64 64 util,
65 65 )
66 from .utils import (
67 stringutil,
68 )
66 69
67 70 # template parsing
68 71
@@ -811,7 +814,8 class templater(object):
811 814 _('"%s" not in template map') % inst.args[0])
812 815 except IOError as inst:
813 816 reason = (_('template file %s: %s')
814 % (self.map[t][1], util.forcebytestr(inst.args[1])))
817 % (self.map[t][1],
818 stringutil.forcebytestr(inst.args[1])))
815 819 raise IOError(inst.args[0], encoding.strfromlocal(reason))
816 820 return self.cache[t]
817 821
@@ -15,6 +15,9 from . import (
15 15 pycompat,
16 16 util,
17 17 )
18 from .utils import (
19 stringutil,
20 )
18 21
19 22 class ResourceUnavailable(error.Abort):
20 23 pass
@@ -281,7 +284,7 def evalboolean(context, mapping, arg):
281 284 thing = func(context, mapping, data, default=None)
282 285 if thing is None:
283 286 # not a template keyword, takes as a boolean literal
284 thing = util.parsebool(data)
287 thing = stringutil.parsebool(data)
285 288 else:
286 289 thing = func(context, mapping, data)
287 290 thing = unwrapvalue(thing)
@@ -37,7 +37,10 from . import (
37 37 scmutil,
38 38 util,
39 39 )
40 from .utils import dateutil
40 from .utils import (
41 dateutil,
42 stringutil,
43 )
41 44
42 45 urlreq = util.urlreq
43 46
@@ -371,7 +374,7 class ui(object):
371 374 except error.ConfigError as inst:
372 375 if trusted:
373 376 raise
374 self.warn(_("ignored: %s\n") % util.forcebytestr(inst))
377 self.warn(_("ignored: %s\n") % stringutil.forcebytestr(inst))
375 378
376 379 if self.plain():
377 380 for k in ('debug', 'fallbackencoding', 'quiet', 'slash',
@@ -591,7 +594,7 class ui(object):
591 594 return default
592 595 if isinstance(v, bool):
593 596 return v
594 b = util.parsebool(v)
597 b = stringutil.parsebool(v)
595 598 if b is None:
596 599 raise error.ConfigError(_("%s.%s is not a boolean ('%s')")
597 600 % (section, name, v))
@@ -821,7 +824,7 class ui(object):
821 824 def shortuser(self, user):
822 825 """Return a short representation of a user name or email address."""
823 826 if not self.verbose:
824 user = util.shortuser(user)
827 user = stringutil.shortuser(user)
825 828 return user
826 829
827 830 def expandpath(self, loc, default=None):
@@ -24,6 +24,9 from . import (
24 24 urllibcompat,
25 25 util,
26 26 )
27 from .utils import (
28 stringutil,
29 )
27 30
28 31 httplib = util.httplib
29 32 stringio = util.stringio
@@ -477,7 +480,7 class cookiehandler(urlreq.basehandler):
477 480 self.cookiejar = cookiejar
478 481 except util.cookielib.LoadError as e:
479 482 ui.warn(_('(error loading cookie file %s: %s; continuing without '
480 'cookies)\n') % (cookiefile, util.forcebytestr(e)))
483 'cookies)\n') % (cookiefile, stringutil.forcebytestr(e)))
481 484
482 485 def http_request(self, request):
483 486 if self.cookiejar:
@@ -820,9 +820,10 class baseproxyobserver(object):
820 820 # Simple case writes all data on a single line.
821 821 if b'\n' not in data:
822 822 if self.logdataapis:
823 self.fh.write(': %s\n' % escapedata(data))
823 self.fh.write(': %s\n' % stringutil.escapedata(data))
824 824 else:
825 self.fh.write('%s> %s\n' % (self.name, escapedata(data)))
825 self.fh.write('%s> %s\n'
826 % (self.name, stringutil.escapedata(data)))
826 827 self.fh.flush()
827 828 return
828 829
@@ -832,7 +833,8 class baseproxyobserver(object):
832 833
833 834 lines = data.splitlines(True)
834 835 for line in lines:
835 self.fh.write('%s> %s\n' % (self.name, escapedata(line)))
836 self.fh.write('%s> %s\n'
837 % (self.name, stringutil.escapedata(line)))
836 838 self.fh.flush()
837 839
838 840 class fileobjectobserver(baseproxyobserver):
@@ -1915,7 +1917,7 def checkwinfilename(path):
1915 1917 "on Windows") % c
1916 1918 if ord(c) <= 31:
1917 1919 return _("filename contains '%s', which is invalid "
1918 "on Windows") % escapestr(c)
1920 "on Windows") % stringutil.escapestr(c)
1919 1921 base = n.split('.')[0]
1920 1922 if base and base.lower() in _winreservednames:
1921 1923 return _("filename contains '%s', which is reserved "
@@ -3679,7 +3681,7 class _zlibengine(compressionengine):
3679 3681 return zlib.decompress(data)
3680 3682 except zlib.error as e:
3681 3683 raise error.RevlogError(_('revlog decompress error: %s') %
3682 forcebytestr(e))
3684 stringutil.forcebytestr(e))
3683 3685
3684 3686 def revlogcompressor(self, opts=None):
3685 3687 return self.zlibrevlogcompressor()
@@ -3905,7 +3907,7 class _zstdengine(compressionengine):
3905 3907 return ''.join(chunks)
3906 3908 except Exception as e:
3907 3909 raise error.RevlogError(_('revlog decompress error: %s') %
3908 forcebytestr(e))
3910 stringutil.forcebytestr(e))
3909 3911
3910 3912 def revlogcompressor(self, opts=None):
3911 3913 opts = opts or {}
@@ -34,6 +34,10 from . import (
34 34 wireprototypes,
35 35 )
36 36
37 from .utils import (
38 stringutil,
39 )
40
37 41 urlerr = util.urlerr
38 42 urlreq = util.urlreq
39 43
@@ -994,7 +998,7 def lookup(repo, proto, key):
994 998 r = c.hex()
995 999 success = 1
996 1000 except Exception as inst:
997 r = util.forcebytestr(inst)
1001 r = stringutil.forcebytestr(inst)
998 1002 success = 0
999 1003 return bytesresponse('%d %s\n' % (success, r))
1000 1004
@@ -1007,7 +1011,7 def known(repo, proto, nodes, others):
1007 1011 def pushkey(repo, proto, namespace, key, old, new):
1008 1012 # compatibility with pre-1.8 clients which were accidentally
1009 1013 # sending raw binary nodes rather than utf-8-encoded hex
1010 if len(new) == 20 and util.escapestr(new) != new:
1014 if len(new) == 20 and stringutil.escapestr(new) != new:
1011 1015 # looks like it could be a binary node
1012 1016 try:
1013 1017 new.decode('utf-8')
@@ -1123,7 +1127,7 def unbundle(repo, proto, heads):
1123 1127 if exc.params:
1124 1128 errpart.addparam('params', '\0'.join(exc.params))
1125 1129 except error.Abort as exc:
1126 manargs = [('message', util.forcebytestr(exc))]
1130 manargs = [('message', stringutil.forcebytestr(exc))]
1127 1131 advargs = []
1128 1132 if exc.hint is not None:
1129 1133 advargs.append(('hint', exc.hint))
@@ -1131,5 +1135,5 def unbundle(repo, proto, heads):
1131 1135 manargs, advargs))
1132 1136 except error.PushRaced as exc:
1133 1137 bundler.newpart('error:pushraced',
1134 [('message', util.forcebytestr(exc))])
1138 [('message', stringutil.forcebytestr(exc))])
1135 1139 return streamres_legacy(gen=bundler.getchunks())
@@ -21,6 +21,9 from . import (
21 21 error,
22 22 util,
23 23 )
24 from .utils import (
25 stringutil,
26 )
24 27
25 28 FRAME_HEADER_SIZE = 6
26 29 DEFAULT_MAX_FRAME_SIZE = 32768
@@ -164,7 +167,7 def makeframefromhumanstring(s):
164 167 else:
165 168 finalflags |= int(flag)
166 169
167 payload = util.unescapestr(payload)
170 payload = stringutil.unescapestr(payload)
168 171
169 172 return makeframe(requestid=requestid, typeid=frametype,
170 173 flags=finalflags, payload=payload)
@@ -22,6 +22,10 from mercurial import (
22 22 util,
23 23 )
24 24
25 from mercurial.utils import (
26 stringutil,
27 )
28
25 29 TestCase = unittest.TestCase
26 30 # bzr compatible interface, for the tests
27 31 class Merge3(simplemerge.Merge3Text):
@@ -34,7 +38,8 class Merge3(simplemerge.Merge3Text):
34 38 basetext = '\n'.join([i.strip('\n') for i in base] + [''])
35 39 atext = '\n'.join([i.strip('\n') for i in a] + [''])
36 40 btext = '\n'.join([i.strip('\n') for i in b] + [''])
37 if util.binary(basetext) or util.binary(atext) or util.binary(btext):
41 if (stringutil.binary(basetext) or stringutil.binary(atext)
42 or stringutil.binary(btext)):
38 43 raise error.Abort("don't know how to merge binary files")
39 44 simplemerge.Merge3Text.__init__(self, basetext, atext, btext,
40 45 base, a, b)
@@ -358,4 +363,3 if __name__ == '__main__':
358 363 unittest.main()
359 364 finally:
360 365 time.time = orig
361
General Comments 0
You need to be logged in to leave comments. Login now